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

# Liquidity-weighted order split

> A complete SauceScript program that splits one order across two Uniswap V3 pools, weighting each leg by the pool's live liquidity at inclusion, swaps both legs, and reverts the whole transaction if the combined output misses a floor. Reproduced from the compiler's example set.

Split one order across two Uniswap V3 pools, weighting each leg by the pool's live liquidity, swap both legs via SwapRouter02, then require the combined output to clear the floor, all inside one transaction. If the floor is not met the whole transaction reverts and no leg settles. The router is fixed (Base mainnet); the tokens, amount, caller, pools and floor are parameters.

## Prerequisites

* Complete [Sauce setup](/programmable-transactions/sauce/getting-started), including access, a Pot and the current Kitchen fee.
* Use Base mainnet (chain ID `8453`) and two Uniswap V3 pools for the same token pair.
* The caller must hold the input tokens and approve the Pot to spend `amountIn`.
* Save these three ABI files beside the program: [IERC20](/cookbook/sauce/abis/IERC20.json), [IV3SwapRouter](/cookbook/sauce/abis/IV3SwapRouter.json), [IUniswapV3Pool](/cookbook/sauce/abis/IUniswapV3Pool.json).
* Supply a minimum acceptable output in the output token's smallest unit. Review the [compiler compatibility limitation](/programmable-transactions/sauce/architecture-and-deployments#compiler-and-engine-compatibility) before execution.

## Program

```typescript order-split.sauce.ts theme={null}
import { IERC20 } from "./IERC20.json";
import { IV3SwapRouter } from "./IV3SwapRouter.json";
import { IUniswapV3Pool } from "./IUniswapV3Pool.json";

// Split one order across two Uniswap V3 pools, weighting each leg by the
// pool's live liquidity, swap both legs via SwapRouter02, then require the
// combined output clears the floor — all inside one transaction. Router is
// fixed (Base mainnet); the tokens, amount, caller, pools and floor are
// parameters.

function main(
  tokenIn: Address, tokenOut: Address, amountIn: Uint256, caller: Address,
  pool1Addr: Address, pool2Addr: Address, minOut: Uint256,
): Uint256 {
  const router: Address = 0x2626664c2603336E57B271c5C0b26F421741e481;

  // Pull the input tokens in and let the router spend them.
  const token = IERC20.at(tokenIn);
  token.transferFrom(caller, ctx.self(), amountIn);
  token.approve(router, amountIn);

  // Weight the split by each pool's live liquidity at inclusion.
  const liqA: Uint256 = IUniswapV3Pool.at(pool1Addr).liquidity();
  const liqB: Uint256 = IUniswapV3Pool.at(pool2Addr).liquidity();
  const liqTotal: Uint256 = liqA + liqB;
  if (liqTotal === 0) throw "no liquidity";

  const legA: Uint256 = (amountIn * liqA) / liqTotal;
  const legB: Uint256 = amountIn - legA;

  const feeA: Uint256 = IUniswapV3Pool.at(pool1Addr).fee();
  const feeB: Uint256 = IUniswapV3Pool.at(pool2Addr).fee();

  // Swap each leg. Keys a-g map positionally onto ExactInputSingleParams:
  //   a=tokenIn, b=tokenOut, c=fee, d=recipient, e=amountIn, f=amountOutMinimum, g=sqrtPriceLimitX96
  const r = IV3SwapRouter.at(router);
  const outA: Uint256 = r.exactInputSingle({ a: tokenIn, b: tokenOut, c: feeA, d: caller, e: legA, f: 0, g: 0 });
  const outB: Uint256 = r.exactInputSingle({ a: tokenIn, b: tokenOut, c: feeB, d: caller, e: legB, f: 0, g: 0 });

  // Recombine and enforce the floor across the whole order.
  const outTotal: Uint256 = outA + outB;
  if (outTotal < minOut) throw "min out not met";
  return outTotal;
}
```

## What to notice

* `throw` aborts the program and reverts every leg. There is no partial fill.
* The split ratio is computed from `liquidity()` read in the same block, not from an off-chain estimate.

## Run it

Same as the [best-pool swap](/cookbook/sauce/best-pool-swap#run-it): compile for `evm` with the three ABI files beside the source, append seven arguments, execute through your Pot.

## Troubleshooting

If execution reverts, check the input balance, allowance to the Pot, pool pair, fee tiers and minimum output. Simulate the complete call and estimate gas before submission. A quote or swap failure reverts the transaction.

## Next steps

Review [SauceScript contract calls](/programmable-transactions/sauce/saucescript#contract-interop) or [package the program as an intent](/programmable-transactions/sauce/programs-as-intents).
