import { PolkadotClient } from "polkadot-api"; import TransactionQueue from "./transactionQueue"; import { TransactionResult } from "./types"; import { UserService } from "./services/userService"; export interface TransferOptions { dest: string; value: bigint; } export interface TransferByUsernameOptions { username: string; value: bigint; } export interface SendAllOptions { dest: string; keepAlive?: boolean; } export interface SendAllByUsernameOptions { username: string; keepAlive?: boolean; } export interface BalanceInfo { free: bigint; reserved: bigint; frozen: bigint; total: bigint; transferable: bigint; } export interface UserInfo { address: string; username: string; } export type TransferExtrinsic = any; export default class Transfer { private readonly clientFactory; private readonly transactionQueue?; private userService; constructor(clientFactory: () => Promise, userService?: UserService, transactionQueue?: TransactionQueue | undefined); setUserService(userService: UserService): void; private getClient; private resolveUsernameToAddress; /** * Transfer a specific amount to a destination address (WAITS FOR INCLUSION) * Returns when transaction is included in block * * @param sessionSigner - Optional session signer for faster transactions * @param options - Transfer options including destination and amount * @returns Promise with transaction result including hash * * @example * const result = await transfer.sendAsync(auth.sessionSigner, { * dest: "5Gq2VNFP4yqK1bk5zt552hBxU68Q3ABewGN99zY7qGbpVTFc", * value: 100_000_000_000n // 0.1 KSM * }); * console.log("Transaction included:", result.hash); */ sendAsync(sessionSigner: any | null, options: TransferOptions): Promise; /** * Transfer a specific amount to a destination address by username (WAITS FOR INCLUSION) * * @param sessionSigner - Optional session signer for faster transactions * @param options - Transfer options including username and amount * @returns Promise with transaction result including hash * * @example * const result = await transfer.sendByUsernameAsync(auth.sessionSigner, { * username: "alice", * value: 100_000_000_000n // 0.1 KSM * }); */ sendByUsernameAsync(sessionSigner: any | null, options: TransferByUsernameOptions): Promise; /** * Transfer all available balance to a destination address (WAITS FOR INCLUSION) * * @param sessionSigner - Optional session signer for faster transactions * @param options - SendAll options including destination * @returns Promise with transaction result including hash * * @example * const result = await transfer.sendAllAsync(auth.sessionSigner, { * dest: "5Gq2VNFP4yqK1bk5zt552hBxU68Q3ABewGN99zY7qGbpVTFc" * }); * console.log("Transaction included:", result.hash); */ sendAllAsync(sessionSigner: any | null, options: SendAllOptions): Promise; /** * Get balance information for an address * * @param address - The SS58 address to query * @returns Promise with detailed balance information * * @example * const balance = await transfer.getBalance("5Gq2VNFP4yqK1bk5zt552hBxU68Q3ABewGN99zY7qGbpVTFc"); * console.log(`Free balance: ${transfer.formatAmount(balance.free)} KSM`); */ getBalance(address: string): Promise; /** * Get balance information for a user by username * * @param username - The username to query * @returns Promise with detailed balance information * * @example * const balance = await transfer.getBalanceByUsername("alice"); * console.log(`Alice's balance: ${transfer.formatAmount(balance.free)} KSM`); */ getBalanceByUsername(username: string): Promise; /** * Get user information by username * * @param username - The username to resolve * @returns Promise with user information including address * * @example * const userInfo = await transfer.getUserInfo("alice"); * console.log(`Alice's address: ${userInfo.address}`); */ getUserInfo(username: string): Promise; /** * Format an amount from units to KSM with decimal places * * @param amount - Amount in units (smallest unit) * @param decimals - Number of decimal places (default: 12 for Kusama) * @returns Formatted string with KSM amount * * @example * transfer.formatAmount(1_000_000_000_000n) // "1.000000000000" * transfer.formatAmount(500_000_000_000n) // "0.500000000000" */ formatAmount(amount: bigint, decimals?: number): string; /** * Parse an amount from KSM string to units * * @param amount - Amount as string (e.g., "1.5" for 1.5 KSM) * @param decimals - Number of decimal places (default: 12 for Kusama) * @returns Amount in units * * @example * transfer.parseAmount("1.5") // 1_500_000_000_000n * transfer.parseAmount("0.001") // 1_000_000_000n */ parseAmount(amount: string, decimals?: number): bigint; /** * Validate if an address is a valid SS58 address * * @param address - The address string to validate * @returns true if valid, false otherwise * * @example * transfer.isValidAddress("5Gq2VNFP4yqK1bk5zt552hBxU68Q3ABewGN99zY7qGbpVTFc") // true * transfer.isValidAddress("invalid") // false */ isValidAddress(address: string): boolean; /** * Creates an unsigned transfer extrinsic for batch operations * * @param options - Transfer options including destination and amount * @returns Promise with the unsigned extrinsic * * @example * const transferExtrinsic = await transfer.createTransferExtrinsic({ * dest: "5Gq2VNFP4yqK1bk5zt552hBxU68Q3ABewGN99zY7qGbpVTFc", * value: 100_000_000_000n * }); */ createTransferExtrinsic(options: TransferOptions): Promise; /** * Creates an unsigned transfer extrinsic by username for batch operations * * @param options - Transfer options including username and amount * @returns Promise with the unsigned extrinsic * * @example * const transferExtrinsic = await transfer.createTransferByUsernameExtrinsic({ * username: "alice", * value: 100_000_000_000n * }); */ createTransferByUsernameExtrinsic(options: TransferByUsernameOptions): Promise; /** * Creates an unsigned send all extrinsic for batch operations * * @param options - SendAll options including destination * @returns Promise with the unsigned extrinsic * * @example * const sendAllExtrinsic = await transfer.createSendAllExtrinsic({ * dest: "5Gq2VNFP4yqK1bk5zt552hBxU68Q3ABewGN99zY7qGbpVTFc" * }); */ createSendAllExtrinsic(options: SendAllOptions): Promise; /** * Creates an unsigned send all extrinsic by username for batch operations * * @param options - SendAll options including username * @returns Promise with the unsigned extrinsic * * @example * const sendAllExtrinsic = await transfer.createSendAllByUsernameExtrinsic({ * username: "alice" * }); */ createSendAllByUsernameExtrinsic(options: SendAllByUsernameOptions): Promise; } //# sourceMappingURL=transfer.d.ts.map