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

Improves #38

Merged
merged 8 commits into from
Nov 24, 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
9 changes: 5 additions & 4 deletions 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.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)
Expand Down Expand Up @@ -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) |

Expand Down Expand Up @@ -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** | - |

Expand Down
2 changes: 1 addition & 1 deletion src/contracts/vaultMulticall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const vaultMulticall = async <T extends unknown>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ describe('parseExitRequests function', () => {
positions: [
{
exitQueueIndex: 1n,
totalShares: '100',
timestamp: '123456',
positionTicket: 'positionTicket-1',
},
{
exitQueueIndex: 2n,
totalShares: '200',
timestamp: '123456',
positionTicket: 'positionTicket-2',
},
Expand Down Expand Up @@ -120,6 +122,7 @@ describe('parseExitRequests function', () => {
expect(result).toEqual({
positions: [ {
exitQueueIndex: 1n,
totalShares: '200',
timestamp: '123456',
positionTicket: 'positionTicket-2',
} ],
Expand All @@ -146,11 +149,13 @@ describe('parseExitRequests function', () => {
positions: [
{
exitQueueIndex: 0n,
totalShares: '100',
timestamp: '123456',
positionTicket: 'positionTicket-1',
},
{
exitQueueIndex: 1n,
totalShares: '200',
timestamp: '123456',
positionTicket: 'positionTicket-2',
},
Expand All @@ -177,11 +182,13 @@ describe('parseExitRequests function', () => {
positions: [
{
exitQueueIndex: 0n,
totalShares: '100',
timestamp: '123456',
positionTicket: 'positionTicket-1',
},
{
exitQueueIndex: 1n,
totalShares: '200',
timestamp: '123456',
positionTicket: 'positionTicket-2',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseE
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, timestamp }
const item = { exitQueueIndex, ...exitRequests[index] }

return [ ...acc, item ]
}
Expand All @@ -85,7 +82,7 @@ const parseExitRequests = async (values: ParseExitRequestsInput): Promise<ParseE
request: {
params: claims.map(({ positionTicket, exitQueueIndex, timestamp }) => ({
method: 'claimExitedAssets',
args: [ positionTicket, exitQueueIndex, timestamp ],
args: [ positionTicket, timestamp, exitQueueIndex ],
})),
callStatic: true,
},
Expand Down
4 changes: 3 additions & 1 deletion src/methods/vault/requests/getMaxWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/methods/vault/transactions/claimExitQueue/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export const commonLogic = async (values: ClaimExitQueueInput) => {
}

const params: Parameters<typeof vaultMulticall>[0]['request']['params'] = positions.map((position) => {
const { positionTicket, exitQueueIndex } = position
const { positionTicket, exitQueueIndex, timestamp } = position

return {
method: 'claimExitedAssets',
args: [ positionTicket, exitQueueIndex ],
args: [ positionTicket, timestamp, exitQueueIndex ],
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/methods/vault/transactions/claimExitQueue/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type ClaimExitQueueInput = {
options: StakeWise.Options
provider: StakeWise.Provider
contracts: StakeWise.Contracts
positions: Awaited<ReturnType<StakeWise.VaultMethods['getExitQueuePositions']>>['data']
positions: Awaited<ReturnType<StakeWise.VaultMethods['getExitQueuePositions']>>['positions']
}

export interface ClaimExitQueue {
Expand Down
Loading