Supply & Collateral
Last updated
Last updated
This guide demonstrates how to integrate with Curvance Protocol using JavaScript and ethers.js v5.7, with specific examples using the Convex stETH-ETH pool for collateral and USDC for lending.
Curvance has two primary token types that together make up the protocol's market infrastructure:
pTokens (Position Tokens): Used for collateral positions. These are ERC4626-compliant vault tokens that represent a user's collateral. Many pTokens are yield-optimized, automatically compounding underlying yields for depositors.
eTokens (Earn Tokens): Used for lending positions. These tokens represent a user's deposits that are being lent out.
mTokens (Market Tokens): The collective term for both pTokens and eTokens.
Yield-optimized pTokens like ConvexSTETH_ETH2PoolPToken provide automatic yield generation for depositors:
Deposit Process: Users deposit Curve stETH-ETH LP tokens into the pToken.
Behind the Scenes: The pToken stakes these LP tokens in Convex Finance.
Yield Generation: The staked position earns CRV and CVX rewards from Convex.
Harvesting: Periodically, these rewards are harvested, swapped to ETH, and used to mint more LP tokens.
Compounding: New LP tokens are staked back in Convex, increasing the total assets.
User Benefit: The value of users' shares increases over time as yields accumulate.
This automated yield optimization happens regardless of whether the position is being used as collateral.
First, install ethers.js v5.7:
You'll need to define your contract addresses and ABIs. Here's a simplified example for the most important ones:
Before sending any transactions, check these important protocol values by calling mintPaused()
in the MarketManager contract.
Protocol Status: Verify if minting of the pToken is not paused:
Call mintPaused()
with the following arguments. Returning a 0 or 1 if not paused, else indicating that minting is paused.
address
Address of the pToken to check the minting status of
Implementation:
Collateral Caps: Check if the asset has reached its collateral cap by calling collateralCaps()
, and collateralPosted()
in the MarketManager contract:
Calling collateralCaps()
using these function arguments, returning uint256 indicating the maximum amounts of pTokens that can be posted as collateral:
address
Address of the pToken to check the max amount of shares that can be posted as collateral
Calling collateralPosted()
using these function arguments, returning uint256 indicating the current amount of pTokens currently posted as collateral:
address
Address of the pToken to check the amount of collateral posted
Implementation:
Minimum Hold Period: Be aware that Curvance implements a 20-minute minimum hold period for deposits to mitigate flash loan attacks.
Yield Optimization: For yield-optimized pTokens, understand that your share value increases over time rather than the number of shares.
Error Handling: Implement proper error handling for all transactions.
Gas Estimation: Use estimateGas before sending transactions to ensure proper gas limits.
Approval Checking: Check existing allowances before sending approval transactions.
Transaction Monitoring: Implement logic to track transaction status after submission.
Read-Only Checks: Use read-only calls to validate operations before sending transactions.
By following this guide, you'll be able to integrate with Curvance's deposit functionality for both yield-optimized collateral positions and lending positions using JavaScript and ethers.js v5.7.
Here's a complete flow for integrating with Curvance:
Set up your provider and signer:
Check protocol status:
Prepare token amount with proper decimals:
Make the deposit:
Monitor your position: