Borrow

When you borrow USDC through Curvance, you're creating a debt position against your collateral. The system constantly evaluates your position to ensure it remains healthy (above the required collateralization ratio). The borrowing process is straightforward - you simply specify how much USDC you want to borrow, and the cUSDC contract handles the debt issuance. The borrowed USDC is sent directly to the receiver wallet.

To borrow, you may call the borrow() function in the respective cToken contract using these function arguments:

Type
Name
Description

uint256

amount

The amount of the underlying asset to borrow.

address

recipient

The address where the borrowed tokens will be sent.

Implementation snippet:

async function borrowUSDC(amount) {
  // USDC has 6 decimal places
  const USDCDecimals = await USDC.decimals();
  const amountInUsdcUnits = ethers.utils.parseUnits(amount.toString(), USDCDecimals);
  
  // Borrow USDC
  const borrowTx = await cUSDC.borrow(amountInUsdcUnits);
  const receipt = await borrowTx.wait();
  
  console.log(`Successfully borrowed ${amount} USDC`);
  return receipt;
}

Your borrowing capacity depends on your collateral value, the collateralization ratio of your assets, and current market conditions. Curvance's risk model determines the maximum amount you can borrow against your collateral.

Error Handling

When interacting with cUSDC contracts, you might encounter various errors. Curvance uses error selectors to provide specific information about what went wrong:

async function safeBorrowUSDC(amount) {
  try {
    return await borrowUSDC(amount);
  } catch (error) {
    console.error('Borrowing failed:');
    
    if (error.data) {
      const errorSelector = error.data.slice(0, 10);
      if (errorSelector === 
        ethers.id('MarketManager__InsufficientCollateral()').slice(2, 10))) 
        console.error('Invalid parameter provided');
    } else {
      console.error('Error details:', error.message);
    }
    throw error;
  }
}

Common error scenarios include:

  • Insufficient collateral for your requested borrow amount.

  • Market paused for borrowing (temporary protocol safety measure).

  • Trying to borrow less than the minimum loan size.

  • Transaction would result in an unhealthy position.

Last updated