> ## 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 programs for a chain

> Compiling programs for a chain: the declaration and description of each of the 18 exports of @eco-incorp/sauce.

The `routes` namespace compiles a SauceScript program for one chain by name and builds the calls that run it. `routes.compileSauceProgram(chain, source, options?)` compiles with the chain's token symbols, protocol namespaces and `@sauce/token` in scope; `routes.encodeEntryArguments(program, values)` encodes `main`'s run-time arguments; `routes.buildSauceEvmCall(params)` builds one `cook(engine, program)` call on a Pot. The chain exports (`Base`, `Solana`, ...), `chain` and `Token` are named exports of the root, and importing the package puts nothing on `globalThis`.

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

Generated from the type declarations of `@eco-incorp/sauce`.

### `routes.compileSauceProgram`

*Function* · `@eco-incorp/sauce`

Compiles a standalone program for `chain`: a program that runs directly on a Pot.

It gets the chain's ambient bundle (`chainId`, protocol addresses and token symbols as
compile-time values scoped to this chain, and the `@sauce/token` functions with no import) and
the token and protocol syntax. So one source compiles, unchanged, for any chain whose names it
uses. `main` may declare typed runtime parameters; `entryParams` reports them and
`encodeEntryArguments` encodes values for them. Or `options.args` binds them into the program as
it compiles.

```typescript theme={null}
export declare function compileSauceProgram(chain: ChainRef, source: string, options?: SauceProgramOptions): CompiledSauceProgram;
```

### `routes.compileSauceRoute`

*Function* · `@eco-incorp/sauce`

Compiles `sauce` for `destination`'s `ChainKind`, and slots the result into exactly one
`CallInput` via the existing `buildSauceEvmCall`/`buildSauceSvmCall` fork - never a new encoder.

`sauce` is a SauceScript file: a module declaring `function main`, or a script whose top-level
statements run as the entry. It reaches the compiler as written, apart from the SDK's rewrites.
A value-returning or early-exiting program declares `main`, since a top-level `return` is not
SauceScript.

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

### `routes.CompiledSauceProgram`

*Interface* · `@eco-incorp/sauce`

A standalone program, compiled for one chain: `compileSauceProgram`'s result.

```typescript theme={null}
export interface CompiledSauceProgram {
    readonly chain: CanonicalChain;
    readonly bytecode: Uint8Array;
    readonly entryEncoding: "abi-v1";
    readonly entryParams: readonly EntryParam[];
    readonly manifest?: AccountManifest;
    readonly derivedAccounts?: Readonly<Record<string, string>>;
    readonly derivedValues?: readonly DerivedValue[];
    readonly stoppable?: readonly string[];
    readonly stoppableRuns?: Readonly<Record<string, number | null>>;
    readonly potMention?: SourcePosition;
    readonly entrySignature: EntrySignature;
    readonly source: string;
}
```

### `routes.CompiledSauceRoute`

*Interface* · `@eco-incorp/sauce`

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

### `routes.SauceCompileOptions`

*Interface* · `@eco-incorp/sauce`

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

### `routes.SauceProgramOptions`

*Interface* · `@eco-incorp/sauce`

`compileSauceProgram`'s options: a route's, and `main`'s arguments to bind.

```typescript theme={null}
export interface SauceProgramOptions extends SauceCompileOptions {
    readonly args?: readonly EntryValue[];
    readonly stops?: readonly string[];
}
```

### `routes.SauceEvmExecutionInput`

*Interface* · `@eco-incorp/sauce`

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

### `routes.SauceSvmExecutionInput`

*Type* · `@eco-incorp/sauce`

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.SourcePosition`

*Interface* · `@eco-incorp/sauce`

A place in a program's text, 1-based.

```typescript theme={null}
export interface SourcePosition {
    readonly line: number;
    readonly column: number;
}
```

### `routes.decodeEntryArguments`

*Function* · `@eco-incorp/sauce`

The strict inverse of `encodeEntryArguments`: `main`'s arguments read back from the bytes a cook
appended to `program`'s bytecode, one value per declared parameter. Throws when `encoded` is not
exactly the encoding `encodeEntryArguments` produces for the values it decodes to - a truncated,
padded or otherwise non-canonical tail - so a decoded value is the only one those bytes carry.

```typescript theme={null}
export declare function decodeEntryArguments(program: ProgramEntry, encoded: Uint8Array): EntryValue[];
```

### `routes.encodeEntryArguments`

*Function* · `@eco-incorp/sauce`

The encoded entry arguments for `program`: `values` checked against `main`'s declared parameters,
in their order, and encoded as the program was compiled to read them. Append them to the program's
bytecode; that whole payload is the `program` of `Pot.cook(engine, program)`.

Throws, naming the parameter and what it takes, on a wrong count or a value that is not of the
declared type.

```typescript theme={null}
export declare function encodeEntryArguments(program: ProgramEntry, values: readonly EntryValue[]): Uint8Array;
```

### `routes.EntryParam`

*Interface* · `@eco-incorp/sauce`

One of `main`'s runtime parameters, as the program declares it.

```typescript theme={null}
export interface EntryParam {
    readonly name: string;
    readonly type: string;
    readonly abi?: AbiParameter;
}
```

### `routes.EntryValue`

*Type* · `@eco-incorp/sauce`

A value for an entry parameter: a scalar as a bigint, safe-integer number or integer string, an
address as hex, a `bool` as a boolean, `bytes` as a `Uint8Array` or hex, an array as an array,
and a tuple as an array of its fields in order or an object naming them.

```typescript theme={null}
export type EntryValue = bigint | number | boolean | string | Uint8Array | readonly EntryValue[] | {
    readonly [field: string]: EntryValue;
};
```

### `routes.isSauceClosure`

*Function* · `@eco-incorp/sauce`

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* · `@eco-incorp/sauce`

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* · `@eco-incorp/sauce`

The ambient-MODULE half of a chain bundle. 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 - `["@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* · `@eco-incorp/sauce`

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.

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* · `@eco-incorp/sauce`

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


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