Skip to main content
Avana logo

Repay Loans

Repay any amount of one debt reserve, or all of it, through the AaveAdapter. Any address can pay, and no Avana pause, breaker, freeze, price or sequencer state can block it.

Overview

A repay moves the debt asset from the payer to the borrower's PositionProxy, which repays its own account on the CDP Spoke; Aave returns the asset to the reserve's funding Hub. The payer is always the caller. Any address can repay any account: the borrower, another wallet of the borrower, a rescue service or the protocol. A payer can never borrow or move collateral, because those calls act only on the caller's own account.

Each call repays one debt reserve of one account and leaves the account's other reserves untouched. Avana has no minimum debt, so a partial repay may leave any remainder. A repay changes no vault token, position, record or booked charge.

A borrower can also repay with liquidity from one of their own pledged positions, without bringing funds. That path is described under repay with collateral on the Manage Loans page.

The Repay Call

repay(address borrower, uint256 marketId, uint256 debtReserveId, uint256 maxRepaySpend, bool repayAll, uint256 deadline) returns (uint256 spent)
ParameterTypeMeaning
borroweraddressThe wallet whose account is repaid. It need not be the caller.
marketIduint256The account's market. With the borrower it names the account.
debtReserveIduint256The debt reserve repaid (GHO, USDC, USDT, WETH or another reserve the Spoke lends).
maxRepaySpenduint256The most the payer allows to be pulled in this call, in the asset's base units.
repayAllboolTrue clears the reserve's whole live debt or reverts; false repays up to the cap.
deadlineuint256Last valid block timestamp, in seconds on both chains.

The payer approves the AaveAdapter for the debt asset beforehand; there is no permit path. The call returns the amount Aave took. In order, it does the following:

  • Take the protocol lock and check the deadline. The caller becomes the payer.
  • Resolve the borrower's proxy for the market from the Adapter's own storage.
  • Read the live debt D of the reserve from the Spoke: drawn debt plus premium, accrued to the block, rounded up. If D is 0, return 0 with no transfer and no event.
  • Size the pull: a partial repay pulls min(maxRepaySpend, D); a repay-all pulls the whole cap, or reverts before any transfer if D is above it.
  • Move the funds from the payer straight to the borrower's proxy and measure what arrived.
  • Have the proxy approve the Spoke for exactly that amount and repay its own account. Aave restores premium first, then drawn debt, and takes at most the debt.
  • Reset the approval to 0 and refund whatever Aave did not take to the payer, in the same call.
  • For a repay-all, require the reserve's debt to be 0. If the account is now debt-free on every reserve, mark it debt-free.
  • Emit Repaid and release the lock.

A token that takes a fee on transfer reduces the repayment instead of blocking it: every step after the pull uses the amount that actually arrived.

Repay All with a Spend Cap

Debt keeps accruing between signing and inclusion, so a cap equal to the debt quoted at signing would always fall short. Instead, the app computes a cap quoted to the deadline and sets both the approval and maxRepaySpend to it:

quoteRepayAll(borrower, marketId, debtReserveId, deadline) = ⌈debt × (1 + rate × (deadline − now)) × 1.001⌉

A repay-all pulls the whole cap, Aave takes the live debt at inclusion, and the proxy refunds the difference to the payer in the same call. The payer never spends more than it signed for, and an approval of exactly the cap ends at 0, so no standing allowance remains. If another payer repays first, the borrower's own repay-all only pays what is left.

To repay every debt reserve and take a position back in one call, use repayAllAndWithdraw, described in Withdraw Collateral.

Interest Accrual

Interest is Aave V4's and accrues every second: the reserve's drawn rate on its funding Hub plus the account's risk premium. The live debt read by a repay is drawn debt plus premium, accrued to the block and rounded up. A repay restores premium first, then drawn debt; when the drawn shares reach 0 the reserve is no longer marked as borrowed.

Avana takes no fee on interest and the repay call charges no fee. Avana Labs charges an app fee in its own app, outside the contracts; calling the contracts directly does not pay it.

Example values: 13,000 USDC borrowed at 6.00% is ⌈13,000,000,000 × (1 + 0.06 × 30 / 365)⌉ = 13,064,109,590 base units (13,064.109590 USDC) after 30 days. 8,000 GHO at 5.00% is 8,032.876712 GHO after 30 days.

What Can Block a Repay

Repay never reads a pause state, a circuit breaker, the address freeze, the sequencer gate or any other MarketRegistry view, and never calls the RiskModule, an oracle or the ParameterStore. The account binding (Spoke, vault token, reserve) comes from the Adapter's own storage written when the proxy was created. So no Avana pause, breaker, freeze, price state or registry fault can block a repay; only Aave can.

StateRepay with funds
Hub None, Frozen, Paused (General) or Paused (MintPathSuspect)Allowed
Payer or borrower is a frozen addressAllowed
Any market or debt breaker trippedAllowed
Base sequencer Down (forced in through L1) or in GraceAllowed
Any price state, stale feeds, USD-band breachAllowed
Market Offboarding, liquidation halted, configuration drift, Hub shares not equal to assetsAllowed
Faulty MarketRegistry, RiskModule or ParameterStoreAllowed: none of them is called
Aave vault-token reserve paused or frozen, repaid reserve frozen, drawCap exhaustedAllowed
Repaid debt reserve paused on AaveRefused by Aave (ReservePaused)
The Hub halts or deactivates the CDP SpokeRefused by Aave (SpokeHalted)
A broken AaveAdapter implementationRefused until fixed by an Adapter upgrade through the chain's Timelock, which every proxy uses at once

The proxy holds no logic and has no upgrade path; it only forwards the Adapter's calls. Aave's listing agreement uses a reserve freeze and a drawCap of 0 for containment, which leave repayment open, and keeps reserve pauses and Spoke halts for a faulty Spoke.

Repayment by Another Payer

Any payer repays through the AaveAdapter with the borrower's address. The funds are pulled from the payer, never from the borrower, and any refund goes back to the payer. This lets a borrower's other wallets, a rescue service or the protocol save an account near liquidation, including one whose key is lost.

Calling the Spoke's repay directly for a proxy fails with Unauthorized, because Aave accepts repayment only from the position owner or an approved position manager, and proxies approve none.

Example values; each market's parameters are set at listing. On Ethereum, a rescue service R repays 3,000 GHO of wallet W's market-A account while the Avana Ethereum Hub is Paused with reason MintPathSuspect, a GHO debt breaker is tripped and W is a frozen address. The call reads none of these states: 3,000 GHO are pulled from R, W's debt falls to 5,032.88 GHO, the event is Repaid with R as payer and W as borrower, and W's collateral does not move. If W's own repay-all with a cap of 8,040 GHO lands later in the same block, Aave takes only the remaining 5,032.876712 GHO and W gets 3,007.123288 GHO back.

Events

  • The asset's Transfer from the payer to the proxy, and the proxy's approval of the Spoke.
  • Hub Restore and Spoke Repay, in Aave's order.
  • The approval reset and, when non-zero, the refund Transfer from the proxy to the payer.
  • Collateralization's DebtFree, only when the account is left with no debt on any reserve.
  • Repaid(payer, borrower, marketId, debtReserveId, spent, debtAfter, repayAll)

A repay at zero debt emits nothing.

Failures

ErrorCause
RepayExceedsMaxRepay-all with a live debt above maxRepaySpend. It reverts before any transfer.
DebtRemainingRepay-all left debt in the reserve, for example when a token transfer fee made the received amount smaller than the debt.
ZeroAmountA partial repay with debt outstanding and maxRepaySpend of 0.
NoProxyThe borrower has no account in the market.
DeadlineExpired / LockHeldCall bounds.
UnitsMismatch / BalanceDeltaMismatchThe proxy received 0 or more than the pulled amount, or its balance did not return to its starting value.
Token errorThe payer's allowance or balance is below the amount pulled; the token's own error passes through.
ReservePaused / SpokeNotActive / SpokeHaltedAave blocks the repay.
UnauthorizedA third party called the Spoke's repay directly for the proxy instead of going through the AaveAdapter.

A repay at zero debt, including debt another payer or a liquidation cleared first, is not a failure: it returns 0 with no token movement.

Worked Examples

Example values; each market's parameters are set at listing. Carol's account in market 3 on Ethereum, 30 days after she borrowed 13,000 USDC at 6.00%: live debt ⌈13,000,000,000 × (1 + 0.06 × 30 / 365)⌉ = 13,064,109,590 base units, HF 16,000 / (13,064.109590 × 0.9999) = 1.2249.

Repay all

  • The app calls quoteRepayAll(Carol, 3, r_USDC, now + 600): ⌈13,064,109,590 × (1 + 0.06 × 600 / 31,536,000) × 1.001⌉ = 13,077,188,628.
  • Carol approves the AaveAdapter for exactly 13,077,188,628 USDC base units and calls repay(Carol, 3, r_USDC, 13,077,188,628, true, now + 600). No pause state, breaker, freeze, price or sequencer gate is read.
  • The call is included 12 seconds (1 block) later, when the live debt is 13,064,109,889.
  • The Adapter pulls 13,077,188,628 into Carol's proxy; Aave takes 13,064,109,889; 13,078,739 is returned to Carol in the same call.
  • The account has no debt left, so Collateralization marks it debt-free. Event Repaid(Carol, Carol, 3, r_USDC, 13,064,109,889, 0, true). Carol's allowance to the Adapter is 0.
  • Carol's $20,000 charge stays booked until she withdraws; her NFTs can now leave through a debt-free withdrawal.

Variants

  • A partial repay of 2,000 USDC leaves 11,064,109,590; any remainder is accepted because there is no minimum debt.
  • A repay-all with a cap of 13,060,000,000 reverts with RepayExceedsMax(13,064,109,590, 13,060,000,000) before any transfer.
  • A repay-all that leaves debt in the reserve reverts with DebtRemaining.
  • On a Base market, the same repay forced in from L1 succeeds while the sequencer is down.
  • The same quote included 24 seconds (2 blocks) later finds a debt of 13,064,110,187 and refunds 13,078,441.
  • A repay after a liquidation already cleared the debt returns 0 with no transfer, approval or event.

The third-party example above shows a rescue service repaying while the Hub is paused, a breaker is tripped and the borrower is frozen.