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 thesauce 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.Pooldeclares no read of the Pot’s USDC debt or of Aave’s prices, so the program does not compute the repayment that restorestarget. It repays a fixed amount, capped bymaxRepayand by the Pot’s USDC, andafterreports where the health factor landed. repay’s result is discarded, and a discarded result is neither decoded nor checked, sorepaidis the change in the Pot’s USDC. When Aave pulled less than the approved amount, the program sets the Pot’s allowance toAaveV3.Poolback to zero, so no allowance outlives the cook.repaytakes interest rate mode2(variable) andpotasonBehalfOf, 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.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
- Borrow with a health-factor floor: opens the kind of position this program repays, with a minimum health factor.
- Supply idle USDC: keeps a USDC reserve in the Pot and supplies the rest to Aave V3.
sauce simulate, Pot, Protocols reference.
