Skip to main content
The program swaps 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: as curve’s output token, and as Token(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), with false for 3pool’s int128 indices. It approves the pool for exactly amount and returns the change in the Pot’s DAI.
  • The pool’s minimum output is 0, so minShares is 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. shares is therefore the change in receiver’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.
1,000 USDC bought 999.869412500378846204 DAI on the 3pool. The vault took all of it, and 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