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)
      • Orderflow Auction 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
Export as PDF
  1. Developer Docs
  2. Quick Start Guides
  3. Borrowing & Repayment

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.

PreviousBorrowing & RepaymentNextRepaying Debt

Last updated 15 days ago