Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Repay with spTokens

The repayWithATokens function on Pool lets a user repay their own debt directly from their AToken balance of the same asset — no underlying transfer, no allowance to Pool required.

The on-chain contract type is AToken. On SparkLend, the AToken for each reserve is deployed with a Spark-branded symbol like spUSDS or spDAI. "Repaying with spTokens" and "repaying with ATokens" refer to the same call.

Signature

function repayWithATokens(address asset, uint256 amount, uint256 interestRateMode) external returns (uint256)
ParamTypeDescription
assetaddressUnderlying debt asset.
amountuint256Underlying amount to credit toward debt, or type(uint256).max to repay up to the caller's full AToken balance without leaving dust.
interestRateModeuint2561 for stable debt, 2 for variable debt.

Returns the actual amount repaid.

Caller constraints

  • msg.sender repays their own debt. There is no onBehalfOf parameter — BorrowLogic.executeRepay is called with onBehalfOf = msg.sender and useATokens = true (Pool.sol).
  • The caller must hold at least amount of the reserve's AToken; the AToken is burned in place of pulling underlying.
  • The debt being repaid must exist in the same interestRateMode.

Example

import { Contract } from "ethers";
const pool = new Contract(POOL_ADDRESS, poolAbi, signer);
 
// Repay up to the full DAI variable debt using the caller's spDAI (AToken) balance.
await pool.repayWithATokens(
  "0x6B175474E89094C44Da98b954EedeAC495271d0F", // DAI underlying
  ethers.constants.MaxUint256,
  2 // variable
);