From 0ec33a67618f9b69f03a647df53a74a79f9c45df Mon Sep 17 00:00:00 2001 From: Stas Leshchina <66851165+Sorizen@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:55:10 +0300 Subject: [PATCH] pool limits calculation fix (#104) --- src/composables/use-pool.ts | 44 +++++++++++++++++++++++++++----- src/types/erc1967-proxy.types.ts | 3 +++ src/types/mor1967-proxy.types.ts | 3 +++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/composables/use-pool.ts b/src/composables/use-pool.ts index 40aae44..eb69bbe 100644 --- a/src/composables/use-pool.ts +++ b/src/composables/use-pool.ts @@ -75,7 +75,7 @@ export const usePool = (poolId: Ref) => { return ( currentTimestamp.value <= - (userPoolData.value.lastClaim || BigNumber.from(0)) + (userPoolData.value.lastClaim || ethers.BigNumber.from(0)) .add(poolData.value.claimLockPeriodAfterClaim) .toNumber() ) @@ -146,15 +146,37 @@ export const usePool = (poolId: Ref) => { ) } + const fetchPoolLimits = async () => { + const isPoolLimitsCanBeFetched = 'poolsLimits' in erc1967ProxyContract.value + + if (isPoolLimitsCanBeFetched) { + const [claimLockPeriodAfterClaim, claimLockPeriodAfterStake] = + await erc1967ProxyContract.value.poolsLimits(poolId.value) + return { + claimLockPeriodAfterStake: claimLockPeriodAfterStake, + claimLockPeriodAfterClaim: claimLockPeriodAfterClaim, + } + } + return { + claimLockPeriodAfterStake: ethers.BigNumber.from(0), + claimLockPeriodAfterClaim: ethers.BigNumber.from(0), + } + } + const fetchPoolData = async (): Promise< Erc1967ProxyType.PoolData | Mor1967ProxyType.PoolData > => { - const [poolsDataResponse, poolsResponse, totalDepositedInPublicPools] = - await Promise.all([ - erc1967ProxyContract.value.poolsData(poolId.value), - erc1967ProxyContract.value.pools(poolId.value), - erc1967ProxyContract.value.totalDepositedInPublicPools(), - ]) + const [ + poolsDataResponse, + poolsResponse, + totalDepositedInPublicPools, + poolLimits, + ] = await Promise.all([ + erc1967ProxyContract.value.poolsData(poolId.value), + erc1967ProxyContract.value.pools(poolId.value), + erc1967ProxyContract.value.totalDepositedInPublicPools(), + fetchPoolLimits(), + ]) const isTotalVirtualDepositedDefined = 'totalVirtualDeposited' in poolsDataResponse @@ -176,6 +198,8 @@ export const usePool = (poolId: Ref) => { rate: poolsDataResponse.rate, rewardDecrease: poolsResponse.rewardDecrease, totalDeposited, + claimLockPeriodAfterStake: poolLimits.claimLockPeriodAfterStake, + claimLockPeriodAfterClaim: poolLimits.claimLockPeriodAfterClaim, withdrawLockPeriod: poolsResponse.withdrawLockPeriod, withdrawLockPeriodAfterStake: poolsResponse.withdrawLockPeriodAfterStake, } as Erc1967ProxyType.PoolData | Mor1967ProxyType.PoolData @@ -207,6 +231,11 @@ export const usePool = (poolId: Ref) => { ? response.virtualDeposited : ethers.BigNumber.from(0) + const isLastClaim = 'lastClaim' in response + const lastClaim = isLastClaim + ? response.lastClaim + : ethers.BigNumber.from(0) + return { claimLockEnd, claimLockStart, @@ -214,6 +243,7 @@ export const usePool = (poolId: Ref) => { lastStake: response.lastStake, pendingRewards: response.pendingRewards, rate: response.rate, + lastClaim, virtualDeposited, } as Erc1967ProxyType.UserData | Mor1967ProxyType.UserData } diff --git a/src/types/erc1967-proxy.types.ts b/src/types/erc1967-proxy.types.ts index 833618b..f774ed8 100644 --- a/src/types/erc1967-proxy.types.ts +++ b/src/types/erc1967-proxy.types.ts @@ -14,6 +14,8 @@ export type PoolData = { withdrawLockPeriod: BigNumber withdrawLockPeriodAfterStake: BigNumber totalVirtualDeposited: BigNumber + claimLockPeriodAfterStake: BigNumber + claimLockPeriodAfterClaim: BigNumber } export type UserData = { @@ -24,4 +26,5 @@ export type UserData = { pendingRewards: BigNumber rate: BigNumber virtualDeposited: BigNumber + lastClaim: BigNumber } diff --git a/src/types/mor1967-proxy.types.ts b/src/types/mor1967-proxy.types.ts index 45458e0..cf7f4f6 100644 --- a/src/types/mor1967-proxy.types.ts +++ b/src/types/mor1967-proxy.types.ts @@ -13,11 +13,14 @@ export type PoolData = { totalDeposited: BigNumber withdrawLockPeriod: BigNumber withdrawLockPeriodAfterStake: BigNumber + claimLockPeriodAfterStake: BigNumber + claimLockPeriodAfterClaim: BigNumber } export type UserData = { deposited: BigNumber lastStake: BigNumber + lastClaim: BigNumber pendingRewards: BigNumber rate: BigNumber