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

    Low-level staking adapter for Move commands, complete transaction builders, event types, and staking-position updates.

    StakingApi is created by AftermathApi.Staking() and requires the network-specific addresses.staking section. The *Tx methods mutate a caller-owned Transaction and perform no network I/O. The complete builders that start with fetchBuild create a new transaction; stake and unstake builders query the coin API to select an input coin. All balance arguments use raw SUI or afSUI units, and decimal percentages are converted to the protocol's 18-decimal fixed-point representation where required.

    The constructor throws when the supplied AftermathApi has no staking addresses. Move calls can return protocol errors such as an inactive validator, an amount below the minimum threshold, an invalid operation cap, or insufficient atomic-unstake reserves.

    Implements

    Index
    • Creates a low-level staking adapter from a configured AftermathApi.

      Construction is local and does not query the network. The provider must include addresses.staking, including the liquid-staking package and its shared objects. Use AftermathApi.Staking() to obtain an instance with the correct address set.

      Parameters

      • api: AftermathApi

        Low-level provider containing the Sui client and staking package and object addresses.

      Returns StakingApi

      Error when api.addresses.staking is missing.

    addresses: StakingAddresses

    Package and shared-object IDs used by staking commands for this network.

    buildEpochWasChangedTx: (
        inputs: { walletAddress: string } & Omit<{ tx: Transaction }, "tx">,
    ) => Transaction = ...

    Builds an unsigned transaction that calls epoch_was_changed for the afSUI vault.

    This wrapper creates a transaction, sets walletAddress as sender, and delegates to epochWasChangedTx. It performs no network I/O and does not execute the transaction.

    Type Declaration

      • (
            inputs: { walletAddress: string } & Omit<{ tx: Transaction }, "tx">,
        ): Transaction
      • Parameters

        • inputs: { walletAddress: string } & Omit<{ tx: Transaction }, "tx">

          Wallet address that signs and sends the crank transaction.

        Returns Transaction

        An unsigned Transaction ready for signing.

    Sui transaction-builder errors for invalid arguments.

    coinTypes: { afSui: string }

    Move coin types used by staking transaction builders.

    Type Declaration

    • afSui: string

      Fully qualified afSUI coin type derived from the configured package.

    eventTypes: {
        epochWasChanged: string;
        staked: string;
        unstaked: string;
        unstakeRequested: string;
    }

    Fully qualified Move event types for normalized staking events.

    Type Declaration

    • epochWasChanged: string

      Type of an afSUI vault epoch-change event.

    • staked: string

      Type of a liquid-staking event.

    • unstaked: string

      Type of a completed afSUI-to-SUI unstake event.

    • unstakeRequested: string

      Type of a queued afSUI-to-SUI unstake event.

    moveErrors: MoveErrors

    Registered Move abort translations for the staking package.

    objectTypes: { unverifiedValidatorOperationCap: string }

    Move object types used to identify staking-related objects.

    Type Declaration

    • unverifiedValidatorOperationCap: string

      Unverified validator operation-cap type from the events package.

    • Adds a Move inspection call that reads the afSUI-to-SUI exchange rate.

      The Move call returns a u128 transaction argument. This method does not execute the inspection or convert the result to a JavaScript number.

      Parameters

      • inputs: { tx: Transaction }

        Transaction to mutate.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The raw transaction argument returned by the Move call. The method does not decode its protocol-specific rate representation.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds a Move inspection call that converts an afSUI amount to its SUI value.

      The call returns a raw u64 transaction argument. It computes a value and does not transfer or burn a coin.

      Parameters

      • inputs: { afSuiAmount: bigint; tx: Transaction }

        Transaction to mutate and raw afSUI amount to convert.

        • afSuiAmount: bigint

          afSUI amount in raw afSUI units.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The transaction argument containing the raw SUI result.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds the immediate afSUI-to-SUI atomic-unstake Move call.

      This method mutates tx and performs no network I/O. The default entry point is request_unstake_atomic; setting withTransfer selects request_unstake_atomic_and_keep. The atomic call can fail with the Move error Insufficient Sui Reserves when the vault lacks enough liquidity.

      Parameters

      • inputs: {
            afSuiCoin: string | TransactionArgument;
            tx: Transaction;
            withTransfer?: boolean;
        }

        Transaction, afSUI coin argument, and optional alternate entry-point flag. The coin amount is already encoded in the supplied coin.

        • afSuiCoin: string | TransactionArgument

          afSUI coin object or transaction argument to provide.

        • tx: Transaction

          Transaction to mutate.

        • OptionalwithTransfer?: boolean

          Selects the request_unstake_atomic_and_keep entry point when true.

      Returns TransactionResult

      The transaction argument returned by the selected Move call. The default entry point returns the SUI coin for a later transfer command.

      Errors from the Sui transaction builder when an argument is invalid.

    • Builds an unsigned transaction that updates a validator fee.

      This local builder creates a transaction, sets its sender, converts the decimal ratio to an 18-decimal fixed-point integer, and adds update_validator_fee. It performs no network I/O and does not execute the transaction.

      Parameters

      • inputs: ApiUpdateValidatorFeeBody

        Wallet sender, operation-cap object ID, new decimal fee ratio, and optional sponsorship flag.

      Returns Promise<Transaction>

      A promise for an unsigned Transaction ready for signing.

      Sui transaction-builder errors for invalid arguments. The executed transaction can fail with Invalid Operation Cap or Invalid Validator Fee.

    • Adds the afSUI vault's epoch-processing Move call to a transaction.

      This local builder mutates tx and performs no network I/O. It calls epoch_was_changed with the configured vault, safe, Sui system state, referral vault, treasury, and a fixed request batch size of 1000.

      Parameters

      • inputs: { tx: Transaction }

        Transaction to mutate.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The transaction result returned by the Move call.

      Errors from the Sui transaction builder when an argument is invalid.

    • Builds a complete programmable transaction block for restaking native StakedSui objects.

      The builder creates a new transaction, sets the wallet sender, optionally updates the referral vault, creates a Move vector from the supplied object IDs, and transfers the returned afSUI to the wallet. It does not fetch coin balances, sign the transaction, or execute it. External fees are not added by this builder.

      Parameters

      • inputs: ApiStakeStakedSuiBody

        Wallet, native staked SUI object IDs, destination validator, and optional referral and sponsorship settings.

      Returns Promise<Transaction>

      A promise for an unsigned Transaction ready for signing.

      Sui transaction-builder errors for invalid object arguments. The executed transaction can fail with Empty Vector or an inactive-validator error.

    • Builds a complete programmable transaction block for liquid staking.

      This builder creates a new transaction, sets walletAddress as its sender, optionally updates the referral vault, fetches a SUI coin through the configured coin client, optionally transfers the external fee, stakes the coin, and transfers the returned afSUI to the wallet. It performs coin selection I/O but does not sign or execute the transaction.

      Parameters

      • inputs: ApiStakeBody

        Wallet, raw SUI amount, validator, and optional referral, external-fee, and sponsorship settings.

      Returns Promise<Transaction>

      A promise for an unsigned Transaction ready for signing.

      Error when the external fee ratio is not greater than 0 and less than 0.5. Coin-selection or Sui-client errors can also reject the promise.

    • Builds a complete programmable transaction block for liquid unstaking.

      This builder creates a new transaction, sets walletAddress as its sender, optionally updates the referral vault, fetches an afSUI coin, optionally transfers the external fee, and selects the atomic or queued Move call from isAtomic. Atomic mode transfers the returned SUI to the wallet. Queued mode creates an unstake request for the next epoch. The builder performs coin-selection I/O but does not sign or execute the transaction.

      Parameters

      • inputs: ApiUnstakeBody

        Wallet, raw afSUI amount, atomic-mode flag, and optional referral, external-fee, and sponsorship settings.

      Returns Promise<Transaction>

      A promise for an unsigned Transaction ready for signing.

      Error when the external fee ratio is not greater than 0 and less than 0.5. Coin-selection or Sui-client errors can also reject the promise. The executed atomic transaction can fail with Insufficient Sui Reserves.

    • Adds the Move call that restakes native StakedSui objects for afSUI.

      The method creates a Move vector from stakedSuiIds, mutates tx, and performs no network I/O. The default entry point is request_stake_staked_sui_vec; withTransfer: true selects its _and_keep variant. An empty vector or inactive validator can produce a Move error.

      Parameters

      • inputs: {
            stakedSuiIds: string[];
            tx: Transaction;
            validatorAddress: string;
            withTransfer?: boolean;
        }

        Transaction, native staked SUI object IDs, destination validator, and optional alternate entry-point flag.

        • stakedSuiIds: string[]

          Native StakedSui object IDs to place in the Move vector.

        • tx: Transaction

          Transaction to mutate.

        • validatorAddress: string

          Validator that receives the restaked objects.

        • OptionalwithTransfer?: boolean

          Selects the _and_keep Move entry point when true.

      Returns TransactionResult

      The transaction argument returned by the selected Move call. The default entry point returns the afSUI coin for a later transfer command.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds the liquid-staking Move call that converts a SUI coin to afSUI.

      This method mutates tx and performs no network I/O. The default entry point is request_stake; setting withTransfer selects request_stake_and_keep. The selected Move call receives the configured vault, safe, Sui system state, and referral vault objects.

      Parameters

      • inputs: {
            suiCoin: string | TransactionArgument;
            tx: Transaction;
            validatorAddress: string;
            withTransfer?: boolean;
        }

        Transaction, SUI coin argument, destination validator, and optional alternate entry-point flag. The coin amount is already encoded in the supplied coin object.

        • suiCoin: string | TransactionArgument

          SUI coin object or transaction argument to stake.

        • tx: Transaction

          Transaction to mutate.

        • validatorAddress: string

          Validator that receives the native stake.

        • OptionalwithTransfer?: boolean

          Selects the request_stake_and_keep Move entry point when true.

      Returns TransactionResult

      The transaction argument returned by the selected Move call. The default entry point returns the afSUI coin for a later transfer command.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds a Move inspection call that reads the SUI-to-afSUI exchange rate.

      The Move call returns a u128 transaction argument. This method does not execute the inspection or convert the result to a JavaScript number.

      Parameters

      • inputs: { tx: Transaction }

        Transaction to mutate.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The raw transaction argument returned by the Move call. The method does not decode its protocol-specific rate representation.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds a Move inspection call that converts a SUI amount to its afSUI value.

      The call returns a raw u64 transaction argument. It computes a value and does not transfer or burn a coin.

      Parameters

      • inputs: { suiAmount: bigint; tx: Transaction }

        Transaction to mutate and raw SUI amount to convert.

        • suiAmount: bigint

          SUI amount in raw SUI units.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The transaction argument containing the raw afSUI result.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds a Move inspection call that reads the vault's total SUI amount.

      The Move call returns a raw u64 transaction argument. The method mutates tx and performs no network I/O.

      Parameters

      • inputs: { tx: Transaction }

        Transaction to mutate.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The transaction argument containing total SUI in raw units.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds a queued afSUI-to-SUI unstake request to a transaction.

      The protocol processes the request at the next epoch boundary. This method mutates tx, performs no network I/O, and calls request_unstake.

      Parameters

      • inputs: { afSuiCoin: string | TransactionArgument; tx: Transaction }

        Transaction to mutate and the afSUI coin to provide.

        • afSuiCoin: string | TransactionArgument

          afSUI coin object or transaction argument to burn or convert.

        • tx: Transaction

          Transaction to mutate.

      Returns TransactionResult

      The transaction result returned by the Move call, which represents the unit-valued request entry point.

      Errors from the Sui transaction builder when an argument is invalid.

    • Adds the Move call that updates a validator's fee.

      This local builder mutates tx and performs no network I/O. newFee must be an 18-decimal fixed-point integer. The operation-cap object must authorize the validator being updated, and the Move contract enforces its maximum validator fee.

      Parameters

      • inputs: { newFee: bigint; tx: Transaction; validatorOperationCapId: string }

        Transaction, operation-cap object ID, and fixed-point fee.

        • newFee: bigint

          New validator fee as an 18-decimal fixed-point integer.

        • tx: Transaction

          Transaction to mutate.

        • validatorOperationCapId: string

          Object ID of the validator operation cap.

      Returns TransactionResult

      The transaction result returned by the Move call.

      Errors from the Sui transaction builder when an argument is invalid. The executed transaction can fail with Invalid Operation Cap or Invalid Validator Fee.

    • Applies one normalized staking event to an existing position list.

      This is a local state transition and performs no network I/O. A stake event is appended as a new stake position. An unstake request is added as state: "REQUEST", and a matching completion event replaces the request with state: "SUI_MINTED" while retaining the request epoch. Matching uses afSuiId. The returned list is sorted by descending timestamp; an absent timestamp sorts after timestamped positions.

      Parameters

      Returns StakingPosition[]

      A new position array containing the event's state transition.