> ## 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: Source globals and token rewrites

> Source globals and token rewrites: 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.sourceGlobals`

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

Every name a program compiled for `chain` may use without declaring it.

```typescript theme={null}
export declare function sourceGlobals(chain: ChainRef): SourceGlobals;
```

### `routes.SourceChainName`

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

```typescript theme={null}
export interface SourceChainName {
    readonly key: string;
    readonly slug: string;
    readonly id: number;
    readonly kind: CanonicalChain["kind"];
}
```

### `routes.SourceContract`

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

```typescript theme={null}
export interface SourceContract {
    readonly name: string;
    readonly address: `0x${string}`;
    readonly protocol: string;
    readonly default: boolean;
    readonly methods: readonly SourceMethod[];
}
```

### `routes.SourceGlobals`

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

```typescript theme={null}
export interface SourceGlobals {
    readonly chain: SourceChainName;
    readonly tokens: readonly SourceToken[];
    readonly protocols: readonly SourceNamespace[];
    readonly venues: readonly SourceVenue[];
    readonly accounts: readonly SvmAccountExpression[];
    readonly interfaces: readonly SourceInterface[];
    readonly chains: readonly SourceChainName[];
    readonly defines: Readonly<Record<string, bigint | boolean | number>>;
    readonly modules: readonly SourceModule[];
}
```

### `routes.SourceInterface`

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

A contract the registry knows only by its ABI - an interface, with no fixed address - which a
program binds to an address it gives: `Erc4626.Vault.at(vault).totalAssets()`.

```typescript theme={null}
export interface SourceInterface {
    readonly namespace: string;
    readonly name: string;
    readonly protocol: string;
    readonly protocolName: string;
    readonly methods: readonly SourceMethod[];
}
```

### `routes.SourceMethod`

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

```typescript theme={null}
export interface SourceMethod {
    readonly name: string;
    readonly signature: string;
    readonly declaration: string;
    readonly stateMutability: StateMutability;
}
```

### `routes.SourceModule`

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

```typescript theme={null}
export interface SourceModule {
    readonly specifier: string;
    readonly functions: readonly string[];
}
```

### `routes.SourceNamespace`

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

```typescript theme={null}
export interface SourceNamespace {
    readonly namespace: string;
    readonly kind: "protocol" | "family";
    readonly protocols: readonly string[];
    readonly name: string;
    readonly contracts: readonly SourceContract[];
}
```

### `routes.SourceToken`

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

```typescript theme={null}
export interface SourceToken {
    readonly symbol: string;
    readonly address: `0x${string}`;
    readonly decimals: number;
    readonly mint?: string;
    readonly stock?: StockToken;
    readonly tokenProgram?: string;
}
```

### `routes.SourceVenue`

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

A Solana venue a program swaps at by its namespace (`Orca.Whirlpool.swap(pool, …)`).

```typescript theme={null}
export interface SourceVenue {
    readonly namespace: string;
    readonly name: string;
    readonly program: string;
    readonly methods: readonly string[];
}
```

### `routes.rewriteTokenMembers`

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

Rewrites every `<Sym>.<method>(...)` call and every `<holder>.<Sym>` value-position read whose
`<Sym>` is in `tokens` (and not shadowed anywhere in `source`) - see the module doc for the
lowering and the disjointness argument. Purely textual surgery over the ORIGINAL source, driven by
parser ranges - never a re-print of the AST, so everything else (formatting, comments, unrelated
code) survives byte-for-byte. Prepend `tokenImportLines(result)` before compiling the result.
`bound` names what the compile binds beside the source (a define, a contract binding, an ambient
module's export): a `pot` or `self` among them is the caller's own holder, never the Pot.

```typescript theme={null}
export declare function rewriteTokenMembers(source: string, tokens: TokenSymbols, native?: NativeCoin, bound?: ReadonlySet<string>): TokenRewriteResult;
```

### `routes.REWRITABLE_METHODS`

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

Every method the SYMBOL syntax lowers: the writes, plus the one read it has always offered.

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

### `routes.tokenImportLines`

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

The import lines a rewritten source needs, for the caller to prepend. The order is fixed, so a
given program always gets the same text and so the same bytecode.

```typescript theme={null}
export declare function tokenImportLines({ writes, erc20 }: TokenImports): readonly string[];
```

### `routes.SafeWrite`

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

```typescript theme={null}
export type SafeWrite = keyof typeof SAFE_WRITES;
```

### `routes.TokenImports`

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

What a rewritten source now needs imported.

```typescript theme={null}
export interface TokenImports {
    readonly writes: ReadonlySet<SafeWrite>;
    readonly erc20: boolean;
}
```

### `routes.TokenRewriteResult`

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

```typescript theme={null}
export interface TokenRewriteResult extends TokenImports {
    readonly source: string;
    readonly rewrote: boolean;
    readonly memberSites: number;
    readonly balanceSites: number;
    readonly freeHolders?: ReadonlyMap<string, string>;
}
```

### `routes.TokenSymbols`

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

The token symbols the rewrites recognise: the registry-resolved `symbol -> address` map, or a
bare set of symbols. Every rewrite emits the symbol itself, which the compile's defines resolve,
so the two forms rewrite alike.

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

### `routes.SvmAccountExpression`

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

An account expression for a person: what a program writes, the account, how it is derived.

```typescript theme={null}
export interface SvmAccountExpression {
    readonly expression: string;
    readonly account: string;
    readonly derive: string;
}
```


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