Skip to content

Instantly share code, notes, and snippets.

@mrnerdhair
Created June 22, 2021 01:08
Show Gist options
  • Save mrnerdhair/85d3884e28418a12a82efdb521099233 to your computer and use it in GitHub Desktop.
Save mrnerdhair/85d3884e28418a12a82efdb521099233 to your computer and use it in GitHub Desktop.
the current public api of xchainjs-lib, all in a single file for easy reference
import { BncClient } from '@binance-chain/javascript-sdk/lib/client'
import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos'
import { Asset, BaseAmount } from '@xchainjs/xchain-util'
import { Network, Address, Balance, TxHistoryParams, TxsPage, Tx, Fees, TxParams, TxHash, FeeOptionKey } from './types'
export type FeeRate = number
export type FeeRates = Record<FeeOptionKey, FeeRate>
export type FeesWithRates = { rates: FeeRates; fees: Fees }
export type ClientUrl = {
testnet: string
mainnet: string
}
export type ExplorerUrl = {
testnet: string
mainnet: string
}
export type NodeAuth = {
username: string
password: string
}
export interface XChainClient {
setNetwork(net: Network): void
getNetwork(): Network
getExplorerUrl(): string
getExplorerAddressUrl(address: Address): string
getExplorerTxUrl(txID: string): string
getAddress(walletIndex?: number): Address
validateAddress(address: Address): boolean
setPhrase(phrase: string, walletIndex?: number): Address
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>
getTransactions(params?: TxHistoryParams): Promise<TxsPage>
getTransactionData(txId: string, assetAddress?: Address): Promise<Tx>
getFees(params?: unknown): Promise<Fees>
transfer(params: TxParams): Promise<TxHash>
purgeClient(): void
}
export type MultiSendParams = {
walletIndex?: number
transactions: Array<{
to: Address
coins: Array<{
asset: Asset
amount: BaseAmount
}>
}>
memo?: string
}
export interface BinanceClient extends XChainClient {
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
getBncClient(): BncClient
getMultiSendFees(): Promise<Fees>
getSingleAndMultiFees(): Promise<{ single: Fees; multi: Fees }>
multiSend(params: MultiSendParams): Promise<TxHash>
}
export interface BitcoinClient extends XChainClient {
getBalance(address: Address): Promise<Balance[]>
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
transfer(params: TxParams & { feeRate?: FeeRate }): Promise<TxHash>
setSochainUrl(url: string): void
setBlockstreamUrl(url: string): void
getFullDerivationPath(index: number): string
getFeesWithRates(memo?: string): Promise<FeesWithRates>
getFeesWithMemo(memo: string): Promise<Fees>
getFeeRates(): Promise<FeeRates>
}
export interface BitcoinCashClient extends XChainClient {
getFullDerivationPath(index: number): string
getBalance(address: Address): Promise<Balance[]>
getTransactions({ address, offset, limit }: TxHistoryParams): Promise<TxsPage>
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
transfer(params: TxParams & { feeRate?: FeeRate }): Promise<TxHash>
setHaskoinURL(url: ClientUrl): void
getHaskoinURL(): string
setNodeURL(url: ClientUrl): void
getNodeURL(): string
getFeesWithRates(memo?: string): Promise<FeesWithRates>
getFeesWithMemo(memo: string): Promise<Fees>
getFeeRates(): Promise<FeeRates>
}
export interface CosmosClient extends XChainClient {
getFullDerivationPath(index: number): string
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
getSDKClient(): CosmosSDKClient
getMainAsset(): Asset
}
export interface EthereumClient extends XChainClient {
getFullDerivationPath(index: number): string
getFees(params: TxParams): Promise<Fees>
transfer(
params: TxParams & { feeOptionKey?: FeeOptionKey; gasPrice?: BaseAmount; gasLimit?: ethers.BigNumber },
): Promise<TxHash>
setExplorerURL(url: ExplorerUrl): void
getWallet(index?: number): ethers.Wallet
setupProviders(): void
getProvider(): Provider
getEtherscanProvider(): EtherscanProvider
call<T>(
walletIndex: number,
contractAddress: Address,
abi: ethers.ContractInterface,
func: string,
params: unknown[],
): Promise<T>
estimateCall(contractAddress: Address, abi: ethers.ContractInterface, func: string, params: any[]): Promise<BigNumber>
approve(params: ApproveParams & { feeOptionKey?: FeeOptionKey }): Promise<TransactionResponse>
isApproved(spender: Address, sender: Address, amount: BaseAmount): Promise<boolean>
estimateApprove(params: Omit<ApproveParams, 'feeOptionKey' | 'walletIndex'>): Promise<BigNumber>
estimateGasPrices(): Promise<GasPrices>
estimateGasLimit(params: EthFeesParams): Promise<BigNumber>
estimateFeesWithGasPricesAndLimits(params: EthFeesParams): Promise<FeesWithGasPricesAndLimits>
}
export interface LitecoinClient extends XChainClient {
getFullDerivationPath(index: number): string
getBalance(address: Address): Promise<Balance[]>
getTransactions(params?: TxHistoryParams): Promise<TxsPage>
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
transfer(params: TxParams & { feeRate?: FeeRate }): Promise<TxHash>
setSochainUrl(url: string): void
getFeesWithRates(memo?: string): Promise<FeesWithRates>
getFeesWithMemo(memo: string): Promise<Fees>
getFeeRates(): Promise<FeeRates>
}
export interface PolkadotClient extends XChainClient {
getFullDerivationPath(index?: number): string
getTransactions(params?: TxHistoryParams): Promise<TxsPage>
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
getClientUrl(): string
getSS58Format(): number
getWsEndpoint(): string
estimateFees(params: TxParams): Promise<Fees>
}
export type NodeUrl = {
node: string
rpc: string
}
export type ExplorerUrls = {
root: ExplorerUrl
tx: ExplorerUrl
address: ExplorerUrl
}
export type DepositParam = {
walletIndex?: number
asset?: Asset
amount: BaseAmount
memo: string
}
export interface ThorchainClient extends XChainClient {
getFullDerivationPath(index: number): string
getTransactions(params?: TxHistoryParams & { filterFn?: (tx: RPCTxResult) => boolean }): Promise<TxsPage>
getTransactionData(txId: string): Promise<Tx>
getFees(): Promise<Fees>
setClientUrl(clientUrl: ClientUrl): void
getClientUrl(): NodeUrl
setExplorerUrls(urls: ExplorerUrls): void
getCosmosClient(): CosmosSDKClient
getChainId(): string
deposit(params: DepositParam): Promise<TxHash>
getDepositTransaction(txId: string): Promise<Omit<Tx, 'date'>>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment