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

# @sauce libraries

> Use the token and swap libraries bundled with the Sauce SDK in your SauceScript programs.

The Sauce SDK includes `@sauce/*` libraries for token operations and swaps. Import them inside a SauceScript program; the compiler includes the required code in your program. You do not install or deploy these libraries separately.

Use these imports in `.sauce.ts` programs. For application code that compiles and submits programs, use the [TypeScript SDK](https://docs.eco.com/sauce-sdk/typescript/overview.md).

| Library | Purpose | Import |
| - | - | - |
| [`@sauce/token`](https://docs.eco.com/sauce-libraries/token) | token reads and checked writes, for ERC-20, SPL Token and Token-2022 | none needed; `import { transfer } from "@sauce/token"` also works |
| [`@sauce/router`](https://docs.eco.com/sauce-libraries/router) | one swap function per venue | `import { uniswapV3 } from "@sauce/router"` |

## Importing a library

A program imports a library's functions by name, like any module. This one imports `@sauce/router`'s `uniswapV3` and calls `@sauce/token`'s `transfer` with no import:

```ts swap-and-pay.sauce.ts theme={null}
// Sells `amount` of the Pot's WETH for USDC in the chain's 0.05% Uniswap V3 pool, then pays the
// USDC received to `to` and returns it. Below `minOut` USDC the whole transaction reverts.
import { uniswapV3 } from "@sauce/router";

function main(amount: Uint256, minOut: Uint256, to: Address): Uint256 {
  const pool = UniswapV3.Factory.getPool(WETH, USDC, 500);
  require(pool != 0, "no 0.05% pool");
  const received = uniswapV3(pool, WETH, USDC, amount, 0, minOut, pot);
  transfer(USDC, to, received);
  return received;
}
```

The CLI, MCP server, `routes.compileSauceProgram` and actions compiler resolve bundled `@sauce/*` imports automatically. When you use the raw compiler, configure a resolver with the package's `resolveSdkModule` and `resolveSdkPackage` ([Compiling programs](https://docs.eco.com/sauce-sdk/typescript/compiling.md#programs-that-import-a-library)).

## `@sauce/token` with no import

The `@sauce/token` functions are in scope in every program the `sauce` command or `routes.compileSauceProgram` compiles, with the token as the first argument, as in `transfer(USDC, to, received)` above. The token methods, `USDC.transfer(to, amount)`, `Token(token).approve(spender, amount)` and `pot.USDC`, compile to calls into the same functions ([Names](https://docs.eco.com/sauce/names.md)). A name the program declares or imports itself takes precedence over the library's.

## EVM and Solana implementations

Each library has an EVM implementation and a Solana implementation. The compiler selects the implementation for your target chain:

* **`@sauce/token`** has the same reads and writes on both, with Solana's taking the accounts they read or move through. `ownerOf`, `transferChecked` and `approveChecked` are Solana only; `permit` and `permitTransferFrom` are EVM only.
* **`@sauce/router`** has a different set of functions on each target: the EVM venues on EVM chains, the Solana venues on Solana.

A function available on only one target produces a compile error on the other. For example, importing an EVM swap function in a Solana program fails at the import:

```ts router-on-solana.sauce.ts theme={null}
import { uniswapV3 } from "@sauce/router";

function main(pool: Address, tokenIn: Address, tokenOut: Address) {
  uniswapV3(pool, tokenIn, tokenOut, 1, 0, 0, pot);
}
```

```text theme={null}
`uniswapV3` is not exported by module "/@eco-incorp/sauce/std/router/router.svm.js"
```

Called with no import, a `@sauce/token` function the target does not support fails with "`permit` is called but never declared" (here `permit` on Solana). A `@sauce/router` function needs its import on every chain: without one it fails with "`uniswapV3` is called but never declared".

## Next steps

* [@sauce/token](https://docs.eco.com/sauce-libraries/token.md): every token function, what it checks and what it refuses.
* [@sauce/router](https://docs.eco.com/sauce-libraries/router.md): the swap functions, the venues and the try forms.
* [Layout of a program](https://docs.eco.com/sauce/program-layout.md): imports, scripts and `main`.
* [Sauce SDK quickstarts](https://docs.eco.com/quickstarts/sauce/overview.md): complete programs that swap, lend and pay.


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