> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eco.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sweep the Pot to one address

> One transaction on Base or Ethereum that sends the Pot's whole USDC, WETH and native balance to one address, and returns what arrived.

The program sends the Pot's whole balance of USDC and of WETH, then its whole native balance, to `to`, and returns the amount that arrived for each. `to` is its only input. It reverts when `to` is the zero address or the Pot, or when `to` ends up with a different amount than the Pot sent.

**Target chains:** Base and Ethereum. The same source compiles for both; the recorded simulations use a Base fork.

> [!WARNING]
>
> The program moves everything the Pot holds of USDC and WETH and all of its native balance. Check `to` before you send: a wrong address receives all of it.

## Prerequisites

Install the [Sauce CLI](https://docs.eco.com/sauce-sdk/installation.md) to compile and simulate. To send the transaction, configure a wallet with funds for gas and the Kitchen fee. Provide the required tokens in your Pot once it is deployed, or through `--fund`; see [funding](https://docs.eco.com/sauce-sdk/cli/funding.md).

## Program

`pot` is the Pot the program runs on, available without declaring it; `balanceOf(token, pot)` reads its token balance and `pot.balance` its native coin ([Names](https://docs.eco.com/sauce/names.md#balances)).

```ts sweep-pot.sauce.ts theme={null}
// Empties the Pot into `to`: its whole balance of USDC and of WETH (both are registry tokens on
// Base and Ethereum), then its whole native balance. Each move is measured at `to`. Returns what
// arrived: USDC, then WETH, then the native amount last. A token the Pot holds none of is skipped
// (0). The cook reverts, and nothing moves, when `to` is the zero address or the Pot, or when `to`
// ends up with a different amount than the Pot sent, of a token (a fee-on-transfer token) or of
// native value (an account whose code forwards what it receives).
//
//   sauce simulate sweep-pot.sauce.ts --chain <chain> --owner <address> \
//     --assume-balance USDC:<whole-tokens> --assume-balance WETH:<whole-tokens> \
//     --assume-balance ETH:<whole-tokens> --args <to>
//   sauce run sweep-pot.sauce.ts --chain <chain> --wallet <name> --args <to>
//
//   to: Address  who receives everything
//
// On Base, sweep the Pot's USDC, WETH and ETH to 0x2154…676d:
//
//   sauce run sweep-pot.sauce.ts --chain base --wallet me \
//     --args 0x21543327A3f4282A3649a7b1AAe499fdCaB3676d
import { balanceOf, transfer } from "@sauce/token";

function main(to: Address): Uint256[] {
  require(to != 0 && to != pot, "to is the zero address or the Pot");

  const tokens = [USDC, WETH];
  const count = tokens.length;
  const moved: Uint256[] = new Array(count + 1);
  for (let i = 0; i < count; i++) {
    const token = tokens[i];
    const held = balanceOf(token, pot);
    if (held > 0) {
      const before = balanceOf(token, to);
      transfer(token, to, held);
      moved[i] = balanceOf(token, to) - before;
      require(moved[i] == held, "to received a different amount of a token");
    }
  }

  // Native value moves only with evm.call; empty calldata makes it a plain transfer.
  const value = pot.balance;
  if (value > 0) {
    const empty = hex``;
    const before = ctx.balance(to);
    evm.call(to, value, empty);
    moved[count] = ctx.balance(to) - before;
    require(moved[count] == value, "to received a different native amount");
  }

  return moved;
}
```

## How it works

* The tokens are the registry names `[USDC, WETH]`, and each chain's compile resolves them to that chain's addresses, so one file serves Base and Ethereum with no address in it. `balanceOf` and `transfer` come from `@sauce/token` and take the token as their first argument. To sweep other tokens, change the list; `sauce globals --chain <chain> --tokens` lists the names a chain has.
* Native value is sent with `evm.call(to, value, empty)`, where `empty` is an empty `hex` literal: `evm.call` is the only way to send value with a call, and empty calldata makes it a plain transfer. A contract at `to` that refuses native value makes the call fail, which reverts the cook.
* The return value is one `Uint256[]` of length `tokens.length + 1`: USDC, then WETH, then the native amount last. A token the Pot does not hold stays `0` and is not transferred.
* Each move is measured at `to` with `balanceOf` or `ctx.balance(to)`. In the second result below, the native value did not stay in the recipient's balance, so the guard reverted the cook.

## Run the example

**1. Compile**

```bash theme={null}
sauce compile sweep-pot.sauce.ts --chain base
```

Replace `base` with `ethereum`. Each compile is 580 bytes, but the bytecode differs, because each carries its chain's USDC and WETH addresses.

**2. Simulate**

```bash theme={null}
sauce simulate sweep-pot.sauce.ts --chain base --owner <your-address> \
  --assume-balance USDC:25 --assume-balance WETH:0.01 --assume-balance ETH:0.002 \
  --args <recipient>
```

Each `--assume-balance` gives the Pot that balance for this simulation only; `ETH:` sets its native balance.

**3. Send**

```bash theme={null}
sauce run sweep-pot.sauce.ts --chain base --wallet <name> \
  --args <recipient>
```

`sauce tx` prints the unsigned transaction instead, for your own signer:

```bash theme={null}
sauce tx sweep-pot.sauce.ts --chain base --owner <your-address> \
  --args <recipient>
```

## Simulation result

Simulated on a local fork of Base at block 53159700 with the current contracts, with the command above, sweeping to `0x2154…676d`, an address with no code. Nothing was signed or sent.

```text theme={null}
The cook succeeds from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266: gas used 198810 for the cook, after the Pot's deploy (1. below), returns 0x00000000000000000000000000000000000000000000000000000000017d7840000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000071afd498d0000
main returns Uint256[]: [25000000, 10000000000000000, 2000000000000000]
...
  2. the cook, from the owner 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, gas used 198810
Assumed for this simulation only, by state override:
  the Pot holds 25 USDC: --assume-balance (its balance word 0xcb5320fe60abad81834e0e994e8a7a8eb33991917b05a5c0498fe1c0373a2087: Solidity mapping at slot 9)
  the Pot holds 0.01 WETH: --assume-balance (its balance word 0x414b65ef17cbb779af5e33937c81e6b35b67a6491f0cc46ef530a2f31a50c704: Solidity mapping at slot 3)
  the Pot holds 0.002 ETH: --assume-balance
What moved, in order:
...
  [3] Pot                -> 0x2154…676d          25 USDC
  [4] Pot                -> 0x2154…676d          0.01 WETH
  [5] Pot                -> 0x2154…676d          0.002 ETH
Net balance changes:
  0xDcFCc75A3C9a0EC798CAf81B6C84D4c5d5988c49 (the Pot): -25 USDC, -0.01 WETH, -0.002 ETH
  0x21543327A3f4282A3649a7b1AAe499fdCaB3676d: +25 USDC, +0.01 WETH, +0.002 ETH
  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 (owner): -0.00000374478538635 ETH
```

The Kitchen's fee was paid from the cook's value before the program ran, so `pot.balance` read the 0.002 ETH assumed for the Pot, and all of it arrived at `to`, as did the 25 USDC and 0.01 WETH.

On the same fork, the guard, with `0x70997970C51812dc3A010C7d01b50e0d17dc79C8` as `to`:

```bash theme={null}
sauce simulate sweep-pot.sauce.ts --chain base --owner <your-address> \
  --assume-balance USDC:25 --assume-balance WETH:0.01 --assume-balance ETH:0.002 \
  --args 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 \
  --expect-revert "to received a different native amount"
```

```text theme={null}
As expected, the cook reverts: the program threw "to received a different native amount"
The cook reverts: the program threw "to received a different native amount"
```

On this fork `0x7099…79C8` has code `0xef0100…`, an EIP-7702 delegation, and the 0.002 ETH sent to it did not stay in its balance. The token moves before it were rolled back with the rest of the cook.

## Next steps

* [Pay USDC from the Pot](https://docs.eco.com/quickstarts/sauce/pay.md): one token, one amount
* [Native USDC payment on Arc](https://docs.eco.com/quickstarts/sauce/arc-native-payment.md): native value where the native coin is USDC
* [Builtins](https://docs.eco.com/sauce/builtins.md), [The Pot](https://docs.eco.com/sauce/pot.md), [`sauce globals`](https://docs.eco.com/sauce-sdk/cli/globals)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.