Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exit queue #37

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

The official SDK designed for effortless data retrieval from the StakeWise platform. This SDK provides a streamlined interface over GraphQL requests and contract interactions.

![Version](https://img.shields.io/badge/version-1.2.8-blue)
![Version](https://img.shields.io/badge/version-1.2.9-blue)
![Unit Tests](https://github.com/stakewise/v3-sdk/actions/workflows/unit-tests.yml/badge.svg)
![GitHub issues](https://img.shields.io/github/issues-raw/stakewise/v3-sdk)
![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/stakewise/v3-sdk)
Expand Down
1 change: 1 addition & 0 deletions src/graphql/subgraph/exitQueue/exitQueueQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ query exitQueue($receiver: Bytes, $vault: String!) {
}) {
positionTicket
totalShares
timestamp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ describe('parseExitRequests function', () => {
exitRequests: [
{
positionTicket: 'positionTicket-1',
timestamp: '123456',
totalShares: '100',
},
{
positionTicket: 'positionTicket-2',
timestamp: '123456',
totalShares: '200',
},
],
Expand Down Expand Up @@ -65,8 +67,16 @@ describe('parseExitRequests function', () => {

expect(result).toEqual({
positions: [
{ exitQueueIndex: 1n, positionTicket: 'positionTicket-1' },
{ exitQueueIndex: 2n, positionTicket: 'positionTicket-2' },
{
exitQueueIndex: 1n,
timestamp: '123456',
positionTicket: 'positionTicket-1',
},
{
exitQueueIndex: 2n,
timestamp: '123456',
positionTicket: 'positionTicket-2',
},
],
total: 100n,
withdrawable: 31n,
Expand Down Expand Up @@ -108,7 +118,11 @@ describe('parseExitRequests function', () => {
const result = await parseExitRequests(input)

expect(result).toEqual({
positions: [ { exitQueueIndex: 1n, positionTicket: 'positionTicket-2' } ],
positions: [ {
exitQueueIndex: 1n,
timestamp: '123456',
positionTicket: 'positionTicket-2',
} ],
total: 50n,
withdrawable: 30n,
})
Expand All @@ -130,8 +144,16 @@ describe('parseExitRequests function', () => {

expect(result).toEqual({
positions: [
{ exitQueueIndex: 0n, positionTicket: 'positionTicket-1' },
{ exitQueueIndex: 1n, positionTicket: 'positionTicket-2' },
{
exitQueueIndex: 0n,
timestamp: '123456',
positionTicket: 'positionTicket-1',
},
{
exitQueueIndex: 1n,
timestamp: '123456',
positionTicket: 'positionTicket-2',
},
],
total: 0n,
withdrawable: 0n,
Expand All @@ -153,8 +175,16 @@ describe('parseExitRequests function', () => {

expect(result).toEqual({
positions: [
{ exitQueueIndex: 0n, positionTicket: 'positionTicket-1' },
{ exitQueueIndex: 1n, positionTicket: 'positionTicket-2' },
{
exitQueueIndex: 0n,
timestamp: '123456',
positionTicket: 'positionTicket-1',
},
{
exitQueueIndex: 1n,
timestamp: '123456',
positionTicket: 'positionTicket-2',
},
],
total: 0n,
withdrawable: 30n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export type ParseExitRequestsInput = {
exitRequests: Array<{
positionTicket: string
totalShares: string
timestamp: string
}>
}

type Position = {
exitQueueIndex: bigint
positionTicket: string
timestamp: string
}

type ParseExitRequestsOutput = {
Expand Down Expand Up @@ -58,13 +60,15 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseE
})

// We need to make a list with ID and Index for those items from which you can get VLT tokens
const claims = (indexesResponse || []).reduce((acc, result, index) => {
const exitQueueIndex = result[0]
const claims = (indexesResponse || []).reduce((acc, item, index) => {
const exitQueueIndex = item[0]

const timestamp = exitRequests[index].timestamp
const positionTicket = exitRequests[index].positionTicket

// If the index is -1 then we cannot claim anything. Otherwise, the value is >= 0.
if (exitQueueIndex > -1n) {
const item = { exitQueueIndex, positionTicket }
const item = { exitQueueIndex, positionTicket, timestamp }

return [ ...acc, item ]
}
Expand All @@ -79,9 +83,9 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseE
exitedAssetsResponse = await vaultMulticall<ExitedAssetsResponse>({
...commonMulticallParams,
request: {
params: claims.map(({ positionTicket, exitQueueIndex }) => ({
params: claims.map(({ positionTicket, exitQueueIndex, timestamp }) => ({
method: 'claimExitedAssets',
args: [ positionTicket, exitQueueIndex ],
args: [ positionTicket, exitQueueIndex, timestamp ],
})),
callStatic: true,
},
Expand Down
Loading