Skip to content
perpsplexity
BOTCHATSECURITY
Built onAFTERMATH
Routers and aggregators | Perpsplexity Docs

Introduction

OverviewFees

Products

Perp meme poolsLaunchSwapLeveraged tokens

Integrate

AddressesRouters and aggregatorsEventsError codes

Reference

Public APISecurityAudits

More

FAQ
Integrate

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#

VenuePairHopNotes
Poolcoin / USDCcomposite_pool::buy, composite_pool::sellBuys return a receipt, sales take one. See Receipts.
Leveraged tokentoken / USDCtoken::mint, token::redeem9 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 packageUpgradeable package
Upgradesnone: it can never be upgradedupgraded in place
Call package0xaedb8c9a905a778e831aeb4928f660210a7a645925348a7c4ec1cb4a6a3fd16ethe UpgradeCap's package field, now 0xd9a6f3a93726b263baffa558935a9153b64c06080d0513938899467dd99d682f
Types and eventssame as the call package0x97fea95545c04dc73f8174c6195013b100a26e3fa978e7cf8b100a51dfaf8354
Config0xb57be7c2f90d8bf9232af4cb967b411861b713f4480dfe50871dc85579f984110x7566f0f6508b7797f906c78ae5a39aaf1cd5aec58ff765b2599a6fba1dfce12c
Poolsthe 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:

TypeScript
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) -> immutable
Calling the upgradeable package

Calls go to the current package; types, events and receipts use the types and events id. The current package is the package field of the UpgradeCap 0x0c48c2bab19ad441b0271d7926ca17d334570e255862e3d547880dd66bf03457. Read it at start-up, or cache it and refresh it when a call fails.

Pool types#

PoolSpot pool
Typecomposite_pool::CompositePool<M, P, Q>pool::Pool<M, Q>
Backinga perp position on Aftermath, lending on Suilend and USDC cashthe USDC in the pool
Priceconstant product on coins against the pool's NAVconstant 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#

StateBuySell
Live (0)composite_pool::buycomposite_pool::sell, sell_partial
Launch curve (6) or resting in cash (2)composite_pool::buy_cashcomposite_pool::sell_cash, sell_cash_partial
Anydeposit (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_partial sells part of one. join merges receipts with the same lock before a sale.
  • Loose Coin<M> (from withdraw, or received from someone) must go through deposit first to get a fresh receipt, then sell it in the same transaction. A fresh receipt pays the maximum exit fee.
  • withdraw turns a receipt back into coins plus any dividends, paying the exit fee due at that moment. Coins outside a receipt earn nothing.
  • early = true sells a locked receipt before its lock ends: it pays the top exit fee and gives up half the dividends it earned. With early = 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:

  1. Build the exact hop in a transaction.
  2. Simulate it and read the hop's event: composite_pool::Swap for a pool, token::Minted or token::Redeemed for a leveraged token.
  3. Use the event's output (or tokens or payout) as the quote and set min_out a little under it.

Quotes are good for about a minute. Every hop takes a deadline in milliseconds, at most 120 seconds ahead.

Cheap first pass

For ranking candidate routes before simulating, call observe (live) or observe_cash (launch curve or cash). It returns a Health sample with quote_nav, hot (the cash) and meme_reserve. A constant-product estimate out = in * reserve / (nav + in) after the fee is close for small trades. Always simulate the final route.

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 ClearingHouse to 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#

RuleApplies toWhat fails
ReceiptspoolsA sale needs a receipt; loose coins must be deposited first.
Deadline at most 120 s aheadallPools abort with 6, leveraged tokens with 4.
Market hours and pauseslive pools, leveraged tokensWhile 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 tradepools that set oneA trade larger than the pool's cap aborts with 3. Split it.
Minimum orderleveraged tokensMints under the market's minimum order size are refused.

Partial results#

  • sell_partial sells part of a receipt and leaves the rest in it.
  • redeem_partial on 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#

WhatEndpoint
Every poolGET /api/markets?network=mainnet
The pools of one coinGET /api/markets/by-coin?network=mainnet&coinType=…
Leveraged tokens with all their object idsGET /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.

PreviousAddressesNext Events

On this page

The venuesTwo packagesPool typesEntry pointsReceipts, not coinsFeesQuotingShared objects taken by valueRules a route must respectPartial resultsFees for the routerListing every venueIndexing what routes did