# Integrate QUOTRON swaps on Ink

Last updated 2026-11-18.

QUOTRON trades in one pool, against native ETH, inside Calamari's PoolManager
on Ink. Calamari is a Uniswap-v4-compatible deployment. It is not Uniswap's
own. There is no project router, no hosted quote API and no API key: quote
with Calamari's V4Quoter by `eth_call` and execute through a router that is
bound to Calamari's PoolManager. The Quotrons site uses Calamari's Universal
Router, and so does this guide.

Routing engines and executor contracts: read
[integration-aggregators.md](/integration-aggregators.md) as well.

## Live deployment

| Item | Value |
| --- | --- |
| Network | Ink |
| Chain id | `57073` |
| Public RPC | `https://rpc-gel.inkonchain.com` |
| Explorer | `https://explorer.inkonchain.com` |
| QUOTRON (ERC-20, 18 decimals) | `0xfe858a0Dd13DB45Cc11E89902B44e139865e2012` |
| Fee hook | `0x4430996A106caF74658c4D6F62b4336fb263e5DC` |
| PoolManager (Calamari) | `0x6E4723A612831AfB9f5B2a5aE22723c37aAB9560` |
| Universal Router (Calamari) | `0x88B60D8d91457C297D50f3739481Db10c9097e5C` |
| V4Quoter (Calamari) | `0x0739Cbf29d499e8c6C3c0b2e3bC2151E986AAA3c` |
| StateView (Calamari) | `0x9Bf3f07e41e05D658248467760C745E278EF6211` |
| Permit2 | `0x000000000022D473030F116dDEE9F6B43aC78BA3` |
| Pool id | `0x2edb48a4d01bf1cccd40410c6ed38efdc955bc8d8e8e73c535b7236611df4a5a` |

Pool key:

| Field | Value |
| --- | --- |
| currency0 | native ETH, `0x0000000000000000000000000000000000000000` |
| currency1 | QUOTRON, `0xfe858a0Dd13DB45Cc11E89902B44e139865e2012` |
| fee | `8388608` (`0x800000`, the dynamic-fee flag) |
| tickSpacing | `60` |
| hooks | `0x4430996A106caF74658c4D6F62b4336fb263e5DC` |

Buying QUOTRON is `zeroForOne = true`. ETH and QUOTRON both use 18 decimals.

Machine-readable: [manifest.json](/integration/manifest.json). Full
reference: [quotrons-llm.md](/quotrons-llm.md). Every contract's verified
source and ABI are on its explorer page;
`https://explorer.inkonchain.com/api/v2/smart-contracts/ADDRESS` returns the
ABI as JSON.

## What a swap costs

- **3% of the ETH side**, on buys and sells, taken by the fee hook inside the
  swap: 2% to the rewards converter, 0.7% to the platform, 0.3% to the
  creator. It is a constant (`FEE_BPS = 300`) in a hook that has no owner. It
  is the same for every address.
- **Calamari's protocol fee**: 0.1% in each direction on 2026-11-18. Calamari
  sets it. Read it from `StateView.getSlot0(poolId).protocolFee`, which packs
  12 bits per direction in hundredths of a basis point (1000 = 0.1%).
- The pool's LP fee is zero.

A quote from the V4Quoter already has both charges taken out.

## Rules to build around

1. **Swap first, settle after.** QUOTRON can move into or out of the
   PoolManager only after the hook has reported the swap in the same
   transaction. Calamari's Universal Router works this way. A router that pays
   QUOTRON into the PoolManager before swapping cannot sell.
2. **Exact ETH amounts must fill completely.** A swap that specifies the ETH
   amount (an exact-input buy, an exact-output sell) reverts with
   `PartialFill()` if a price limit stops it early.
3. **Whole tokens carry terminals.** When an ordinary address reaches another
   whole QUOTRON, a terminal is created for it inside the transfer; when it
   drops below one, a terminal is dissolved. That costs gas. A transfer that
   creates more than about 100 terminals does not fit in one Ink transaction
   (16,777,216 gas). Simulate with a gas limit under that ceiling.
4. **Trading can be paused.** Check `token.transfersOpen()` first. While it is
   false every swap reverts with `TradingNotOpen()`.
5. **Sells go through Permit2.** Two approvals: QUOTRON to Permit2, then
   Permit2 to the router.

## Router encoding

`UniversalRouter.execute(bytes commands, bytes[] inputs, uint256 deadline)`.

- Command `0x10` (`V4_SWAP`) takes `abi.encode(bytes actions, bytes[] params)`.
- Exact input: actions `0x06 0x0c 0x0f` (`SWAP_EXACT_IN_SINGLE`, `SETTLE_ALL`,
  `TAKE_ALL`).
- Exact output: actions `0x08 0x0c 0x0f` (`SWAP_EXACT_OUT_SINGLE`,
  `SETTLE_ALL`, `TAKE_ALL`).
- Command `0x04` (`SWEEP`) after a buy returns unused native ETH. The recipient
  `0x0000000000000000000000000000000000000001` means the caller.
- **Calamari's swap structs have six fields**, with `minHopPriceX36` before
  `hookData`. The five-field Uniswap layout does not work with this router.
  Pass `minHopPriceX36 = 0` and empty hook data.
- The quoter takes the standard four-field struct.

## Quote, buy and sell (viem)

This code was run against the live pool on 2026-11-18 in simulation: a buy
filled at exactly the quote, both authorizations and a full sell went through,
and an exact-output buy refunded the unused ETH.

```ts
import {
  createPublicClient, createWalletClient, custom, defineChain,
  encodeAbiParameters, http, parseAbi, parseEther,
} from "viem";

const ink = defineChain({
  id: 57073,
  name: "Ink",
  nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
  rpcUrls: { default: { http: ["https://rpc-gel.inkonchain.com"] } },
  blockExplorers: { default: { name: "Ink Explorer", url: "https://explorer.inkonchain.com" } },
});

const QUOTRON = "0xfe858a0Dd13DB45Cc11E89902B44e139865e2012";
const FEE_HOOK = "0x4430996A106caF74658c4D6F62b4336fb263e5DC";
const ROUTER = "0x88B60D8d91457C297D50f3739481Db10c9097e5C"; // Calamari Universal Router
const QUOTER = "0x0739Cbf29d499e8c6C3c0b2e3bC2151E986AAA3c"; // Calamari V4Quoter
const PERMIT2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
const NATIVE = "0x0000000000000000000000000000000000000000";
const MSG_SENDER = "0x0000000000000000000000000000000000000001"; // router shorthand for the caller

// currency0 is native ETH, so buying QUOTRON is zeroForOne = true.
const POOL_KEY = { currency0: NATIVE, currency1: QUOTRON, fee: 0x800000, tickSpacing: 60, hooks: FEE_HOOK };

const POOL_KEY_TYPE = [
  { name: "currency0", type: "address" },
  { name: "currency1", type: "address" },
  { name: "fee", type: "uint24" },
  { name: "tickSpacing", type: "int24" },
  { name: "hooks", type: "address" },
];
// Calamari's router structs have SIX fields: minHopPriceX36 sits before hookData.
const swapStruct = (amountField, limitField) => [
  {
    type: "tuple",
    components: [
      { name: "poolKey", type: "tuple", components: POOL_KEY_TYPE },
      { name: "zeroForOne", type: "bool" },
      { name: amountField, type: "uint128" },
      { name: limitField, type: "uint128" },
      { name: "minHopPriceX36", type: "uint256" },
      { name: "hookData", type: "bytes" },
    ],
  },
];
const PAIR = [{ type: "address" }, { type: "uint256" }];
const v4 = (actions, params) =>
  encodeAbiParameters([{ type: "bytes" }, { type: "bytes[]" }], [actions, params]);
const sweepEth = encodeAbiParameters(
  [{ type: "address" }, { type: "address" }, { type: "uint256" }],
  [NATIVE, MSG_SENDER, 0n],
);

const routerAbi = parseAbi([
  "function execute(bytes commands, bytes[] inputs, uint256 deadline) payable",
]);
const quoterAbi = parseAbi([
  "struct PoolKey { address currency0; address currency1; uint24 fee; int24 tickSpacing; address hooks; }",
  "struct QuoteExactSingleParams { PoolKey poolKey; bool zeroForOne; uint128 exactAmount; bytes hookData; }",
  "function quoteExactInputSingle(QuoteExactSingleParams params) returns (uint256 amountOut, uint256 gasEstimate)",
  "function quoteExactOutputSingle(QuoteExactSingleParams params) returns (uint256 amountIn, uint256 gasEstimate)",
]);

/** Exact input in either direction. Actions 0x06 0x0c 0x0f:
 *  SWAP_EXACT_IN_SINGLE, SETTLE_ALL, TAKE_ALL. A buy also sweeps unused ETH. */
function exactInput({ buy, amountIn, minOut }) {
  const currencyIn = buy ? NATIVE : QUOTRON;
  const currencyOut = buy ? QUOTRON : NATIVE;
  const swap = encodeAbiParameters(swapStruct("amountIn", "amountOutMinimum"), [
    { poolKey: POOL_KEY, zeroForOne: buy, amountIn, amountOutMinimum: minOut, minHopPriceX36: 0n, hookData: "0x" },
  ]);
  const input = v4("0x060c0f", [
    swap,
    encodeAbiParameters(PAIR, [currencyIn, amountIn]),
    encodeAbiParameters(PAIR, [currencyOut, minOut]),
  ]);
  return buy
    ? { commands: "0x1004", inputs: [input, sweepEth], value: amountIn }
    : { commands: "0x10", inputs: [input], value: 0n };
}

/** Buy an exact amount of QUOTRON for at most maxEthIn. Actions 0x08 0x0c 0x0f:
 *  SWAP_EXACT_OUT_SINGLE, SETTLE_ALL, TAKE_ALL, then the sweep refunds the rest. */
function exactOutputBuy({ quotronOut, maxEthIn }) {
  const swap = encodeAbiParameters(swapStruct("amountOut", "amountInMaximum"), [
    { poolKey: POOL_KEY, zeroForOne: true, amountOut: quotronOut, amountInMaximum: maxEthIn, minHopPriceX36: 0n, hookData: "0x" },
  ]);
  const input = v4("0x080c0f", [
    swap,
    encodeAbiParameters(PAIR, [NATIVE, maxEthIn]),
    encodeAbiParameters(PAIR, [QUOTRON, quotronOut]),
  ]);
  return { commands: "0x1004", inputs: [input, sweepEth], value: maxEthIn };
}

/** Quotes are not view functions: call them with eth_call (simulateContract). */
async function quoteIn(client, account, buy, amountIn) {
  const { result } = await client.simulateContract({
    account,
    address: QUOTER,
    abi: quoterAbi,
    functionName: "quoteExactInputSingle",
    args: [{ poolKey: POOL_KEY, zeroForOne: buy, exactAmount: amountIn, hookData: "0x" }],
  });
  return result[0]; // net of the 3% hook fee and Calamari's fee
}
```

### Buy

```ts
const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
const client = createPublicClient({ chain: ink, transport: http() });
const wallet = createWalletClient({ account, chain: ink, transport: custom(window.ethereum) });
const deadline = () => BigInt(Math.floor(Date.now() / 1000) + 20 * 60);
const slippageBps = 100n; // chosen by the user

const ethIn = parseEther("0.1");
const quoted = await quoteIn(client, account, true, ethIn);
const minOut = (quoted * (10_000n - slippageBps)) / 10_000n;
if (minOut === 0n) throw new Error("minimum output is zero");

const buy = exactInput({ buy: true, amountIn: ethIn, minOut });
// Simulate the exact call under Ink's gas ceiling before asking for a signature.
await client.simulateContract({
  account, address: ROUTER, abi: routerAbi, functionName: "execute",
  args: [buy.commands, buy.inputs, deadline()], value: buy.value, gas: 16_000_000n,
});
const hash = await wallet.writeContract({
  address: ROUTER, abi: routerAbi, functionName: "execute",
  args: [buy.commands, buy.inputs, deadline()], value: buy.value,
});
```

### Sell

Approve only what the sale needs, and wait for each receipt before the next
step.

```ts
const quotronIn = parseEther("1");
const erc20Abi = parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]);
const permit2Abi = parseAbi([
  "function approve(address token, address spender, uint160 amount, uint48 expiration)",
]);

let tx = await wallet.writeContract({
  address: QUOTRON, abi: erc20Abi, functionName: "approve", args: [PERMIT2, quotronIn],
});
await client.waitForTransactionReceipt({ hash: tx });
tx = await wallet.writeContract({
  address: PERMIT2, abi: permit2Abi, functionName: "approve",
  args: [QUOTRON, ROUTER, quotronIn, Math.floor(Date.now() / 1000) + 30 * 60],
});
await client.waitForTransactionReceipt({ hash: tx });

const ethOut = await quoteIn(client, account, false, quotronIn);
const minEthOut = (ethOut * (10_000n - slippageBps)) / 10_000n;
const sell = exactInput({ buy: false, amountIn: quotronIn, minOut: minEthOut });
await client.simulateContract({
  account, address: ROUTER, abi: routerAbi, functionName: "execute",
  args: [sell.commands, sell.inputs, deadline()], gas: 16_000_000n,
});
await wallet.writeContract({
  address: ROUTER, abi: routerAbi, functionName: "execute",
  args: [sell.commands, sell.inputs, deadline()],
});
```

Selling below a whole QUOTRON dissolves the seller's most recent dark
terminal. Hardwired terminals are not affected by any token movement.

### Buy an exact amount of QUOTRON

```ts
const quotronOut = parseEther("0.25");
const { result } = await client.simulateContract({
  account, address: QUOTER, abi: quoterAbi, functionName: "quoteExactOutputSingle",
  args: [{ poolKey: POOL_KEY, zeroForOne: true, exactAmount: quotronOut, hookData: "0x" }],
});
const cost = result[0]; // fees included
const maxEthIn = (cost * (10_000n + slippageBps) + 9_999n) / 10_000n;
const top = exactOutputBuy({ quotronOut, maxEthIn });
await wallet.writeContract({
  address: ROUTER, abi: routerAbi, functionName: "execute",
  args: [top.commands, top.inputs, deadline()], value: top.value,
});
// The router refunds whatever ETH the swap did not use.
```

## Preflight

1. Require chain id `57073`.
2. Read `token.transfersOpen()`. It is true only when the token is launched
   and not paused.
3. Read Calamari's fee from `StateView.getSlot0(poolId)`.
4. Quote with the V4Quoter. For a sell, read the balance,
   `token.allowance(user, Permit2)` and `Permit2.allowance(user, token,
   router)`.
5. Show the input, the quote, both fees, the slippage and the minimum
   received.
6. Simulate the exact router call with a gas limit under 16,777,216. If it
   reverts, do not send it.
7. Send only after the user has approved.

## Errors you may see

| Selector | Error | Meaning |
| --- | --- | --- |
| `0xe09f0331` | `TradingNotOpen()` | The token is not launched or is paused |
| `0xd964f528` | `PartialFill()` | A swap that specifies the ETH amount did not fill completely |
| `0x99b6a9eb` | `VenueNotAllowed(address,bytes32,bool)` | QUOTRON moved to or from the PoolManager without reported flow, or to or from a refused venue |
| `0xab35696f` | `ContractPaused()` | The token is paused |
| `0x8b063d73` | `V4TooLittleReceived(uint256,uint256)` | Output below the minimum (router) |
| `0x12bacdd3` | `V4TooMuchRequested(uint256,uint256)` | Cost above the maximum (router) |
| `0x5bf6f916` | `TransactionDeadlinePassed()` | Deadline passed (router) |
| `0xd81b2f2e` | `AllowanceExpired(uint256)` | No Permit2 allowance for the router, or it expired |
| `0xf96fb071` | `InsufficientAllowance(uint256)` | Permit2 allowance below the amount |

## Not on Ink

The contracts this guide described before 2026-11-18 (`QuotronWethRouter`,
`QuotronWethQuoter`, `QuotronWethHook`, `Quotron404V2`) were on Robinhood
Chain. That deployment is retired and its token is paused. The ABI files of
those names under `/integration/` are kept for reference only.

Support and addresses: [quotrons.cash/docs](https://quotrons.cash/docs)
