Overview
routr is one NEAR contract that holds two registries: platforms (a launchpad, a wallet, any front end that opens markets) and pools, one per token, quote and platform. A pool is a constant-product market with a virtual quote reserve: the token side is seeded once, there are no LP shares and no liquidity withdrawal, and the quote side starts from a virtual reserve that, with the seed, sets the opening price. Swaps are a single ft_transfer_call, and a route through two or three pools is one too. Fees are booked per account at swap time and paid out by anyone.
Which build these docs describe. The contract source of 2026-10-05 (commit 7d6f0c3). routr.near runs build 76c5992 (since 2026-09-30). Build 57d03cd is staged and can land from 2026-10-10 18:32 UTC; rows marked staged build exist in it and not in the live build. Rows marked next stage are in the source and in no deployed build yet; planned rows are decided and not yet written, so their arguments may change. routr-dev.testnet runs development builds.
Concepts
Platform
A registered id (for example fastr) with an owner, a fee recipient, a creator_bps and a builder_bps. Registration is open to anyone and costs the record's storage plus a 0.5 NEAR bond that becomes the platform's storage credit. A platform can name up to 8 pool_creators (usually its factory) so nobody else opens pools under its id, and up to 32 approved builders it pays for routing orders.
Pool key
Every pool has a lookup key token|quote|platform_id that is known before the pool exists, so a token contract can embed its own route at creation. Methods that take a pool_id accept the numeric id or the key.
Curve
Price follows x · (y_real + y_virtual) = k. The seed amount and virtual_quote set the opening price (virtual_quote / seed). Sales pay out of the real quote reserve only, never the virtual one. If tokens exist outside the pool that were not bought from it, selling them can take the price below the opening price. A buy that would push the quote reserve past a fixed bound is refused, which bounds the arithmetic on that path.
Frozen terms
At create_pool the pool copies the protocol share, the protocol recipient, the platform recipient, creator_bps and builder_bps; the caller sets fee_bps. Later changes to the platform or the protocol apply to new pools only. The creator can hand its entitlement to another account, and the platform's list of approved builders applies to all its pools at once.
Who receives a swap's output
In every deployed build the recipient field names any account. From the next stage the output goes to the sender unless the sender is one of the platform's pool creators (a launchpad's factory delivering a creator's first buy to the creator or to an escrow); any other recipient is refused with reason recipient and the input returned. The reason: every new recipient is a delivery record that the platform's storage credit pays for, and a stranger naming a fresh account per dust swap could drain that credit at half the cost in gas. next stage
Quickstart
A launchpad's full path with near-api-js: register once, then per launch create the pool, seed it, quote and route a trade, and claim fees. One script runs on either network; NETWORK picks the routr account, wNEAR and the RPC. Before you run it:
- routr needs a storage deposit on your token: call
storage_depositon the token for the routr account. Tokens that register their venues at creation, as fastr's do, need nothing. routr is already registered on mainnet wNEAR and USDC. SEEDis the amount of your token the script puts into the pool, in raw units; replace the example value with yours. A seed is final: there is no way to take it back out.- The example buy spends
BUYwNEAR (default 1). Your account must hold that much wNEAR: callnear_depositon the wNEAR contract to wrap NEAR.
Mainnet
| Account | What |
|---|---|
routr.near | routr |
wrap.near | wNEAR, a quote token |
17208628f84f5d6ad33f0da3bbbeb27ffcb398eac501a31bd6ad2011e36133a1 | native USDC, a quote token |
https://rpc.mainnet.fastnear.com | an RPC endpoint (any mainnet RPC works) |
npm i near-api-js tsx
NETWORK=mainnet PLATFORM=mypad ACCOUNT=mypad.near TOKEN=mytoken.mypad.near SEED=1000000000000000000000000000 npx tsx quickstart.ts
On mainnet the script spends real funds. Registering a platform attaches 0.52 NEAR, about $2.50 at $4.80 per NEAR on 2026-10-05: the 0.5 NEAR bond is kept as the platform's storage credit and is not refunded, and whatever the record's storage does not use of the rest comes back. Each pool attaches the create_pool_deposit that get_launch_status quotes; the unused part is refunded. Then it seeds SEED of your token for good and buys with BUY wNEAR, paying the pool fee (1% in the example) and any price impact. Platform ids are first come, first served and a platform cannot be deleted, so run the same script on testnet first. The signing key is read from ~/.near-credentials/mainnet/.
Testnet
| Account | What |
|---|---|
routr-dev.testnet | routr (development builds) |
wrap.testnet | wNEAR, a quote token |
https://rpc.testnet.fastnear.com | an RPC endpoint |
NETWORK=testnet PLATFORM=mypad ACCOUNT=mypad.testnet TOKEN=mytoken.mypad.testnet SEED=1000000000000000000000000000 npx tsx quickstart.ts
Testnet NEAR is free from the NEAR faucet. routr-dev.testnet runs development builds, which can be ahead of mainnet and are reset when the stored layout changes. The signing key is read from ~/.near-credentials/testnet/.
The script
/**
* routr quickstart for a launchpad (NEAR, near-api-js v5): register your platform once, then per launch
* create the pool, seed it with the token supply, quote and route a first trade, and claim fees.
*
* npm i near-api-js tsx
* NETWORK=mainnet PLATFORM=mypad ACCOUNT=mypad.near TOKEN=mytoken.mypad.near SEED=<raw amount> npx tsx quickstart.ts
* NETWORK=testnet PLATFORM=mypad ACCOUNT=mypad.testnet TOKEN=mytoken.mypad.testnet SEED=<raw amount> npx tsx quickstart.ts
*
* NETWORK picks routr's account, wNEAR and the RPC (mainnet: routr.near, wrap.near; testnet: routr-dev.testnet,
* wrap.testnet). routr must hold a storage deposit on TOKEN before the seed (storage_deposit on the token for the
* routr account); it already has one on wNEAR and native USDC on mainnet.
*
* On mainnet this spends real funds: the 0.5 NEAR platform bond (kept as storage credit, not refunded), the pool's
* storage deposit, the SEED of your token (final: a seed cannot be withdrawn) and BUY wNEAR (default 1) for the
* example buy, which ACCOUNT must already hold (near_deposit on wrap.near wraps NEAR). Try it on testnet first.
*
* Every call below is one contract method; the contract's own docs are in contracts/routr/src/lib.rs.
* Amounts are strings of raw units (yocto for wNEAR). Pools are addressable by their key
* `${token}|${quote}|${platform}` before they exist, so a token can carry its own route.
*/
import { connect, keyStores, Account, utils } from "near-api-js";
const NETWORK = process.env.NETWORK ?? "mainnet";
const NET = ({
mainnet: { routr: "routr.near", wrap: "wrap.near", rpc: "https://rpc.mainnet.fastnear.com" },
testnet: { routr: "routr-dev.testnet", wrap: "wrap.testnet", rpc: "https://rpc.testnet.fastnear.com" },
} as Record<string, { routr: string; wrap: string; rpc: string }>)[NETWORK];
if (!NET) throw new Error(`NETWORK must be mainnet or testnet, not ${NETWORK}`);
const ROUTR = process.env.ROUTR ?? NET.routr;
const PLATFORM = process.env.PLATFORM ?? "mypad";
const ACCOUNT = process.env.ACCOUNT!; // your platform's account (its factory/locker seeds pools)
const WRAP = NET.wrap;
const TGAS = (n: number) => BigInt(n) * 10n ** 12n;
const NEAR = (n: string) => utils.format.parseNearAmount(n)!;
const SEED = process.env.SEED; // raw units of TOKEN to seed; required, because a seed is final
const BUY = process.env.BUY ?? "1"; // wNEAR for the example buy
async function main() {
const near = await connect({
networkId: NETWORK,
nodeUrl: NET.rpc,
keyStore: new keyStores.UnencryptedFileSystemKeyStore(`${process.env.HOME}/.near-credentials`),
});
const me = await near.account(ACCOUNT);
const view = (method: string, args: object) => me.viewFunction({ contractId: ROUTR, methodName: method, args });
// 1. Register the platform once: 70% of the platform's part to each pool's creator, 5% to builders you approve
// (`builders`), 2% to ANY builder that has registered itself on routr (`open_builder_bps`; a wallet, a bot, a
// terminal that pays its own claim storage with `register_builder`), only this account may create pools under
// the id. The 0.5 NEAR bond is the platform's storage credit for the claim keys its pools' swaps create (top it
// up any time with `platform_top_up`).
const existing = await view("get_platform", { platform_id: PLATFORM });
if (existing && existing.owner !== ACCOUNT) {
throw new Error(`platform id ${PLATFORM} belongs to ${existing.owner}; pick another id`);
}
if (!existing) {
await me.functionCall({
contractId: ROUTR, methodName: "register_platform", gas: TGAS(30), attachedDeposit: BigInt(NEAR("0.52")),
args: { platform_id: PLATFORM, fee_recipient: ACCOUNT, creator_bps: 7000, builder_bps: 500,
pool_creators: [ACCOUNT], builders: [], open_builder_bps: 200 },
});
}
// 2. Per launch: check the key, create the pool, seed it. `virtual_quote` sets the starting price:
// opening price = virtual_quote / seed; seeding the whole supply with virtual_quote 1,000 NEAR opens the supply's
// value at 1,000 NEAR. This is an opening price, not a promise about any later price. `fee_schedule` (optional)
// is an opening fee against snipers: here 20% the moment the pool is seeded, falling in a straight line to 1% over
// ten minutes, then the pool's static `fee_bps`; the whole fee is split like the static one (creator, platform,
// protocol, builder), so the first-block buy funds the launch. Both are fixed for the pool's life.
const token = process.env.TOKEN ?? `mytoken.${ACCOUNT}`; // an NEP-141 whose supply this account holds
if (!SEED || !/^[0-9]+$/.test(SEED)) throw new Error("set SEED to the raw amount of TOKEN to seed");
const status = await view("get_launch_status", { token, quote: WRAP, platform_id: PLATFORM });
console.log("launch status", status.state, "terms", status.terms, "deposit", status.create_pool_deposit);
if (status.state === "absent") {
await me.functionCall({
contractId: ROUTR, methodName: "create_pool", gas: TGAS(30), attachedDeposit: BigInt(status.create_pool_deposit),
args: { token, quote: WRAP, platform_id: PLATFORM, creator: ACCOUNT, seeder: ACCOUNT, fee_bps: 100,
virtual_quote: NEAR("1000"),
fee_schedule: { start_bps: 2000, end_bps: 100, duration_ms: String(10 * 60 * 1000) } },
});
}
if (status.state !== "seeded") {
// the seed is one ft_transfer_call of the supply; `expect_creator` binds the pool to the fee recipient you expect
await me.functionCall({
contractId: token, methodName: "ft_transfer_call", gas: TGAS(60), attachedDeposit: 1n,
args: { receiver_id: ROUTR, amount: SEED,
msg: JSON.stringify({ Seed: { pool_id: status.key, expect_creator: ACCOUNT } }) },
});
}
// 3. Quote and route a buy: the quote is what you show before the user signs (fee waterfall, the fee rate in
// force now, impact, executable). `builder` names the integration that earns the builder leg (`builder_tier`
// tells you whether it is approved, open, or earns nothing).
const amountIn = NEAR(BUY);
const q = await view("quote_swap", { pool_id: status.key, token_in: WRAP, amount_in: amountIn, builder: null });
if (!q) throw new Error(`no pool ${status.key}`);
console.log("quote", q.amount_out, "fee bps now", q.fee_bps_applied, "impact bps", q.price_impact_bps,
"executable", q.executable, q.reason ?? "");
if (q.executable) {
const minOut = (BigInt(q.amount_out) * 98n) / 100n; // 2% slippage
await me.functionCall({
contractId: WRAP, methodName: "ft_transfer_call", gas: TGAS(100), attachedDeposit: 1n,
args: { receiver_id: ROUTR, amount: amountIn,
msg: JSON.stringify({ Swap: { pool_id: status.key, min_out: minOut.toString(), recipient: null, builder: null } }) },
});
}
// By output instead ("I want exactly N tokens"): `quote_swap_out` names the least input that buys at least N;
// execute it as the same exact-in swap of `amount_in` with `min_out: N`. `quote_route_out` does the same for a
// `Route` through two or three pools.
const qo = await view("quote_swap_out", { pool_id: status.key, token_out: token, amount_out: "1000000000000000000000", builder: null });
console.log("exact-out: pay", qo.amount_in, "to get at least 1e21, executable", qo.executable, qo.reason ?? "");
// A contract recipient (an Intents vault, your own router) can take the output in the same receipt chain:
// `deliver_msg` is OFF for now (a swap naming one is refused, E_DELIVER_MSG_OFF). When it returns, it makes routr
// pay by `ft_transfer_call(recipient, amount, deliver_msg)` (`deliver_gas` optional,
// 50 Tgas by default; attach it on top). Whatever the recipient's `ft_on_transfer` returns is booked as owed
// to the sender (`withdraw`). The recipient is still the sender unless the sender is one of the platform's
// `pool_creators`.
// { Swap: { pool_id, min_out, recipient: null, builder: null, deliver_msg: JSON.stringify({ ... }), deliver_gas: null } }
// 4. Fees: booked per account at swap time; anyone can push them. A contract recipient reconciles with
// `get_claim_info` (cumulative creator leg vs cumulative delivered) instead of trusting a single push.
const info = await view("get_claim_info", { pool_id: status.key, account: ACCOUNT });
console.log("creator leg", info.fees_creator, "delivered so far", info.delivered);
await me.functionCall({ contractId: ROUTR, methodName: "push", gas: TGAS(40), args: { account: ACCOUNT, token: WRAP } });
// 5. Events for your indexer: NEP-297 standard "routr" 1.1.0 (pool_created with the terms and the schedule,
// pool_seeded with seeded_ms, swap with every fee leg incl. fee_open_builder, builder_tier, fee_bps_applied and
// the reserves after, route, payout with used/refund). Page your own pools with
// get_platform_pools(platform_id, from, limit). A wallet or bot that wants the open builder leg on every
// platform registers once: `register_builder` from its own account with ~0.05 NEAR (the record plus credit for
// its claim storage; `get_builder` shows the credit, `builder_top_up` refills it).
console.log("my pools", await view("get_platform_pools", { platform_id: PLATFORM, from: 0, limit: 20 }));
}
main().catch((e) => { console.error(e); process.exit(1); });
The example registers a platform id only if it is free. If get_platform returns a record, check that its owner, recipient and pool creators are yours before using it.
Messages
Seeding, swapping and routing are NEP-141 transfers to routr with a JSON msg. routr returns the unused amount, so a rejected seed, a swap below min_out or a route that cannot run costs only gas.
Seed (once, from the pool's seeder, the pool's token)
{"Seed": {"pool_id": "<id or token|quote|platform>", "expect_creator": "<account>"}}
expect_creator binds the seed to the creator the seeder expects; if the pool names someone else, the seed is refused.
Swap (either side of a seeded pool)
{"Swap": {"pool_id": "<id or token|quote|platform>", "min_out": "<raw units>", "recipient": null, "builder": null}}
recipient defaults to the sender (and from the next stage must be the sender unless the sender is a pool creator of the platform, see Concepts). builder earns the platform's builder_bps only if the platform approved it; otherwise that leg stays with the platform.
Route (two or three pools in one receipt) staged build
{"Route": {"pool_ids": ["<id or key>", "<id or key>"], "min_out": "<raw units of the last output>", "recipient": null, "builder": null}}
The output of each pool is the input of the next and only the last output leaves the venue. All of it runs or none of it does: if any leg cannot run, or the final output is under min_out, the whole input goes back and a route_rejected event says why. Each leg pays its own pool's fee and emits its own swap event with hop set. A token in the middle of a route is never transferred, so nothing a token contract does on a transfer (a sell tax, a wallet cap) applies to that hop. A leg that would sell more than the pool's real quote reserve is refused (drained) rather than paid short. Preview a route with quote_route.
Methods
| Method | Arguments | Caller | What it does |
|---|---|---|---|
register_platform | platform_id, fee_recipient, creator_bps, builder_bps, pool_creators?, builders?, open_builder_bps? | anyone, payable | Registers a platform. Attach the record's storage plus the 0.5 NEAR bond (the rest is refunded). creator_bps + builder_bps ≤ 10,000. Up to 8 pool creators and 32 builders. open_builder_bps (next stage, default 0) is the share paid to any registered builder a swap names; builder_bps stays the higher rate for the approved list. |
set_platform | platform_id, fee_recipient?, creator_bps?, builder_bps?, owner?, pool_creators?, builders? | platform owner, payable | Changes the platform. Fee terms apply to pools created afterwards; the creator and builder lists apply at once. |
platform_top_up | platform_id | anyone, payable | Adds NEAR to a platform's storage credit. |
create_pool | token, quote, platform_id, creator, seeder?, fee_bps, virtual_quote, fee_schedule? | anyone (or the platform's pool creators), payable | Creates an unseeded pool and freezes its terms. fee_bps in 1..1,000. Attach get_launch_status().create_pool_deposit; the unused part is refunded. fee_schedule {start_bps, end_bps, duration_ms} is the next stage's opening fee: it decays from start_bps to end_bps over duration_ms from the seed, frozen at creation. |
drop_pool | pool_id | platform owner or seeder | Removes an unseeded pool so its key can be created again. A seeded pool can never be removed. |
set_pool_creator | pool_id, creator | the pool's creator, payable | Hands the creator share to another account. |
ft_on_transfer | sender_id, amount, msg | NEP-141 token | Receives a Seed, a Swap or a Route message (below). Returns the unused amount, which the token refunds. Route: staged build and later. |
push | account, token | anyone | Pays what the venue holds for an account in a token (fee shares, undeliverable output). From the next stage the paid record's storage credit goes back to the platform that paid for it. |
withdraw | token | anyone, for themselves | The caller's own push. |
register_builder next stage | (none) | the builder, payable | Registers the caller as an open builder: it can then be named on swaps of any platform that sets open_builder_bps and earns that share. The deposit is the builder's own storage credit, charged for the builder's claim records so a dust swap can never charge a platform for a stranger's records; a builder whose credit is spent stops earning in new quotes until it tops up (builder_topped_up). In the source, under review. |
set_protocol | protocol_fee_bps?, protocol_recipient? | protocol owner, payable | The protocol's share (≤ 3,000 bps) and where it goes, for pools created afterwards. |
set_guardian | guardian? | protocol owner, payable | Names or removes the guardian. |
pause | guardian or owner | Freezes the venue at once: swaps and seeds return their input, every other user call fails with E_PAUSED, transfers already in flight still settle. Cancels a staged unpause. | |
stage_unpause / unpause | protocol owner | Announces an unpause; it can land after upgrade_delay_ms. | |
stage_upgrade | code_hash (sha256, base58) | protocol owner | Announces new code by its hash; the upgrade_staged event carries the hash and the earliest time it can land (now + upgrade_delay_ms). Staging again restarts the clock. |
cancel_upgrade | protocol owner | Withdraws a staged upgrade. | |
apply_upgrade | the wasm bytes as the raw call input (not JSON) | protocol owner, not payable | After the delay, with bytes whose sha256 is the staged hash: schedules one receipt that re-checks the stage (check_dispatch), deploys the bytes and runs their migrate. A stage changed in between, or a failed migrate, fails that receipt and rolls the deploy back; the stage is consumed when migrate lands (upgrade_landed). |
propose_owner / accept_owner | owner? / — | protocol owner, payable / the proposed account | Ownership moves in two steps; accepting clears anything the previous owner had staged. |
Views
| View | Arguments | Returns |
|---|---|---|
get_launch_status | token, quote, platform_id | One read for the pool key, state (absent, created, seeded), the terms, the estimated create_pool deposit, whether swaps are open and the platform's storage credit. |
quote_swap | pool_id, token_in, amount_in, builder? | A snapshot: output, the whole fee waterfall, price before and after, impact in bps, and whether the contract would currently accept it (reason when not: empty, reserve, storage, unseeded, not_in_pool). Null for an unknown pool. State can change before execution: always set min_out. |
quote_route staged build | pool_ids, token_in, amount_in | What a Route through those pools would return now: executable, the final amount_out, and per leg pool_id, token_in, amount_in, token_out, amount_out, fee and fee_token. When it would not run, reason is one of paused, route_len, route_repeat, no_pool, unseeded, not_in_pool, reserve, storage, drained, empty. |
quote_swap_out next stage | pool_id, token_out, amount_out, builder? | The inverse of quote_swap: the input that delivers exactly amount_out, with the same fee waterfall and executable/reason fields. In the source, under review. |
quote_route_out next stage | pool_ids, token_in, amount_out | The inverse of quote_route: amount_in for a wanted final output, per leg. In the source, under review. |
get_pool | pool_id | The pool record: reserves, virtual quote, frozen terms, cumulative volume and fees. pool_id is the numeric id or the key. |
get_pool_id | token, quote, platform_id | The numeric id for a key, if the pool exists. |
get_price | pool_id | Spot price as [quote, token]; quote per token = price[0] / price[1]. |
get_pools | from, limit | Pools by id, at most 100 ids per call. |
get_platform | platform_id | The platform record. |
get_platform_pools | platform_id, from, limit | A platform's pools in creation order. |
get_claim_info | pool_id, account | The pool's cumulative creator leg and what the venue has delivered to the account in the quote: the numbers a contract recipient reconciles. |
get_owed / get_pending / get_delivered | account, token | What the venue holds for an account, what is in flight, and what has arrived. |
get_owed_total | token | Total liabilities in a token. |
get_storage | platform_id? | The venue's storage reserve and a platform's remaining credit, in swaps' worth of claim keys. |
get_protocol | Owner, pending owner, guardian, protocol share and recipient, both caps, pool count, paused, upgrade_delay_ms, the staged upgrade (hash, ready_ms) and a staged unpause's ready_ms. |
Events
NEP-297 logs with standard: "routr", version: "1.0.0". Amounts are strings of raw units. A route emits one swap per leg (with hop) and then one route; index by swap for per-pool trades and by route for what the trader sent and received.
| Event | Data |
|---|---|
platform_registered | platform_id, owner, fee_recipient, creator_bps, builder_bps, pool_creators, builders |
platform_changed | the full platform record after the change |
platform_topped_up | platform_id, by, amount, credit |
pool_created | pool_id, token, quote, platform_id, creator, seeder, fee_bps, virtual_quote, terms |
pool_seeded | pool_id, token, quote, amount, virtual_quote, platform_id |
pool_dropped | pool_id, by |
pool_creator_changed | pool_id, creator |
swap | pool_id, token, quote, trader, recipient, side, token_in, amount_in, token_out, amount_out, fee, fee_protocol, fee_platform, fee_creator, fee_builder, builder, platform_id, hop, real_token, real_quote. One per pool a trade touches; hop is [index, count] when the swap is one leg of a route, null otherwise |
swap_rejected | pool_id, trader, token_in, amount_in, out, min_out, reason: a swap refunded before it touched the pool. reason is min_out, storage or reserve; recipient from the next stage |
route staged build | pool_ids, trader, recipient, token_in, amount_in, token_out, amount_out: emitted after the per-leg swap events |
route_rejected staged build | pool_ids, trader, token_in, amount_in, out, min_out, reason (the quote_route reasons plus min_out and recipient) |
payout | token, account, amount, ok, why (swap or push) |
builder_registered / builder_topped_up next stage | the builder and its storage credit |
protocol_changed | protocol_fee_bps, protocol_recipient, owner |
guardian_changed / owner_proposed / owner_changed | the new guardian, pending owner or owner |
paused / unpause_staged / unpaused | by; ready_ms; — |
upgrade_staged / upgrade_cancelled / upgrade_dispatched / upgrade_landed | code_hash (and ready_ms when staged). Watch upgrade_staged: it is the notice. |
refused_paused | token, sender, amount: a seed or swap returned to its sender because the venue is paused |
invariant_broken | should never appear; emitted instead of failing a payout callback. Monitor it with the liability views |
Errors
A panic code is what a refused call returns. A refused transfer (a swap, a route or a seed through ft_on_transfer) does not panic where it can avoid it: it returns the input and emits swap_rejected, route_rejected or refused_paused with a reason, so the token's refund path runs.
| Code | Meaning |
|---|---|
E_NO_PLATFORM / E_NO_POOL | Unknown platform id or pool. |
E_PLATFORM_EXISTS / E_POOL_EXISTS | The id or key is taken. |
E_PLATFORM_ID | Platform ids are short lowercase identifiers. |
E_BPS | A share is above 10,000 or the two shares add up to more. |
E_TOO_MANY_CREATORS / E_TOO_MANY_BUILDERS | More than 8 pool creators or 32 builders. |
E_FEE | Pool fee outside 1..1,000 bps. |
E_VIRTUAL_QUOTE | Virtual quote is zero or above the bound. |
E_SAME_TOKEN | A pool's token and quote must differ. |
E_NOT_A_POOL_CREATOR | The platform restricts who may open its pools. |
E_PLATFORM_OWNER / E_OWNER_ONLY | Only the platform owner or the protocol owner may call this. |
E_NOT_ALLOWED / E_NOT_CREATOR | drop_pool needs the platform owner or the seeder; set_pool_creator needs the current creator. |
E_NOT_THE_SEEDER / E_NOT_THE_TOKEN / E_SEEDED / E_AMOUNT | Only the named seeder seeds, with the pool's own token, only once, and never zero. |
E_CREATOR_MISMATCH | The seed's expect_creator differs from the pool's creator. |
E_NOT_SEEDED / E_NOT_IN_POOL | A swap into an unseeded pool, or with a token that is not one of the pool's two. |
E_RECIPIENT / E_BUILDER | The recipient or builder is the venue itself. |
E_ROUTE_LEN / E_ROUTE_REPEAT staged build | A Route names fewer than 2 or more than 3 pools, or the same pool twice. |
E_STORAGE_DEPOSIT | The attached deposit does not cover the storage the call adds. |
E_MSG | The transfer message is not a valid Seed, Swap or Route. |
E_PROTOCOL_FEE | set_protocol above the 3,000 bps cap. |
E_PAUSED | The venue is paused; only admin calls and in-flight settlements run. |
E_NOT_GUARDIAN / E_NOT_PROPOSED | Only the guardian or owner may pause; only the proposed owner may accept. |
E_NOT_PAUSED | stage_unpause while the venue is not paused. |
E_NOT_STAGED / E_NOT_YET / E_CODE_HASH | Nothing staged, the delay has not passed, or the bytes do not hash to the staged value. |
E_NOT_PAYABLE / E_NO_CODE | apply_upgrade takes no deposit and needs the wasm as its raw input. |
E_STORAGE_HEADROOM | The account's balance would not cover the new code's storage plus the reserve for in-flight payouts; top it up first. |
E_STALE_DISPATCH | The stage changed between apply_upgrade and its deploy receipt; nothing was deployed. |
E_DELAY / E_DELAY_REQUIRED | new and migrate need a non-zero upgrade delay. |
Fees and terms
A pool charges fee_bps (1 to 1,000) of the quote leg of each swap. From that fee the protocol takes protocol_fee_bps (2,000 today, capped at 3,000 in the code). The remainder is the platform's: creator_bps of it goes to the pool's creator, builder_bps of it to an approved builder named on the swap, and the rest to the platform's recipient. Every leg is visible in quote_swap before signing and in the swap event after. On a route each leg pays its own pool's fee in that pool's quote.
Storage and payouts
Output and fee shares are liabilities first: a swap's output is recorded as pending while its transfer is in flight and becomes owed if the transfer fails (for example an unregistered recipient). push pays anything owed, for anyone, at any time. Claim records cost storage that traders do not attach, so each platform's bond is its own credit, charged per new claim record its pools create (a swap may add at most 12 records' worth: four fee claims with their payer notes, the pending record and its note, two token totals); a platform whose credit is spent has its pools' swaps refused until someone tops it up. The contract also checks the venue's shared storage room before accepting a swap. From the next stage every owed record carries a note of the platform that paid for it, and a push that clears the record returns that storage credit to the platform. next stage The payout callback is written not to panic: it uses saturating arithmetic and emits invariant_broken instead, so monitor get_pending, get_owed and that event.
Gas
Measured figures only, each with its method and date. They are results of those runs, not guarantees; the venue held at most 40 pools in every run so far, and a run at 1,000 and 10,000 pools is planned before we call the gas flat.
| Call | Gas | What was measured | When and where |
|---|---|---|---|
launch (fastr: token, pool, seed, first buy) | 54 Tgas | whole transaction, the same across 15 launches; 53 Tgas on testnet | 2026-09-30, sandbox launch_gas_on_routr_is_flat_over_many_launches and testnet |
Seed | 1.86 Tgas | largest routr receipt, within 0.3% from the 1st to the 40th pool | 2026-09-30, sandbox seed_and_swap_gas_do_not_grow_with_the_number_of_pools |
Swap | 4.05 to 4.15 Tgas | largest routr receipt, over the same 40 pools | 2026-09-30, the same test |
Route, two pools staged build | 14 Tgas | whole transaction (ft_transfer_call on the token, the route, the delivery) | 2026-10-05, sandbox routr_route.rs on the current source |
Route, three pools staged build | 15 Tgas | whole transaction, as above | 2026-10-05, the same test |
register_platform, create_pool, push | pending measurement | will be taken with the next build at 1,000 and 10,000 pools | — |
register_builder, quote_swap_out, a payout with a message, a swap under an opening fee next stage | pending measurement | in the source, under review; measured when the build is staged | — |
What is coming
The next stage is one build with one review round, published from the public source, and it carries everything marked next stage above plus these, marked planned in the tables. Names and arguments are not final until the build is staged.
- Payout with a message: off. A Swap or Route that names a
deliver_msgis refused (E_DELIVER_MSG_OFF) and its input returned. Paying byft_transfer_calltrusts the token's resolver to report what arrived, and a resolver that runs out of gas after the transfer would have the venue pay again; it comes back only with a payout whose outcome the venue can establish itself. - Exact-output quotes.
quote_swap_outandquote_route_out: the input a given output needs, for routers that quote by output. In the source, under review. - An open builder leg. Any account that registered once with
register_buildercan be named on a swap and earnopen_builder_bps, a share the platform sets and each pool freezes at creation; the approved list stays for the higherbuilder_bps. Theswapandrouteevents then carryfee_open_builder,builder_tierandfee_bps_applied(event version 1.1.0). In the source, under review. - An opening fee schedule.
create_pooltakes an optionalfee_schedule(start_bps,end_bps,duration_ms): the fee decays from the seed over that window and is split like the static fee;quote_swapshows the rate applied. In the source, under review.
After that, in a second stage: a trading balance with scoped-key swaps, and resting orders on it.
Deployments
| Network | Account | Build |
|---|---|---|
testnet | routr-dev.testnet | development build; reset when the stored layout changes |
mainnet | routr.near | build 76c5992 below; owner routr.sputnik-dao.near (2 of 3), guardian guardian.routr.near, no access keys, 2-day delay; not audited |
routr builds
Every build is a reproducible CI build (cargo-near, pinned container); the hash is the sha256 of the wasm in base58, which is what the chain reports as the account's code_hash. The current candidate from the build pipeline is 81SqTvHwPzwQ4EpWzF2D4igGjVbu8zXS3RgDrkTWAsB5 (476,696 bytes, commit 57d03cd). See Security for the commands that check them.
| Code hash (sha256, base58) | Bytes | Commit | CI | State | Dates |
|---|---|---|---|---|---|
81SqTvHwPzwQ4EpWzF2D4igGjVbu8zXS3RgDrkTWAsB5 | 476,696 | 57d03cd | run 37824589200 | staged, can land from 2026-10-10 18:32 UTC | built 2026-10-08, staged 2026-10-08 |
8ps26KJ9BhWRPBZrNAuK6HCcb9vy59XqRzQXJmgFJ3yf | 476,893 | d2bf5cc | run 37800085617 | replaced | built 2026-10-08, staged 2026-10-08 |
6AnEQtya3RZqKqTecRb1bZj8aJjqP5F2PSUE4mL7Tvcg | 348,079 | a1e325e | run 37075456485 | replaced | built 2026-10-02, staged 2026-10-03 |
H4G6bhZXHKnhecs6gwgL3fQ4F3pt4RPHw34L2uaVhWdN | 331,716 | 76c5992 | run 36777691705 | live on routr.near | built 2026-09-30, applied 2026-09-30 |
The source repository is not public yet. Every build above names https://github.com/routrdottrade/routr and its commit in its NEP-330 metadata, but that repository is still being prepared for publication under a source-available licence. Until it is public, these hashes can be checked against the chain but not rebuilt by anyone outside, and by our own rule a staged build whose source is not public counts as unverified; that applies to our staged build too. This note changes the hour the repository goes up.