Skip to content

Commit

Permalink
pool limits calculation fix (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sorizen authored Oct 16, 2024
1 parent ae105a2 commit 0ec33a6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
44 changes: 37 additions & 7 deletions src/composables/use-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const usePool = (poolId: Ref<number>) => {

return (
currentTimestamp.value <=
(userPoolData.value.lastClaim || BigNumber.from(0))
(userPoolData.value.lastClaim || ethers.BigNumber.from(0))
.add(poolData.value.claimLockPeriodAfterClaim)
.toNumber()
)
Expand Down Expand Up @@ -146,15 +146,37 @@ export const usePool = (poolId: Ref<number>) => {
)
}

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
Expand All @@ -176,6 +198,8 @@ export const usePool = (poolId: Ref<number>) => {
rate: poolsDataResponse.rate,
rewardDecrease: poolsResponse.rewardDecrease,
totalDeposited,
claimLockPeriodAfterStake: poolLimits.claimLockPeriodAfterStake,
claimLockPeriodAfterClaim: poolLimits.claimLockPeriodAfterClaim,
withdrawLockPeriod: poolsResponse.withdrawLockPeriod,
withdrawLockPeriodAfterStake: poolsResponse.withdrawLockPeriodAfterStake,
} as Erc1967ProxyType.PoolData | Mor1967ProxyType.PoolData
Expand Down Expand Up @@ -207,13 +231,19 @@ export const usePool = (poolId: Ref<number>) => {
? response.virtualDeposited
: ethers.BigNumber.from(0)

const isLastClaim = 'lastClaim' in response
const lastClaim = isLastClaim
? response.lastClaim
: ethers.BigNumber.from(0)

return {
claimLockEnd,
claimLockStart,
deposited: response.deposited,
lastStake: response.lastStake,
pendingRewards: response.pendingRewards,
rate: response.rate,
lastClaim,
virtualDeposited,
} as Erc1967ProxyType.UserData | Mor1967ProxyType.UserData
}
Expand Down
3 changes: 3 additions & 0 deletions src/types/erc1967-proxy.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type PoolData = {
withdrawLockPeriod: BigNumber
withdrawLockPeriodAfterStake: BigNumber
totalVirtualDeposited: BigNumber
claimLockPeriodAfterStake: BigNumber
claimLockPeriodAfterClaim: BigNumber
}

export type UserData = {
Expand All @@ -24,4 +26,5 @@ export type UserData = {
pendingRewards: BigNumber
rate: BigNumber
virtualDeposited: BigNumber
lastClaim: BigNumber
}
3 changes: 3 additions & 0 deletions src/types/mor1967-proxy.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0ec33a6

Please sign in to comment.