UNPKG

@kaiachain/ethers-ext

Version:
80 lines (79 loc) 3.96 kB
import { ethers, BigNumberish, Contract, TransactionLike } from "ethers"; import { TransactionRequest } from "./types.js"; /** * 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, address?: string): Promise<Contract>; /** * 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 * @returns The amount to repay */ export declare function getAmountRepay(approveRequired: boolean, gasPrice: number): bigint; /** * 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 commissionRateBps The commission rate in basis points (e.g., 1000 = 10%) * @returns The minimum amount out */ export declare function getMinAmountOut(amountRepay: BigNumberish, appTxFee: BigNumberish, commissionRateBps: BigNumberish): bigint; /** * Calculate the amount in based on minimum amount out and slippage * @param router The gasless swap router contract * @param tokenAddress The token address * @param minAmountOut The minimum amount out * @param slippageBps The slippage basis point (e.g., 50 basis points = 0.5%) * @returns The amount in */ export declare function getAmountIn(router: ethers.Contract, tokenAddress: string, minAmountOut: BigNumberish, slippageBps: BigNumberish): Promise<bigint>; /** * Generate a approve transaction * @param provider The ethers provider * @param fromAddress The sender address * @param tokenAddress 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, tokenAddress: string, routerAddress: string, gasPrice: BigNumberish): Promise<ethers.TransactionRequest>; /** * Generate an swap transaction * @param provider The ethers provider * @param fromAddress The sender address * @param tokenAddress 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, tokenAddress: string, routerAddress: string, amountIn: BigNumberish, minAmountOut: BigNumberish, amountRepay: BigNumberish, gasPrice: BigNumberish, approveRequired?: boolean, deadlineBuffer?: BigNumberish): Promise<ethers.TransactionRequest>; /** * Check if a transaction is a gasless approve transaction * @param provider The ethers provider * @param tx The transaction * @returns True if the transaction is a gasless approve transaction, false otherwise */ export declare function isGaslessApprove(provider: ethers.Provider, router: Contract, transactionOrRLP: TransactionRequest | string): Promise<{ ok: boolean; error?: string; }>; /** * Check if transactions form a valid gasless swap * @param approveTxOrNull The approve transaction or null if not needed * @param transactionOrRLP 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, router: Contract, approveTxOrNull: TransactionLike | string | null, transactionOrRLP: TransactionLike | string): Promise<{ ok: boolean; error?: string; }>;