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

    Represents one Aftermath AMM pool and its local math, API reads, and transaction builders.

    Coin and LP amounts accepted by this class are bigint values in the corresponding coin's smallest unit. Spot prices are decimal number ratios. Local calculations use JavaScript floating-point intermediates and can differ from Move by a rounding unit. Transaction builders use the pool estimate as the expected value and pass the caller's slippage to Move for the final check.

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

    const pools = afSdk.Pools();
    const pool = await pools.getPool({ objectId: "0x..." });

    const stats = await pool.getStats();
    const tradeTx = await pool.getTradeTransaction({
    walletAddress: "0x...",
    coinInType: "0x2::sui::SUI",
    coinInAmount: BigInt(1e9),
    coinOutType: "0x<yourCoin>",
    slippage: 0.01,
    });

    Hierarchy (View Summary)

    Index
    • Creates a local view of a fetched pool object.

      The constructor does not make a network request. Supply api when you need transaction builders. Without it, API-backed transaction methods throw Error("missing AftermathApi instance").

      Parameters

      • pool: PoolObject

        The fetched PoolObject, including normalized coin balances.

      • Optionalconfig: CallerConfig

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

      • Optionalapi: AftermathApi

        Optional provider used by transaction builders and referral setup.

      Returns Pool

    Optional provider used by transaction builders and referral setup.

    config: CallerConfig

    The mutable configuration used for subsequent requests.

    The fetched PoolObject, including normalized coin balances.

    stats: PoolStats | undefined

    The last statistics object loaded by getStats, or undefined until a stats read completes. The cache is not refreshed automatically.

    • Returns the pool coin types in ascending lexicographic order.

      Returns string[]

      An array of coin type strings.

    • Returns the current DAO fee as a decimal fraction, if configured.

      Returns number | undefined

      The fee fraction, where 0.01 is 1%, or undefined without a DAO fee pool.

    • Returns the Sui address that receives the configured DAO fee.

      Returns string | undefined

      The normalized recipient address, or undefined without a DAO fee pool.

    • Calculates a proportionate all-coin withdrawal.

      Here lpRatio is the fraction of LP supply burned, unlike the retained ratio accepted by getWithdrawAmountsOut. For example, 0.1 burns 10% and returns 10% of each pool balance after the configured DAO fee. The referral flag is accepted for API compatibility but does not alter this local estimate.

      Parameters

      • inputs: { lpRatio: number; referral?: boolean }

        Decimal LP fraction to burn. It must be less than 1.

      Returns CoinsToBalance

      All pool coin amounts in smallest units, after DAO fee adjustment.

      Error when lpRatio is at least 1.

      const allOut = pool.getAllCoinWithdrawAmountsOut({ lpRatio: 0.1 });
      console.log(allOut); // amounts for each coin
    • Converts an all-coin LP burn amount into the burned pool ratio.

      For a supply of 200 and a burn of 50, this method returns 0.25.

      Parameters

      • inputs: { lpCoinAmountIn: bigint }

        LP amount to burn in the LP coin's smallest unit.

      Returns number

      The decimal fraction of the pool burned.

    • Builds a transaction that burns an LP amount and returns every pool coin in proportion to the pool balances.

      lpCoinAmount is in LP smallest units. The returned Transaction is unsigned and not serialized. A configured referrer is registered before the withdrawal command, but this path does not take a slippage parameter.

      Parameters

      Returns Promise<Transaction>

      An unsigned Transaction containing the all-coin withdrawal.

      Error when no provider is attached or coin selection fails.

      const allCoinWithdrawTx = await pool.getAllCoinWithdrawTransaction({
      walletAddress: "0x...",
      lpCoinAmount: BigInt(500000),
      });
    • Calculates the LP result for a fixed-amount liquidity deposit.

      lpAmountOut is a smallest-unit LP amount. lpRatio is the decimal retained-balance scalar used by the CMMM solver. The implementation derives lpAmountOut as floor(lpCoinSupply * (1 / lpRatio - 1)), so lpRatio is not itself the minted-LP fraction. The optional referral flag does not alter this local estimate.

      Parameters

      • inputs: { amountsIn: CoinsToBalance; referral?: boolean }

        Deposit amounts keyed by coin type in each coin's smallest unit.

      Returns { lpAmountOut: bigint; lpRatio: number }

      The estimated LP smallest-unit amount and the decimal solver ratio.

      Error when the solver returns a ratio of at least 1.

      const depositCalc = pool.getDepositLpAmountOut({
      amountsIn: { "0x<coinA>": BigInt(1000000), "0x<coinB>": BigInt(500000) },
      });
      console.log(depositCalc.lpAmountOut, depositCalc.lpRatio);
    • Builds a transaction that deposits liquidity into this pool.

      The method selects the wallet's input coin objects through AftermathApi, computes an expected LP ratio locally, and adds the Move deposit command. The returned Transaction is not signed or serialized.

      Parameters

      • inputs: ApiPoolDepositBody

        Wallet address, smallest-unit amounts keyed by coin type, and slippage.

      Returns Promise<Transaction>

      An unsigned Transaction containing the deposit commands.

      Error when no provider is attached or local pool math rejects the deposit.

      const depositTx = await pool.getDepositTransaction({
      walletAddress: "0x...",
      amountsIn: { "0x<coin>": BigInt(1000000) },
      slippage: 0.01,
      });
    • Fetches fee data points for a supported analytics timeframe.

      Parameters

      Returns Promise<PoolDataPoint[]>

      A promise for API timestamps and numeric fee values.

      AftermathTransportError when the API request or response fails.

      const feeData = await pool.getFeeData({ timeframe: "1D" });
      console.log(feeData);
    • Converts a multi-coin LP burn amount into the retained pool ratio.

      For a supply of 1_000 and a burn of 100, this method returns 0.9.

      Parameters

      • inputs: { lpCoinAmountIn: bigint }

        LP amount to burn in the LP coin's smallest unit.

      Returns number

      The decimal fraction of the pool retained after the burn.

    • Calculates the instantaneous spot price from one pool coin to another.

      The result is a decimal coinIn-per-coinOut ratio adjusted for each coin's decimal scalar. By default the result excludes swap and DAO fees. Set withFees to true to include the fee terms used by the local CMMM calculation.

      Parameters

      • inputs: { coinInType: string; coinOutType: string; withFees?: boolean }

        Input and output coin types, plus the optional fee flag.

      Returns number

      The decimal spot-price ratio in coin units, not a smallest-unit bigint.

      When either coin type is not present in this pool.

      const price = pool.getSpotPrice({
      coinInType: "0x<coinA>",
      coinOutType: "0x<coinB>",
      withFees: true,
      });
      console.log("Spot Price:", price);
    • Fetches the pool's analytics from the Aftermath API and caches the result.

      The API returns numeric metrics without a unit conversion in this class. Inspect the configured API's PoolStats contract for the meaning of each metric.

      Returns Promise<PoolStats>

      A promise for the current PoolStats object. The same object is stored in stats.

      AftermathTransportError when the API request fails or its response cannot be decoded.

      const stats = await pool.getStats();
      console.log(stats.volume, stats.fees, stats.apr);
    • Calculates the input for an exact-output swap in this pool.

      The input and output are smallest-unit bigint amounts. The local calculation applies pool, protocol, and DAO fees when reversing the quote. The referral flag is accepted for API compatibility but does not currently change this local estimate.

      Parameters

      • inputs: {
            coinInType: string;
            coinOutAmount: bigint;
            coinOutType: string;
            referral?: boolean;
        }

        Input type, desired output in smallest units, output type, and optional referral flag.

      Returns bigint

      The required input in coinInType smallest units.

      Error when the requested output or calculated input exceeds the configured pool-balance limit or the result is zero.

      const amountIn = pool.getTradeAmountIn({
      coinInType: "0x<coinA>",
      coinOutAmount: BigInt(1000000),
      coinOutType: "0x<coinB>"
      });
    • Calculates the output for an exact-input swap in this pool.

      The input and return value are smallest-unit bigint amounts. The local calculation applies the pool swap fees, the protocol fee, and the configured DAO fee. The referral flag is accepted for API compatibility but does not currently change this local estimate. A transaction referrer is registered separately by getTradeTransaction.

      Parameters

      • inputs: {
            coinInAmount: bigint;
            coinInType: string;
            coinOutType: string;
            referral?: boolean;
        }

        Input type, smallest-unit amount, output type, and optional referral flag.

      Returns bigint

      The expected output in coinOutType smallest units.

      Error when the input or output exceeds the configured pool-balance limit or the result is zero.

      const amountOut = pool.getTradeAmountOut({
      coinInType: "0x<coinA>",
      coinInAmount: BigInt(1000000),
      coinOutType: "0x<coinB>",
      });
    • Builds an unsigned exact-input swap transaction for two pool coin types.

      The method computes an expected output in smallest units, selects the input coin through AftermathApi, registers an optional referrer, and encodes the expected output with the caller's decimal slippage tolerance. It does not sign or serialize the returned Transaction.

      Parameters

      • inputs: ApiPoolTradeBody

        Wallet address, coin types, input amount in smallest units, and slippage.

      Returns Promise<Transaction>

      An unsigned Transaction containing the swap command.

      Error when no provider is attached, coin selection fails, or local math rejects the trade.

      const tradeTx = await pool.getTradeTransaction({
      walletAddress: "0x...",
      coinInType: "0x<coinA>",
      coinInAmount: BigInt(1000000),
      coinOutType: "0x<coinB>",
      slippage: 0.005,
      });
    • Builds an unsigned transaction that updates this pool's DAO fee recipient.

      The caller must own the daoFeePoolOwnerCapId capability. The recipient is normalized to a full Sui address before it is encoded in Move.

      Parameters

      • inputs: { daoFeePoolOwnerCapId: string; newFeeRecipient: string; walletAddress: string }

        Wallet address, owner-cap object ID, and new recipient address.

      Returns Promise<Transaction>

      An unsigned Transaction that updates the DAO fee recipient.

      Error when this pool has no DAO fee configuration or no provider is attached.

      const tx = await pool.getUpdateDaoFeeRecipientTransaction({
      walletAddress: "0x...",
      daoFeePoolOwnerCapId: "0x<capId>",
      newFeeRecipient: "0x<recipient>",
      });
    • Builds an unsigned transaction that updates this pool's DAO fee.

      The provider converts newFeePercentage to basis points before encoding the Move call. The caller must own the daoFeePoolOwnerCapId capability.

      Parameters

      • inputs: {
            daoFeePoolOwnerCapId: string;
            newFeePercentage: number;
            walletAddress: string;
        }

        Wallet address, owner-cap object ID, and new decimal fee fraction.

      Returns Promise<Transaction>

      An unsigned Transaction that updates the DAO fee in basis points.

      Error when this pool has no DAO fee configuration or no provider is attached.

      const tx = await pool.getUpdateDaoFeeTransaction({
      walletAddress: "0x...",
      daoFeePoolOwnerCapId: "0x<capId>",
      newFeePercentage: 0.01, // 1%
      });
    • Fetches this pool's 24-hour volume from the API.

      Returns Promise<number>

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

      AftermathTransportError when the API request or response fails.

      const vol24h = await pool.getVolume24hrs();
      console.log("Pool 24h Volume:", vol24h);
    • Fetches volume data points for a supported analytics timeframe.

      Parameters

      Returns Promise<PoolDataPoint[]>

      A promise for API timestamps and numeric volume values.

      AftermathTransportError when the API request or response fails.

      const volumeData = await pool.getVolumeData({ timeframe: "1D" });
      console.log(volumeData); // e.g. [{ time: 1686000000, value: 123.45 }, ...]
    • Calculates a multi-coin withdrawal for a retained LP ratio and output direction.

      lpRatio is the fraction of the original pool balance retained after the LP burn. For example, 0.9 means that 10% of the LP position is burned. Positive entries in amountsOutDirection select the direction and relative amounts. The returned record contains every pool coin in smallest units. DAO fees are deducted from selected positive outputs. The referral flag is currently accepted but does not change the local estimate.

      Parameters

      • inputs: { amountsOutDirection: CoinsToBalance; lpRatio: number; referral?: boolean }

        Retained LP ratio, output direction, and optional referral flag.

      Returns CoinsToBalance

      Output amounts keyed by pool coin type, in smallest units.

      Error when a selected output is zero, too large for the pool, or fails the local invariant solve.

      const outAmounts = pool.getWithdrawAmountsOut({
      lpRatio: 0.1,
      amountsOutDirection: { "0x<coinA>": BigInt(500000) },
      });
      console.log(outAmounts);
    • Estimates a multi-coin withdrawal from an LP amount and selected output types.

      The method first estimates each selected coin from the LP share, uses those amounts as the direction vector, and returns the full pool-coin map produced by getWithdrawAmountsOut. Amounts are smallest-unit bigint values.

      Parameters

      • inputs: { coinTypesOut: string[]; lpCoinAmountIn: bigint; referral?: boolean }

        LP amount to burn in smallest units, selected output types, and optional referral flag.

      Returns CoinsToBalance

      Estimated output amounts keyed by pool coin type, in smallest units.

      Error when the LP amount or a selected output fails pool-balance checks.

    • Builds a transaction that withdraws a fixed LP amount in a selected output direction.

      amountsOutDirection describes the relative output direction. The method computes expected smallest-unit outputs from lpCoinAmount, then encodes those expectations and slippage in the Move command. The returned Transaction is unsigned and not serialized.

      Parameters

      • inputs: ApiPoolWithdrawBody

        Wallet address, direction amounts, LP amount in smallest units, and slippage.

      Returns Promise<Transaction>

      An unsigned Transaction containing the withdrawal commands.

      Error when no provider is attached or local pool math rejects the withdrawal.

      const withdrawTx = await pool.getWithdrawTransaction({
      walletAddress: "0x...",
      amountsOutDirection: {
      "0x<coin>": BigInt(500000),
      },
      lpCoinAmount: BigInt(1000000),
      slippage: 0.01,
      });
    • 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.