supra-ts-sdk - v2.0.0
    Preparing search index...

    Class Automation

    The Automation class provides methods for managing the automation tasks of an account on the Supra network. A task is registered with an automation registration transaction (transaction.build.automationRegistrationRawTxnObject).

    Hierarchy (View Summary)

    Index
    • The constructor function takes a NetworkConfig object as a parameter and assigns it to the networkInformation property.

      Parameters

      • networkInformation: NetworkConfig

        A NetworkConfig object that contains information about the network on which the Supra client is running.

      Returns Automation

      import { SupraClient,Network } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
    • Cancels a user automation task of the sender with 0x1::automation_registry::cancel_task. A task that has not run yet is removed and half of its deposit is refunded. An active task is marked cancelled: it runs until the end of the current automation cycle, and its deposit is refunded then. The transaction aborts when the task does not exist, is not the sender's, is a system task or is already cancelled, and while the registry moves to the next cycle.

      The sequence number comes from the client's counter unless optionalTransactionPayloadArgs.sequenceNumber is set, and the client submits its calls from one account one after another. The client checks the chain ID of its node before it signs; see SupraConfig.

      Parameters

      • args: {
            senderAccount: SupraAccount;
            taskIndex: number | bigint;
            optionalTransactionArgs?: OptionalTransactionArgs;
        }
        • senderAccount: SupraAccount

          The owner of the task.

        • taskIndex: number | bigint

          The index of the task in the automation registry, a u64: the task_index of the 0x1::automation_registry::AutomationTaskMetaData event of its registration.

        • OptionaloptionalTransactionArgs?: OptionalTransactionArgs

          Optional transaction arguments. The gas settings in optionalTransactionPayloadArgs apply to the transaction; without maxGas it is estimated (see OptionalTransactionPayloadArgs). The object is not modified.

      Returns Promise<SubmitTransactionResponse>

      A Promise that resolves to a SubmitTransactionResponse. Submit describes the statuses and errors of a submission.

      Before any request, when taskIndex is not an integer from 0 to 2^64 - 1 (a number must be a safe integer).

      When the estimating simulation or an enabled simulation does not succeed.

      When the node refuses the submission or a simulation because the gas unit price is below its minimum (this replaces SupraSimulationFailedError and SupraAPIError for that refusal).

      When enableWaitForTransaction is set and the transaction fails.

      When the submission request times out, fails before the node answers or is answered with a 5xx status other than 503 (after the wait, with enableWaitForTransaction).

      Before signing, when the chain ID is not the node's.

      import { Network, SupraAccount, SupraClient } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
      const owner = new SupraAccount(); // the account that registered the task

      async function runExample() {
      const response = await supra.automation.cancelAutomationTask({
      senderAccount: owner,
      taskIndex: 42n,
      optionalTransactionArgs: { enableTransactionWaitAndSimulationArgs: { enableWaitForTransaction: true } },
      });
      console.log(response.hash, response.status);
      }

      runExample().catch(console.error);
    • Stops user automation tasks of the sender at once with 0x1::automation_registry::stop_tasks. Each task is removed from the registry; its deposit is refunded (half of it for a task that has not run yet) together with half of its fee for the rest of the current automation cycle. Indexes of tasks that do not exist are skipped. The transaction aborts when a task is not the sender's or is a system task, and while the registry moves to the next cycle.

      The sequence number comes from the client's counter unless optionalTransactionPayloadArgs.sequenceNumber is set, and the client submits its calls from one account one after another. The client checks the chain ID of its node before it signs; see SupraConfig.

      Parameters

      • args: {
            senderAccount: SupraAccount;
            taskIndexes: (number | bigint)[];
            optionalTransactionArgs?: OptionalTransactionArgs;
        }
        • senderAccount: SupraAccount

          The owner of the tasks.

        • taskIndexes: (number | bigint)[]

          The indexes of the tasks in the automation registry, each a u64: the task_index of the 0x1::automation_registry::AutomationTaskMetaData event of the task's registration. At least one.

        • OptionaloptionalTransactionArgs?: OptionalTransactionArgs

          Optional transaction arguments. The gas settings in optionalTransactionPayloadArgs apply to the transaction; without maxGas it is estimated (see OptionalTransactionPayloadArgs). The object is not modified.

      Returns Promise<SubmitTransactionResponse>

      A Promise that resolves to a SubmitTransactionResponse. Submit describes the statuses and errors of a submission.

      Before any request, when taskIndexes is empty or one of its elements is not an integer from 0 to 2^64 - 1 (a number must be a safe integer).

      When the estimating simulation or an enabled simulation does not succeed.

      When the node refuses the submission or a simulation because the gas unit price is below its minimum (this replaces SupraSimulationFailedError and SupraAPIError for that refusal).

      When enableWaitForTransaction is set and the transaction fails.

      When the submission request times out, fails before the node answers or is answered with a 5xx status other than 503 (after the wait, with enableWaitForTransaction).

      Before signing, when the chain ID is not the node's.

      import { Network, SupraAccount, SupraClient } from "supra-ts-sdk";

      const supra = new SupraClient({ network: Network.TESTNET });
      const owner = new SupraAccount(); // the account that registered the tasks

      async function runExample() {
      const response = await supra.automation.stopAutomationTasks({
      senderAccount: owner,
      taskIndexes: [42n, 43n],
      optionalTransactionArgs: { enableTransactionWaitAndSimulationArgs: { enableWaitForTransaction: true } },
      });
      console.log(response.hash, response.status);
      }

      runExample().catch(console.error);