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

    High-level reads and transaction builders for Sui staking pools.

    The class reads pools, positions, capabilities, TVL, summaries, and user events through the farm API. Its transaction methods delegate to AftermathApi.Farms() and return unsigned transaction data. They do not sign or submit transactions. Pass an AftermathApi instance to the constructor when you use those builders.

    const farms = new Farms({ network: "MAINNET" });
    const pools = await farms.getAllStakingPools();

    Hierarchy (View Summary)

    Index

    Optional provider used by transaction builders. Reads do not require it.

    config: CallerConfig

    The mutable configuration used for subsequent requests.

    constants: { maxLockMultiplier: number; minRewardsToClaim: bigint } = ...

    Thresholds used by the high-level reward and multiplier helpers.

    Type Declaration

    • maxLockMultiplier: number

      Maximum human-readable lock multiplier exposed by the legacy helper, represented as 2 for a 2x multiplier. Pool objects store the precise value as an 18-decimal fixed-point bigint.

    • minRewardsToClaim: bigint

      Minimum claimable reward amount, in the reward coin's base units. Rewards below this threshold are reported as zero by FarmsStakedPosition.rewardsEarned.

    • Fetches all existing staking pools registered within the indexer or farm API.

      Parameters

      • OptionalabortSignal: AbortSignal

        Optional signal that cancels the API request.

      Returns Promise<FarmsStakingPool[]>

      An array of FarmsStakingPool objects.

      const allPools = await farms.getAllStakingPools();
      console.log(allPools.map(pool => pool.stakingPool));
    • Deprecated: Use getCreateStakingPoolTransactionV2() instead.

      Builds a transaction to create a new staking pool (farming vault) on version 1 of the farm system.

      Parameters

      Returns Promise<Transaction>

      A transaction object (or bytes) that can be signed and submitted.

      Please use getCreateStakingPoolTransactionV2.

    • Builds a transaction to create a new staking pool (farming vault) on version 2 of the farm system.

      Parameters

      Returns Promise<Transaction>

      A transaction object (or bytes) that can be signed and submitted.

      An error if no AftermathApi instance was provided.

      const tx = await farms.getCreateStakingPoolTransactionV2({
      minLockDurationMs: 604800000, // 1 week
      maxLockDurationMs: 31536000000, // 1 year
      maxLockMultiplier: BigInt("2000000000000000000"), // 2.0x in 18-decimal fixed point
      minStakeAmount: BigInt("1000000"),
      stakeCoinType: "0x<coin_type>",
      walletAddress: "0x<admin_address>"
      });
      // sign and submit the transaction
    • Fetches TVL and reward TVL for multiple farms in a single batch response. When farmIds is omitted, the API returns summaries for all farms.

      Parameters

      • Optionalinputs: ApiFarmsSummaryBody

        Optionally provide the farm IDs to include.

      • OptionalabortSignal: AbortSignal

        An optional signal for cancelling the request.

      Returns Promise<FarmSummary[]>

      TVL and reward TVL metrics for each requested farm.

    • Retrieves the total value locked (TVL) of reward coins across specified farm IDs or all farms if none are specified.

      Parameters

      • Optionalinputs: { farmIds?: string[] }

        An optional object containing an array of farmIds. If not provided, returns global reward TVL.

      • OptionalabortSignal: AbortSignal

        Optional signal that cancels the API request.

      Returns Promise<number>

      A promise that resolves to the reward TVL as a number in the API's reporting currency.

      const rewardsTvl = await farms.getRewardsTVL();
      console.log("All farms' rewards TVL:", rewardsTvl);

      const singleFarmRewardsTvl = await farms.getRewardsTVL({ farmIds: ["0x<farm_id>"] });
      console.log("Single farm's rewards TVL:", singleFarmRewardsTvl);
    • Fetches a single staking pool by its objectId from the farm API/indexer.

      Parameters

      • inputs: { objectId: string }

        An object containing the objectId of the staking pool.

      • OptionalabortSignal: AbortSignal

        Optional signal that cancels the API request.

      Returns Promise<FarmsStakingPool>

      A FarmsStakingPool object representing the staking pool.

      const pool = await farms.getStakingPool({ objectId: "0x<pool_id>" });
      console.log(pool.stakingPool);
    • Fetches multiple staking pools by their objectIds.

      Parameters

      • inputs: { objectIds: string[] }

        An object containing an array of objectIds.

      • OptionalabortSignal: AbortSignal

        Optional signal that cancels the API request.

      Returns Promise<FarmsStakingPool[]>

      An array of FarmsStakingPool instances corresponding to each objectId.

      const pools = await farms.getStakingPools({
      objectIds: ["0x<id1>", "0x<id2>"]
      });
      console.log(pools[0].stakingPool, pools[1].stakingPool);
    • Retrieves the total value locked (TVL) in the specified farm IDs or in all farms if none are specified.

      Parameters

      • Optionalinputs: { farmIds?: string[] }

        An optional object containing an array of farmIds to filter TVL by. If not provided, returns global TVL.

      • OptionalabortSignal: AbortSignal

        Optional signal that cancels the API request.

      Returns Promise<number>

      A promise that resolves to the TVL as a number in the API's reporting currency.

      const tvl = await farms.getTVL();
      console.log("All farms' TVL:", tvl);

      const tvlForSpecificFarm = await farms.getTVL({ farmIds: ["0x<farm_id>"] });
      console.log("Specific farm's TVL:", tvlForSpecificFarm);
    • 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.