collateral WETH from the Pot to Aave V3, borrows borrowUsdc USDC at the variable rate against it, reads the Pot’s health factor, and sends the USDC to recipient. If the health factor after the borrow is below minHealthFactor, the borrow delivers a different amount, or Aave refuses the supply or the borrow, the cook reverts and nothing moves.
Target chains: Base. The example uses WETH, USDC and AaveV3.Pool; the recorded simulation is on a Base fork.
Prerequisites
Install the Sauce CLI to compile and simulate. To send the transaction, configure a wallet with WETH for the program and native coin for gas and the Kitchen fee.Program
pot is the Pot the program runs on, available without declaring it (Names).
aave-borrow-guard.sauce.ts
How it works
supplyandborrowboth namepotasonBehalfOf: the aWETH collateral and the USDC debt are the Pot’s, and Aave checks the borrow against the Pot’s own collateral.- The health factor is read with
AaveV3.Pool.getUserAccountData(pot)after the borrow, in the same transaction, so therequiresees the position the borrow left. Aave treats a health factor below 1.0 (1000000000000000000) as liquidatable;minHealthFactoris the higher floor this cook enforces. borrowedis the change in the Pot’s USDC, required to equalborrowUsdcbefore any USDC leaves the Pot.
Run the example
1
Compile
2
Simulate
--assume-balance WETH:1 gives the Pot 1 WETH for this simulation only. The result lists the health factor and what the cook left in the Pot.3
Send
--fund WETH:1 pulls 1 WETH from your wallet into the Pot in the same cook. 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 WETH into the Pot, 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.Next steps
- Repay by health factor: repays the Pot’s USDC debt when its health factor is below a target.
- Supply idle USDC: keeps a USDC reserve in the Pot and supplies the rest to Aave V3.
sauce simulate, Pot, Protocols reference.
