aftermath-ts-sdk - v3.3.3
    Preparing search index...

    Provides HTTP reads, route construction, and transaction builders for Aftermath's smart order router.

    Route amounts and fees are bigint values in the corresponding coin's smallest unit. Decimal percentages such as slippage and external fees use number values where 0.01 means 1%. The router can split a trade across several sub-routes and can chain several protocol paths within each route.

    // Create provider
    const router = (await Aftermath.create({ network: "MAINNET" })).Router();
    // Retrieve 24h volume
    const volume24h = await router.getVolume24hrs();
    // Get supported coins
    const supportedCoins = await router.getSupportedCoins();

    Hierarchy (View Summary)

    Index
    • Creates a router client without making a network request.

      A later read or transaction request fails with an AftermathTransportError of kind network when neither config.baseUrl nor config.network is set.

      Parameters

      • Optionalconfig: CallerConfig

        Optional API host, network, endpoint, and access-token configuration.

      Returns Router

      const afSdk = await Aftermath.create({ network: "MAINNET" });

      const router = afSdk.Router();
    config: CallerConfig

    The mutable configuration used for subsequent requests.

    constants: { maxExternalFeePercentage: number } = ...

    Static safety limits used by router requests.

    Type Declaration

    • maxExternalFeePercentage: number

      The maximum external fee fraction accepted in a route request. 0.5 is 50%.

    • Appends a complete route to an existing transaction.

      The method serializes the supplied transaction for the API, sends the route request, and parses the returned serialized transaction into a new Transaction. The input transaction is not mutated. Use the returned coinOutId when the response exposes the swap output. It can be undefined.

      Parameters

      Returns Promise<{ coinOutId: TransactionObjectArgument | undefined; tx: Transaction }>

      A new transaction and the optional output coin argument.

      AftermathTransportError when the API request, serialization response, or transaction parsing fails.

      // 1) Create a route
      const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });

      // 2) Initialize your transaction
      const tx = new Transaction();

      // 3) Add router instructions
      const { tx: updatedTx, coinOutId } =
      await router.addTransactionForCompleteTradeRoute({
      tx,
      completeRoute: route,
      slippage: 0.01,
      walletAddress: "0x<your_address>"
      });

      // 4) Continue building your transaction with the resulting coinOutId, if desired
      updatedTx.transferObjects([coinOutId!], "0x<your_address>");
    • Requests an exact-input route for a specified coin amount.

      The API may split the input across several routes. Each route can contain several sequential paths, and each path identifies its DEX protocol and pool. referrer and externalFee are forwarded to the API. Protocol and pool allowlists and blocklists constrain route selection.

      Parameters

      • inputs: ApiRouterPartialCompleteTradeRouteBody & { coinInAmount: bigint }

        Input and output types, input amount in smallest units, and optional routing constraints.

        • coinInAmount: bigint

          Amount of coin being given away

      • OptionalabortSignal: AbortSignal

        Optional caller-owned cancellation signal.

      Returns Promise<RouterCompleteTradeRoute>

      A promise for the complete route, including split portions, path fees, and amounts.

      AftermathTransportError when the route request fails or the response cannot be decoded.

      const route = await router.getCompleteTradeRouteGivenAmountIn({
      coinInType: "0x2::sui::SUI",
      coinOutType: "0x<...>::coin::TOKEN",
      coinInAmount: BigInt(10_000_000_000),
      // optional fields:
      referrer: "0x<referrer_address>",
      externalFee: {
      recipient: "0x<fee_collector>",
      feePercentage: 0.01
      },
      protocolBlacklist: ["Cetus", "BlueMove"],
      poolBlacklist: ["0x<pool_id>"]
      });
      console.log(route);
    • Requests an exact-output route for a target coin amount.

      slippage is required because the router must protect the input needed to reach the target. The API may split the trade across routes and chain paths across protocols. Amounts are smallest-unit bigint values.

      Parameters

      • inputs: ApiRouterPartialCompleteTradeRouteBody & {
            coinOutAmount: bigint;
            slippage: number;
        }

        Input and output types, target output in smallest units, slippage, and optional constraints.

        • coinOutAmount: bigint

          Amount of coin expected to receive

        • slippage: number
      • OptionalabortSignal: AbortSignal

        Optional caller-owned cancellation signal.

      Returns Promise<RouterCompleteTradeRoute>

      A promise for the complete exact-output route.

      AftermathTransportError when the route request fails or the response cannot be decoded.

      const route = await router.getCompleteTradeRouteGivenAmountOut({
      coinInType: "0x2::sui::SUI",
      coinOutType: "0x<...>::coin::TOKEN",
      coinOutAmount: BigInt(20_000_000),
      slippage: 0.01, // 1%
      protocolWhitelist: ["Aftermath", "Cetus"],
      poolWhitelist: ["0x<pool_id>"]
      });
      console.log(route);
    • Fetches every coin type currently supported by the router.

      Returns Promise<string[]>

      A promise for fully qualified Sui coin type strings.

      AftermathTransportError when the API request or response fails.

      const supportedCoins = await router.getSupportedCoins();
      console.log(supportedCoins); // ["0x2::sui::SUI", "0x<...>::coin::TOKEN", ...]
    • Fetches an unsigned transaction for a previously calculated complete route.

      The request serializes nested bigint amounts and fixed split portions as strings ending in n. The API response is parsed into a Transaction, and walletAddress is assigned as its sender. The method does not sign or submit it.

      Parameters

      Returns Promise<Transaction>

      A promise for the unsigned parsed Transaction returned by the API.

      AftermathTransportError for transport, response decoding, or transaction parsing failures.

      const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
      const transactionBytes = await router.getTransactionForCompleteTradeRoute({
      walletAddress: "0x<your_address>",
      completeRoute: route,
      slippage: 0.01
      });
      // The returned bytes can now be signed and executed using your chosen wallet.
    • Fetches the router's total 24-hour trading volume.

      Returns Promise<number>

      A promise for the numeric API value. This class does not convert its unit.

      AftermathTransportError for HTTP, network, abort, timeout, or decode failures.

      const volume = await router.getVolume24hrs();
      console.log(volume); // e.g. 1234567.89
    • Fetches supported coin types whose API path matches a filter string.

      Parameters

      • inputs: { filter: string }

        The filter segment appended to the supported-coins endpoint.

      • OptionalabortSignal: AbortSignal

        Optional caller-owned cancellation signal.

      Returns Promise<string[]>

      A promise for matching fully qualified coin type strings.

      AftermathTransportError when the request is cancelled, fails, or cannot be decoded.

      const searchResult = await router.searchSupportedCoins({ filter: "SUI" });
      console.log(searchResult); // e.g. ["0x2::sui::SUI"]
    • Returns the canonical Aftermath API host for a Sui network.

      To target a custom or local host, pass baseUrl in CallerConfig to the constructor instead.

      Parameters

      • network: SuiNetwork

        The Sui network whose host to return.

      Returns string

      The network's HTTPS or local HTTP API host.