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

# routes: Compiling a route body

> Compiling a route body: 18 exports of the routes module of @eco-incorp/sauce, including chain, chainAccessors, compileSauceRoute, wrapSauceBody, CompiledSauceRoute, SauceCompileOptions.

The `routes` namespace packages a Sauce program as an Eco intent. `Base(body, options)` and the other chain globals (installed by importing the root package) forward to `routes.openRoute(destination, body, options)`, which returns a `PendingSauceRoute`; `.nest(...)` adds child intents and `.reward(...)` returns a `BuiltIntent`.

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

This page covers `sdk/dist/routes/accessors.d.ts`, `sdk/dist/routes/sauce-route.d.ts`, `sdk/dist/routes/closure.d.ts`, `sdk/dist/routes/ambient.d.ts`, `sdk/dist/routes/token-rewrite.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>

### `routes.chain`

*Function* · `sdk/dist/routes/accessors.d.ts`

Dynamic front door for a runtime-resolved chain (`chain('eth')`,
`chain(8453)`, `chain('BNB Chain')`) - delegates to `requireChain`, so it
inherits the registry's alias resolution and unknown-chain throw.

```typescript theme={null}
export declare function chain(ref: number | string | bigint | CanonicalChain): ChainGlobal;
```

### `routes.chainAccessors`

*Variable* · `sdk/dist/routes/accessors.d.ts`

The generated record: `const { Base, Solana, Ethereum } = chainAccessors;` -- each entry is
BOTH callable (`Base(sauce, opts)`) and a namespace (`Base.chain`/`Base.route`).

```typescript theme={null}
chainAccessors: ChainGlobals
```

### `routes.compileSauceRoute`

*Function* · `sdk/dist/routes/sauce-route.d.ts`

Compiles `sauce` (a complete `function main(){...}` program, or a bare body auto-wrapped by
`wrapSauceBody`) for `destination`'s `ChainKind`, and slots the result into exactly one
`CallInput` via the existing `buildSauceEvmCall`/`buildSauceSvmCall` fork - never a new encoder.

```typescript theme={null}
export declare function compileSauceRoute(destination: ChainRef, sauce: string, execution: SauceEvmExecutionInput | SauceSvmExecutionInput, options?: SauceCompileOptions): CompiledSauceRoute;
```

### `routes.wrapSauceBody`

*Function* · `sdk/dist/routes/sauce-route.d.ts`

```typescript theme={null}
export declare function wrapSauceBody(sauce: string): string;
```

### `routes.CompiledSauceRoute`

*Interface* · `sdk/dist/routes/sauce-route.d.ts`

```typescript theme={null}
export interface CompiledSauceRoute {
    readonly calls: readonly CallInput[];
    readonly compiled: CompileResult;
    readonly source: string;
}
```

### `routes.SauceCompileOptions`

*Interface* · `sdk/dist/routes/sauce-route.d.ts`

```typescript theme={null}
export interface SauceCompileOptions {
    target?: CompileTarget;
    baseDirs?: string[];
    defines?: Record<string, bigint | boolean | number>;
    tokens?: Readonly<Record<string, AddressInput>>;
    contracts?: ContractsConfig;
    accessors?: boolean | ProtocolRewriteOptions;
    ambient?: string[];
}
```

### `routes.SauceEvmExecutionInput`

*Interface* · `sdk/dist/routes/sauce-route.d.ts`

```typescript theme={null}
export interface SauceEvmExecutionInput {
    pot: AddressInput;
    engine: AddressInput;
    value?: bigint | number | string;
}
```

### `routes.SauceSvmExecutionInput`

*Type* · `sdk/dist/routes/sauce-route.d.ts`

Staged SVM execution settings from the route call builder. The caller supplies a finalized CODE
account and its execution accounts. `expectedSha256` is rejected because the engine instruction
does not carry a pin; see `svm/instructions.ts#assertNoExecutePin`.

```typescript theme={null}
export type SauceSvmExecutionInput = SauceSvmCallParams;
```

### `routes.isSauceClosure`

*Function* · `sdk/dist/routes/closure.d.ts`

True for anything `sauceBodyToSource` (rather than the plain string path) should handle.

```typescript theme={null}
export declare function isSauceClosure(body: SauceBody): body is () => unknown;
```

### `routes.sauceBodyToSource`

*Function* · `sdk/dist/routes/closure.d.ts`

Extracts a complete `function main(){...}` program from a closure's own declared source text.
Fails closed (never silently falls back) on anything this first cut doesn't support.

```typescript theme={null}
export declare function sauceBodyToSource(body: () => unknown): string;
```

### `routes.chainAmbient`

*Function* · `sdk/dist/routes/ambient.d.ts`

The ambient-MODULE half of a chain bundle (`chainDefines` above is the scalar-DEFINES half - two
distinct mechanisms, see `plugin/index.ts`'s note). Returns the ambient module specifier list
active for `chain`: whole SauceScript library modules whose exported functions/consts are
broadcast into a chain's compiled program with no `import` line (see
`sauce-route.ts#SauceCompileOptions.ambient`/`rs-compile.ts`).

Currently a SINGLE source of truth, not yet chain-specific: every chain gets the same list, the
plugin manifest's own `ambient` array (`plugin/index.ts#loadPlugin`) - `["@sauce/token"]` by
default, resolved to the SDK's own vendored copy on the route path. Extensible to a genuinely
per-chain bundle later (e.g. an SVM destination activating an SVM-only ambient module an EVM one
shouldn't see) without changing this function's signature - a caller already threads `chain`
through.

```typescript theme={null}
export declare function chainAmbient(_chain: CanonicalChain): string[];
```

### `routes.chainDefines`

*Function* · `sdk/dist/routes/ambient.d.ts`

The chain-scoped ambient defines map for `chain`: `chainId`/`CHAIN_ID`, every EVM protocol
contract address that has a real entry on `chain.id`, and any caller-supplied token symbols.

P8: `protocolAddresses`/`tokens` are read through `loadPluginData()` (`plugin/index.ts`) rather
than importing `descriptors/registry.ts`/`token-registry.ts` directly - the SAME underlying
array/function, re-exposed through the plugin accessor as the single point the SDK reads
Layer-B data through. Byte-identical output: `loadPluginData().protocolAddresses` IS
`DESCRIPTORS` and `.tokens` IS `resolveTokenMap`, not a copy.

```typescript theme={null}
export declare function chainDefines(chain: CanonicalChain, opts?: AmbientDefinesOptions): Record<string, bigint | boolean | number>;
```

### `routes.AmbientDefinesOptions`

*Interface* · `sdk/dist/routes/ambient.d.ts`

```typescript theme={null}
export interface AmbientDefinesOptions {
    readonly tokens?: Readonly<Record<string, AddressInput>>;
}
```

### `routes.rewriteTokenMembers`

*Function* · `sdk/dist/routes/token-rewrite.d.ts`

Rewrites every `<Sym>.transfer/.approve/.balanceOf(...)` call (U4) and every `<holder>.<Sym>`
value-position read (balance sugar) whose `<Sym>` is in `tokens` (and not shadowed anywhere in
`source`) - see the module doc for the full disjointness argument. Purely textual surgery over
the ORIGINAL source, driven by acorn ranges - never a re-print of the AST, so everything else
(formatting, comments, unrelated code) survives byte-for-byte.

```typescript theme={null}
export declare function rewriteTokenMembers(source: string, tokens: TokenSymbols): TokenRewriteResult;
```

### `routes.REWRITABLE_METHODS`

*Variable* · `sdk/dist/routes/token-rewrite.d.ts`

```typescript theme={null}
REWRITABLE_METHODS: ReadonlySet<string>
```

### `routes.TokenRewriteResult`

*Interface* · `sdk/dist/routes/token-rewrite.d.ts`

```typescript theme={null}
export interface TokenRewriteResult {
    readonly source: string;
    readonly rewrote: boolean;
    readonly memberSites: number;
    readonly balanceSites: number;
}
```

### `routes.TokenSymbols`

*Type* · `sdk/dist/routes/token-rewrite.d.ts`

Either the full registry-resolved `symbol -> address` map (enables BOTH rewrites), or a bare set
of symbols with no addresses (U4 only -- the sugar has no address to inline, so it yields no
sites; documented, not a silent surprise -- see the module doc).

```typescript theme={null}
export type TokenSymbols = ReadonlyMap<string, bigint> | ReadonlySet<string>;
```

### `routes.SauceBody`

*Type* · `sdk/dist/routes/closure.d.ts`

```typescript theme={null}
export type SauceBody = string | (() => unknown);
```
