Repay a loan

This guide explains how to repay debt owed to an inventory pool

Prerequisites

  • A whitelisted borrower with current debt on an inventory pool

Process Overview

  1. Approve the inventory pool contract to spend your tokens

  2. Call the repay() function directly on the inventory pool contract

Step 1: Approve Token Spending

First, get the token address from the inventory pool and approve it to spend your tokens:

// Using ethers.js
const inventoryPoolContract = new ethers.Contract(
  inventoryPoolAddress,
  [
    "function asset() view returns (address)"
  ],
  signer
);

// Get the token address from the inventory pool
const tokenAddress = await inventoryPoolContract.asset();

// Set up the token contract
const tokenContract = new ethers.Contract(
  tokenAddress,
  [
    "function approve(address spender, uint256 amount) returns (bool)",
    "function decimals() view returns (uint8)"
  ],
  signer
);

const decimals = await tokenContract.decimals();
const amount = ethers.parseUnits("1000.0", decimals);

// Approve the inventory pool to spend your tokens
const tx = await tokenContract.approve(inventoryPoolAddress, amount);
await tx.wait();

Step 2: Repay the Loan

After approval, call the repay() function on the inventory pool contract. Note that the borrower parameter can be any address that has an active loan - it doesn't have to be the caller of the function:

// Using ethers.js
const inventoryPoolContract = new ethers.Contract(
  inventoryPoolAddress,
  [
    "function repay(uint256 amount, address borrower)"
  ],
  signer
);

// Repay the loan
const tx = await inventoryPoolContract.repay(amount, borrowerAddress);
await tx.wait();

Important Notes

  • If repayment amount exceeds debt, the inventory pool will take the exact amount owed

Last updated