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.

Last updated