UNPKG

@kaiachain/ethers-ext

Version:
114 lines (113 loc) 6.3 kB
import { ethers, TransactionLike } from "ethers"; /** * Calculate the amount to repay based on whether approval is required and gas price * @param approveRequired Whether approval transaction is required * @param gasPrice Gas price in gkei (default: 25gkei) * @returns The amount to repay */ export declare function getAmountRepay(approveRequired: boolean, gasPrice?: number): string; /** * Get the gasless swap router for the specified chain * @param provider The ethers provider * @param chainId The chain ID * @param address Override the address of the gasless swap router (optional) * @returns The gasless swap router contract */ export declare function getGaslessSwapRouter(provider: ethers.Provider, chainId: number, address?: string): Promise<any>; /** * Get the commission rate for the specified gasless swap router * @param gsr The gasless swap router contract * @returns The commission rate */ export declare function getCommissionRate(gsr: ethers.Contract): Promise<number>; /** * Calculate the minimum amount out based on amount to repay, app transaction fee, and commission rate * @param amountRepay The amount to repay * @param appTxFee The application transaction fee * @param commissionRateBasisPoints The commission rate in basis points (e.g., 1000 = 10%) * @returns The minimum amount out */ export declare function getMinAmountOut(amountRepay: string, appTxFee: string, commissionRateBasisPoints: number): string; /** * Calculate the amount in based on minimum amount out and slippage * @param gsr The gasless swap router contract * @param token The token address * @param minAmountOut The minimum amount out * @param slippageBasisPoints The slippage basis point (e.g., 50 basis points = 0.5%) * @returns The amount in */ export declare function getAmountIn(gsr: ethers.Contract, token: string, minAmountOut: string, slippageBasisPoints: number): Promise<string>; /** * Generate a approve transaction * @param provider The ethers provider * @param fromAddress The sender address * @param tokenAddr The token address * @param routerAddress The router address * @param amount The amount to approve * @returns The approve transaction */ export declare function getApproveTx(provider: ethers.Provider, fromAddress: string, tokenAddr: string, routerAddress: string): Promise<ethers.TransactionRequest>; /** * Generate an swap transaction * @param provider The ethers provider * @param fromAddress The sender address * @param tokenAddr The token address to swap * @param amountIn The amount to swap * @param minAmountOut The minimum amount out * @param amountRepay The amount to repay * @param isSingle Whether this is a single transaction (default: true) * @param deadline The deadline in seconds (default: 1800) * @returns The swap transaction */ export declare function getSwapTx(provider: ethers.Provider, fromAddress: string, tokenAddr: string, amountIn: string, minAmountOut: string, amountRepay: string, isSingle?: boolean, deadline?: number): Promise<ethers.TransactionRequest>; /** * Send gasless transactions * @param approveTxOrNull The approve transaction or null if not needed * @param swapTx The swap transaction * @param provider Optional provider to use for sending transactions * @returns Array of transaction hashes */ export declare function sendGaslessTx(approveTxOrNull: string | null, swapTx: string, provider: ethers.Provider): Promise<string[]>; /** * Check if a token is supported for gasless transactions * @param signer The ethers signer * @param token The token address * @param chainId The chain ID * @returns True if the token is supported, false otherwise */ export declare function isGaslessSupportedToken(provider: ethers.Provider, token: string, chainId: number): Promise<boolean>; /** * Check if a transaction is a gasless approve transaction * @param provider The ethers provider * @param tx The transaction * @param chainId The chain ID * @returns True if the transaction is a gasless approve transaction, false otherwise */ export declare function isGaslessApprove(provider: ethers.Provider, tx: string | any, chainId: number): Promise<boolean>; export declare function isValidSwapTxFormat(txRequest: TransactionLike<string>): boolean; export declare function isValidRouterAddress(provider: ethers.Provider, txRequest: TransactionLike<string>, chainId: number): Promise<boolean>; export declare function validateAndDecodeSwapFunction(data: string): { isValid: boolean; decodedParams?: { tokenData: string; amountInData: string; amountRepayData: string; }; }; export declare function validateApproveToken(approveTxRequest: TransactionLike<string>, tokenData: string): boolean; export declare function validateApproveAmount(approveTxRequest: TransactionLike<string>, amountInData: string): boolean; export declare function validateNonceWithApprove(provider: ethers.Provider, approveTxRequest: TransactionLike<string>, swapTxRequest: TransactionLike<string>): Promise<boolean>; export declare function validateAmountRepayWithApprove(swapTxRequest: TransactionLike<string>, amountRepayData: string): boolean; export declare function validateNonceWithoutApprove(provider: ethers.Provider, swapTxRequest: TransactionLike<string>): Promise<boolean>; export declare function validateAmountRepayWithoutApprove(swapTxRequest: TransactionLike<string>, amountRepayData: string): boolean; export declare function validateWithApprove(provider: ethers.Provider, approveTx: string | any, swapTxRequest: TransactionLike<string>, tokenData: string, amountInData: string, amountRepayData: string, chainId: number): Promise<boolean>; export declare function validateWithoutApprove(provider: ethers.Provider, swapTxRequest: TransactionLike<string>, amountRepayData: string): Promise<boolean>; /** * Check if transactions form a valid gasless swap * @param approveTxOrNull The approve transaction or null if not needed * @param swapTx The swap transaction * @param chainId The chain ID * @param provider The ethers provider * @returns True if the transactions form a valid gasless swap, false otherwise */ export declare function isGaslessSwap(provider: ethers.Provider, approveTxOrNull: string | any | null, swapTx: string | any, chainId: number): Promise<boolean>;