From 4165ed40f65f31c0b9c5cb2d3c7bf2e57f022200 Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 16:21:18 +0500 Subject: [PATCH 1/8] [improves] check claimExitedAssets with from --- src/contracts/vaultMulticall.ts | 6 ++---- .../parseExitRequests.spec.ts | 7 ------- .../getExitQueuePositions/parseExitRequests.ts | 14 ++++++++------ src/methods/vault/requests/getMaxWithdraw.ts | 4 +++- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/contracts/vaultMulticall.ts b/src/contracts/vaultMulticall.ts index 95bed8a9..115604e5 100644 --- a/src/contracts/vaultMulticall.ts +++ b/src/contracts/vaultMulticall.ts @@ -32,9 +32,7 @@ const vaultMulticall = async (values: VaultMulticallInput): P let contract = vaultContract - const withSigner = !callStatic && !transactionData - - if (withSigner) { + if (!transactionData) { const config = configs[options.network] const library = options.provider || new JsonRpcProvider(config.network.url) @@ -64,7 +62,7 @@ const vaultMulticall = async (values: VaultMulticallInput): P }) if (callStatic) { - let result = await contract.multicall.staticCall(calls) + let result = await contract.multicall.staticCall(calls, { from: userAddress }) if (canHarvest) { // Data from updateState not needed diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts index 50e75988..ed218ae8 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts @@ -69,12 +69,10 @@ describe('parseExitRequests function', () => { positions: [ { exitQueueIndex: 1n, - timestamp: '123456', positionTicket: 'positionTicket-1', }, { exitQueueIndex: 2n, - timestamp: '123456', positionTicket: 'positionTicket-2', }, ], @@ -120,7 +118,6 @@ describe('parseExitRequests function', () => { expect(result).toEqual({ positions: [ { exitQueueIndex: 1n, - timestamp: '123456', positionTicket: 'positionTicket-2', } ], total: 50n, @@ -146,12 +143,10 @@ describe('parseExitRequests function', () => { positions: [ { exitQueueIndex: 0n, - timestamp: '123456', positionTicket: 'positionTicket-1', }, { exitQueueIndex: 1n, - timestamp: '123456', positionTicket: 'positionTicket-2', }, ], @@ -177,12 +172,10 @@ describe('parseExitRequests function', () => { positions: [ { exitQueueIndex: 0n, - timestamp: '123456', positionTicket: 'positionTicket-1', }, { exitQueueIndex: 1n, - timestamp: '123456', positionTicket: 'positionTicket-2', }, ], diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts index 4c65a1bc..7ad871d2 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts @@ -23,7 +23,7 @@ type Position = { type ParseExitRequestsOutput = { total: bigint withdrawable: bigint - positions: Position[] + positions: Array> } type ExitedAssetsResponse = Array<{ @@ -63,12 +63,9 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise { 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, timestamp } + const item = { exitQueueIndex, ...exitRequests[index] } return [ ...acc, item ] } @@ -130,8 +127,13 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise ({ + exitQueueIndex, + positionTicket, + })) + return { - positions: claims, + positions, total: totalExitingAssets, withdrawable: withdrawableAssets, } diff --git a/src/methods/vault/requests/getMaxWithdraw.ts b/src/methods/vault/requests/getMaxWithdraw.ts index 13b3f9d6..161832ea 100644 --- a/src/methods/vault/requests/getMaxWithdraw.ts +++ b/src/methods/vault/requests/getMaxWithdraw.ts @@ -10,10 +10,12 @@ type GetMaxWithdrawInput = { contracts: StakeWise.Contracts } +const min = parseEther('0.00001') + const getMaxWithdraw = async (values: GetMaxWithdrawInput) => { const { contracts, mintedAssets, stakedAssets, ltvPercent } = values - if (ltvPercent <= 0) { + if (ltvPercent <= 0 || stakedAssets < min) { return 0n } From 1c7b472a0679e9221efadc9cf84d067450be59b4 Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 16:55:12 +0500 Subject: [PATCH 2/8] [improves] remove exitQueue positions filter --- src/contracts/vaultMulticall.ts | 4 +++- .../parseExitRequests.spec.ts | 14 ++++++++++++++ .../getExitQueuePositions/parseExitRequests.ts | 7 +------ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/contracts/vaultMulticall.ts b/src/contracts/vaultMulticall.ts index 115604e5..94100c51 100644 --- a/src/contracts/vaultMulticall.ts +++ b/src/contracts/vaultMulticall.ts @@ -32,7 +32,9 @@ const vaultMulticall = async (values: VaultMulticallInput): P let contract = vaultContract - if (!transactionData) { + const withSigner = !callStatic && !transactionData + + if (withSigner) { const config = configs[options.network] const library = options.provider || new JsonRpcProvider(config.network.url) diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts index ed218ae8..e4837e81 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.spec.ts @@ -69,10 +69,14 @@ describe('parseExitRequests function', () => { positions: [ { exitQueueIndex: 1n, + totalShares: '100', + timestamp: '123456', positionTicket: 'positionTicket-1', }, { exitQueueIndex: 2n, + totalShares: '200', + timestamp: '123456', positionTicket: 'positionTicket-2', }, ], @@ -118,6 +122,8 @@ describe('parseExitRequests function', () => { expect(result).toEqual({ positions: [ { exitQueueIndex: 1n, + totalShares: '200', + timestamp: '123456', positionTicket: 'positionTicket-2', } ], total: 50n, @@ -143,10 +149,14 @@ describe('parseExitRequests function', () => { positions: [ { exitQueueIndex: 0n, + totalShares: '100', + timestamp: '123456', positionTicket: 'positionTicket-1', }, { exitQueueIndex: 1n, + totalShares: '200', + timestamp: '123456', positionTicket: 'positionTicket-2', }, ], @@ -172,10 +182,14 @@ describe('parseExitRequests function', () => { positions: [ { exitQueueIndex: 0n, + totalShares: '100', + timestamp: '123456', positionTicket: 'positionTicket-1', }, { exitQueueIndex: 1n, + totalShares: '200', + timestamp: '123456', positionTicket: 'positionTicket-2', }, ], diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts index 7ad871d2..c402e27e 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts @@ -127,13 +127,8 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise ({ - exitQueueIndex, - positionTicket, - })) - return { - positions, + positions: claims, total: totalExitingAssets, withdrawable: withdrawableAssets, } From 5c65c194be4b438dea024fc6daafd285907b715c Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 17:15:32 +0500 Subject: [PATCH 3/8] [improves] fix exitQueue positions type --- .../vault/requests/getExitQueuePositions/parseExitRequests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts index c402e27e..7ac323a6 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts @@ -23,7 +23,7 @@ type Position = { type ParseExitRequestsOutput = { total: bigint withdrawable: bigint - positions: Array> + positions: Position[] } type ExitedAssetsResponse = Array<{ From 8a98b10998afd5ef4bf950a20bfe4fc0028f6238 Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 17:19:43 +0500 Subject: [PATCH 4/8] [improves] fix claim exitQueue --- src/methods/vault/transactions/claimExitQueue/common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/methods/vault/transactions/claimExitQueue/common.ts b/src/methods/vault/transactions/claimExitQueue/common.ts index 6bc9d5f3..e026c7cc 100644 --- a/src/methods/vault/transactions/claimExitQueue/common.ts +++ b/src/methods/vault/transactions/claimExitQueue/common.ts @@ -24,11 +24,11 @@ export const commonLogic = async (values: ClaimExitQueueInput) => { } const params: Parameters[0]['request']['params'] = positions.map((position) => { - const { positionTicket, exitQueueIndex } = position + const { positionTicket, exitQueueIndex, timestamp } = position return { method: 'claimExitedAssets', - args: [ positionTicket, exitQueueIndex ], + args: [ positionTicket, exitQueueIndex, timestamp ], } }) From 0dd7d738e2ae29a1dcee793ebbbb2d7b2df00e27 Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 17:47:51 +0500 Subject: [PATCH 5/8] [improves] fix claim args --- .../vault/requests/getExitQueuePositions/parseExitRequests.ts | 2 +- src/methods/vault/transactions/claimExitQueue/common.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts index 7ac323a6..30da11f0 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts @@ -82,7 +82,7 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise ({ method: 'claimExitedAssets', - args: [ positionTicket, exitQueueIndex, timestamp ], + args: [ exitQueueIndex, timestamp, positionTicket ], })), callStatic: true, }, diff --git a/src/methods/vault/transactions/claimExitQueue/common.ts b/src/methods/vault/transactions/claimExitQueue/common.ts index e026c7cc..8a1c7397 100644 --- a/src/methods/vault/transactions/claimExitQueue/common.ts +++ b/src/methods/vault/transactions/claimExitQueue/common.ts @@ -28,7 +28,7 @@ export const commonLogic = async (values: ClaimExitQueueInput) => { return { method: 'claimExitedAssets', - args: [ positionTicket, exitQueueIndex, timestamp ], + args: [ exitQueueIndex, timestamp, positionTicket ], } }) From d8c4696d009754aa8f6d8752e315f4634abbbfab Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 17:58:45 +0500 Subject: [PATCH 6/8] [improves] fix claim args 2 --- .../vault/requests/getExitQueuePositions/parseExitRequests.ts | 2 +- src/methods/vault/transactions/claimExitQueue/common.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts index 30da11f0..7ac323a6 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts @@ -82,7 +82,7 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise ({ method: 'claimExitedAssets', - args: [ exitQueueIndex, timestamp, positionTicket ], + args: [ positionTicket, exitQueueIndex, timestamp ], })), callStatic: true, }, diff --git a/src/methods/vault/transactions/claimExitQueue/common.ts b/src/methods/vault/transactions/claimExitQueue/common.ts index 8a1c7397..e026c7cc 100644 --- a/src/methods/vault/transactions/claimExitQueue/common.ts +++ b/src/methods/vault/transactions/claimExitQueue/common.ts @@ -28,7 +28,7 @@ export const commonLogic = async (values: ClaimExitQueueInput) => { return { method: 'claimExitedAssets', - args: [ exitQueueIndex, timestamp, positionTicket ], + args: [ positionTicket, exitQueueIndex, timestamp ], } }) From 787a9b9cf21968dd4619f44e5955a707b0f8174e Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Thu, 23 Nov 2023 18:03:25 +0500 Subject: [PATCH 7/8] [improves] fix claim args 3 --- .../vault/requests/getExitQueuePositions/parseExitRequests.ts | 2 +- src/methods/vault/transactions/claimExitQueue/common.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts index 7ac323a6..0e5efd23 100644 --- a/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts +++ b/src/methods/vault/requests/getExitQueuePositions/parseExitRequests.ts @@ -82,7 +82,7 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise ({ method: 'claimExitedAssets', - args: [ positionTicket, exitQueueIndex, timestamp ], + args: [ positionTicket, timestamp, exitQueueIndex ], })), callStatic: true, }, diff --git a/src/methods/vault/transactions/claimExitQueue/common.ts b/src/methods/vault/transactions/claimExitQueue/common.ts index e026c7cc..a1f69a5a 100644 --- a/src/methods/vault/transactions/claimExitQueue/common.ts +++ b/src/methods/vault/transactions/claimExitQueue/common.ts @@ -28,7 +28,7 @@ export const commonLogic = async (values: ClaimExitQueueInput) => { return { method: 'claimExitedAssets', - args: [ positionTicket, exitQueueIndex, timestamp ], + args: [ positionTicket, timestamp, exitQueueIndex ], } }) From 00d0ad4940010d61bccc5b58eb21c649103915f3 Mon Sep 17 00:00:00 2001 From: Andrey Kopylov Date: Fri, 24 Nov 2023 14:09:12 +0500 Subject: [PATCH 8/8] [improves] change docs --- README.md | 9 +++++---- src/methods/vault/transactions/claimExitQueue/types.d.ts | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 90d41c80..ce2e5c97 100644 --- a/README.md +++ b/README.md @@ -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.9-blue) +![Version](https://img.shields.io/badge/version-1.3.0-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) @@ -245,18 +245,19 @@ Returns the withdrawal queue for a specific user. type Position = { exitQueueIndex: bigint positionTicket: string + timestamp: string } type Output = { total: bigint - data: Position[] withdrawable: bigint + positions: Position[] } ``` | Name | Description | |------|-------------| -| `data` | Queue positions | +| `positions` | Queue positions | | `total` | Total withdrawal amount (in ETH) | | `withdrawable` | Amount available for withdrawal (in ETH) | @@ -902,7 +903,7 @@ Take the freed tokens from the queue | Name | Type | Type | Description | |------|------|-------------|---------| -| positions | `string` | **Require** | `data` from [sdk.vault.getExitQueuePositions](#sdkvaultgetexitqueuepositions) | +| positions | `string` | **Require** | `postions` from [sdk.vault.getExitQueuePositions](#sdkvaultgetexitqueuepositions) | | userAddress | `string` | **Require** | - | | vaultAddress | `string` | **Require** | - | diff --git a/src/methods/vault/transactions/claimExitQueue/types.d.ts b/src/methods/vault/transactions/claimExitQueue/types.d.ts index 2143a8a8..f58c8959 100644 --- a/src/methods/vault/transactions/claimExitQueue/types.d.ts +++ b/src/methods/vault/transactions/claimExitQueue/types.d.ts @@ -8,7 +8,7 @@ export type ClaimExitQueueInput = { options: StakeWise.Options provider: StakeWise.Provider contracts: StakeWise.Contracts - positions: Awaited>['data'] + positions: Awaited>['positions'] } export interface ClaimExitQueue {