Delayed Withdraws
Legacy. Replaced with BoringQueue.
Introduction
Delayed withdraws are withdraws where a user must wait a certain amount of time before being able to return and claim their tokens.
delayWithdraw
This function checks if a user has approved the withdraw contract a sufficient amount to transfer vault tokens, if not prompts the user to do so, and finally submits a withdraw intent.
IMPORTANT NOTE: If this function is called multiple times for a specific token, the amounts will stack/be summed (as opposed to being replaced). It is recommended to disable additional withdraw intents if one is already ongoing.
Inputs
- signer: an ethers
JsonRPCSigner
. If you are using viem, you may use this example to create an ethers signer out of a viem wallet client: ethers.tsx - shareAmount: a decimal adjusted (human readable) string that represents the amount of vault shares a user wants to withdraw
- tokenOut: the token the user wants to receive
- address: token contract address
- decimals: decimal precision of the token
- maxLoss: a human readable percent (e.g. 1 = 1%) as a string that represents the max deviation from the share price the user is willing to accept. If the share price deviates by more than this percent in either direction (up/down) the withdraw becomes invalid.
- IMPORTANT NOTE: If this is set to 0, the default value for the contract will be used
- thirdPartyClaimer: a boolean representing if the user wants to allow anyone to finish their withdraw for them. A user will still receive their tokens, it simply indicates that someone else can initiate the claim intent on their behalf.
Outputs
- A promise that returns a
WithdrawStatus
- initiated: boolean representing if the withdraw function has been called and is in progress of being executed
- loading: boolean representing if there is a relevant withdraw transaction ongoing (e.g. approval and/or withdraw)
- success (optional): boolean representing if the withdraw intent action succeeded
- error (optional): string representing why a withdraw failed (e.g. insufficient balance, approval rejected, etc.)
- tx_hash (optional): the string of a successful withdraw transaction hash
Example
delayWithdrawStatuses
This function retrieves a list of all non zero withdraw intents.
Inputs
- signer: an ethers
JsonRPCSigner
. If you are using viem, you may use this example to create an ethers signer out of a viem wallet client: ethers.tsx
Outputs
- A promise that returns a list of
DelayWithdrawStatus
\es- allowThirdPartyToComplete: boolean if another account may complete the withdraw intent on behalf of the user
- maxLoss: number representing the max share value deviation the request is willing to accept (e.g. 1 = 1%)
- maturity: a unix timestamp (number) that indicates when the request may be completed/output tokens claimed
- shares: human readable number of how many shares the user indicated they wanted to withdraw
- exchangeRateAtTimeOfRequest: the human readable exchange rate that 1 share may have been redeemed for at the time of the request (this is mostly informational and does not need to be considered in the user render/ux flow)
- token: the output token of the request
- address: token contract address
- decimals: decimal precision of the token
Example
delayWithdrawCancel
This function cancels a users withdraw request for a given output asset.
Inputs
- signer: an ethers
JsonRPCSigner
. If you are using viem, you may use this example to create an ethers signer out of a viem wallet client: ethers.tsx - tokenOut: the output token to cancel the request for
- address: token contract address
- decimals: decimal precision of the token
Outputs
- A promise that returns a
WithdrawStatus
- initiated: boolean representing if the withdraw function has been called and is in progress of being executed
- loading: boolean representing if there is a relevant withdraw transaction ongoing
- success (optional): boolean representing if the withdraw intent action succeeded
- error (optional): string representing why a withdraw failed
- tx_hash (optional): the string of a successful withdraw transaction hash
Example
delayWithdrawComplete
This function completes a withdraw for a given asset and transfer the output tokens to the user that created the original withdraw intent.
Important Note: Your UX should validate that the requests maturity is greater than or equal to the current time. If this is not the case at the time of calling this function, the execution will revert.
Inputs
- signer: an ethers
JsonRPCSigner
. If you are using viem, you may use this example to create an ethers signer out of a viem wallet client: ethers.tsx - tokenOut: the output token to cancel the request for
- address: token contract address
- decimals: decimal precision of the token
Outputs
- A promise that returns a
WithdrawStatus
- initiated: boolean representing if the withdraw function has been called and is in progress of being executed
- loading: boolean representing if there is a relevant withdraw transaction ongoing
- success (optional): boolean representing if the withdraw intent action succeeded
- error (optional): string representing why a withdraw failed
- tx_hash (optional): the string of a successful withdraw transaction hash