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)| Param | Type | Description |
|---|---|---|
asset | address | Underlying debt asset. |
amount | uint256 | Underlying amount to credit toward debt, or type(uint256).max to repay up to the caller's full AToken balance without leaving dust. |
interestRateMode | uint256 | 1 for stable debt, 2 for variable debt. |
Returns the actual amount repaid.
Caller constraints
msg.senderrepays their own debt. There is noonBehalfOfparameter —BorrowLogic.executeRepayis called withonBehalfOf = msg.senderanduseATokens = true(Pool.sol).- The caller must hold at least
amountof 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
);