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

Repaying Debt

When you're ready to reduce or eliminate your debt, you can repay it through the eUSDC contract. Repayment requires you to first approve the eUSDC contract to spend your USDC, then call the repay() function with the following function arguments:

Type
Name
Description

uint256

amount

The amount of the underlying asset to repay, or 0 for the full outstanding amount.

Implementation snippet:

async function repayUSDCDebt(amount) {
  const USDCDecimals = await USDC.decimals();
  
  // Use 0 to repay the full outstanding amount
  const isFullRepay = amount === 'full';
  const amountToRepay = isFullRepay ? '0' : amount;
  const amountInSmallestUnit = ethers.utils.parseUnits(amountToRepay, USDCDecimals);
  
  // Approve USDC to be spent by eUSDC contract
  let approvalAmount = amountInSmallestUnit;
  if (isFullRepay) {
    // Get current debt balance for full repayment
    approvalAmount = await eUSDC.debtBalanceCached(wallet.address);
    // Add 1% buffer for accrued interest
    approvalAmount = approvalAmount.mul(101).div(100);
  }
  
  await USDC.approve(eUSDCAddress, approvalAmount);
  
  // Repay the debt
  const repayTx = await eUSDC.repay(amountInSmallestUnit);
  const receipt = await repayTx.wait();
  
  console.log(`Repaid ${isFullRepay ? 'full debt' : amount + ' USDC'}`);
  return receipt;
}

Curvance makes full repayment convenient by allowing you to pass 0 as the amount, which automatically repays your entire outstanding debt. This saves you from having to calculate the exact debt amount with accrued interest.

Repaying Debt on Behalf of Others

A unique feature of Curvance is the ability to repay debt on behalf of another address. This can be useful in various scenarios, such as:

  • Helping a friend avoid liquidation.

  • Managing multiple wallets in a DAO or organization.

  • Implementing complex DeFi strategies.

The process is similar to regular repayment but uses the repayFor function using the following arguments:

Type
Name
Description

address

account

The account address to repay on behalf of.

uint256

amount

The amount to repay, or 0 for the full outstanding amount.

Implementation snippets:

async function repayForAccount(account, amount) {
  const USDCDecimals = await USDC.decimals();
  const amountInSmallestUnit = ethers.utils.parseUnits(amount.toString(), USDCDecimals);
  
  // Approve USDC to be spent by eUSDC contract
  await USDC.approve(eUSDCAddress, amountInSmallestUnit);
  
  // Repay debt on behalf of another account
  const repayTx = await eUSDC.repayFor(account, amountInSmallestUnit);
  const receipt = await repayTx.wait();
  
  console.log(`Repaid ${amount} USDC on behalf of ${account}`);
  return receipt;
}

This function allows anyone to repay debt for any user without requiring permission from the borrower, creating interesting possibilities for social coordination in DeFi.

PreviousBorrowNextLeverage

Last updated 15 days ago