Skip to main content
The program reads the Pot’s health factor from AaveV3.Pool.getUserAccountData. Below target, it repays the Pot’s variable-rate USDC debt with maxRepay USDC, or with what the Pot holds if that is less, and returns the health factor before and after. At or above target, it moves nothing. The cook reverts if target is not above 1.0, if the Pot holds no USDC when a repayment is due, or if Aave refuses the repayment. Target chains: Base and Ethereum. Both registries include USDC and AaveV3.Pool. The recorded Base simulation exercises only the branch that skips repayment.

Prerequisites

You need the sauce command (npm install -g @eco-incorp/sauce) and, to send, a wallet (sauce wallet new) holding the USDC for the Pot and the gas. See Installation.

Program

pot is the Pot the program runs on, available without declaring it (Names).
aave-repay-by-health.sauce.ts

How it works

  • The registry’s AaveV3.Pool declares no read of the Pot’s USDC debt or of Aave’s prices, so the program does not compute the repayment that restores target. It repays a fixed amount, capped by maxRepay and by the Pot’s USDC, and after reports where the health factor landed.
  • repay’s result is discarded, and a discarded result is neither decoded nor checked, so repaid is the change in the Pot’s USDC. When Aave pulled less than the approved amount, the program sets the Pot’s allowance to AaveV3.Pool back to zero, so no allowance outlives the cook.
  • repay takes interest rate mode 2 (variable) and pot as onBehalfOf, so it repays only the Pot’s own position.

Run the example

1

Compile

2

Simulate

--assume-balance USDC:500 gives the Pot 500 USDC for this simulation only. The result lists the health factor before and after and the USDC repaid.
3

Send

--fund USDC:500 pulls 500 USDC from your wallet into the Pot in the same cook; leave it out when the Pot already holds the USDC. sauce tx prints the unsigned transactions instead, for your own signer: the Pot’s deployment if it has no code yet, the transfer of the USDC into the Pot (with --fund), then the cook.

Simulation result

Simulated on a local fork of Base at block 52965104 with the current contracts, with the command above. Nothing was signed or sent.
The Pot is deployed inside the simulation and has no Aave position, so getUserAccountData reports the largest uint256 as its health factor. That is at or above any target, so the program returned at once with repaid: 0; no USDC moved, and the only moves in the output are the cook’s value and the Kitchen’s fee. The cook used 88,867 gas. Not simulated: the repay branch. It runs only when the Pot has USDC debt on Aave V3 and a health factor below target. The Pot in this simulation was deployed inside the simulation and has no Aave position; --assume-balance sets token balances, not Aave debt. The compile output for Base, from sauce compile aave-repay-by-health.sauce.ts --chain base --json:

Next steps