> ## 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.

# Read the Pot's holdings on each chain from one file

> One SauceScript file, compiled for Ethereum and for Base, that returns the Pot's USDC, WETH and bCSPX balances and that chain's Uniswap V3 USDC/WETH pool.

The program returns what the Pot holds in `USDC`, `WETH` and `bCSPX`, and the address of the chain's Uniswap V3 USDC/WETH pool at `fee`. It names no chain and no address: `--chain` decides which token and factory each name resolves to. It moves nothing, and reverts only when the chain has no pool at `fee`.

**Target chains:** Ethereum and Base. Both registries have every name the file uses. On Arc, `sauce compile` refuses the file: Arc's registry has no `bCSPX`.

## Prerequisites

You need the `sauce` command (`npm install -g @eco-incorp/sauce`). See [Installation](https://docs.eco.com/sauce-sdk/installation.md). The program moves nothing, so a simulation returns everything it does; there is no step that sends.

## Program

`pot` is the Pot the program runs on, available without declaring it ([Names](https://docs.eco.com/sauce/names.md#balances)).

```ts holdings-per-chain.sauce.ts theme={null}
// Reads what the Pot holds on the chain the file is compiled for, and that chain's Uniswap V3
// USDC/WETH pool at `fee`. The file names no chain and no address: compiled with `--chain`,
// `USDC`, `WETH` and `bCSPX` (Backed's tokenized S&P 500 fund) are that chain's tokens and
// `UniswapV3.Factory` is its factory. A chain that lacks one of these names refuses to compile
// the file. The program moves nothing; it reverts only when the chain has no pool at `fee`.
//
//   sauce simulate holdings-per-chain.sauce.ts --chain <chain> --owner <address> --args <fee>
//
//   fee: Uint256  the pool's fee tier, in millionths: 500 is 0.05%, 3000 is 0.3%
//
// On Base, the 0.05% pool, and the addresses the names resolve to there:
//
//   sauce simulate holdings-per-chain.sauce.ts --chain base --owner <address> --args 500
//   sauce compile holdings-per-chain.sauce.ts --chain base --json
function main(fee: Uint256): { pool: Address; usdc: Uint256; weth: Uint256; bcspx: Uint256 } {
  // This chain's factory, asked for this chain's pair: the pool is a different contract per chain.
  const pool = UniswapV3.Factory.getPool(USDC, WETH, fee);
  require(pool != 0, "no USDC/WETH pool at that fee on this chain");
  return {
    pool: pool,
    usdc: pot.USDC,
    weth: pot.WETH,
    bcspx: pot.bCSPX,
  };
}
```

## How it works

* `pot.USDC` is the Pot's balance of the chain's `USDC` token. The same expression reads a different contract on Ethereum and on Base.
* `UniswapV3.Factory.getPool(USDC, WETH, fee)` asks each chain's own factory for each chain's own pair, so `pool` is a different address per chain.
* `bCSPX` is Backed's tokenized S\&P 500 fund, registered on both chains. A name that one chain lacks makes the compile for that chain fail, before anything runs.

## Run the example

**1. Compile**

```bash theme={null}
sauce compile holdings-per-chain.sauce.ts --chain ethereum
sauce compile holdings-per-chain.sauce.ts --chain base
```

**2. Simulate**

```bash theme={null}
sauce simulate holdings-per-chain.sauce.ts --chain ethereum --owner <your-address> \
  --assume-balance USDC:100 --assume-balance WETH:0.5 --assume-balance bCSPX:2 --args 500
sauce simulate holdings-per-chain.sauce.ts --chain base --owner <your-address> \
  --assume-balance USDC:100 --assume-balance WETH:0.5 --assume-balance bCSPX:2 --args 500
```

The `--assume-balance` flags give the Pot 100 USDC, 0.5 WETH and 2 bCSPX for the simulation only, so the balances it returns are not zero. Without them it returns the Pot's real balances.

**3. List what each name resolved to**

```bash theme={null}
sauce compile holdings-per-chain.sauce.ts --chain base --json
```

The `defines` field lists each token name with its address on that chain, and `contracts` lists `UniswapV3.Factory` with its address.

## Simulation result

Simulated on a local fork of Ethereum at block 26252095 and on a local fork of Base at block 52965104, with the current contracts and the commands above. Nothing was signed or sent.

```text theme={null}
main returns { pool: Address, usdc: Uint256, weth: Uint256, bcspx: Uint256 }: { pool: 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640, usdc: 100000000, weth: 500000000000000000, bcspx: 2000000000000000000 }
```

```text theme={null}
main returns { pool: Address, usdc: Uint256, weth: Uint256, bcspx: Uint256 }: { pool: 0xd0b53D9277642d899DF5C87A3966A349A798F224, usdc: 100000000, weth: 500000000000000000, bcspx: 2000000000000000000 }
```

The first result is Ethereum, the second Base. The balances are the assumed ones, in each token's base units: 100 USDC (6 decimals), 0.5 WETH and 2 bCSPX (18 decimals). The 0.05% pool is `0x88e6…5640` on Ethereum and `0xd0b5…F224` on Base, from the same line of source.

## Next steps

* [Rebalance](https://docs.eco.com/quickstarts/sauce/rebalance.md): trade the Pot's WETH and USDC back to a target share.
* [Buy a tokenized stock](https://docs.eco.com/quickstarts/sauce/buy-tokenized-stock.md): swap into a tokenized stock.
* [Names](https://docs.eco.com/sauce/names.md), [Tokens reference](https://docs.eco.com/sauce-sdk/reference/tokens.md), [Chains reference](https://docs.eco.com/sauce-sdk/reference/chains.md), [`sauce compile`](https://docs.eco.com/sauce-sdk/cli/compile).


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