@cfxlabsinc/b2b-services
    Preparing search index...

    A pool of Solana nonce accounts, used for durable transactions

    A nonce is reserved for a period of time. During this time, it can be locked for usage and will remain locked indefinitely until released. If a nonce is not locked within the reservation period, the fillSolanaNoncePoolWorkflow sync returns it to the pool.

    The pool stores each account's current nonce value, so building a durable transaction needs no RPC read: reserve hands the value out, and release takes the value the account holds afterwards.

    This service can be used in two ways:

    a) We know who will be locking the nonce at reservation time:

    service.reserve({ reservedFor: "<locker id>" });
    // later...
    service.lock({ reservedFor: "<locker id>" })
    service.release({ lockedBy: "<locker id>", nonce })

    b) We do not know the ID of locker upfront:

    service.reserve({ reservedFor: "<domain>.<purpose>" })
    // later...
    service.lock({ address, lockedBy: "<locker id>" })
    service.release({ address, nonce })

    In this scenario, you have to carry forward the nonce address in code so it can be supplied to lock().

    ATTENTION: If you are using this service in an application, please ensure fillSolanaNoncePoolWorkflow is added to the same worker where the durable transaction will be executed

    Index
    instance: (...args: []) => SolanaNonceService = ...

    The process default: built from each dependency's own instance().

    • Lock a previously-reserved nonce

      This method is invoked differently, depending on how reservation was done:

      // An ID was provided during reservation
      lock({ reservedFor: "<ID>" });
      // Otherwise, lock by address and supply the ID now
      lock({ address, lockedBy: "<ID>" })

      Parameters

      • input:
            | { address: Address; lockedBy: string }
            | { lockedBy?: string; reservedFor: string }
        • { address: Address; lockedBy: string }
          • address: Address
          • lockedBy: string

            ID

        • { lockedBy?: string; reservedFor: string }
          • OptionallockedBy?: string

            ID

          • reservedFor: string

            ID

      Returns Promise<{ ok: true; value: SolanaNonce } | { error: ServiceError; ok: false }>

    • Locked nonces must be released.

      Ideally this should be invoked in a finally logic to ensure it is executed regardless of errors.

      Parameters

      • input: ({ address: Address } | { lockedBy: string }) & { nonce: Nonce }
        • { address: Address }
        • { lockedBy: string }
          • lockedBy: string

            ID

        • nonce: Nonce

          The value the account holds now: read on-chain once a transaction using it has landed, or the reserved value when nothing was sent.

      Returns Promise<{ ok: true; value: undefined }>

    • Reserve a nonce for later locking.

      If it is not locked in the reservation period, the pool sync returns it to the pool.

      Remember to sign the transaction that includes this nonce, with the nonce authority via sign

      Parameters

      • __namedParameters: { expiresAt?: Date; reservedFor: string }
        • OptionalexpiresAt?: Date

          How long the reservation is valid for. Default: 5 minutes

        • reservedFor: string

          The ID of what will be using the nonce, or alternatively <domain>[.<domain model>][.<purpose>], e.g. SWAP, or DEPOSIT.US_CASH.MINT

          The latter is informational only and won't be used in code logic.

      Returns Promise<{ ok: true; value: ReservedSolanaNonce }>