Skip to content

Commit

Permalink
[duration]: add ExitRequests, finalized logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dfkadyr committed Apr 4, 2024
1 parent d540f3f commit 4973136
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 5 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,17 @@ type Position = {

type Output = {
total: bigint
duration: number
withdrawable: bigint
positions: Position[]
}
```
| Name | Description |
|------|-------------|
| `positions` | Queue positions |
| `total` | Total withdrawal amount (in ETH) |
| Name | Description |
|------|------------------------------------------|
| `positions` | Queue positions |
| `total` | Total withdrawal amount (in ETH) |
| `duration` | Queue duration time (in minutes) |
| `withdrawable` | Amount available for withdrawal (in ETH) |
#### Example:
Expand Down
5 changes: 5 additions & 0 deletions src/graphql/backend/vault/exitRequestsQuery.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query ExitRequests($user: String!, $vault: String!) {
exitRequests(user: $user, vault: $vault) {
duration
}
}
3 changes: 3 additions & 0 deletions src/graphql/backend/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ export type { ValidatorsQueryPayload, ValidatorsQueryVariables } from './validat
export { fetchUserRewardsQuery } from './userRewardsQuery.graphql'
export type { UserRewardsQueryPayload, UserRewardsQueryVariables } from './userRewardsQuery.graphql'

export { fetchExitRequestsQuery } from './exitRequestsQuery.graphql'
export type { ExitRequestsQueryPayload, ExitRequestsQueryVariables } from './exitRequestsQuery.graphql'

export { fetchScorePercentilesQuery } from './scorePercentilesQuery.graphql'
export type { ScorePercentilesQueryPayload, ScorePercentilesQueryVariables } from './scorePercentilesQuery.graphql'
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import graphql from '../../../../graphql'
import { apiUrls } from '../../../../utils'


export type FetchExitQueuePositionsInput = {
options: StakeWise.Options
vaultAddress: string
userAddress: string
}

const fetchExitRequestDuration = (values: FetchExitQueuePositionsInput) => {
const { options, vaultAddress, userAddress } = values

return graphql.backend.vault.fetchExitRequestsQuery({
url: apiUrls.getSubgraphqlUrl(options),
variables: {
vault: vaultAddress.toLowerCase(),
user: userAddress.toLowerCase(),
},
modifyResult: (data) => {
if (!data || !data.exitRequests || !data.exitRequests.length) {
return 0
}

const durations = data.exitRequests.map(request => request.duration)

return Math.max(...durations)
},
})
}


export default fetchExitRequestDuration
4 changes: 4 additions & 0 deletions src/methods/vault/requests/getExitQueuePositions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { validateArgs } from '../../../../utils'
import parseExitRequests from './parseExitRequests'
import fetchExitQueuePositions from './fetchExitQueuePositions'
import fetchExitRequestDuration from './fetchExitRequestDuration'
import type { FetchExitQueuePositionsInput } from './fetchExitQueuePositions'


Expand All @@ -21,6 +22,8 @@ const getExitQueuePositions = async (input: GetExitQueuePositionsInput) => {

validateArgs.address({ vaultAddress, userAddress })

const duration = await fetchExitRequestDuration({ options, vaultAddress, userAddress })

return fetchExitQueuePositions({ options, vaultAddress, userAddress })
.then((data) => {
if (!data) {
Expand All @@ -29,6 +32,7 @@ const getExitQueuePositions = async (input: GetExitQueuePositionsInput) => {

return parseExitRequests({
options,
duration,
provider,
contracts,
userAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('parseExitRequests function', () => {

const input: ParseExitRequestsInput = {
contracts,
duration: 1440,
options: { network },
userAddress: ZeroAddress,
vaultAddress: ZeroAddress,
Expand Down Expand Up @@ -109,6 +110,7 @@ describe('parseExitRequests function', () => {
},
],
total: 431n,
duration: 1440,
withdrawable: 281n,
})
})
Expand All @@ -132,6 +134,7 @@ describe('parseExitRequests function', () => {

expect(result).toEqual({
total: 100n,
duration: 1440,
positions: [],
withdrawable: 0n,
})
Expand All @@ -150,6 +153,7 @@ describe('parseExitRequests function', () => {
expect(result).toEqual({
positions: [],
total: 50n,
duration: 1440,
withdrawable: 0n,
})
})
Expand Down Expand Up @@ -180,6 +184,7 @@ describe('parseExitRequests function', () => {
positionTicket: 'positionTicket-2',
} ],
total: 380n,
duration: 1440,
withdrawable: 30n,
})
})
Expand Down Expand Up @@ -222,6 +227,7 @@ describe('parseExitRequests function', () => {
},
],
total: 603n,
duration: 1440,
withdrawable: 603n,
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type ParseExitRequestsInput = {
contracts: StakeWise.Contracts
provider: StakeWise.Provider
options: StakeWise.Options
duration: number
userAddress: string
vaultAddress: string
exitRequests: Array<{
Expand All @@ -24,6 +25,7 @@ type Position = {

export type ParseExitRequestsOutput = {
total: bigint
duration: number
withdrawable: bigint
positions: Position[]
}
Expand All @@ -47,7 +49,7 @@ const _checkTimestamp = async (timestamp: string, provider: StakeWise.Provider)
}

const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseExitRequestsOutput> => {
const { options, contracts, provider, userAddress, vaultAddress, exitRequests } = values
const { options, contracts, provider, userAddress, vaultAddress, duration, exitRequests } = values

const keeperContract = contracts.base.keeper
const vaultContract = contracts.helpers.createVault(vaultAddress)
Expand Down Expand Up @@ -116,6 +118,7 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseE
// If there are no positions with an index greater than 0 or their timestamp has failed the 24-hour check.
// Then we can use totalShares from the subgraph to show total
return {
duration,
positions: [],
withdrawable: 0n,
total: totalV1QueuedAssets + queuedAssets,
Expand Down Expand Up @@ -167,6 +170,7 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseE

return {
total,
duration,
positions: claims,
withdrawable: withdrawableAssets,
}
Expand Down

0 comments on commit 4973136

Please sign in to comment.