Withdraw Loans
Querying Redeem Amounts
If you would like your platform to display the amount of underlying tokens the user would receive for redeeming eTokens, you may use the convertToAsset()
function present in all eToken contracts using the following arguments:
uint256
tokens
The number of eToken shares to theoretically convert to underlying assets
Conversely, if you want to let the user choose how much underlying assets to withdraw, you may use the convertToShares()
function:
uint256
amount
The number of underlying tokens to theoretically convert to eTokens
Withdraw USDC from Lending (eUSDC)
To withdraw USDC from eUSDC directly, you may use the redeem()
function present in all eToken contracts using the following arguments:
uint256
tokens
The number of eTokens to redeem for underlying tokens
address
recipient
The account who will receive the underlying assets
Below is a full implementation, letting the user choose how much underlying to redeem:
// Get the eUSDC contract with signer
const eUSDC = new ethers.Contract(ADDRESSES.EUSDC, ETOKEN_ABI, signer);
// Get the amount of shares to redeem from the user's input amount
// userInputAmount being equal to "1000", representing 1000 USDC
// which should be formatted to 1000 * 10^6
const USDCWithdrawAmountFormatted = ethers.utils.parseUnits(userInputAmount, 6);
// Convert the underlying amount to shares
const eUSDCSharesToRedeem = await eUSDC.convertToShares(USDCWithdrawAmountFormatted);
// Redeem eUSDC for USDC
const underlyingRedeemed = await eUSDC.redeem(depositAmount);
Using redeemFor
If your app requires users to withdraw underlying assets to another address, you can use the redeemFor()
function in the eToken contract using the following function arguments:
Calling redeemFor():
uint256
amount
The amount of the eToken shares to redeem.
address
recipient
The account that should receive the underlying assets.
The Universal Balance System: A Simplified Interface
Curvance offers a Universal Balance system that provides a simplified way to manage withdrawals by calling withdraw()
in the UniversalBalance contract using the following function arguments:
uint256
amount
The amount of underlying token to be withdrawn.
bool
forceLentRedemption
Whether the withdrawn underlying tokens should be pulled only from owner's lent position or the full account.
address
recipient
The account who will receive the underlying assets.
Implementation snippet:
const universalBalance = new ethers.Contract(
UNIVERSAL_BALANCE_ADDRESS,
UNIVERSAL_BALANCE_ABI,
signer
);
// Withdraw from Universal Balance.
// withdrawAmount = unit formatted amount of lent asset (eg. BigInt(1000000000)).
// using true, to withdraw from the lent balance only, instead of the sitting balance.
// using recipient as the recipient address, can be the user's address or any address.
await universalBalance.withdraw(withdrawAmount, true, recipient);
For native gas tokens, Curvance provides a specialized Universal Balance Native contract:
const universalBalanceNative = new ethers.Contract(
UNIVERSAL_BALANCE_NATIVE_ADDRESS,
UNIVERSAL_BALANCE_NATIVE_ABI,
signer
);
// Withdraw from Universal Balance Native.
// withdrawAmount = Amount of native assets in wei.
// using true, to withdraw from the lent balance only, instead of the sitting balance.
// using recipient as the recipient address, can be the user's address or any address.
await universalBalance.withdrawNative(withdrawAmount, true, recipient);
Alternatively, if your app requires depositing for another address, you may use the withdrawFor()
and withdrawNativeFor()
functions in their respective contracts.
Last updated