Skip to content

Commit

Permalink
[fix-exit-queue] fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Cast0001 committed Nov 21, 2023
1 parent 198ad0d commit 1b3066e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
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

0 comments on commit 1b3066e

Please sign in to comment.