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

    The Dca class provides functionality for automating Dollar-Cost Averaging (DCA) strategies on the Aftermath platform. It allows you to create, query, and close DCA orders that execute periodic trades based on user-defined parameters.

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

    const dca = afSdk.Dca();

    Hierarchy (View Summary)

    Index
    • Creates a new instance of the Dca class, responsible for managing DCA orders (querying, creating, closing).

      Parameters

      • Optionalconfig: CallerConfig

        Optional caller configuration, such as network, API host, access token, and API path.

      Returns Dca

    config: CallerConfig

    The mutable configuration used for subsequent requests.

    constants: { gasAmount: bigint } = ...

    Contains static values related to DCA on the Aftermath platform, such as default gas usage for DCA transactions.

    Type Declaration

    • gasAmount: bigint

      The default gas budget for DCA-related transactions, in MIST. 50_000_000n equals 0.05 SUI.

    • Sends a signed request to cancel one or more DCA orders.

      Sign the exact string returned by UserData.createTermsAndConditionsMessage() as a personal message over its UTF-8 bytes. Send those signed bytes and the signature in inputs. The order IDs are sent in orderObjectIds; the deprecated per-action message from closeDcaOrdersMessageToSign is not the current credential.

      Parameters

      Returns Promise<boolean>

      The backend cancellation result. false is a valid response.

      AftermathTransportError when the API request or response fails.

      const success = await dca.closeDcaOrder({
      walletAddress: "0x...",
      bytes: "0x<signed_bytes>",
      signature: "0x<signature>",
      });
    • Builds the legacy per-action message for canceling DCA orders.

      This method performs no network I/O. The current cancellation endpoint authenticates with the canonical terms message instead. Put the order IDs in closeDcaOrder's orderObjectIds field.

      Parameters

      • inputs: { orderIds: string[] }

        An object containing orderIds, an array of order object IDs to cancel.

      Returns { action: string; order_object_ids: string[] }

      { action: "CANCEL_DCA_ORDERS", order_object_ids: inputs.orderIds }.

      af-fe no longer accepts this per-action message. Sign UserData.createTermsAndConditionsMessage and pass orderObjectIds in the closeDcaOrder body instead.

    • Deprecated. Generates a message object used in older flows to create a DCA user account. Use the userData package for user key storage or account creation.

      Returns { action: string }

      { action: "CREATE_DCA_ACCOUNT" }. No network request is made.

      Please use method from userData package instead.

    • Deprecated. Creates the user's public key in the older DCA system. Please use createUserPublicKey from the userData package instead.

      Parameters

      Returns Promise<boolean>

      true if the public key was stored. false is also a valid backend response.

      Use userData package method instead

      AftermathTransportError when the API request or response fails.

    • Retrieves the currently active DCA orders for a specific user.

      Parameters

      • inputs: { walletAddress: string }

        An object containing the user's walletAddress.

      Returns Promise<DcaOrderObject[]>

      A promise that resolves to an array of DcaOrderObject for the active orders.

      AftermathTransportError when the API request or response fails.

      const activeOrders = await dca.getActiveDcaOrders({ walletAddress: "0x..." });
      console.log(activeOrders); // Array of active DCA orders
    • Deprecated. Fetches both active and past DCA orders for a given user in one response. Use getActiveDcaOrders and getPastDcaOrders for a more explicit approach.

      Parameters

      Returns Promise<DcaOrdersObject>

      A DcaOrdersObject grouping active and past orders.

      AftermathTransportError when the API request or response fails.

      Please use getActiveDcaOrders & getPastDcaOrders instead.

      // Old usage:
      const allOrders = await dca.getAllDcaOrders({ walletAddress: "0x..." });
      console.log(allOrders.active, allOrders.past);
    • Requests a transaction block from the Aftermath API to create a new DCA order. The returned Transaction is not signed or executed.

      Parameters

      Returns Promise<Transaction>

      A parsed Transaction with the wallet address set as its sender.

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

      const createOrderTx = await dca.getCreateDcaOrderTx({
      walletAddress: "0x<user>",
      allocateCoinType: "0x2::sui::SUI",
      allocateCoinAmount: BigInt(1_000_000_000),
      buyCoinType: "0x<coin>",
      frequencyMs: 3600000, // Every hour
      tradesAmount: 5,
      // ...other fields...
      });
      // sign & send the transaction
    • Retrieves the past (completed or canceled) DCA orders for a specific user.

      Parameters

      • inputs: { walletAddress: string }

        An object containing the user's walletAddress.

      Returns Promise<DcaOrderObject[]>

      A promise that resolves to an array of DcaOrderObject for the past orders.

      AftermathTransportError when the API request or response fails.

      const pastOrders = await dca.getPastDcaOrders({ walletAddress: "0x..." });
      console.log(pastOrders); // Array of past DCA orders
    • Deprecated. Fetches the user's public key from the older DCA system. Please use getUserPublicKey from the userData package instead.

      Parameters

      • inputs: { walletAddress: string }

        Contains the user's walletAddress.

      Returns Promise<string | undefined>

      The stored public key, or undefined when the API returns no key.

      Use userData package method instead

      AftermathTransportError when the API request or response fails.

    • 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.