UNPKG

@dzapio/sdk

Version:

A TypeScript/JavaScript SDK for interacting with the DZap protocol, providing utilities for DeFi operations including Swaps, Bridges, and Zaps.

384 lines (383 loc) 12.9 kB
import { Signer, Wallet } from 'ethers'; import { StatusCodes, TxnStatus } from 'src/enums'; import { ApprovalMode, AvailableDZapServices, CalculatePointsRequest, ChainData, ExecuteTxnData, HexString, OtherAvailableAbis, PermitMode, TokenInfo, TokenResponse, TradeBuildTxnRequest, TradeBuildTxnResponse, TradeQuotesRequest, TradeQuotesResponse, TradeStatusResponse } from 'src/types'; import { ZapBuildTxnRequest, ZapBuildTxnResponse, ZapQuoteRequest, ZapQuoteResponse, ZapStatusRequest, ZapStatusResponse } from 'src/types/zap'; import { ZapTransactionStep } from 'src/types/zap/step'; import { TransactionReceipt, WalletClient } from 'viem'; declare class DZapClient { private static instance; private cancelTokenSource; private static chainConfig; private priceService; rpcUrlsByChainId: Record<number, string[]>; private constructor(); static getInstance(rpcUrlsByChainId?: Record<number, string[]>): DZapClient; static getChainConfig(): Promise<ChainData>; static getDZapAbi(service: AvailableDZapServices): import("viem").Abi; static getOtherAbi: (name: OtherAvailableAbis) => ({ inputs: { internalType: string; name: string; type: string; }[]; name: string; type: string; anonymous?: undefined; outputs?: undefined; stateMutability?: undefined; } | { anonymous: boolean; inputs: { indexed: boolean; internalType: string; name: string; type: string; }[]; name: string; type: string; outputs?: undefined; stateMutability?: undefined; } | { inputs: { internalType: string; name: string; type: string; }[]; name: string; outputs: { internalType: string; name: string; type: string; }[]; stateMutability: string; type: string; anonymous?: undefined; } | { inputs: ({ internalType: string; name: string; type: string; components?: undefined; } | { components: ({ components: { internalType: string; name: string; type: string; }[]; internalType: string; name: string; type: string; } | { internalType: string; name: string; type: string; components?: undefined; })[]; internalType: string; name: string; type: string; })[]; name: string; outputs: never[]; stateMutability: string; type: string; anonymous?: undefined; })[] | readonly [{ readonly constant: true; readonly inputs: readonly []; readonly name: "name"; readonly outputs: readonly [{ readonly name: ""; readonly type: "string"; }]; readonly payable: false; readonly stateMutability: "view"; readonly type: "function"; }, { readonly constant: false; readonly inputs: readonly [{ readonly name: "_spender"; readonly type: "address"; }, { readonly name: "_value"; readonly type: "uint256"; }]; readonly name: "approve"; readonly outputs: readonly []; readonly payable: false; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly constant: true; readonly inputs: readonly []; readonly name: "totalSupply"; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; }]; readonly payable: false; readonly stateMutability: "view"; readonly type: "function"; }, { readonly constant: false; readonly inputs: readonly [{ readonly name: "_from"; readonly type: "address"; }, { readonly name: "_to"; readonly type: "address"; }, { readonly name: "_value"; readonly type: "uint256"; }]; readonly name: "transferFrom"; readonly outputs: readonly [{ readonly name: ""; readonly type: "bool"; }]; readonly payable: false; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly constant: true; readonly inputs: readonly []; readonly name: "decimals"; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint8"; }]; readonly payable: false; readonly stateMutability: "view"; readonly type: "function"; }, { readonly constant: true; readonly inputs: readonly [{ readonly name: "_owner"; readonly type: "address"; }]; readonly name: "balanceOf"; readonly outputs: readonly [{ readonly name: "balance"; readonly type: "uint256"; }]; readonly payable: false; readonly stateMutability: "view"; readonly type: "function"; }, { readonly constant: true; readonly inputs: readonly []; readonly name: "symbol"; readonly outputs: readonly [{ readonly name: ""; readonly type: "string"; }]; readonly payable: false; readonly stateMutability: "view"; readonly type: "function"; }, { readonly constant: false; readonly inputs: readonly [{ readonly name: "_to"; readonly type: "address"; }, { readonly name: "_value"; readonly type: "uint256"; }]; readonly name: "transfer"; readonly outputs: readonly [{ readonly name: ""; readonly type: "bool"; }]; readonly payable: false; readonly stateMutability: "nonpayable"; readonly type: "function"; }, { readonly constant: true; readonly inputs: readonly [{ readonly name: "_owner"; readonly type: "address"; }, { readonly name: "_spender"; readonly type: "address"; }]; readonly name: "allowance"; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; }]; readonly payable: false; readonly stateMutability: "view"; readonly type: "function"; }, { readonly payable: true; readonly stateMutability: "payable"; readonly type: "fallback"; }, { readonly anonymous: false; readonly inputs: readonly [{ readonly indexed: true; readonly name: "owner"; readonly type: "address"; }, { readonly indexed: true; readonly name: "spender"; readonly type: "address"; }, { readonly indexed: false; readonly name: "value"; readonly type: "uint256"; }]; readonly name: "Approval"; readonly type: "event"; }, { readonly anonymous: false; readonly inputs: readonly [{ readonly indexed: true; readonly name: "from"; readonly type: "address"; }, { readonly indexed: true; readonly name: "to"; readonly type: "address"; }, { readonly indexed: false; readonly name: "value"; readonly type: "uint256"; }]; readonly name: "Transfer"; readonly type: "event"; }]; getTradeQuotes(request: TradeQuotesRequest): Promise<TradeQuotesResponse>; buildTradeTxn(request: TradeBuildTxnRequest): Promise<TradeBuildTxnResponse>; getTradeTxnStatus({ txHash, txIds, chainId, }: { txHash?: string; txIds?: string; chainId?: number; }): Promise<TradeStatusResponse | Record<string, TradeStatusResponse>>; getAllSupportedChains(): Promise<ChainData>; getAllTokens(chainId: number, source?: string, account?: string): Promise<any>; getTokenDetails(tokenAddress: string, chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean): Promise<TokenInfo>; getTokensDetails(tokenAddresses: string[], chainId: number, account?: string, includeBalance?: boolean, includePrice?: boolean): Promise<Record<string, TokenInfo>>; getTokenPrices(tokenAddresses: string[], chainId: number): Promise<Record<string, string | null>>; trade({ request, signer, txnData, }: { request: TradeBuildTxnRequest; signer: Signer | WalletClient; txnData?: TradeBuildTxnResponse; }): Promise<import("src/types").DZapTransactionResponse>; sendTransaction({ signer, txnData }: { chainId: number; signer: Signer | WalletClient; txnData: ExecuteTxnData; }): Promise<{ status: TxnStatus; error: any; errorMsg: any; code: StatusCodes; } | { status: TxnStatus; code: StatusCodes; txnHash: HexString; }>; decodeTxnData({ data, service, chainId }: { data: TransactionReceipt; service: AvailableDZapServices; chainId: number; }): Promise<{ swapFailPairs: string[]; swapInfo: import("src/types").SwapInfo | import("src/types").SwapInfo[]; }>; calculatePoints(request: CalculatePointsRequest): Promise<{ points: number; }>; getDZapContractAddress({ chainId, service }: { chainId: number; service: AvailableDZapServices; }): Promise<string>; getAllowance({ chainId, sender, tokens, service, rpcUrls, spender, mode, }: { chainId: number; sender: HexString; tokens: { address: HexString; amount: bigint; }[]; service: AvailableDZapServices; rpcUrls?: string[]; spender?: HexString; mode?: ApprovalMode; }): Promise<{ status: TxnStatus; code: StatusCodes; data: { [key: string]: { allowance: bigint; approvalNeeded: boolean; signatureNeeded: boolean; }; }; }>; approve({ chainId, signer, tokens, approvalTxnCallback, service, mode, rpcUrls, spender, }: { chainId: number; signer: WalletClient | Signer; tokens: { address: HexString; amount: bigint; }[]; approvalTxnCallback?: ({ txnDetails, address, }: { txnDetails: { txnHash: string; code: StatusCodes; status: TxnStatus; }; address: HexString; }) => Promise<TxnStatus | void>; service: AvailableDZapServices; spender?: HexString; rpcUrls?: string[]; mode?: ApprovalMode; }): Promise<{ status: TxnStatus; code: StatusCodes; }>; sign({ chainId, sender, tokens, service, spender, rpcUrls, signer, permitType, signatureCallback, }: { chainId: number; sender: HexString; tokens: { address: HexString; amount: string; }[]; service: AvailableDZapServices; signer: WalletClient | Wallet; spender?: HexString; rpcUrls?: string[]; permitType?: PermitMode; signatureCallback?: ({ permitData, srcToken, amount, permitType, }: { permitData: HexString; srcToken: string; amount: bigint; permitType: PermitMode; }) => Promise<void>; }): Promise<{ status: TxnStatus; tokens: { address: HexString; permitData?: HexString; amount: string; }[]; code: StatusCodes; }>; zap({ request, steps, signer }: { request: ZapBuildTxnRequest; signer: WalletClient | Signer; steps?: ZapTransactionStep[]; }): Promise<import("src/types").DZapTransactionResponse | { status: TxnStatus.success; code: StatusCodes | number; txnHash: HexString; }>; buildZapTxn(request: ZapBuildTxnRequest): Promise<ZapBuildTxnResponse>; getZapQuote(request: ZapQuoteRequest): Promise<ZapQuoteResponse>; getZapTxnStatus(request: ZapStatusRequest): Promise<ZapStatusResponse>; getBalances(chainId: number, account: string): Promise<Record<string, TokenResponse>>; } export default DZapClient;