import { Aptos, AccountAddress, Account, InputGenerateTransactionOptions, PendingTransactionResponse, InputGenerateTransactionPayloadData } from '@aptos-labs/ts-sdk'; import { ShelbyIndexerClient } from '../operations/index.js'; import { SenderBuiltMicropayment, ChannelInfo } from '../types/payments.js'; import { ShelbyClientConfig } from './ShelbyClientConfig.js'; import 'graphql-request'; import '../operations/generated/sdk.js'; import 'graphql'; import '../networks.js'; declare class ShelbyMicropaymentChannelClient { readonly aptos: Aptos; readonly deployer: AccountAddress; readonly indexer: ShelbyIndexerClient; /** * The ShelbyMicropaymentChannelClient is used to interact with the Micropayment contract on the Aptos blockchain. This * includes functions for the full lifecycle of micropayment channels: creation, withdrawals, expiration extensions, etc. * * @param config - The client configuration object. * @param config.network - The Shelby network to use. * * @example * ```typescript * const client = new ShelbyMicropaymentChannelClient({ * aptos: { * network: Network.SHELBYNET, * clientConfig: { * API_KEY: "AG-***", * }, * }, * }); * ``` */ constructor(config: ShelbyClientConfig); /** * Calls initialize function so caller can thereafter create micropayment channels. * * @param params.sender - The account that will be sending funds to various receivers in micropayment channels. * @param params.options - Optional transaction building options. * * @returns An object containing the pending transaction. * * @example * ```typescript * * const { transaction } = await client.initializePaymentChannels({ * sender: sender, * }); * ``` */ initializePaymentChannels(params: { sender: Account; options?: InputGenerateTransactionOptions; }): Promise<{ transaction: PendingTransactionResponse; }>; /** * Creates a micropayment channel to start a channel bweteen a sender and a receiver for a specific asset. * * @param params.deployer - Optional deployer account address. Defaults to SHELBY_DEPLOYER. * @param params.sender - The account that will be sending funds. * @param params.receiver - The account that will be receiving funds. * @param params.expirationMicros - The expiration of the micropayment channel. * @param params.depositAmount - The amount of the asset locked to the channel. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.options - Optional transaction building options. * * @returns An object containing the pending transaction. * * @example * ```typescript * * const { transaction } = await client.createChannel({ * sender: sender, * receiver: receiver, * expirationMicros: Date.now() * 1000 + 86400_000_000, // 1 day from now in microseconds * depositAmount: 0.001, * fungibleAssetAddress: fungibleAssetAddress, * }); * ``` */ createChannel(params: { sender: Account; receiver: AccountAddress; expirationMicros: number | bigint; depositAmount: number; fungibleAssetAddress: AccountAddress; publicKey?: Uint8Array; options?: InputGenerateTransactionOptions; }): Promise<{ transaction: PendingTransactionResponse; }>; /** * Creates a micropayment channel creation payload to start a channel between a sender and a receiver for a specific asset. * This is a static helper method for constructing the Move function call payload. * * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER. * @param params.sender - The account that will be sending funds. * @param params.receiver - The account that will be receiving funds. * @param params.expirationMicros - The expiration of the micropayment channel. * @param params.depositAmount - The amount of the asset locked to the channel. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.publicKey - The Ed25519 public key bytes for the channel. * * @returns An Aptos transaction payload data object for the create_channel Move function. */ static makeCreateMicropaymentChannelPayload(params: { deployer?: AccountAddress; receiver: AccountAddress; expirationMicros: number | bigint; depositAmount: number; fungibleAssetAddress: AccountAddress; publicKey: Uint8Array; }): InputGenerateTransactionPayloadData; /** * Withdraws funds from a micropayment channel as the sender. * * @param params.sender - The account that is withdrawing funds. * @param params.receiver - The account the channel is configured to send funds to. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.options - Optional transaction generation options. * * @returns An object containing the pending transaction. * * @example * ```typescript * const { transaction } = await client.senderWithdraw({ * sender: sender, * receiver: receiver, * fungibleAssetAddress: fungibleAssetAddress, * }); * ``` */ senderWithdraw(params: { sender: Account; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; options?: InputGenerateTransactionOptions; }): Promise<{ transaction: PendingTransactionResponse; }>; /** * Creates a static payload for the sender_withdraw Move function. * This is a helper method for constructing the transaction payload without signing. * * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER. * @param params.receiver - The account address of the receiver. * @param params.fungibleAssetAddress - The account address of the fungible asset. * * @returns An Aptos transaction payload data object for the sender_withdraw Move function. */ static createSenderWithdrawPayload(params: { deployer?: AccountAddress; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; }): InputGenerateTransactionPayloadData; /** * Creates a micropayment that can be sent to a receiver. * The sender signs a WithdrawApproval message that authorizes the receiver * to withdraw funds from the micropayment channel. * * @param params.sender - The account that owns the payment channel and signs the approval. * @param params.receiver - The account address that will receive funds. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.amount - The cumulative amount to authorize (not incremental). * @param params.paymentChannelId - The id of the payment channel. * @param params.sequenceNumber - The sequence number of the micropayment. Must be >= channel's next_withdrawn_sequence_number. * * @returns A SenderBuiltMicropayment containing the signed approval. * * @example * ```typescript * const senderBuiltMicropayment = client.createMicropayment({ * sender: senderAccount, * receiver: receiverAddress, * fungibleAssetAddress: fungibleAssetAddress, * amount: 100, * paymentChannelId: channelId, * sequenceNumber: 1, * }); * ``` */ createMicropayment(params: { sender: Account; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; amount: number | bigint; paymentChannelId: number | bigint; sequenceNumber: number | bigint; }): SenderBuiltMicropayment; /** * Creates a static payload for the receiver_withdraw Move function. * This is a helper method for constructing the transaction payload. * * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER. * @param params.sender - The sender's account address. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.amount - The cumulative amount authorized to withdraw. * @param params.paymentChannelId - The payment channel id. * @param params.sequenceNumber - The sequence number for this withdrawal. * @param params.signature - The Ed25519 signature bytes. * * @returns An Aptos transaction payload data object for the receiver_withdraw Move function. */ static createMicropaymentTransactionPayload(params: { deployer?: AccountAddress; sender: AccountAddress; fungibleAssetAddress: AccountAddress; amount: number | bigint; paymentChannelId: number | bigint; sequenceNumber: number | bigint; signature: Uint8Array; }): InputGenerateTransactionPayloadData; /** * Withdraws funds from a micropayment channel as the receiver. * The receiver submits the sender's signed approval to claim funds. * * @param params.receiver - The receiver account that will sign and submit the transaction. * @param params.micropayment - The sender's signed micropayment approval. * @param params.options - Optional transaction generation options. * * @returns An object containing the pending transaction. * * @example * ```typescript * const { transaction } = await client.receiverWithdraw({ * receiver: receiverAccount, * micropayment: senderBuiltMicropayment, * }); * ``` */ receiverWithdraw(params: { receiver: Account; micropayment: SenderBuiltMicropayment; options?: InputGenerateTransactionOptions; }): Promise<{ transaction: PendingTransactionResponse; }>; /** * Extends the expiration time of a micropayment channel. * * @param params.sender - The owner of the account. * @param params.receiver - The account address of the receiver. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.newExpirationMicros - The new expiration time in microseconds. * @param params.options - Optional transaction generation options. * * @returns An object containing the pending transaction. * * @example * ```typescript * const { transaction } = await client.extendExpirationTime({ * sender: sender, * receiver: receiverAddress, * fungibleAssetAddress: fungibleAssetAddress, * newExpirationMicros: Date.now() * 1000 + 172800_000_000, // 2 days from now * }); * ``` */ extendExpirationTime(params: { sender: Account; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; newExpirationMicros: number | bigint; options?: InputGenerateTransactionOptions; }): Promise<{ transaction: PendingTransactionResponse; }>; /** * Creates a payload to extend the expiration time on a micropayment channel. * This is a static helper method for constructing the Move function call payload. * * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER. * @param params.receiver - The account that will be receiving funds. * @param params.expirationMicros - The new expiration of the micropayment channel. * @param params.fungibleAssetAddress - The account address of the fungible asset. * * @returns An Aptos transaction payload data object for the extend_expiration_time Move function. */ static makeExtendExpirationTimePayload(params: { deployer?: AccountAddress; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; newExpirationMicros: number | bigint; }): InputGenerateTransactionPayloadData; /** * Increases the deposit amount locked in a micropayment channel. * * @param params.sender - The account that is increasing the deposit. * @param params.receiver - The account address of the receiver. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.additionalAmount - The additional amount to deposit. * @param params.options - Optional transaction generation options. * * @returns An object containing the pending transaction. * * @example * ```typescript * const { transaction } = await client.increaseDepositAmount({ * sender: sender, * receiver: receiverAddress, * fungibleAssetAddress: fungibleAssetAddress, * additionalAmount: 500, * }); * ``` */ increaseDepositAmount(params: { sender: Account; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; additionalAmount: number; options?: InputGenerateTransactionOptions; }): Promise<{ transaction: PendingTransactionResponse; }>; /** * Creates a payload to increase the deposit amount on a micropayment channel. * This is a static helper method for constructing the Move function call payload. * * @param params.deployer - Optional deployer account address. Defaults to MICROPAYMENTS_DEPLOYER. * @param params.receiver - The account that will be receiving funds. * @param params.fungibleAssetAddress - The account address of the fungible asset. * @param params.additionalAmount - The amount of the fungible asset to add to the channel's balance. * * @returns An Aptos transaction payload data object for the extend_expiration_time Move function. */ static makeIncreaseDepositAmountPayload(params: { deployer?: AccountAddress; receiver: AccountAddress; fungibleAssetAddress: AccountAddress; additionalAmount: number; }): InputGenerateTransactionPayloadData; /** * Retrieves the vector of channels owned by the sender, optionally * filtered by the receiver. * * @param params.sender - The account namespace owning the micropayment channels. * @param params.receiver? - An optional receiver account address. * @returns A vector of ChannelInfo objects. * * @example * ```typescript * const channelInfoVec = await client.getChannelInfo({ * sender: AccountAddress.fromString("0x1"), * receiver: AccountAddress.fromString("0x2"), * }); * ``` */ getChannelInfo(params: { sender: AccountAddress; receiver?: AccountAddress; }): Promise; } export { ShelbyMicropaymentChannelClient };