import { Interface } from '@ethersproject/abi'; import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, PoolLiquidity, DexExchangeParam, Logger } from '../../types'; import { SwapSide, Network } from '../../constants'; import { Context, IDex } from '../idex'; import { IDexHelper } from '../../dex-helper'; import { CollateralReserves, DebtReserves, FluidDexData, FluidDexPool, DexLimits, TokenLimit, PoolWithDecimals } from './types'; import { SimpleExchange } from '../simple-exchange'; import { FluidDexFactory } from './fluid-dex-factory'; import { FluidDexLiquidityProxy } from './fluid-dex-liquidity-proxy'; import { FluidDexEventPool } from './fluid-dex-pool'; export declare class FluidDex extends SimpleExchange implements IDex { readonly network: Network; readonly dexKey: string; readonly dexHelper: IDexHelper; readonly hasConstantPriceLargeAmounts = false; readonly needWrapNative = false; readonly isFeeOnTransferSupported = false; readonly isStatePollingDex = true; static dexKeysWithNetwork: { key: string; networks: Network[]; }[]; logger: Logger; pools: FluidDexPool[]; eventPools: FluidDexEventPool[]; readonly factory: FluidDexFactory; readonly liquidityProxy: FluidDexLiquidityProxy; readonly fluidDexPoolIface: Interface; private reserveUpdateIntervalTask?; constructor(network: Network, dexKey: string, dexHelper: IDexHelper); private fetchFluidDexPools; private generateFluidDexPoolsFromPoolsFactory; initializePricing(blockNumber: number): Promise; private updateReserves; getAdapters(side: SwapSide): null; protected onPoolCreatedUpdatePools(poolsFromFactory: readonly PoolWithDecimals[]): void; getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise; getPoolsByTokenPair(srcToken: Address, destToken: Address): FluidDexPool[]; getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise>; getCalldataGasCost(poolPrices: PoolPrices): number | number[]; getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: FluidDexData, side: SwapSide): AdapterExchangeParam; updatePoolState(): Promise; getTopPoolsForToken(tokenAddress: Address, limit: number): Promise; getDexParam(srcToken: Address, destToken: Address, srcAmount: string, destAmount: string, recipient: Address, data: FluidDexData, side: SwapSide, context: Context, executorAddress: Address): Promise; /** * Calculates the output amount for a given input amount in a swap operation. * @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise. * @param amountIn - The amount of input token to be swapped (as a BigInt). * @param colReserves - The reserves of the collateral pool. * @param debtReserves - The reserves of the debt pool. * @param inDecimals - The number of decimals for the input token. * @param outDecimals - The number of decimals for the output token. * @returns The calculated output amount (as a BigInt). */ swapIn(swap0To1: boolean, amountIn: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, inDecimals: number, outDecimals: number, fee: bigint, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint; /** * Calculates the output amount for a given input amount in a swap operation. * @param swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise. * @param amountToSwap - The amount of input token to be swapped. * @param colReserves - The reserves of the collateral pool. * @param debtReserves - The reserves of the debt pool. * @returns The calculated output amount. */ swapInAdjusted(swap0To1: boolean, amountToSwap: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, fee: bigint, outDecimals: number, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint; /** * Checks if token0 reserves are sufficient compared to token1 reserves. * This helps prevent edge cases and ensures high precision in calculations. * @param {number} token0Reserves - The reserves of token0. * @param {number} token1Reserves - The reserves of token1. * @param {number} price - The current price used for calculation. * @returns {boolean} - Returns false if token0 reserves are too low, true otherwise. */ protected verifyToken0Reserves(token0Reserves: bigint, token1Reserves: bigint, price: bigint): boolean; /** * Checks if token1 reserves are sufficient compared to token0 reserves. * This helps prevent edge cases and ensures high precision in calculations. * @param {number} token0Reserves - The reserves of token0. * @param {number} token1Reserves - The reserves of token1. * @param {number} price - The current price used for calculation. * @returns {boolean} - Returns false if token1 reserves are too low, true otherwise. */ protected verifyToken1Reserves(token0Reserves: bigint, token1Reserves: bigint, price: bigint): boolean; /** * Calculates the currently available swappable amount for a token limit considering expansion since last syncTime. * @param syncTime - timestamp in seconds when the limits were synced * @param limit - token limit object containing available amount, expandsTo amount, and expandDuration * @returns The calculated available swappable amount (borrowable or withdrawable) */ getExpandedLimit(syncTime: number, limit: TokenLimit): bigint; /** * Given an input amount of asset and pair reserves, returns the maximum output amount of the other asset. * @param amountIn - The amount of input asset. * @param iReserveIn - Imaginary token reserve with input amount. * @param iReserveOut - Imaginary token reserve of output amount. * @returns The maximum output amount of the other asset. */ getAmountOut(amountIn: bigint, iReserveIn: bigint, iReserveOut: bigint): bigint; /** * Given an output amount of asset and pair reserves, returns the input amount of the other asset * @param amountOut - Desired output amount of the asset. * @param iReserveIn - Imaginary token reserve of input amount. * @param iReserveOut - Imaginary token reserve of output amount. * @returns The input amount of the other asset. */ getAmountIn(amountOut: bigint, iReserveIn: bigint, iReserveOut: bigint): bigint; /** * Calculates how much of a swap should go through the collateral pool for output amount. * @param t - Total amount out. * @param x - Imaginary reserves of token in of collateral. * @param y - Imaginary reserves of token out of collateral. * @param x2 - Imaginary reserves of token in of debt. * @param y2 - Imaginary reserves of token out of debt. * @returns How much swap should go through collateral pool. Remaining will go from debt. * @note If a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool. * @note If a > t then entire trade route through col pool and col pool arbitrage with debt pool. * @note If a > 0 & a < t then swap will route through both pools. */ swapRoutingOut(t: bigint, x: bigint, y: bigint, x2: bigint, y2: bigint): bigint; /** * Calculates how much of a swap should go through the collateral pool. * @param t - Total amount in. * @param x - Imaginary reserves of token out of collateral. * @param y - Imaginary reserves of token in of collateral. * @param x2 - Imaginary reserves of token out of debt. * @param y2 - Imaginary reserves of token in of debt. * @returns How much swap should go through collateral pool. Remaining will go from debt. * @note If a < 0 then entire trade route through debt pool and debt pool arbitrage with col pool. * @note If a > t then entire trade route through col pool and col pool arbitrage with debt pool. * @note If a > 0 & a < t then swap will route through both pools. */ swapRoutingIn(t: bigint, x: bigint, y: bigint, x2: bigint, y2: bigint): bigint; /** * Calculates the input amount for a given output amount in a swap operation. * @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise. * @param {bigint} amountOut - The amount of output token to be swapped. * @param {Reserves} colReserves - The reserves of the collateral pool. * @param {Reserves} debtReserves - The reserves of the debt pool. * @param {number} inDecimals - The number of decimals for the input token. * @param {number} outDecimals - The number of decimals for the output token. * @param {number} fee - The fee for the swap. 1e4 = 1% * @returns {bigint} amountIn - The calculated input amount required for the swap. */ swapOut(swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, inDecimals: number, outDecimals: number, fee: bigint, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint; /** * Calculates the input amount for a given output amount in a swap operation. * @param {boolean} swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise. * @param {bigint} amountOut - The amount of output token to be swapped. * @param {CollateralReserves} colReserves - The reserves of the collateral pool. * @param {DebtReserves} debtReserves - The reserves of the debt pool. * @returns {bigint} The calculated input amount required for the swap. */ swapOutAdjusted(swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, fee: bigint, outDecimals: number, currentLimits: DexLimits, centerPrice: bigint, syncTime: number): bigint; private applyFeeForBuy; private applyFeeForSell; private abs; releaseResources(): void; }