Curvance
  • Protocol Overview
    • Click Less, Earn More
    • Protocol Architecture
    • Asset Types
    • Liquidity Markets
      • Borrowing
      • Liquidations
      • Interest Rates
      • Oracles
      • Collateral Caps
      • Bad Debt Socialization
    • Application Specific Sequencing
    • New Age Liquidity Mining
      • Protocols
    • How Are New Assets Integrated
    • Plugin System
    • Universal Account Balance
    • Token Approval Management
    • Lending Risks
  • Security
    • Security and Audits
  • Miscellaneous
    • RPCs and Testnet Stability
    • Glossary
    • TL;DR
      • Customer Types and Benefits
    • Brand Assets
    • Weblinks
    • Disclaimer
    • Frequently Asked Questions
  • Developer Docs
    • Overview
    • Quick Start Guides
      • Atlas Fastlane Auctions (coming soon)
      • Plugin Integration
        • List of Delegable Actions
      • Loans & Collateral
        • Lend Assets
        • Deposit into pTokens
        • Withdraw Loans
        • Withdraw pTokens
      • Borrowing & Repayment
        • Borrow
        • Repaying Debt
      • Leverage
        • Leveraging
        • Deleveraging
    • Lending Protocol
      • Market Manager
      • Position Tokens (pToken)
      • Earn Tokens (eTokens)
      • Dynamic Interest Rate Model
      • Universal Balance
    • Position Management
      • Leverage
      • Deleverage / Fold
    • Dynamic Liquidation Engine (DLE)
      • OEV Liquidation System
      • Bad Debt Socialization
    • Plugin & Delegation System
      • Transfer Lock Mechanism
      • Delegable Actions
    • Cross-Chain Functionality
      • Messaging Hub
      • Fee Manager
      • Reward Manager
    • Auxiliary Functionality
Powered by GitBook
On this page
  • Querying Redeem Amounts
  • Withdraw USDC from Lending (eUSDC)
  • The Universal Balance System: A Simplified Interface
Export as PDF
  1. Developer Docs
  2. Quick Start Guides
  3. Loans & Collateral

Withdraw Loans

PreviousDeposit into pTokensNextWithdraw pTokens

Last updated 6 days ago

For a detailed explanation of eTokens, check out this article:

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:

Type
Name
Description

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:

Type
Name
Description

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:

Type
Name
Description

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():

Type
Parameter
Description

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:

Type
Name
Description

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.

Earn Tokens (eTokens)