> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boltliquidity.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Off-Chain Quoting Setup

> Simulate Bolt swaps off-chain with deterministic results. Index pool state, fetch oracle prices, and compute amountOut locally for sub-300ms quote latency.

Bolt's pricing and execution logic is fully deterministic given the current pool state and oracle price. This means you can simulate `amountIn` to `amountOut` off-chain without issuing repeated on-chain quote calls, and get identical results to what the Outpost would return on-chain.

<Info>
  Off-chain simulation is recommended for applications that require sub-300ms quote latency, route optimization across many liquidity sources, or trade splitting and pathfinding. If you only need a quick quote for a single swap, [simulateSwap()](https://docs.boltliquidity.io/sui-typescript-sdk#simulate-a-swap) in the SDK handles this in one call.
</Info>

***

## How off-chain quoting works

Unlike traditional AMMs, where price depends on pool depth and changes with every trade, Bolt's oracle-anchored pricing is independent of pool depth. A quote remains valid as long as the oracle price and pool inventory are unchanged. No bonding curve, no price impact, no quote staleness between trades.

<Steps>
  <Step title="Index current pool state">
    Pull the current inventory, fee parameters, and pool thresholds from the Bolt Outpost. Pool state changes infrequently between swaps, so you can cache it locally.

    <Note>
      The TypeScript SDK does not currently expose `QuoteAssetReserve` queries. Off-chain quoting requires direct on-chain state indexing. Contact the Bolt team for guidance on querying pool reserves directly. Reach out on [Telegram](https://t.me/BoltOnboarding) or [book a call](https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ0h8Dz0XD9uiYnrWu6PUHvRfnuoNjXyCJYnzFX8t548I1YO-qnJxJSOrvuWeenqacByagNyyB0E).
    </Note>
  </Step>

  <Step title="Fetch the current oracle price">
    Query the Bolt Oracle for the live reference price. This is the authoritative price used for all settlement math.

    ```typescript theme={null}
    // Get price for a specific pair
    const price = await client.getPrice(
      '0x2::sui::SUI',
      '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC'
    );

    console.log(`SUI/USDC price: ${price.price}`);
    console.log(`Expires: ${new Date(Number(price.expiryTime) / 1000000)}`);

    // Or fetch all prices at once for batch evaluation
    const allPrices = await client.getAllPrices();
    ```
  </Step>

  <Step title="Apply the Bolt contract math">
    Compute `amountOut` using the oracle price, fee rates, and inventory constraints. Because pricing is deterministic, the result is identical to what the on-chain Outpost would return.

    <Note>
      Contact the Bolt team to obtain the latest contract math formulas and reference test vectors. These must always match the current on-chain implementation. Reach out on [Telegram](https://t.me/BoltOnboarding) or [book a call](https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ0h8Dz0XD9uiYnrWu6PUHvRfnuoNjXyCJYnzFX8t548I1YO-qnJxJSOrvuWeenqacByagNyyB0E).
    </Note>
  </Step>

  <Step title="Evaluate inventory and execute">
    Confirm that pool inventory is sufficient to settle the requested amount. If inventory is available, submit the swap on-chain with confidence that the quote matches.

    ```typescript theme={null}
    // Check pool liquidity before submitting
    const liquidity = await client.getAllBaseAssetsLiquidity();

    Object.entries(liquidity).forEach(([denom, details]) => {
      console.log(`${denom}: ${details.baseLiquidity.amount} available`);
    });
    ```
  </Step>
</Steps>

***

## Quick path: simulateSwap()

If you don't need to implement the full contract math locally, the SDK's `simulateSwap()` method performs a deterministic dry run against the current pool state and oracle price with no gas cost.

```typescript theme={null}
const simulation = await client.simulateSwap({
  assetIn: '0x2::sui::SUI',
  amountIn: '1000000000', // 1 SUI (9 decimals)
  assetOut: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',
});

console.log(`Expected output: ${simulation.amountOut}`);
console.log(`Protocol fee: ${simulation.protocolFee}`);
console.log(`LP fee: ${simulation.lpFee}`);
console.log(`Total fees: ${simulation.totalFees}`);
```

<Tip>
  `simulateSwap()` is the fastest way to get a quote. Use it for single-pair checks and UI price displays. Reserve the full off-chain math implementation for batch route evaluation across many pools and pairs.
</Tip>

***

## Determinism guarantees

<AccordionGroup>
  <Accordion title="Same inputs, same outputs">
    Given identical pool state and oracle price, the computed `amountOut` is exactly the same whether calculated on-chain by the Outpost or off-chain by your integration. There is no randomness, no auction, and no variable spread.
  </Accordion>

  <Accordion title="No curve-based slippage">
    Traditional AMMs derive price from a bonding curve where every trade moves the price. Bolt's prop-AMM references an external oracle, so trade size does not affect the quoted price. A 10 USDC swap and a 1,000 USDC swap receive the same rate per unit.
  </Accordion>

  <Accordion title="Quote stability across trades">
    Because pricing is oracle-anchored rather than inventory-derived, quotes remain valid across multiple consecutive trades as long as the oracle price and pool inventory are unchanged. This eliminates the "quote goes stale the moment someone else trades" problem.
  </Accordion>
</AccordionGroup>

***

## Use cases

<Tabs>
  <Tab title="DEX Aggregators">
    Aggregators evaluate multiple routes simultaneously by simulating swaps across all available pools. Off-chain quoting enables batch route evaluation without repeated RPC calls.

    <Steps>
      <Step title="Cache pool state for all Bolt pools" />

      <Step title="Compute quotes for all possible routes in parallel" />

      <Step title="Select the route with the best amountOut" />

      <Step title="Submit a single on-chain settlement" />
    </Steps>
  </Tab>

  <Tab title="DApp Builders">
    Builders integrate Bolt quotes into user interfaces to display real-time execution prices and validate user input before trade submission. Off-chain simulation enables instant price updates without waiting for on-chain confirmation.

    <Steps>
      <Step title="Cache pool state locally" />

      <Step title="Update the UI price on every user input change" />

      <Step title="Validate that the pool has sufficient inventory" />

      <Step title="Submit the trade knowing the quote is still valid" />
    </Steps>
  </Tab>
</Tabs>

***

## Handling state freshness

<AccordionGroup>
  <Accordion title="When to refresh pool state">
    Pool state changes when swaps execute or when pool parameters are updated. For most integrations, refreshing every 10 to 15 seconds provides a good balance between accuracy and RPC efficiency. For high-frequency applications, use WebSocket subscriptions to the Outpost contract if your RPC provider supports them.
  </Accordion>

  <Accordion title="Checking oracle price expiry">
    Every oracle price includes an `expiryTime` field (Unix timestamp in nanoseconds). Always check that the price has not expired before using it in your local math. The SDK's `getOracleConfig()` method returns the `priceExpireTime` setting so you can anticipate refresh intervals.

    ```typescript theme={null}
    const config = await client.getOracleConfig();
    console.log('Price expiry window:', config.priceExpireTime?.secs, 'seconds');
    ```
  </Accordion>

  <Accordion title="Re-validating before submission">
    For high-value trades, re-check pool inventory immediately before on-chain submission. Pool state can change between your simulation and the transaction landing on-chain. Setting `minimumAmountOut` on the swap call provides an additional safety net.
  </Accordion>
</AccordionGroup>

***

## Reference materials

Bolt provides swap math formulas, worked examples, and reference test vectors for off-chain implementation. These must always match the current on-chain contracts.

<Warning>
  The contract math and test vectors are distributed directly by the Bolt team to ensure they stay in sync with the live Outpost. [Contact the team](https://docs.boltliquidity.io/contact) or [book a call](https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ0h8Dz0XD9uiYnrWu6PUHvRfnuoNjXyCJYnzFX8t548I1YO-qnJxJSOrvuWeenqacByagNyyB0E) to obtain the latest version.
</Warning>

<CardGroup cols={2}>
  <Card title="Contract Math" icon="square-root-variable" href="/contract-math">
    Oracle-anchored pricing formulas and fee calculations.
  </Card>

  <Card title="Pool State Indexing" icon="database" href="/pool-state-indexing">
    How to index and subscribe to Outpost state changes.
  </Card>

  <Card title="Sui TypeScript SDK" icon="code" href="/sui-typescript-sdk">
    Full API reference including simulateSwap() and pool queries.
  </Card>

  <Card title="Sui Outpost Addresses" icon="map-pin" href="/sui-outpost-addresses">
    Contract addresses for mainnet and testnet.
  </Card>
</CardGroup>
