amount of the Pot’s USDC for DAI on Curve’s 3pool with @sauce/router’s curve, then deposits all the DAI received into Maker.SDAI for receiver. If the Pot holds less than amount USDC, the vault does not take all the DAI, or receiver gains fewer than minShares sDAI, the cook reverts and nothing moves.
Target chains: Ethereum. The example uses USDC, Curve.ThreePool, Maker.Dai and Maker.SDAI.
Prerequisites
Install the Sauce CLI to compile and simulate. To send the transaction, configure a wallet with USDC 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).
usdc-to-sdai.sauce.ts
How it works
- DAI has no token symbol on Ethereum in the registry, so the program names it
Maker.Dai: ascurve’s output token, and asToken(Maker.Dai)for the balance read and the approval to the vault. curve(Curve.ThreePool, USDC, Maker.Dai, amount, 1, 0, false, 0, pot)swaps coin 1 (USDC) for coin 0 (DAI), withfalsefor 3pool’sint128indices. It approves the pool for exactlyamountand returns the change in the Pot’s DAI.- The pool’s minimum output is
0, sominSharesis the only bound on the swap price. Set it from a fresh simulation, minus the slippage you accept. deposit’s result is discarded, and a discarded result is neither decoded nor checked.sharesis therefore the change inreceiver’s sDAI balance.
Run the example
1
Compile
2
Simulate
--assume-balance USDC:1000 gives the Pot 1,000 USDC for this simulation only. The result lists the DAI the swap delivered and the sDAI shares receiver gained.3
Send
--fund USDC:1000 pulls 1,000 USDC 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 USDC into the Pot, then the cook.Simulation result
Simulated on a local fork of Ethereum at block 26252095 with the current contracts, with the command above. Nothing was signed or sent.receiver gained 845.864860423695566047 sDAI, above the 800 sDAI floor. The cook used 390,673 gas.
On the same fork, with minShares at 900 sDAI, the cook reverts:
Next steps
- Supply idle USDC: keeps a USDC reserve in the Pot and supplies the rest to Aave V3.
- Quote, swap and supply: compares two pools’ quotes before a swap and supplies the output.
sauce simulate, Names, Protocols reference.
