Routers and aggregators
How a DEX aggregator or bot trades Perpsplexity pools and leveraged tokens: packages, entry points, receipts, quoting and the rules a route must respect.
Perpsplexity pools and leveraged tokens can be a hop inside any Sui router. Every venue quotes against USDC, settles in one transaction and needs no off-chain order book. This page lists what a router has to know. Partners can ask us for the integration kit, which has the full Move interface, a TypeScript SDK and runnable examples.
The venues#
| Venue | Pair | Hop | Notes |
|---|---|---|---|
| Pool | coin / USDC | composite_pool::buy, composite_pool::sell | Buys return a receipt, sales take one. See Receipts. |
| Leveraged token | token / USDC | token::mint, token::redeem | 9 decimals, fixed leverage. See Leveraged tokens. |
Pairs that do not involve USDC route through USDC: SUI to a coin is SUI to USDC on another venue, then USDC to the coin here.
Two packages#
Pools live in two packages of the same design. Both still run, so a router that covers every pool must handle both.
| Immutable package | Upgradeable package | |
|---|---|---|
| Upgrades | none: it can never be upgraded | upgraded in place |
| Call package | 0xaedb8c9a905a778e831aeb4928f660210a7a645925348a7c4ec1cb4a6a3fd16e | the UpgradeCap's package field, now 0xd9a6f3a93726b263baffa558935a9153b64c06080d0513938899467dd99d682f |
| Types and events | same as the call package | 0x97fea95545c04dc73f8174c6195013b100a26e3fa978e7cf8b100a51dfaf8354 |
| Config | 0xb57be7c2f90d8bf9232af4cb967b411861b713f4480dfe50871dc85579f98411 | 0x7566f0f6508b7797f906c78ae5a39aaf1cd5aec58ff765b2599a6fba1dfce12c |
| Pools | the ZUK pool and the earliest launches (SUINU, MEOWL and others) | every other pool |
A pool's package is the package in its object type plus the Config it points at:
import { SuiGrpcClient } from "@mysten/sui/grpc";
import { normalizeSuiAddress, parseStructTag } from "@mysten/sui/utils";
const client = new SuiGrpcClient({ network: "mainnet", baseUrl: "https://fullnode.mainnet.sui.io:443" });
const PACKAGES = [
{ name: "immutable", types: "0xaedb8c9a905a778e831aeb4928f660210a7a645925348a7c4ec1cb4a6a3fd16e", config: "0xb57be7c2f90d8bf9232af4cb967b411861b713f4480dfe50871dc85579f98411" },
{ name: "upgradeable", types: "0x97fea95545c04dc73f8174c6195013b100a26e3fa978e7cf8b100a51dfaf8354", config: "0x7566f0f6508b7797f906c78ae5a39aaf1cd5aec58ff765b2599a6fba1dfce12c" },
];
export async function packageOf(poolId: string) {
const { object }: any = await client.core.getObject({ objectId: poolId, include: { json: true } });
const tag = parseStructTag(object.type);
const config = normalizeSuiAddress(object.json.config);
return PACKAGES.find((c) => normalizeSuiAddress(c.types) === normalizeSuiAddress(tag.address) && normalizeSuiAddress(c.config) === config) ?? null;
}
// packageOf(ZUK pool 0x3387…777c) -> immutablePool types#
| Pool | Spot pool | |
|---|---|---|
| Type | composite_pool::CompositePool<M, P, Q> | pool::Pool<M, Q> |
| Backing | a perp position on Aftermath, lending on Suilend and USDC cash | the USDC in the pool |
| Price | constant product on coins against the pool's NAV | constant product on coins against quote_reserve |
| Type arguments | [M, P, Q], where P is 0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::suilend::MAIN_POOL | [M, Q] |
Before bonding, both add virtual liquidity to the quote side.
Entry points#
| State | Buy | Sell |
|---|---|---|
| Live (0) | composite_pool::buy | composite_pool::sell, sell_partial |
| Launch curve (6) or resting in cash (2) | composite_pool::buy_cash | composite_pool::sell_cash, sell_cash_partial |
| Any | deposit (coins into a receipt) | withdraw, withdraw_partial (a receipt back to coins) |
buy takes, in order: the pool, the Config, the pool's engine, vault, account, the market's ClearingHouse (by value), the engine's Suilend sleeve, the Suilend lending market, the pool's sleeve, the reserve vault and reserve account, the Aftermath registry, the base and collateral oracles, the USDC coin, min_out, the deadline and the clock. It returns the ClearingHouse and the receipt. sell takes the same objects, then the receipt, early, hot_only, min_out, the deadline and the clock, and returns the ClearingHouse and the USDC.
The kit's resolveCompositePool resolves every object from the pool and its manifest, and its builder places them in order. Copy that code rather than assembling the argument list by hand.
Receipts, not coins#
A buy does not return Coin<M>. It returns a position::Position<M> receipt owned by the buyer. The receipt holds the coins, records when each lot was bought (for the exit fee) and earns dividends.
- After a buy, transfer the returned receipt to the user.
- To sell, pass one of the user's receipts.
sell_partialsells part of one.joinmerges receipts with the same lock before a sale. - Loose
Coin<M>(fromwithdraw, or received from someone) must go throughdepositfirst to get a fresh receipt, thensellit in the same transaction. A fresh receipt pays the maximum exit fee. withdrawturns a receipt back into coins plus any dividends, paying the exit fee due at that moment. Coins outside a receipt earn nothing.early = truesells a locked receipt before its lock ends: it pays the top exit fee and gives up half the dividends it earned. Withearly = false, a locked receipt aborts.
Fees#
- Buys pay 1% of the input.
- Sales pay an exit fee that starts at 5% and falls smoothly to 0.5% as each lot ages (about 1.84% after 30 hours, 0.5% after about 69 hours). In the launch curve or while resting in cash, every sale pays 0.5%; while the backing market is closed, 5%.
- Fees split 50% pool treasury, 25% holder dividends, 15% platform, 10% creator.
Quoting#
There is no closed-form quote that stays right: pool prices move with the live perp position, and leveraged tokens fill on Aftermath. Quote the way the site does:
- Build the exact hop in a transaction.
- Simulate it and read the hop's event:
composite_pool::Swapfor a pool,token::Mintedortoken::Redeemedfor a leveraged token. - Use the event's
output(ortokensorpayout) as the quote and setmin_outa little under it.
Quotes are good for about a minute. Every hop takes a deadline in milliseconds, at most 120 seconds ahead.
Shared objects taken by value#
Every hop that trades on Aftermath (a live pool, a leveraged token) takes the market's ClearingHouse by value and returns it. Inside one transaction:
- pass the returned
ClearingHouseto the next hop on the same market, instead of the shared object; - share each market back once, at the end, with
0xe54757433d663835bda85cfc89c6c44bc8d952e941affa5ae57bba0baa226c1b::clearing_house::share<USDC>.
A transaction that leaves a ClearingHouse unshared fails to build (UnusedValueWithoutDrop).
Rules a route must respect#
| Rule | Applies to | What fails |
|---|---|---|
| Receipts | pools | A sale needs a receipt; loose coins must be deposited first. |
| Deadline at most 120 s ahead | all | Pools abort with 6, leveraged tokens with 4. |
| Market hours and pauses | live pools, leveraged tokens | While a market is closed or paused, a pool with the market-hours guard (the default) refuses buys and position sales with session_policy code 1, and a leveraged token refuses trades on it. A pool sale with hot_only = true is paid from cash and still works. |
| Cap per trade | pools that set one | A trade larger than the pool's cap aborts with 3. Split it. |
| Minimum order | leveraged tokens | Mints under the market's minimum order size are refused. |
Partial results#
sell_partialsells part of a receipt and leaves the rest in it.redeem_partialon a leveraged token sells what the book can take and returns the rest.
Fees for the router#
None of these venues pays a fee to the router. Take yours from the user's input before the first hop, or from the output after the last one. Leveraged tokens accept a referrer address that receives 20% of that holder's fees for that token; it is fixed by the holder's first trade naming one.
Listing every venue#
| What | Endpoint |
|---|---|
| Every pool | GET /api/markets?network=mainnet |
| The pools of one coin | GET /api/markets/by-coin?network=mainnet&coinType=… |
| Leveraged tokens with all their object ids | GET /api/lev/tokens?network=mainnet |
See Public API for request and response examples.
Indexing what routes did#
Follow the events on Events. Every trade emits exactly one Swap (pools) or Minted / Redeemed (leveraged tokens) per hop, with the trader's address and the amounts.