Loans & Collateral

This guide demonstrates how to integrate with Curvance Protocol using JavaScript and ethers.js v5.7, with specific examples using the shMON for collateral and USDC for lending.

The MarketManager coordinates all cTokens, for a deep dive check out this article: Market Manager

Setting Up Your Integration

First, install ethers.js, for the examples in these docs, we use ethers 5.7.x.

npm install [email protected]

You'll need to define your contract addresses and ABIs. Here's a simplified example for the most important ones:

const ADDRESSES = {
  SHMON: "0x21E27a5E5513D6e65C4f830167390997aA84843a",
  USDC: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
  SHMON_CTOKEN: "0x..." // Replace with actual cToken address
  USDC_CTOKEN: "0x..." // Replace with actual cToken address
};

Important Considerations Before Depositing

Before sending any transactions, check these important protocol values by calling mintPaused() in the MarketManager contract.

  1. Protocol Status: Verify if minting of the cToken is not paused:

Call actionsPaused() with the following arguments. Returning a tuple of booleans, indicating if minting, collateralization, and borrowing is paused.

Type
Description

address

Address of the cToken to check the minting status of.

Implementation:

const marketManager = new ethers.Contract(MARKET_MANAGER_ADDRESS, MARKET_MANAGER_ABI, provider);
const actionsPaused = await marketManager.mintPaused(SHMON_CTOKEN);
  1. Collateral Caps: If depositing as collateral, check if the asset has reached its collateral cap by calling collateralCaps(), and marketCollateralPosted() in the MarketManager contract:

Calling collateralCaps() using these function arguments, returning uint256 indicating the maximum amounts of cTokens that can be posted as collateral:

Type
Description

address

Address of the cToken to check the max amount of shares that can be posted as collateral.

Call marketCollateralPosted() which returns a uint256 indicating the current amount of cTokens currently posted as collateral:

Type
Description

address

Address of the cToken to check the amount of collateral posted.

Implementation:

const cap = await marketManager.collateralCaps(SHMON_CTOKEN);
const posted = await marketManager.marketCollateralPosted(SHMON_CTOKEN)
const capReached = posted.gte(cap) && !cap.isZero();
  1. Minimum Hold Period: Be aware that Curvance implements a 20-minute minimum hold period for collateralized deposits to mitigate flash loan attacks.

  2. Non Rebasing: Understand that your share value increases over time rather than the number of shares.

Best Practices for Production Implementations

  1. Error Handling: Implement proper error handling for all transactions.

  2. Gas Estimation: Use estimateGas before sending transactions to ensure proper gas limits.

  3. Approval Checking: Check existing allowances before sending approval transactions.

  4. Transaction Monitoring: Implement logic to track transaction status after submission.

  5. 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.

Last updated