UNPKG

@xchainjs/xchain-doge

Version:

Custom Doge client and utilities used by XChain clients

153 lines (152 loc) 6.22 kB
import { AssetInfo, FeeRate } from '@xchainjs/xchain-client'; import { Address } from '@xchainjs/xchain-util'; import { Client as UTXOClient, PreparedTx, TxParams, UTXO, UtxoClientParams, UtxoSelectionPreferences } from '@xchainjs/xchain-utxo'; import * as Dogecoin from 'bitcoinjs-lib'; import { LedgerTxInfo, LedgerTxInfoParams } from './types/ledger'; /** * Default parameters for Dogecoin UTXO client. * Contains default values for network, phrase, explorer providers, data providers, root derivation paths, and fee bounds. */ export declare const defaultDogeParams: UtxoClientParams; /** * Custom Dogecoin client extending UTXOClient. * Implements methods for Dogecoin-specific functionality. */ declare abstract class Client extends UTXOClient { /** * Constructor for initializing the Dogecoin client. * Initializes the client with the provided parameters. * * @param {DogecoinClientParams} params Parameters for initializing the Dogecoin client. */ constructor(params?: UtxoClientParams); /** * Get Dogecoin asset information. * * @returns {AssetInfo} Dogecoin asset information. */ getAssetInfo(): AssetInfo; /** * Validate the given address. * * @param {Address} address The Dogecoin address to validate. * @returns {boolean} `true` if the address is valid, otherwise `false`. */ validateAddress(address: string): boolean; /** * Builds a Dogecoin transaction (PSBT). * * Builds a Partially Signed Bitcoin Transaction (PSBT) with the specified parameters. * @param {BuildParams} params The transaction build options including sender, recipient, amount, memo, and fee rate. * @returns {Transaction} A promise that resolves to the built PSBT and the unspent transaction outputs (UTXOs) used in the transaction. * @deprecated This method is deprecated. Use the `transfer` method instead. */ buildTx: ({ amount, recipient, memo, feeRate, sender, }: TxParams & { feeRate: FeeRate; sender: Address; }) => Promise<{ psbt: Dogecoin.Psbt; utxos: UTXO[]; inputs: UTXO[]; }>; /** * Asynchronously creates transaction information for ledger sign. * * Builds a transaction (PSBT) and prepares necessary information for ledger signing. * * @param {LedgerTxInfoParams} params The parameters for creating transaction information. * @returns {LedgerTxInfo} A promise that resolves to the transaction information used for ledger sign. */ createTxInfo(params: LedgerTxInfoParams): Promise<LedgerTxInfo>; /** * Asynchronously prepares a transaction for transfer. * * Builds a transaction (PSBT) with the specified transfer options. * @deprecated Use `prepareTxEnhanced` instead for better UTXO selection and error handling. * @param {TxParams & { sender: Address; feeRate: FeeRate; spendPendingUTXO?: boolean }} params The transfer options including sender address, fee rate, and optional flag for spending pending UTXOs. * @returns {Promise<PreparedTx>} A promise that resolves to the raw unsigned transaction (PSBT). */ prepareTx({ sender, memo, amount, recipient, feeRate, }: TxParams & { sender: Address; feeRate: FeeRate; spendPendingUTXO?: boolean; }): Promise<PreparedTx & { utxos: UTXO[]; inputs: UTXO[]; }>; /** * Compiles the memo into a buffer for inclusion in a Dogecoin transaction. * * @param {string} memo The memo to be compiled. * @returns {Buffer} The compiled memo as a buffer. */ protected compileMemo(memo: string): Buffer; /** * Calculates the transaction fee based on the provided UTXOs, fee rate, and optional data. * * @param {UTXO[]} inputs The unspent transaction outputs (UTXOs) used as inputs. * @param {FeeRate} feeRate The fee rate for the transaction. * @param {Buffer | null} data The compiled memo (optional). * @returns {number} The calculated transaction fee. */ protected getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data?: Buffer | null): number; /** * Build transaction with enhanced UTXO selection * Note: Doge uses legacy P2PKH addresses (nonWitnessUtxo) */ buildTxEnhanced({ amount, recipient, memo, feeRate, sender, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: TxParams & { feeRate: FeeRate; sender: Address; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<{ psbt: Dogecoin.Psbt; utxos: UTXO[]; inputs: UTXO[]; }>; /** * Prepare transaction with enhanced UTXO selection */ prepareTxEnhanced({ sender, memo, amount, recipient, spendPendingUTXO, feeRate, utxoSelectionPreferences, selectedUtxos, }: TxParams & { sender: Address; feeRate: FeeRate; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<PreparedTx>; /** * Send maximum possible amount (sweep) */ sendMax({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: { sender: Address; recipient: Address; memo?: string; feeRate: FeeRate; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<{ psbt: Dogecoin.Psbt; utxos: UTXO[]; inputs: UTXO[]; maxAmount: number; fee: number; }>; /** * Prepare max send transaction */ prepareMaxTx({ sender, recipient, memo, feeRate, spendPendingUTXO, utxoSelectionPreferences, selectedUtxos, }: { sender: Address; recipient: Address; memo?: string; feeRate: FeeRate; spendPendingUTXO?: boolean; utxoSelectionPreferences?: UtxoSelectionPreferences; selectedUtxos?: UTXO[]; }): Promise<PreparedTx & { maxAmount: number; fee: number; }>; } export { Client };