> ## 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: Swap source emission

> Swap source emission: 5 exports of the swap module of @eco-incorp/sauce, including swapCallStatement, swapSource, swapImportLines, SWAP_BASE_DIRS, SwapSourceOptions.

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/source.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.swapCallStatement`

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

One `ISauceRouter.at(ctx.self()).swap({...})` statement for `spec` - for splicing into a
larger, hand-written program. Runs the FULL `toSwapParams` normalization/guard pass (a
`"balance"` `amountIn` reuses every other field's normalization, only the amount itself is
emitted as a runtime expression instead of a literal).

```typescript theme={null}
export declare function swapCallStatement(spec: SwapSourceSpec): string;
```

### `swap.swapSource`

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

A complete, compilable `function main() { ... }` program: one `ISauceRouter.swap(...)` statement
per spec, in the given order, inside ONE function - because `V12Pot.cook` takes exactly one
program (its own doc), a multi-hop route is ONE program with N swap statements, not N separate
cooks. See `sdk/src/swap/index.ts` for the full compile → `routes.buildSauceEvmCall`
seam.

```typescript theme={null}
export declare function swapSource(spec: SwapSourceSpec | readonly SwapSourceSpec[], opts?: SwapSourceOptions): string;
```

### `swap.swapImportLines`

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

The import lines a `swapSource(specs)` program needs - `ISauceRouter` always, plus `IERC20` iff
any spec uses `amountIn: "balance"`. Extracted so `swapThenDepositSource` (E4.2's composition
seam) can union these with the deposit side's own import lines instead of duplicating this rule;
`swapSource` itself just calls this, so its own output is unaffected byte-for-byte.

```typescript theme={null}
export declare function swapImportLines(specs: SwapSourceSpec | readonly SwapSourceSpec[]): readonly string[];
```

### `swap.SWAP_BASE_DIRS`

*Variable* · `sdk/dist/swap/source.d.ts`

`baseDirs` for compiling any program `swapSource`/`swapCallStatement` produces - resolves the
generated `import { ISauceRouter } from "./artifacts/ISauceRouter.json"` (and, for a `"balance"`
leg, `./artifacts/IERC20.json`) against this installed package's dist root. Same value/pattern as
`sdk/src/recipes/index.ts`'s `SAUCE_BASE_DIRS`.

```typescript theme={null}
SWAP_BASE_DIRS: readonly string[]
```

### `swap.SwapSourceOptions`

*Interface* · `sdk/dist/swap/source.d.ts`

```typescript theme={null}
export interface SwapSourceOptions {
    functionName?: string;
    imports?: readonly string[];
}
```
