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

# swap: Parameter normalization

> Parameter normalization: 2 exports of the swap module of @eco-incorp/sauce, including toSwapParams, amountSpecifiedFor.

The `swap` namespace emits a complete `function main() { ... }` program with one `ISauceRouter.swap(...)` statement per spec. Compile with `baseDirs: [...swap.SWAP_BASE_DIRS]`.

```typescript theme={null}
import { swap } from "@eco-incorp/sauce";
```

This page covers `sdk/dist/swap/params.d.ts`.

<Note>
  Generated from the type declarations shipped in `@eco-incorp/sauce` 0.99.4. Each entry shows the package authors' JSDoc and declaration for this SDK version. For runtime compatibility and deployed addresses, see [architecture and deployments](/programmable-transactions/sauce/architecture-and-deployments).
</Note>

### `swap.toSwapParams`

*Function* · `sdk/dist/swap/params.d.ts`

The whole normalization + sign + defaulting + guard decision: lowers a chain-agnostic
`SwapSpec` into a fully normalized `SwapParams` - plain bigints (+ the `"self"`
sentinel for a defaulted `payer`/`recipient`), in exact ABI-declaration order, so
`Object.keys(toSwapParams(spec))` matches the vendored `ISauceRouter.json` component order.

Throws (never emits a program that would revert on-chain) for: poolType 9/10 (Infinity - not
dispatchable through `swap()`, see `UndispatchablePoolType`); any other out-of-range
poolType; UniV4 missing `poolKey`; UniV2 `poolKey.fee >= 1_000_000`; a non-empty `callback` on a
non-callback-driven pool type; a non-empty `callback` with an overridden `payer`/`recipient`; and
any numeric field given as a `number` that is not a safe integer (past 2^53-1 pass a bigint or a
string, since the double has already been rounded).

```typescript theme={null}
export declare function toSwapParams(spec: SwapSpec): SwapParams;
```

### `swap.amountSpecifiedFor`

*Function* · `sdk/dist/swap/params.d.ts`

The single, standalone sign rule (E4.3): given a POSITIVE exact-input amount, returns the
`amountSpecified` value the given pool type's handler actually wants.

* UniV3 (`Router.sol:431`, passthrough into Uniswap V3's own `pool.swap`): POSITIVE = exact
  input (fork-verified; contradicts `IRouter.sol`'s own struct doc comment - see `SwapParams`).
* UniV4 (`Router.sol`'s `unlockCallback` → `V4SwapParams`): NEGATIVE = exact input (Uniswap V4's
  flipped convention). Encoded as the exact two's-complement `uint256` (`2**256 - amountIn`), not
  `-amountIn` - see the module doc for why the compact spelling is deliberately deferred.
* Every other pool type (0, 3, 4, 5, 6, 7, 8): the handler takes `abs(amountSpecified)`, so the
  canonical positive form is used as-is.

```typescript theme={null}
export declare function amountSpecifiedFor(poolType: SwapPoolType, amountIn: bigint): bigint;
```
