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 eUSDC contract handles the debt issuance. The borrowed USDC is sent directly to your wallet.

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

Type
Name
Description

uint256

amount

The amount of the underlying asset to borrow.

Implementation snippet:

async function borrowUSDC(amount) {
  // USDC has 6 decimal places
  const USDCDecimals = await USDC.decimals();
  const amountInSmallestUnit = ethers.utils.parseUnits(amount.toString(), USDCDecimals);
  
  // Borrow USDC
  const borrowTx = await eUSDC.borrow(amountInSmallestUnit);
  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 eUSDC 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 === '0x65513fc1') console.error('Invalid parameter provided');
      else if (errorSelector === '0x37cf6ad5') console.error('Unauthorized access');
      else if (errorSelector === '0x4f3013c5') console.error('Token not listed in this market');
      else if (errorSelector === '0xf47323f4') console.error('Market is currently paused');
      else console.error('Unknown error code:', errorSelector);
    } 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