From 9f4d82e56eac81048a1916cf1ee65e7f909d45b0 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 24 Sep 2024 04:07:10 +0530 Subject: [PATCH 01/64] initial commit --- src/abi/fluid-dex/fluid-dex.abi.json | 922 ++++++++++++++++++ src/dex/fluid-dex/config.ts | 26 + src/dex/fluid-dex/fluid-dex-e2e.test.ts | 155 +++ src/dex/fluid-dex/fluid-dex-events.test.ts | 106 ++ .../fluid-dex/fluid-dex-integration.test.ts | 251 +++++ src/dex/fluid-dex/fluid-dex-pool.ts | 115 +++ src/dex/fluid-dex/fluid-dex.ts | 409 ++++++++ src/dex/fluid-dex/types.ts | 51 + 8 files changed, 2035 insertions(+) create mode 100644 src/abi/fluid-dex/fluid-dex.abi.json create mode 100644 src/dex/fluid-dex/config.ts create mode 100644 src/dex/fluid-dex/fluid-dex-e2e.test.ts create mode 100644 src/dex/fluid-dex/fluid-dex-events.test.ts create mode 100644 src/dex/fluid-dex/fluid-dex-integration.test.ts create mode 100644 src/dex/fluid-dex/fluid-dex-pool.ts create mode 100644 src/dex/fluid-dex/fluid-dex.ts create mode 100644 src/dex/fluid-dex/types.ts diff --git a/src/abi/fluid-dex/fluid-dex.abi.json b/src/abi/fluid-dex/fluid-dex.abi.json new file mode 100644 index 000000000..14ada197a --- /dev/null +++ b/src/abi/fluid-dex/fluid-dex.abi.json @@ -0,0 +1,922 @@ +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "errorId", + "type": "uint256" + } + ], + "name": "FluidDexError", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares", + "type": "uint256" + } + ], + "name": "FluidDexLiquidityOutput", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "token0Amt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt", + "type": "uint256" + } + ], + "name": "FluidDexPerfectLiquidityOutput", + "type": "error" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex_", + "type": "tuple" + } + ], + "name": "FluidDexPricesAndExchangeRates", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmt", + "type": "uint256" + } + ], + "name": "FluidDexSingleTokenOutput", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + } + ], + "name": "FluidDexSwapResult", + "type": "error" + }, + { + "inputs": [], + "name": "DEX_ID", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxSharesAmt_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "borrow", + "outputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken0Borrow_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken1Borrow_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "borrowPerfect", + "outputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "constantsView", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "shift", + "type": "address" + }, + { + "internalType": "address", + "name": "admin", + "type": "address" + }, + { + "internalType": "address", + "name": "colOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "debtOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "perfectOperationsAndOracle", + "type": "address" + } + ], + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", + "type": "tuple" + }, + { + "internalType": "address", + "name": "deployerContract", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantsView_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "constantsView2", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0DenominatorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1DenominatorPrecision", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantsView2_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minSharesAmt_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "deposit", + "outputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken0Deposit_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken1Deposit_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "depositPerfect", + "outputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "geometricMean_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0SupplyExchangePrice_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1SupplyExchangePrice_", + "type": "uint256" + } + ], + "name": "getCollateralReserves", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "c_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "geometricMean_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0BorrowExchangePrice_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1BorrowExchangePrice_", + "type": "uint256" + } + ], + "name": "getDebtReserves", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "d_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getPricesAndExchangePrices", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256[]", + "name": "secondsAgos_", + "type": "uint256[]" + } + ], + "name": "oraclePrice", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "twap1by0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowestPrice1by0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "highestPrice1by0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "twap0by1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowestPrice0by1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "highestPrice0by1", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.Oracle[]", + "name": "twaps_", + "type": "tuple[]" + }, + { + "internalType": "uint256", + "name": "currentPrice_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minSharesAmt_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "payback", + "outputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken0Payback_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken1Payback_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "paybackPerfect", + "outputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken0_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken1_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "paybackPerfectInOneToken", + "outputs": [ + { + "internalType": "uint256", + "name": "paybackAmt_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "slot_", + "type": "bytes32" + } + ], + "name": "readFromStorage", + "outputs": [ + { + "internalType": "uint256", + "name": "result_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amountIn_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin_", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to_", + "type": "address" + } + ], + "name": "swapIn", + "outputs": [ + { + "internalType": "uint256", + "name": "amountOut_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amountOut_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax_", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to_", + "type": "address" + } + ], + "name": "swapOut", + "outputs": [ + { + "internalType": "uint256", + "name": "amountIn_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxSharesAmt_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "withdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken0Withdraw_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken1Withdraw_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "withdrawPerfect", + "outputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken0_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken1_", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "estimate_", + "type": "bool" + } + ], + "name": "withdrawPerfectInOneToken", + "outputs": [ + { + "internalType": "uint256", + "name": "withdrawAmt_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts new file mode 100644 index 000000000..a3eebae2f --- /dev/null +++ b/src/dex/fluid-dex/config.ts @@ -0,0 +1,26 @@ +import { DexParams } from './types'; +import { DexConfigMap, AdapterMappings } from '../../types'; +import { Network, SwapSide } from '../../constants'; + +export const FluidDexConfig: DexConfigMap = { + FluidDex: { + [Network.MAINNET]: { + pools: [ + { + id: 'FluidDex_0x6d83f60eEac0e50A1250760151E81Db2a278e03a', // Pool identifier: `{dex_key}_{pool_address}` + address: '0x6d83f60eEac0e50A1250760151E81Db2a278e03a', // Address of the pool + token0: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // wstETH + token1: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH + }, + ], + }, + }, +}; + +export const FLUID_DEX_GAS_COST = 80_000; + +export const Adapters: Record = { + // TODO: add adapters for each chain + // This is an example to copy + [Network.MAINNET]: { [SwapSide.SELL]: [{ name: '', index: 0 }] }, +}; diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts new file mode 100644 index 000000000..23d0a0caf --- /dev/null +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -0,0 +1,155 @@ +/* eslint-disable no-console */ +import dotenv from 'dotenv'; +dotenv.config(); + +import { testE2E } from '../../../tests/utils-e2e'; +import { + Tokens, + Holders, + NativeTokenSymbols, +} from '../../../tests/constants-e2e'; +import { Network, ContractMethod, SwapSide } from '../../constants'; +import { StaticJsonRpcProvider } from '@ethersproject/providers'; +import { generateConfig } from '../../config'; + +/* + README + ====== + + This test script should add e2e tests for FluidDex. The tests + should cover as many cases as possible. Most of the DEXes follow + the following test structure: + - DexName + - ForkName + Network + - ContractMethod + - ETH -> Token swap + - Token -> ETH swap + - Token -> Token swap + + The template already enumerates the basic structure which involves + testing simpleSwap, multiSwap, megaSwap contract methods for + ETH <> TOKEN and TOKEN <> TOKEN swaps. You should replace tokenA and + tokenB with any two highly liquid tokens on FluidDex for the tests + to work. If the tokens that you would like to use are not defined in + Tokens or Holders map, you can update the './tests/constants-e2e' + + Other than the standard cases that are already added by the template + it is highly recommended to add test cases which could be specific + to testing FluidDex (Eg. Tests based on poolType, special tokens, + etc). + + You can run this individual test script by running: + `npx jest src/dex//-e2e.test.ts` + + e2e tests use the Tenderly fork api. Please add the following to your + .env file: + TENDERLY_TOKEN=Find this under Account>Settings>Authorization. + TENDERLY_ACCOUNT_ID=Your Tenderly account name. + TENDERLY_PROJECT=Name of a Tenderly project you have created in your + dashboard. + + (This comment should be removed from the final implementation) +*/ + +function testForNetwork( + network: Network, + dexKey: string, + tokenASymbol: string, + tokenBSymbol: string, + tokenAAmount: string, + tokenBAmount: string, + nativeTokenAmount: string, +) { + const provider = new StaticJsonRpcProvider( + generateConfig(network).privateHttpProvider, + network, + ); + const tokens = Tokens[network]; + const holders = Holders[network]; + const nativeTokenSymbol = NativeTokenSymbols[network]; + + // TODO: Add any direct swap contractMethod name if it exists + const sideToContractMethods = new Map([ + [SwapSide.SELL, [ContractMethod.swapExactAmountIn]], + // TODO: If buy is not supported remove the buy contract methods + [SwapSide.BUY, [ContractMethod.swapExactAmountOut]], + ]); + + describe(`${network}`, () => { + sideToContractMethods.forEach((contractMethods, side) => + describe(`${side}`, () => { + contractMethods.forEach((contractMethod: ContractMethod) => { + describe(`${contractMethod}`, () => { + it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { + await testE2E( + tokens[nativeTokenSymbol], + tokens[tokenASymbol], + holders[nativeTokenSymbol], + side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[nativeTokenSymbol], + holders[tokenASymbol], + side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[tokenBSymbol], + holders[tokenASymbol], + side === SwapSide.SELL ? tokenAAmount : tokenBAmount, + side, + dexKey, + contractMethod, + network, + provider, + ); + }); + }); + }); + }), + ); + }); +} + +describe('FluidDex E2E', () => { + const dexKey = 'FluidDex'; + + describe('Mainnet', () => { + const network = Network.MAINNET; + + // TODO: Modify the tokenASymbol, tokenBSymbol, tokenAAmount; + const tokenASymbol: string = 'tokenASymbol'; + const tokenBSymbol: string = 'tokenBSymbol'; + + const tokenAAmount: string = 'tokenAAmount'; + const tokenBAmount: string = 'tokenBAmount'; + const nativeTokenAmount = '1000000000000000000'; + + testForNetwork( + network, + dexKey, + tokenASymbol, + tokenBSymbol, + tokenAAmount, + tokenBAmount, + nativeTokenAmount, + ); + + // TODO: Add any additional test cases required to test FluidDex + }); +}); diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts new file mode 100644 index 000000000..867a0f4c3 --- /dev/null +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -0,0 +1,106 @@ +/* eslint-disable no-console */ +import dotenv from 'dotenv'; +dotenv.config(); + +import { FluidDexEventPool } from './fluid-dex-pool'; +import { Network } from '../../constants'; +import { Address } from '../../types'; +import { DummyDexHelper } from '../../dex-helper/index'; +import { testEventSubscriber } from '../../../tests/utils-events'; +import { PoolState } from './types'; + +/* + README + ====== + + This test script adds unit tests for FluidDex event based + system. This is done by fetching the state on-chain before the + event block, manually pushing the block logs to the event-subscriber, + comparing the local state with on-chain state. + + Most of the logic for testing is abstracted by `testEventSubscriber`. + You need to do two things to make the tests work: + + 1. Fetch the block numbers where certain events were released. You + can modify the `./scripts/fetch-event-blocknumber.ts` to get the + block numbers for different events. Make sure to get sufficient + number of blockNumbers to cover all possible cases for the event + mutations. + + 2. Complete the implementation for fetchPoolState function. The + function should fetch the on-chain state of the event subscriber + using just the blocknumber. + + The template tests only include the test for a single event + subscriber. There can be cases where multiple event subscribers + exist for a single DEX. In such cases additional tests should be + added. + + You can run this individual test script by running: + `npx jest src/dex//-events.test.ts` + + (This comment should be removed from the final implementation) +*/ + +jest.setTimeout(50 * 1000); + +async function fetchPoolState( + fluidDexPools: FluidDexEventPool, + blockNumber: number, + poolAddress: string, +): Promise { + // TODO: complete me! + return {}; +} + +// eventName -> blockNumbers +type EventMappings = Record; + +describe('FluidDex EventPool Mainnet', function () { + const dexKey = 'FluidDex'; + const network = Network.MAINNET; + const dexHelper = new DummyDexHelper(network); + const logger = dexHelper.getLogger(dexKey); + let fluidDexPool: FluidDexEventPool; + + // poolAddress -> EventMappings + const eventsToTest: Record = { + // TODO: complete me! + }; + + beforeEach(async () => { + fluidDexPool = new FluidDexEventPool( + dexKey, + network, + dexHelper, + logger, + /* TODO: Put here additional constructor arguments if needed */ + ); + }); + + Object.entries(eventsToTest).forEach( + ([poolAddress, events]: [string, EventMappings]) => { + describe(`Events for ${poolAddress}`, () => { + Object.entries(events).forEach( + ([eventName, blockNumbers]: [string, number[]]) => { + describe(`${eventName}`, () => { + blockNumbers.forEach((blockNumber: number) => { + it(`State after ${blockNumber}`, async function () { + await testEventSubscriber( + fluidDexPool, + fluidDexPool.addressesSubscribed, + (_blockNumber: number) => + fetchPoolState(fluidDexPool, _blockNumber, poolAddress), + blockNumber, + `${dexKey}_${poolAddress}`, + dexHelper.provider, + ); + }); + }); + }); + }, + ); + }); + }, + ); +}); diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts new file mode 100644 index 000000000..1c71cb982 --- /dev/null +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -0,0 +1,251 @@ +/* eslint-disable no-console */ +import dotenv from 'dotenv'; +dotenv.config(); + +import { Interface, Result } from '@ethersproject/abi'; +import { DummyDexHelper } from '../../dex-helper/index'; +import { Network, SwapSide } from '../../constants'; +import { BI_POWS } from '../../bigint-constants'; +import { FluidDex } from './fluid-dex'; +import { + checkPoolPrices, + checkPoolsLiquidity, + checkConstantPoolPrices, +} from '../../../tests/utils'; +import { Tokens } from '../../../tests/constants-e2e'; + +/* + README + ====== + + This test script adds tests for FluidDex general integration + with the DEX interface. The test cases below are example tests. + It is recommended to add tests which cover FluidDex specific + logic. + + You can run this individual test script by running: + `npx jest src/dex//-integration.test.ts` + + (This comment should be removed from the final implementation) +*/ + +function getReaderCalldata( + exchangeAddress: string, + readerIface: Interface, + amounts: bigint[], + funcName: string, + // TODO: Put here additional arguments you need +) { + return amounts.map(amount => ({ + target: exchangeAddress, + callData: readerIface.encodeFunctionData(funcName, [ + // TODO: Put here additional arguments to encode them + amount, + ]), + })); +} + +function decodeReaderResult( + results: Result, + readerIface: Interface, + funcName: string, +) { + // TODO: Adapt this function for your needs + return results.map(result => { + const parsed = readerIface.decodeFunctionResult(funcName, result); + return BigInt(parsed[0]._hex); + }); +} + +async function checkOnChainPricing( + fluidDex: FluidDex, + funcName: string, + blockNumber: number, + prices: bigint[], + amounts: bigint[], +) { + const exchangeAddress = ''; // TODO: Put here the real exchange address + + // TODO: Replace dummy interface with the real one + // Normally you can get it from fluidDex.Iface or from eventPool. + // It depends on your implementation + const readerIface = new Interface(''); + + const readerCallData = getReaderCalldata( + exchangeAddress, + readerIface, + amounts.slice(1), + funcName, + ); + const readerResult = ( + await fluidDex.dexHelper.multiContract.methods + .aggregate(readerCallData) + .call({}, blockNumber) + ).returnData; + + const expectedPrices = [0n].concat( + decodeReaderResult(readerResult, readerIface, funcName), + ); + + expect(prices).toEqual(expectedPrices); +} + +async function testPricingOnNetwork( + fluidDex: FluidDex, + network: Network, + dexKey: string, + blockNumber: number, + srcTokenSymbol: string, + destTokenSymbol: string, + side: SwapSide, + amounts: bigint[], + funcNameToCheck: string, +) { + const networkTokens = Tokens[network]; + + const pools = await fluidDex.getPoolIdentifiers( + networkTokens[srcTokenSymbol], + networkTokens[destTokenSymbol], + side, + blockNumber, + ); + console.log( + `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `, + pools, + ); + + expect(pools.length).toBeGreaterThan(0); + + const poolPrices = await fluidDex.getPricesVolume( + networkTokens[srcTokenSymbol], + networkTokens[destTokenSymbol], + amounts, + side, + blockNumber, + pools, + ); + console.log( + `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `, + poolPrices, + ); + + expect(poolPrices).not.toBeNull(); + if (fluidDex.hasConstantPriceLargeAmounts) { + checkConstantPoolPrices(poolPrices!, amounts, dexKey); + } else { + checkPoolPrices(poolPrices!, amounts, side, dexKey); + } + + // Check if onchain pricing equals to calculated ones + await checkOnChainPricing( + fluidDex, + funcNameToCheck, + blockNumber, + poolPrices![0].prices, + amounts, + ); +} + +describe('FluidDex', function () { + const dexKey = 'FluidDex'; + let blockNumber: number; + let fluidDex: FluidDex; + + describe('Mainnet', () => { + const network = Network.MAINNET; + const dexHelper = new DummyDexHelper(network); + + const tokens = Tokens[network]; + + // TODO: Put here token Symbol to check against + // Don't forget to update relevant tokens in constant-e2e.ts + const srcTokenSymbol = 'srcTokenSymbol'; + const destTokenSymbol = 'destTokenSymbol'; + + const amountsForSell = [ + 0n, + 1n * BI_POWS[tokens[srcTokenSymbol].decimals], + 2n * BI_POWS[tokens[srcTokenSymbol].decimals], + 3n * BI_POWS[tokens[srcTokenSymbol].decimals], + 4n * BI_POWS[tokens[srcTokenSymbol].decimals], + 5n * BI_POWS[tokens[srcTokenSymbol].decimals], + 6n * BI_POWS[tokens[srcTokenSymbol].decimals], + 7n * BI_POWS[tokens[srcTokenSymbol].decimals], + 8n * BI_POWS[tokens[srcTokenSymbol].decimals], + 9n * BI_POWS[tokens[srcTokenSymbol].decimals], + 10n * BI_POWS[tokens[srcTokenSymbol].decimals], + ]; + + const amountsForBuy = [ + 0n, + 1n * BI_POWS[tokens[destTokenSymbol].decimals], + 2n * BI_POWS[tokens[destTokenSymbol].decimals], + 3n * BI_POWS[tokens[destTokenSymbol].decimals], + 4n * BI_POWS[tokens[destTokenSymbol].decimals], + 5n * BI_POWS[tokens[destTokenSymbol].decimals], + 6n * BI_POWS[tokens[destTokenSymbol].decimals], + 7n * BI_POWS[tokens[destTokenSymbol].decimals], + 8n * BI_POWS[tokens[destTokenSymbol].decimals], + 9n * BI_POWS[tokens[destTokenSymbol].decimals], + 10n * BI_POWS[tokens[destTokenSymbol].decimals], + ]; + + beforeAll(async () => { + blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); + fluidDex = new FluidDex(network, dexKey, dexHelper); + if (fluidDex.initializePricing) { + await fluidDex.initializePricing(blockNumber); + } + }); + + it('getPoolIdentifiers and getPricesVolume SELL', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + srcTokenSymbol, + destTokenSymbol, + SwapSide.SELL, + amountsForSell, + '', // TODO: Put here proper function name to check pricing + ); + }); + + it('getPoolIdentifiers and getPricesVolume BUY', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + srcTokenSymbol, + destTokenSymbol, + SwapSide.BUY, + amountsForBuy, + '', // TODO: Put here proper function name to check pricing + ); + }); + + it('getTopPoolsForToken', async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + const newFluidDex = new FluidDex(network, dexKey, dexHelper); + if (newFluidDex.updatePoolState) { + await newFluidDex.updatePoolState(); + } + const poolLiquidity = await newFluidDex.getTopPoolsForToken( + tokens[srcTokenSymbol].address, + 10, + ); + console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); + + if (!newFluidDex.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][srcTokenSymbol].address, + dexKey, + ); + } + }); + }); +}); diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts new file mode 100644 index 000000000..1a0b7a87e --- /dev/null +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -0,0 +1,115 @@ +import { Interface } from '@ethersproject/abi'; +import { DeepReadonly } from 'ts-essentials'; +import { Log, Logger } from '../../types'; +import { catchParseLogError } from '../../utils'; +import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; +import { IDexHelper } from '../../dex-helper/idex-helper'; +import FluidDexABI from '../../abi/fluid-dex/fluid-dex.abi.json'; +import { FluidDexPool, FluidDexPoolState } from './types'; + +export class FluidDexEventPool extends StatefulEventSubscriber { + handlers: { + [event: string]: ( + event: any, + state: DeepReadonly, + log: Readonly, + ) => DeepReadonly | null; + } = {}; + + logDecoder: (log: Log) => any; + + addressesSubscribed: string[]; + + constructor( + readonly parentName: string, + readonly pool: FluidDexPool, + protected network: number, + protected dexHelper: IDexHelper, + logger: Logger, + protected fluidDexIface = new Interface(FluidDexABI), // TODO: add any additional params required for event subscriber + ) { + // TODO: Add pool name + super(parentName, pool.id, dexHelper, logger); + + // TODO: make logDecoder decode logs that + this.logDecoder = (log: Log) => this.fluidDexIface.parseLog(log); + this.addressesSubscribed = [pool.address, pool.token0, pool.token1]; + + // Add handlers + // this.handlers['Swap'] = this.handleSwap.bind(this); + } + + /** + * The function is called every time any of the subscribed + * addresses release log. The function accepts the current + * state, updates the state according to the log, and returns + * the updated state. + * @param state - Current state of event subscriber + * @param log - Log released by one of the subscribed addresses + * @returns Updates state of the event subscriber after the log + */ + protected processLog( + state: DeepReadonly, + log: Readonly, + ): DeepReadonly | null { + try { + const event = this.logDecoder(log); + if (event.name in this.handlers) { + return this.handlers[event.name](event, state, log); + } + } catch (e) { + catchParseLogError(e, this.logger); + } + + return null; + } + + async getStateOrGenerate( + blockNumber: number, + readonly: boolean = true, + ): Promise { + let state = this.getState(blockNumber); + if (!state) { + state = await this.generateState(blockNumber); + if (!readonly) this.setState(state, blockNumber); + } + return state; + } + + /** + * The function generates state using on-chain calls. This + * function is called to regenerate state if the event based + * system fails to fetch events and the local state is no + * more correct. + * @param blockNumber - Blocknumber for which the state should + * should be generated + * @returns state of the event subscriber at blocknumber + */ + async generateState( + blockNumber: number, + ): Promise> { + // TODO: complete me! + const poolReserves = await this.dexHelper.multiContract.methods + .getPoolReserves(this.pool.address) + .call({}, blockNumber); + + return poolReserves; + // return { + // token0RealReserves: poolReserves.collateralReserves.token0RealReserves.toString(), + // token1RealReserves: poolReserves.collateralReserves.token1RealReserves.toString(), + // token0ImaginaryReserves: poolReserves.collateralReserves.token0ImaginaryReserves.toString(), + // token1ImaginaryReserves: poolReserves.collateralReserves.token1ImaginaryReserves.toString(), + // token0Debt: poolReserves.debtReserves.token0Debt.toString(), + // token1Debt: poolReserves.debtReserves.token1Debt.toString(), + // }; + } + + // Its just a dummy example + handleMyEvent( + event: any, + state: DeepReadonly, + log: Readonly, + ): DeepReadonly | null { + return null; + } +} diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts new file mode 100644 index 000000000..0b12d5593 --- /dev/null +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -0,0 +1,409 @@ +import { AsyncOrSync } from 'ts-essentials'; +import { + Token, + Address, + ExchangePrices, + PoolPrices, + AdapterExchangeParam, + SimpleExchangeParam, + PoolLiquidity, + Logger, +} from '../../types'; +import { SwapSide, Network } from '../../constants'; +import * as CALLDATA_GAS_COST from '../../calldata-gas-cost'; +import { IDex } from '../../dex/idex'; +import { IDexHelper } from '../../dex-helper/idex-helper'; +import { + CollateralReserves, + DebtReserves, + FluidDexData, + FluidDexPool, +} from './types'; +import { SimpleExchange } from '../simple-exchange'; +import { FluidDexConfig, Adapters, FLUID_DEX_GAS_COST } from './config'; +import { FluidDexEventPool } from './fluid-dex-pool'; +import { applyTransferFee } from '../../lib/token-transfer-fee'; +import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; + +export class FluidDex extends SimpleExchange implements IDex { + readonly eventPools: { [id: string]: FluidDexEventPool } = {}; + + readonly hasConstantPriceLargeAmounts = false; + // TODO: set true here if protocols works only with wrapped asset + readonly needWrapNative = true; + + readonly isFeeOnTransferSupported = false; + + public static dexKeysWithNetwork: { key: string; networks: Network[] }[] = + getDexKeysWithNetwork(FluidDexConfig); + + logger: Logger; + + readonly pools: [FluidDexPool]; + + constructor( + readonly network: Network, + readonly dexKey: string, + readonly dexHelper: IDexHelper, + protected adapters = Adapters[network] || {}, // TODO: add any additional optional params to support other fork DEXes + ) { + super(dexHelper, dexKey); + this.logger = dexHelper.getLogger(dexKey); + this.pools = FluidDexConfig[dexKey][network].pools; + } + + // Initialize pricing is called once in the start of + // pricing service. It is intended to setup the integration + // for pricing requests. It is optional for a DEX to + // implement this function + async initializePricing(blockNumber: number) { + // TODO: complete me! + } + + // Returns the list of contract adapters (name and index) + // for a buy/sell. Return null if there are no adapters. + getAdapters(side: SwapSide): { name: string; index: number }[] | null { + return this.adapters[side] ? this.adapters[side] : null; + } + + // Returns list of pool identifiers that can be used + // for a given swap. poolIdentifiers must be unique + // across DEXes. It is recommended to use + // ${dexKey}_${poolAddress} as a poolIdentifier + async getPoolIdentifiers( + srcToken: Token, + destToken: Token, + side: SwapSide, + blockNumber: number, + ): Promise { + // TODO: complete me! + // return []; + const pool = this.getPoolByTokenPair(srcToken, destToken); + return pool ? [pool.id] : []; + } + + getPoolByTokenPair(srcToken: Token, destToken: Token): FluidDexPool | null { + const srcAddress = srcToken.address.toLowerCase(); + const destAddress = destToken.address.toLowerCase(); + + // A pair must have 2 different tokens. + if (srcAddress === destAddress) return null; + + for (const pool of this.pools) { + if ( + (srcAddress === pool.token0 && destAddress === pool.token1) || + (srcAddress === pool.token1 && destAddress === pool.token0) + ) { + return pool; + } + } + return null; + } + + // Returns pool prices for amounts. + // If limitPools is defined only pools in limitPools + // should be used. If limitPools is undefined then + // any pools can be used. + async getPricesVolume( + srcToken: Token, + destToken: Token, + amounts: bigint[], + side: SwapSide, + blockNumber: number, + limitPools?: string[], + ): Promise> { + try { + // Get the pool to use. + const pool = this.getPoolByTokenPair(srcToken, destToken); + if (!pool) return null; + + // Make sure the pool meets the optional limitPools filter. + if (limitPools && !limitPools.includes(pool.id)) return null; + + const eventPool = this.eventPools[pool.id]; + + if (!eventPool) { + this.logger.error(`OSwap pool ${pool.id}: No EventPool found.`); + + return null; + } + + const state = await eventPool.generateState(blockNumber); + + // Calculate the prices + const unitAmount = getBigIntPow(18); + // const unitPrice = this.calcPrice( + // pool, + // state, + // srcToken, + // unitAmount, + // side, + // false, + // ); + + const swap0To1: boolean = side === SwapSide.SELL; + + const prices = amounts.map(amount => + // this.calcPrice(pool, state, srcToken, amount, side), + this.swapIn( + swap0To1, + amount as any, + state.collateralReserves, + state.debtReserves, + ), + ); + + // const [unitPriceWithFee, ...pricesWithFee] = applyTransferFee( + // [unitPrice, ...prices], + // side, + // side === SwapSide.SELL ? transferFees.srcFee : transferFees.destFee, + // side === SwapSide.SELL + // ? SRC_TOKEN_PARASWAP_TRANSFERS + // : DEST_TOKEN_PARASWAP_TRANSFERS, + // ); + + return [ + { + prices: [BigInt(0)], // to be done + unit: BigInt(0), // to be done + data: { + colReserves: state.collateralReserves, + debtReserves: state.debtReserves, + exchange: this.dexKey, + }, + exchange: this.dexKey, + poolIdentifier: pool.id, + gasCost: FLUID_DEX_GAS_COST, // to be done + poolAddresses: [pool.address], + }, + ]; + } catch (e) { + this.logger.error( + `Error_getPricesVolume ${srcToken.address || srcToken.symbol}, ${ + destToken.address || destToken.symbol + }, ${side}:`, + e, + ); + + return null; + } + } + + // Returns estimated gas cost of calldata for this DEX in multiSwap + getCalldataGasCost(poolPrices: PoolPrices): number | number[] { + // TODO: update if there is any payload in getAdapterParam + return CALLDATA_GAS_COST.DEX_NO_PAYLOAD; + } + + // Encode params required by the exchange adapter + // V5: Used for multiSwap, buy & megaSwap + // V6: Not used, can be left blank + // Hint: abiCoder.encodeParameter() could be useful + getAdapterParam( + srcToken: string, + destToken: string, + srcAmount: string, + destAmount: string, + data: FluidDexData, + side: SwapSide, + ): AdapterExchangeParam { + // TODO: complete me! + const { exchange } = data; + + // Encode here the payload for adapter + const payload = ''; + + return { + targetExchange: exchange, + payload, + networkFee: '0', + }; + } + + // This is called once before getTopPoolsForToken is + // called for multiple tokens. This can be helpful to + // update common state required for calculating + // getTopPoolsForToken. It is optional for a DEX + // to implement this + async updatePoolState(): Promise { + // TODO: complete me! + } + + // Returns list of top pools based on liquidity. Max + // limit number pools should be returned. + async getTopPoolsForToken( + tokenAddress: Address, + limit: number, + ): Promise { + //TODO: complete me! + return []; + } + + // This is optional function in case if your implementation has acquired any resources + // you need to release for graceful shutdown. For example, it may be any interval timer + releaseResources(): AsyncOrSync { + // TODO: complete me! + } + + /** + * Calculates the output amount for a given input amount in a swap operation. + * @param {boolean} swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise. + * @param {number} amountToSwap - The amount of input token to be swapped. + * @param {Object} colReserves - The reserves of the collateral pool. + * @param {number} colReserves.token0RealReserves - Real reserves of token0 in the collateral pool. + * @param {number} colReserves.token1RealReserves - Real reserves of token1 in the collateral pool. + * @param {number} colReserves.token0ImaginaryReserves - Imaginary reserves of token0 in the collateral pool. + * @param {number} colReserves.token1ImaginaryReserves - Imaginary reserves of token1 in the collateral pool. + * @param {Object} debtReserves - The reserves of the debt pool. + * @param {number} debtReserves.token0RealReserves - Real reserves of token0 in the debt pool. + * @param {number} debtReserves.token1RealReserves - Real reserves of token1 in the debt pool. + * @param {number} debtReserves.token0ImaginaryReserves - Imaginary reserves of token0 in the debt pool. + * @param {number} debtReserves.token1ImaginaryReserves - Imaginary reserves of token1 in the debt pool. + * @returns {Object} An object containing the input amount and the calculated output amount. + * @returns {number} amountIn - The input amount. + * @returns {number} amountOut - The calculated output amount. + */ + swapIn( + swap0To1: Boolean, + amountToSwap: number, + colReserves: CollateralReserves, + debtReserves: DebtReserves, + ) { + const { + token0RealReserves, + token1RealReserves, + token0ImaginaryReserves, + token1ImaginaryReserves, + } = colReserves; + + const { + token0RealReserves: debtToken0RealReserves, + token1RealReserves: debtToken1RealReserves, + token0ImaginaryReserves: debtToken0ImaginaryReserves, + token1ImaginaryReserves: debtToken1ImaginaryReserves, + } = debtReserves; + + // Check if all reserves of collateral pool are greater than 0 + const colPoolEnabled = + token0RealReserves > 0 && + token1RealReserves > 0 && + token0ImaginaryReserves > 0 && + token1ImaginaryReserves > 0; + + // Check if all reserves of debt pool are greater than 0 + const debtPoolEnabled = + debtToken0RealReserves > 0 && + debtToken1RealReserves > 0 && + debtToken0ImaginaryReserves > 0 && + debtToken1ImaginaryReserves > 0; + + let colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut; + + if (swap0To1) { + colIReserveIn = token0ImaginaryReserves; + colIReserveOut = token1ImaginaryReserves; + debtIReserveIn = debtToken0ImaginaryReserves; + debtIReserveOut = debtToken1ImaginaryReserves; + } else { + colIReserveIn = token1ImaginaryReserves; + colIReserveOut = token0ImaginaryReserves; + debtIReserveIn = debtToken1ImaginaryReserves; + debtIReserveOut = debtToken0ImaginaryReserves; + } + + let a; + if (colPoolEnabled && debtPoolEnabled) { + a = this.swapRoutingIn( + amountToSwap, + colIReserveOut, + colIReserveIn, + debtIReserveOut, + debtIReserveIn, + ); + } else if (debtPoolEnabled) { + a = -1; // Route from debt pool + } else if (colPoolEnabled) { + a = amountToSwap + 1; // Route from collateral pool + } else { + throw new Error('No pools are enabled'); + } + + let amountOutCollateral = 0; + let amountOutDebt = 0; + + if (a <= 0) { + // Entire trade routes through debt pool + amountOutDebt = this.getAmountOut( + amountToSwap, + debtIReserveIn, + debtIReserveOut, + ); + } else if (a >= amountToSwap) { + // Entire trade routes through collateral pool + amountOutCollateral = this.getAmountOut( + amountToSwap, + colIReserveIn, + colIReserveOut, + ); + } else { + // Trade routes through both pools + amountOutCollateral = this.getAmountOut(a, colIReserveIn, colIReserveOut); + amountOutDebt = this.getAmountOut( + amountToSwap - a, + debtIReserveIn, + debtIReserveOut, + ); + } + + const totalAmountOut = amountOutCollateral + amountOutDebt; + + return totalAmountOut; + } + + /** + * Calculates how much of a swap should go through the collateral pool. + * @param {number} t - Total amount in. + * @param {number} x - Imaginary reserves of token out of collateral. + * @param {number} y - Imaginary reserves of token in of collateral. + * @param {number} x2 - Imaginary reserves of token out of debt. + * @param {number} y2 - Imaginary reserves of token in of debt. + * @returns {number} a - 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: number, + x: number, + y: number, + x2: number, + y2: number, + ): number { + // Adding 1e18 precision + var xyRoot = Math.sqrt(x * y * 1e18); + var x2y2Root = Math.sqrt(x2 * y2 * 1e18); + // Calculating 'a' using the given formula + var a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root); + return a; + } + + /** + * Given an input amount of asset and pair reserves, returns the maximum output amount of the other asset. + * @param {number} amountIn - The amount of input asset. + * @param {number} iReserveIn - Imaginary token reserve with input amount. + * @param {number} iReserveOut - Imaginary token reserve of output amount. + * @returns {number} - The maximum output amount of the other asset. + */ + getAmountOut( + amountIn: number, + iReserveIn: number, + iReserveOut: number, + ): number { + // Both numerator and denominator are scaled to 1e6 to factor in fee scaling. + const numerator = amountIn * iReserveOut; + const denominator = iReserveIn + amountIn; + + // Using the swap formula: (AmountIn * iReserveY) / (iReserveX + AmountIn) + return numerator / denominator; + } +} diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts new file mode 100644 index 000000000..df26b102c --- /dev/null +++ b/src/dex/fluid-dex/types.ts @@ -0,0 +1,51 @@ +import { Address } from '../../types'; + +export type FluidDexPoolState = { + // TODO: poolState is the state of event + // subscriber. This should be the minimum + // set of parameters required to compute + // pool prices. Complete me! + collateralReserves: CollateralReserves; + debtReserves: DebtReserves; +}; + +export type CollateralReserves = { + token0RealReserves: number; // Changed from uint to number + token1RealReserves: number; // Changed from uint to number + token0ImaginaryReserves: number; // Changed from uint to number + token1ImaginaryReserves: number; // Changed from uint to number +}; + +export type DebtReserves = { + token0Debt: number; // Changed from uint to number + token1Debt: number; // Changed from uint to number + token0RealReserves: number; // Changed from uint to number + token1RealReserves: number; // Changed from uint to number + token0ImaginaryReserves: number; // Changed from uint to number + token1ImaginaryReserves: number; // Changed from uint to number +}; + +export type FluidDexData = { + // TODO: FluidDexData is the dex data that is + // returned by the API that can be used for + // tx building. The data structure should be minimal. + // Complete me! + colReserves: CollateralReserves; + debtReserves: DebtReserves; + exchange: Address; +}; + +// Each pool has a contract address and token pairs. +export type FluidDexPool = { + id: string; + address: Address; + token0: Address; + token1: Address; +}; + +export type DexParams = { + // TODO: DexParams is set of parameters the can + // be used to initiate a DEX fork. + // Complete me! + pools: [FluidDexPool]; +}; From 98dfb9debbb56c56a7d40a96759d9f719181ad03 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 26 Sep 2024 19:14:22 +0530 Subject: [PATCH 02/64] added logOperate reading functionality --- .../fluid-dex/liquidityUserModule.abi.json | 145 +++ src/abi/fluid-dex/resolver.abi.json | 840 ++++++++++++++++++ src/dex/fluid-dex/config.ts | 8 +- src/dex/fluid-dex/fluid-dex-pool.ts | 187 +++- src/dex/fluid-dex/fluid-dex.ts | 8 +- src/dex/fluid-dex/types.ts | 13 + 6 files changed, 1166 insertions(+), 35 deletions(-) create mode 100644 src/abi/fluid-dex/liquidityUserModule.abi.json create mode 100644 src/abi/fluid-dex/resolver.abi.json diff --git a/src/abi/fluid-dex/liquidityUserModule.abi.json b/src/abi/fluid-dex/liquidityUserModule.abi.json new file mode 100644 index 000000000..a892ce865 --- /dev/null +++ b/src/abi/fluid-dex/liquidityUserModule.abi.json @@ -0,0 +1,145 @@ +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "errorId_", + "type": "uint256" + } + ], + "name": "FluidLiquidityCalcsError", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "errorId_", + "type": "uint256" + } + ], + "name": "FluidLiquidityError", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "errorId_", + "type": "uint256" + } + ], + "name": "FluidSafeTransferError", + "type": "error" + }, + { + "anonymous": false, + "inputs": [], + "name": "BorrowRateMaxCap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "token", + "type": "address" + }, + { + "indexed": false, + "internalType": "int256", + "name": "supplyAmount", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "borrowAmount", + "type": "int256" + }, + { + "indexed": false, + "internalType": "address", + "name": "withdrawTo", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "borrowTo", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "totalAmounts", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "exchangePricesAndConfig", + "type": "uint256" + } + ], + "name": "LogOperate", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token_", + "type": "address" + }, + { + "internalType": "int256", + "name": "supplyAmount_", + "type": "int256" + }, + { + "internalType": "int256", + "name": "borrowAmount_", + "type": "int256" + }, + { + "internalType": "address", + "name": "withdrawTo_", + "type": "address" + }, + { + "internalType": "address", + "name": "borrowTo_", + "type": "address" + }, + { + "internalType": "bytes", + "name": "callbackData_", + "type": "bytes" + } + ], + "name": "operate", + "outputs": [ + { + "internalType": "uint256", + "name": "memVar3_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "memVar4_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + } +] diff --git a/src/abi/fluid-dex/resolver.abi.json b/src/abi/fluid-dex/resolver.abi.json new file mode 100644 index 000000000..0125bb605 --- /dev/null +++ b/src/abi/fluid-dex/resolver.abi.json @@ -0,0 +1,840 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "factory_", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "FACTORY", + "outputs": [ + { + "internalType": "contract IFluidDexFactory", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amountIn_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin_", + "type": "uint256" + } + ], + "name": "estimateSwapIn", + "outputs": [ + { + "internalType": "uint256", + "name": "amountOut_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amountOut_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax_", + "type": "uint256" + } + ], + "name": "estimateSwapOut", + "outputs": [ + { + "internalType": "uint256", + "name": "amountIn_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [], + "name": "getAllPoolAddresses", + "outputs": [ + { + "internalType": "address[]", + "name": "pools_", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllPools", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + } + ], + "internalType": "struct Structs.Pool[]", + "name": "pools_", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllPoolsReserves", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves[]", + "name": "poolsReserves_", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexCollateralReserves", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "reserves_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexDebtReserves", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "reserves_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexPricesAndExchangePrices", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "poolId_", + "type": "uint256" + } + ], + "name": "getPool", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + } + ], + "internalType": "struct Structs.Pool", + "name": "pool_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "poolId_", + "type": "uint256" + } + ], + "name": "getPoolAddress", + "outputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "name": "getPoolConstantsView", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "shift", + "type": "address" + }, + { + "internalType": "address", + "name": "admin", + "type": "address" + }, + { + "internalType": "address", + "name": "colOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "debtOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "perfectOperationsAndOracle", + "type": "address" + } + ], + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", + "type": "tuple" + }, + { + "internalType": "address", + "name": "deployerContract", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantsView_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "name": "getPoolConstantsView2", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0DenominatorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1DenominatorPrecision", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantsView2_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "name": "getPoolReserves", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves", + "name": "poolReserves_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "name": "getPoolTokens", + "outputs": [ + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "pools_", + "type": "address[]" + } + ], + "name": "getPoolsReserves", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves[]", + "name": "poolsReserves_", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalPools", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index a3eebae2f..3692ffed7 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -9,6 +9,12 @@ export const FluidDexConfig: DexConfigMap = { { id: 'FluidDex_0x6d83f60eEac0e50A1250760151E81Db2a278e03a', // Pool identifier: `{dex_key}_{pool_address}` address: '0x6d83f60eEac0e50A1250760151E81Db2a278e03a', // Address of the pool + debtOperations: '0xaf19a6F318b7F8f58c9F9C89Acc1eC40a3AFcdF5', + colOperations: '0x835a8E10e8F473174F937AFA0eC22fC9a7Fa504F', + perfectOperationsAndSwapOut: + '0x8Cf39E1bD5722BAaC7056E1A02eE139296B224ED', + liquidityUserModule: '0x8eC5e29eA39b2f64B21e32cB9Ff11D5059982F8C', + resolver: '0xfE1CBE632855e279601EaAF58D3cB552271BfDF5', token0: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // wstETH token1: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH }, @@ -17,7 +23,7 @@ export const FluidDexConfig: DexConfigMap = { }, }; -export const FLUID_DEX_GAS_COST = 80_000; +export const FLUID_DEX_GAS_COST = 160_000; export const Adapters: Record = { // TODO: add adapters for each chain diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 1a0b7a87e..28ffd3727 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -5,7 +5,14 @@ import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; import FluidDexABI from '../../abi/fluid-dex/fluid-dex.abi.json'; -import { FluidDexPool, FluidDexPoolState } from './types'; +import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; +import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; +import { FluidDexPool, FluidDexPoolState, PoolWithReserves } from './types'; +import { ethers } from 'ethers'; +import { eachOfSeries } from 'async'; +import { USD_PRECISION } from '../woo-fi-v2/constants'; +import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; +import { BytesLike, defaultAbiCoder } from 'ethers/lib/utils'; export class FluidDexEventPool extends StatefulEventSubscriber { handlers: { @@ -13,7 +20,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber, log: Readonly, - ) => DeepReadonly | null; + ) => Promise | null>; } = {}; logDecoder: (log: Log) => any; @@ -26,19 +33,138 @@ export class FluidDexEventPool extends StatefulEventSubscriber this.fluidDexIface.parseLog(log); - this.addressesSubscribed = [pool.address, pool.token0, pool.token1]; + this.logDecoder = (log: Log) => this.liquidityIface.parseLog(log); + this.addressesSubscribed = [pool.liquidityUserModule]; // Add handlers - // this.handlers['Swap'] = this.handleSwap.bind(this); + this.handlers['LogOperate'] = this.handleOperate.bind(this); } + /** + * Handle a trade rate change on the pool. + */ + async handleOperate( + event: any, + state: DeepReadonly, + log: Readonly, + ): Promise | null> { + const ResolverAbi = new Interface(ResolverABI); + if ( + !( + event.args.user in + [ + this.pool.address, + this.pool.colOperations, + this.pool.debtOperations, + this.pool.perfectOperationsAndSwapOut, + ] + ) + ) { + return null; + } + const callData: MultiCallParams[] = [ + { + target: this.pool.resolver, + callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ + this.pool.address, + ]), + decodeFunction: await this.decodePoolWithReserves, + }, + ]; + + const results: PoolWithReserves[] = + await this.dexHelper.multiWrapper.aggregate( + callData, + await this.dexHelper.provider.getBlockNumber(), + this.dexHelper.multiWrapper.defaultBatchSize, + ); + + return { + collateralReserves: results[0].collateralReserves, + debtReserves: results[0].debtReserves, + }; + } + + decodePoolWithReserves = ( + result: MultiResult | BytesLike, + ): PoolWithReserves => { + const [isSuccess, toDecode] = this.extractSuccessAndValue(result); + + // if (!isSuccess) { + // return null; + // } + + const decodedResult = defaultAbiCoder.decode( + [ + 'tuple(address pool, address token0_, address token1_, ' + + 'tuple(uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) collateralReserves, ' + + 'tuple(uint256 token0Debt, uint256 token1Debt, uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) debtReserves)', + ], + toDecode, + )[0]; + + return { + pool: decodedResult.pool, + token0_: decodedResult.token0_, + token1_: decodedResult.token1_, + collateralReserves: { + token0RealReserves: Number( + decodedResult.collateralReserves.token0RealReserves, + ), + token1RealReserves: Number( + decodedResult.collateralReserves.token1RealReserves, + ), + token0ImaginaryReserves: Number( + decodedResult.collateralReserves.token0ImaginaryReserves, + ), + token1ImaginaryReserves: Number( + decodedResult.collateralReserves.token1ImaginaryReserves, + ), + }, + debtReserves: { + token0Debt: Number(decodedResult.debtReserves.token0Debt), + token1Debt: Number(decodedResult.debtReserves.token1Debt), + token0RealReserves: Number( + decodedResult.debtReserves.token0RealReserves, + ), + token1RealReserves: Number( + decodedResult.debtReserves.token1RealReserves, + ), + token0ImaginaryReserves: Number( + decodedResult.debtReserves.token0ImaginaryReserves, + ), + token1ImaginaryReserves: Number( + decodedResult.debtReserves.token1ImaginaryReserves, + ), + }, + }; + }; + + extractSuccessAndValue = ( + result: MultiResult | BytesLike, + ): [boolean, BytesLike] => { + return this.isMultiResult(result) + ? [result.success, result.returnData] + : [true, result]; + }; + + isMultiResult = ( + result: MultiResult | BytesLike, + ): result is MultiResult => { + return ( + typeof result === 'object' && + result !== null && + 'success' in result && + 'returnData' in result + ); + }; + /** * The function is called every time any of the subscribed * addresses release log. The function accepts the current @@ -48,14 +174,14 @@ export class FluidDexEventPool extends StatefulEventSubscriber, log: Readonly, - ): DeepReadonly | null { + ): Promise | null> { try { const event = this.logDecoder(log); if (event.name in this.handlers) { - return this.handlers[event.name](event, state, log); + return await this.handlers[event.name](event, state, log); } } catch (e) { catchParseLogError(e, this.logger); @@ -88,28 +214,27 @@ export class FluidDexEventPool extends StatefulEventSubscriber> { - // TODO: complete me! - const poolReserves = await this.dexHelper.multiContract.methods - .getPoolReserves(this.pool.address) - .call({}, blockNumber); - - return poolReserves; - // return { - // token0RealReserves: poolReserves.collateralReserves.token0RealReserves.toString(), - // token1RealReserves: poolReserves.collateralReserves.token1RealReserves.toString(), - // token0ImaginaryReserves: poolReserves.collateralReserves.token0ImaginaryReserves.toString(), - // token1ImaginaryReserves: poolReserves.collateralReserves.token1ImaginaryReserves.toString(), - // token0Debt: poolReserves.debtReserves.token0Debt.toString(), - // token1Debt: poolReserves.debtReserves.token1Debt.toString(), - // }; - } + const ResolverAbi = new Interface(ResolverABI); + const callData: MultiCallParams[] = [ + { + target: this.pool.resolver, + callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ + this.pool.address, + ]), + decodeFunction: await this.decodePoolWithReserves, + }, + ]; - // Its just a dummy example - handleMyEvent( - event: any, - state: DeepReadonly, - log: Readonly, - ): DeepReadonly | null { - return null; + const results: PoolWithReserves[] = + await this.dexHelper.multiWrapper.aggregate( + callData, + blockNumber, + this.dexHelper.multiWrapper.defaultBatchSize, + ); + + return { + collateralReserves: results[0].collateralReserves, + debtReserves: results[0].debtReserves, + }; } } diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 0b12d5593..fca50490d 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -128,7 +128,7 @@ export class FluidDex extends SimpleExchange implements IDex { return null; } - const state = await eventPool.generateState(blockNumber); + const state = await eventPool.getStateOrGenerate(blockNumber); // Calculate the prices const unitAmount = getBigIntPow(18); @@ -164,8 +164,10 @@ export class FluidDex extends SimpleExchange implements IDex { return [ { - prices: [BigInt(0)], // to be done - unit: BigInt(0), // to be done + prices: amounts, // to be done + unit: getBigIntPow( + (side === SwapSide.SELL ? destToken : srcToken).decimals, + ), // to be done data: { colReserves: state.collateralReserves, debtReserves: state.debtReserves, diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index df26b102c..297c082a3 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -25,6 +25,14 @@ export type DebtReserves = { token1ImaginaryReserves: number; // Changed from uint to number }; +export interface PoolWithReserves { + pool: string; + token0_: string; + token1_: string; + collateralReserves: CollateralReserves; + debtReserves: DebtReserves; +} + export type FluidDexData = { // TODO: FluidDexData is the dex data that is // returned by the API that can be used for @@ -39,6 +47,11 @@ export type FluidDexData = { export type FluidDexPool = { id: string; address: Address; + debtOperations: Address; + colOperations: Address; + perfectOperationsAndSwapOut: Address; + liquidityUserModule: Address; + resolver: Address; token0: Address; token1: Address; }; From 4b1c5b0ffc45afcf8fa1e9f6dc95b5ca85973af6 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 26 Sep 2024 19:25:38 +0530 Subject: [PATCH 03/64] resolved the github comment --- src/dex/fluid-dex/fluid-dex.ts | 133 +++++++++++++++++---------------- 1 file changed, 69 insertions(+), 64 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index fca50490d..12c2c2be2 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -130,38 +130,18 @@ export class FluidDex extends SimpleExchange implements IDex { const state = await eventPool.getStateOrGenerate(blockNumber); - // Calculate the prices - const unitAmount = getBigIntPow(18); - // const unitPrice = this.calcPrice( - // pool, - // state, - // srcToken, - // unitAmount, - // side, - // false, - // ); - const swap0To1: boolean = side === SwapSide.SELL; const prices = amounts.map(amount => // this.calcPrice(pool, state, srcToken, amount, side), this.swapIn( swap0To1, - amount as any, + amount, state.collateralReserves, state.debtReserves, ), ); - // const [unitPriceWithFee, ...pricesWithFee] = applyTransferFee( - // [unitPrice, ...prices], - // side, - // side === SwapSide.SELL ? transferFees.srcFee : transferFees.destFee, - // side === SwapSide.SELL - // ? SRC_TOKEN_PARASWAP_TRANSFERS - // : DEST_TOKEN_PARASWAP_TRANSFERS, - // ); - return [ { prices: amounts, // to be done @@ -266,8 +246,8 @@ export class FluidDex extends SimpleExchange implements IDex { * @returns {number} amountOut - The calculated output amount. */ swapIn( - swap0To1: Boolean, - amountToSwap: number, + swap0To1: boolean, + amountToSwap: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, ) { @@ -285,35 +265,34 @@ export class FluidDex extends SimpleExchange implements IDex { token1ImaginaryReserves: debtToken1ImaginaryReserves, } = debtReserves; - // Check if all reserves of collateral pool are greater than 0 + // Convert all reserves to BigInt const colPoolEnabled = - token0RealReserves > 0 && - token1RealReserves > 0 && - token0ImaginaryReserves > 0 && - token1ImaginaryReserves > 0; + BigInt(token0RealReserves) > 0n && + BigInt(token1RealReserves) > 0n && + BigInt(token0ImaginaryReserves) > 0n && + BigInt(token1ImaginaryReserves) > 0n; - // Check if all reserves of debt pool are greater than 0 const debtPoolEnabled = - debtToken0RealReserves > 0 && - debtToken1RealReserves > 0 && - debtToken0ImaginaryReserves > 0 && - debtToken1ImaginaryReserves > 0; + BigInt(debtToken0RealReserves) > 0n && + BigInt(debtToken1RealReserves) > 0n && + BigInt(debtToken0ImaginaryReserves) > 0n && + BigInt(debtToken1ImaginaryReserves) > 0n; let colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut; if (swap0To1) { - colIReserveIn = token0ImaginaryReserves; - colIReserveOut = token1ImaginaryReserves; - debtIReserveIn = debtToken0ImaginaryReserves; - debtIReserveOut = debtToken1ImaginaryReserves; + colIReserveIn = BigInt(token0ImaginaryReserves); + colIReserveOut = BigInt(token1ImaginaryReserves); + debtIReserveIn = BigInt(debtToken0ImaginaryReserves); + debtIReserveOut = BigInt(debtToken1ImaginaryReserves); } else { - colIReserveIn = token1ImaginaryReserves; - colIReserveOut = token0ImaginaryReserves; - debtIReserveIn = debtToken1ImaginaryReserves; - debtIReserveOut = debtToken0ImaginaryReserves; + colIReserveIn = BigInt(token1ImaginaryReserves); + colIReserveOut = BigInt(token0ImaginaryReserves); + debtIReserveIn = BigInt(debtToken1ImaginaryReserves); + debtIReserveOut = BigInt(debtToken0ImaginaryReserves); } - let a; + let a: bigint; if (colPoolEnabled && debtPoolEnabled) { a = this.swapRoutingIn( amountToSwap, @@ -323,17 +302,17 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveIn, ); } else if (debtPoolEnabled) { - a = -1; // Route from debt pool + a = -1n; // Route from debt pool } else if (colPoolEnabled) { - a = amountToSwap + 1; // Route from collateral pool + a = amountToSwap + 1n; // Route from collateral pool } else { throw new Error('No pools are enabled'); } - let amountOutCollateral = 0; - let amountOutDebt = 0; + let amountOutCollateral: bigint = 0n; + let amountOutDebt: bigint = 0n; - if (a <= 0) { + if (a <= 0n) { // Entire trade routes through debt pool amountOutDebt = this.getAmountOut( amountToSwap, @@ -375,17 +354,42 @@ export class FluidDex extends SimpleExchange implements IDex { * @note If a > 0 & a < t then swap will route through both pools. */ swapRoutingIn( - t: number, - x: number, - y: number, - x2: number, - y2: number, - ): number { - // Adding 1e18 precision - var xyRoot = Math.sqrt(x * y * 1e18); - var x2y2Root = Math.sqrt(x2 * y2 * 1e18); + t: bigint, + x: bigint, + y: bigint, + x2: bigint, + y2: bigint, + ): bigint { + const precision = BigInt(1e18); + + // Helper function for integer square root + const sqrtBigInt = (value: bigint): bigint => { + if (value < 0n) { + throw new Error('Square root of negative number is not allowed'); + } + if (value < 2n) { + return value; + } + + let x = value; + let y = (x + 1n) / 2n; + while (y < x) { + x = y; + y = (x + value / x) / 2n; + } + return x; + }; + + const xyRoot = sqrtBigInt((x * y * precision) / precision); + const x2y2Root = sqrtBigInt((x2 * y2 * precision) / precision); + // Calculating 'a' using the given formula - var a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root); + const numerator = y2 * xyRoot + t * xyRoot - y * x2y2Root; + const denominator = xyRoot + x2y2Root; + + // Perform the division and maintain precision + const a = (numerator * precision) / denominator / precision; + return a; } @@ -397,15 +401,16 @@ export class FluidDex extends SimpleExchange implements IDex { * @returns {number} - The maximum output amount of the other asset. */ getAmountOut( - amountIn: number, - iReserveIn: number, - iReserveOut: number, - ): number { + amountIn: bigint, + reserveIn: bigint, + reserveOut: bigint, + ): bigint { // Both numerator and denominator are scaled to 1e6 to factor in fee scaling. - const numerator = amountIn * iReserveOut; - const denominator = iReserveIn + amountIn; + const scale = BigInt(1_000_000); + const numerator = amountIn * reserveOut * scale; + const denominator = reserveIn * scale + amountIn * scale; - // Using the swap formula: (AmountIn * iReserveY) / (iReserveX + AmountIn) + // Using the swap formula: (AmountIn * ReserveOut * scale) / (ReserveIn * scale + AmountIn * scale) return numerator / denominator; } } From baf6ed2bde6070092b45b626c03d04b9096053e4 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Sat, 28 Sep 2024 04:02:56 +0530 Subject: [PATCH 04/64] fluid-dex-events.test.ts complete but not working because of no txn in the dex --- .env.example | 7 -- src/dex/fluid-dex/fluid-dex-events.test.ts | 28 ++++--- src/dex/fluid-dex/fluid-dex-pool.ts | 91 +++++++++++----------- 3 files changed, 62 insertions(+), 64 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index cc27ae949..000000000 --- a/.env.example +++ /dev/null @@ -1,7 +0,0 @@ -HTTP_PROVIDER_1= -HTTP_PROVIDER_137= -HTTP_PROVIDER_43114= - -TENDERLY_TOKEN= -TENDERLY_ACCOUNT_ID= -TENDERLY_PROJECT= \ No newline at end of file diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 867a0f4c3..225137a3a 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -7,7 +7,8 @@ import { Network } from '../../constants'; import { Address } from '../../types'; import { DummyDexHelper } from '../../dex-helper/index'; import { testEventSubscriber } from '../../../tests/utils-events'; -import { PoolState } from './types'; +import { FluidDexPool, FluidDexPoolState } from './types'; +import { FluidDexConfig } from './config'; /* README @@ -45,12 +46,11 @@ import { PoolState } from './types'; jest.setTimeout(50 * 1000); async function fetchPoolState( - fluidDexPools: FluidDexEventPool, + fluidDexPool: FluidDexEventPool, blockNumber: number, - poolAddress: string, -): Promise { +): Promise { // TODO: complete me! - return {}; + return fluidDexPool.generateState(blockNumber); } // eventName -> blockNumbers @@ -61,16 +61,22 @@ describe('FluidDex EventPool Mainnet', function () { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); - let fluidDexPool: FluidDexEventPool; + const fluidDexPool: FluidDexPool = FluidDexConfig[dexKey][network].pools[0]; // poolAddress -> EventMappings const eventsToTest: Record = { // TODO: complete me! + [fluidDexPool.liquidityUserModule]: { + LogOperate: [18917344], + }, }; + let fluidDexEventPool: FluidDexEventPool; + beforeEach(async () => { - fluidDexPool = new FluidDexEventPool( - dexKey, + fluidDexEventPool = new FluidDexEventPool( + 'FluidDex', + fluidDexPool, network, dexHelper, logger, @@ -87,10 +93,10 @@ describe('FluidDex EventPool Mainnet', function () { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async function () { await testEventSubscriber( - fluidDexPool, - fluidDexPool.addressesSubscribed, + fluidDexEventPool, + fluidDexEventPool.addressesSubscribed, (_blockNumber: number) => - fetchPoolState(fluidDexPool, _blockNumber, poolAddress), + fetchPoolState(fluidDexEventPool, _blockNumber), blockNumber, `${dexKey}_${poolAddress}`, dexHelper.provider, diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 28ffd3727..33fe8410c 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -13,6 +13,8 @@ import { eachOfSeries } from 'async'; import { USD_PRECISION } from '../woo-fi-v2/constants'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; import { BytesLike, defaultAbiCoder } from 'ethers/lib/utils'; +import { Address } from '../../types'; +import { generalDecoder } from '../../lib/decoders'; export class FluidDexEventPool extends StatefulEventSubscriber { handlers: { @@ -25,7 +27,8 @@ export class FluidDexEventPool extends StatefulEventSubscriber any; - addressesSubscribed: string[]; + addressesSubscribed: Address[]; + protected liquidityIface = new Interface(LiquidityABI); // TODO: add any additional params required for event subscriber constructor( readonly parentName: string, @@ -33,7 +36,6 @@ export class FluidDexEventPool extends StatefulEventSubscriber | BytesLike, ): PoolWithReserves => { - const [isSuccess, toDecode] = this.extractSuccessAndValue(result); - - // if (!isSuccess) { - // return null; - // } - - const decodedResult = defaultAbiCoder.decode( + return generalDecoder( + result, [ 'tuple(address pool, address token0_, address token1_, ' + 'tuple(uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) collateralReserves, ' + 'tuple(uint256 token0Debt, uint256 token1Debt, uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) debtReserves)', ], - toDecode, - )[0]; - - return { - pool: decodedResult.pool, - token0_: decodedResult.token0_, - token1_: decodedResult.token1_, - collateralReserves: { - token0RealReserves: Number( - decodedResult.collateralReserves.token0RealReserves, - ), - token1RealReserves: Number( - decodedResult.collateralReserves.token1RealReserves, - ), - token0ImaginaryReserves: Number( - decodedResult.collateralReserves.token0ImaginaryReserves, - ), - token1ImaginaryReserves: Number( - decodedResult.collateralReserves.token1ImaginaryReserves, - ), + undefined, + decoded => { + const [decodedResult] = decoded; + return { + pool: decodedResult.pool, + token0_: decodedResult.token0_, + token1_: decodedResult.token1_, + collateralReserves: { + token0RealReserves: Number( + decodedResult.collateralReserves.token0RealReserves, + ), + token1RealReserves: Number( + decodedResult.collateralReserves.token1RealReserves, + ), + token0ImaginaryReserves: Number( + decodedResult.collateralReserves.token0ImaginaryReserves, + ), + token1ImaginaryReserves: Number( + decodedResult.collateralReserves.token1ImaginaryReserves, + ), + }, + debtReserves: { + token0Debt: Number(decodedResult.debtReserves.token0Debt), + token1Debt: Number(decodedResult.debtReserves.token1Debt), + token0RealReserves: Number( + decodedResult.debtReserves.token0RealReserves, + ), + token1RealReserves: Number( + decodedResult.debtReserves.token1RealReserves, + ), + token0ImaginaryReserves: Number( + decodedResult.debtReserves.token0ImaginaryReserves, + ), + token1ImaginaryReserves: Number( + decodedResult.debtReserves.token1ImaginaryReserves, + ), + }, + }; }, - debtReserves: { - token0Debt: Number(decodedResult.debtReserves.token0Debt), - token1Debt: Number(decodedResult.debtReserves.token1Debt), - token0RealReserves: Number( - decodedResult.debtReserves.token0RealReserves, - ), - token1RealReserves: Number( - decodedResult.debtReserves.token1RealReserves, - ), - token0ImaginaryReserves: Number( - decodedResult.debtReserves.token0ImaginaryReserves, - ), - token1ImaginaryReserves: Number( - decodedResult.debtReserves.token1ImaginaryReserves, - ), - }, - }; + ); }; extractSuccessAndValue = ( From 6a84bda91a7887e78a32c515dbcf0962d327e8ef Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 30 Sep 2024 02:26:07 +0530 Subject: [PATCH 05/64] made changes in integration and e2e tests --- src/abi/fluid-dex/resolver.abi.json | 5452 +++++++++++++++-- src/dex/fluid-dex/config.ts | 18 +- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 20 +- .../fluid-dex/fluid-dex-integration.test.ts | 103 +- src/dex/fluid-dex/fluid-dex-pool.ts | 8 +- src/dex/fluid-dex/fluid-dex.ts | 71 +- 6 files changed, 5138 insertions(+), 534 deletions(-) diff --git a/src/abi/fluid-dex/resolver.abi.json b/src/abi/fluid-dex/resolver.abi.json index 0125bb605..08a2cbf87 100644 --- a/src/abi/fluid-dex/resolver.abi.json +++ b/src/abi/fluid-dex/resolver.abi.json @@ -5,11 +5,39 @@ "internalType": "address", "name": "factory_", "type": "address" + }, + { + "internalType": "address", + "name": "liquidity_", + "type": "address" + }, + { + "internalType": "address", + "name": "liquidityResolver_", + "type": "address" + }, + { + "internalType": "address", + "name": "deployer_", + "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" }, + { + "inputs": [], + "name": "DEPLOYER_CONTRACT", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "FACTORY", @@ -23,6 +51,32 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "LIQUIDITY", + "outputs": [ + { + "internalType": "contract IFluidLiquidity", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "LIQUIDITY_RESOLVER", + "outputs": [ + { + "internalType": "contract IFluidLiquidityResolver", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -31,30 +85,30 @@ "type": "address" }, { - "internalType": "bool", - "name": "swap0to1_", - "type": "bool" + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" }, { "internalType": "uint256", - "name": "amountIn_", + "name": "token1Amt_", "type": "uint256" }, { "internalType": "uint256", - "name": "amountOutMin_", + "name": "maxSharesAmt_", "type": "uint256" } ], - "name": "estimateSwapIn", + "name": "estimateBorrow", "outputs": [ { "internalType": "uint256", - "name": "amountOut_", + "name": "shares_", "type": "uint256" } ], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -65,167 +119,69 @@ "type": "address" }, { - "internalType": "bool", - "name": "swap0to1_", - "type": "bool" + "internalType": "uint256", + "name": "shares_", + "type": "uint256" }, { "internalType": "uint256", - "name": "amountOut_", + "name": "minToken0Borrow_", "type": "uint256" }, { "internalType": "uint256", - "name": "amountInMax_", + "name": "minToken1Borrow_", "type": "uint256" } ], - "name": "estimateSwapOut", + "name": "estimateBorrowPerfect", "outputs": [ { "internalType": "uint256", - "name": "amountIn_", + "name": "token0Amt_", "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [], - "name": "getAllPoolAddresses", - "outputs": [ + }, { - "internalType": "address[]", - "name": "pools_", - "type": "address[]" + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { - "inputs": [], - "name": "getAllPools", - "outputs": [ + "inputs": [ { - "components": [ - { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0_", - "type": "address" - }, - { - "internalType": "address", - "name": "token1_", - "type": "address" - } - ], - "internalType": "struct Structs.Pool[]", - "name": "pools_", - "type": "tuple[]" + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minSharesAmt_", + "type": "uint256" } ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getAllPoolsReserves", + "name": "estimateDeposit", "outputs": [ { - "components": [ - { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0_", - "type": "address" - }, - { - "internalType": "address", - "name": "token1_", - "type": "address" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "collateralReserves", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "debtReserves", - "type": "tuple" - } - ], - "internalType": "struct Structs.PoolWithReserves[]", - "name": "poolsReserves_", - "type": "tuple[]" + "internalType": "uint256", + "name": "shares_", + "type": "uint256" } ], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -234,39 +190,37 @@ "internalType": "address", "name": "dex_", "type": "address" + }, + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken0Deposit_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken1Deposit_", + "type": "uint256" } ], - "name": "getDexCollateralReserves", + "name": "estimateDepositPerfect", "outputs": [ { - "components": [ - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "reserves_", - "type": "tuple" + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" } ], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -275,285 +229,4743 @@ "internalType": "address", "name": "dex_", "type": "address" - } - ], - "name": "getDexDebtReserves", - "outputs": [ + }, { - "components": [ - { - "internalType": "uint256", - "name": "token0Debt", + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minSharesAmt_", + "type": "uint256" + } + ], + "name": "estimatePayback", + "outputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken0Payback_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken1Payback_", + "type": "uint256" + } + ], + "name": "estimatePaybackPerfect", + "outputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken0_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxToken1_", + "type": "uint256" + } + ], + "name": "estimatePaybackPerfectInOneToken", + "outputs": [ + { + "internalType": "uint256", + "name": "paybackAmt_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amountIn_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountOutMin_", + "type": "uint256" + } + ], + "name": "estimateSwapIn", + "outputs": [ + { + "internalType": "uint256", + "name": "amountOut_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "amountOut_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountInMax_", + "type": "uint256" + } + ], + "name": "estimateSwapOut", + "outputs": [ + { + "internalType": "uint256", + "name": "amountIn_", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxSharesAmt_", + "type": "uint256" + } + ], + "name": "estimateWithdraw", + "outputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken0Withdraw_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken1Withdraw_", + "type": "uint256" + } + ], + "name": "estimateWithdrawPerfect", + "outputs": [ + { + "internalType": "uint256", + "name": "token0Amt_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken0_", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minToken1_", + "type": "uint256" + } + ], + "name": "estimateWithdrawPerfectInOneToken", + "outputs": [ + { + "internalType": "uint256", + "name": "withdrawAmt_", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAllDexAddresses", + "outputs": [ + { + "internalType": "address[]", + "name": "dexes_", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllDexEntireDatas", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "dex", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "shift", + "type": "address" + }, + { + "internalType": "address", + "name": "admin", + "type": "address" + }, + { + "internalType": "address", + "name": "colOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "debtOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "perfectOperationsAndOracle", + "type": "address" + } + ], + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", + "type": "tuple" + }, + { + "internalType": "address", + "name": "deployerContract", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantViews", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0DenominatorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1DenominatorPrecision", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantViews2", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isSmartCollateralEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isSmartDebtEnabled", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "revenueCut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shiftingTime", + "type": "uint256" + }, + { + "internalType": "address", + "name": "centerPriceAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "hookAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + } + ], + "internalType": "struct Structs.Configs", + "name": "configs", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "colReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lastToLastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastPricesTimeDiff", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleCheckPoint", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalSupplyShares", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalBorrowShares", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isSwapAndArbitragePaused", + "type": "bool" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isRangeChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isThresholdChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isCenterPriceShiftActive", + "type": "bool" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "rangeShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "thresholdShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "shiftPercentage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + } + ], + "internalType": "struct Structs.CenterPriceShift", + "name": "centerPriceShift", + "type": "tuple" + } + ], + "internalType": "struct Structs.ShiftChanges", + "name": "shifts", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexState", + "name": "dexState", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "liquiditySupplyToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquiditySupplyToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", + "type": "tuple" + } + ], + "internalType": "struct Structs.SwapLimitsAndAvailability", + "name": "limitsAndAvailability", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexEntireData[]", + "name": "datas_", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getCenterPriceShiftRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "dexId_", + "type": "uint256" + } + ], + "name": "getDexAddress", + "outputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexCollateralReserves", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "reserves_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexConfigs", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isSmartCollateralEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isSmartDebtEnabled", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "revenueCut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shiftingTime", + "type": "uint256" + }, + { + "internalType": "address", + "name": "centerPriceAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "hookAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + } + ], + "internalType": "struct Structs.Configs", + "name": "configs_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexConstantsView", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "shift", + "type": "address" + }, + { + "internalType": "address", + "name": "admin", + "type": "address" + }, + { + "internalType": "address", + "name": "colOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "debtOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "perfectOperationsAndOracle", + "type": "address" + } + ], + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", + "type": "tuple" + }, + { + "internalType": "address", + "name": "deployerContract", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantsView_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexConstantsView2", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0DenominatorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1DenominatorPrecision", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantsView2_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexDebtReserves", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "reserves_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexEntireData", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "dex", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "shift", + "type": "address" + }, + { + "internalType": "address", + "name": "admin", + "type": "address" + }, + { + "internalType": "address", + "name": "colOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "debtOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "perfectOperationsAndOracle", + "type": "address" + } + ], + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", + "type": "tuple" + }, + { + "internalType": "address", + "name": "deployerContract", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantViews", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0DenominatorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1DenominatorPrecision", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantViews2", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isSmartCollateralEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isSmartDebtEnabled", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "revenueCut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shiftingTime", + "type": "uint256" + }, + { + "internalType": "address", + "name": "centerPriceAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "hookAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + } + ], + "internalType": "struct Structs.Configs", + "name": "configs", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "colReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lastToLastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastPricesTimeDiff", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleCheckPoint", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalSupplyShares", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalBorrowShares", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isSwapAndArbitragePaused", + "type": "bool" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isRangeChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isThresholdChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isCenterPriceShiftActive", + "type": "bool" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "rangeShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "thresholdShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "shiftPercentage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + } + ], + "internalType": "struct Structs.CenterPriceShift", + "name": "centerPriceShift", + "type": "tuple" + } + ], + "internalType": "struct Structs.ShiftChanges", + "name": "shifts", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexState", + "name": "dexState", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "liquiditySupplyToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquiditySupplyToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", + "type": "tuple" + } + ], + "internalType": "struct Structs.SwapLimitsAndAvailability", + "name": "limitsAndAvailability", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexEntireData", + "name": "data_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "dexes_", + "type": "address[]" + } + ], + "name": "getDexEntireDatas", + "outputs": [ + { + "components": [ + { + "internalType": "address", + "name": "dex", + "type": "address" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, + { + "internalType": "address", + "name": "factory", + "type": "address" + }, + { + "components": [ + { + "internalType": "address", + "name": "shift", + "type": "address" + }, + { + "internalType": "address", + "name": "admin", + "type": "address" + }, + { + "internalType": "address", + "name": "colOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "debtOperations", + "type": "address" + }, + { + "internalType": "address", + "name": "perfectOperationsAndOracle", + "type": "address" + } + ], + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", + "type": "tuple" + }, + { + "internalType": "address", + "name": "deployerContract", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantViews", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0DenominatorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1NumeratorPrecision", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1DenominatorPrecision", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantViews2", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isSmartCollateralEnabled", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isSmartDebtEnabled", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "revenueCut", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerShiftThreshold", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shiftingTime", + "type": "uint256" + }, + { + "internalType": "address", + "name": "centerPriceAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "hookAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "maxCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minCenterPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + } + ], + "internalType": "struct Structs.Configs", + "name": "configs", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "colReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "lastToLastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastPricesTimeDiff", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleCheckPoint", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalSupplyShares", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalBorrowShares", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isSwapAndArbitragePaused", + "type": "bool" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isRangeChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isThresholdChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isCenterPriceShiftActive", + "type": "bool" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "rangeShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "thresholdShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "shiftPercentage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + } + ], + "internalType": "struct Structs.CenterPriceShift", + "name": "centerPriceShift", + "type": "tuple" + } + ], + "internalType": "struct Structs.ShiftChanges", + "name": "shifts", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexState", + "name": "dexState", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "liquiditySupplyToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquiditySupplyToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", + "type": "tuple" + } + ], + "internalType": "struct Structs.SwapLimitsAndAvailability", + "name": "limitsAndAvailability", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexEntireData[]", + "name": "datas_", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexId", + "outputs": [ + { + "internalType": "uint256", + "name": "id_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256[]", + "name": "secondsAgos_", + "type": "uint256[]" + } + ], + "name": "getDexOraclePrice", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "twap1by0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowestPrice1by0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "highestPrice1by0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "twap0by1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowestPrice0by1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "highestPrice0by1", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.Oracle[]", + "name": "twaps_", + "type": "tuple[]" + }, + { + "internalType": "uint256", + "name": "currentPrice_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexPricesAndExchangePrices", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexState", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "lastToLastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastPricesTimeDiff", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleCheckPoint", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalSupplyShares", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "totalBorrowShares", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isSwapAndArbitragePaused", + "type": "bool" + }, + { + "components": [ + { + "internalType": "bool", + "name": "isRangeChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isThresholdChangeActive", + "type": "bool" + }, + { + "internalType": "bool", + "name": "isCenterPriceShiftActive", + "type": "bool" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "rangeShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "oldUpper", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldLower", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "oldTime", + "type": "uint256" + } + ], + "internalType": "struct Structs.ShiftData", + "name": "thresholdShift", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "shiftPercentage", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "duration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "startTimestamp", + "type": "uint256" + } + ], + "internalType": "struct Structs.CenterPriceShift", + "name": "centerPriceShift", + "type": "tuple" + } + ], + "internalType": "struct Structs.ShiftChanges", + "name": "shifts", + "type": "tuple" + } + ], + "internalType": "struct Structs.DexState", + "name": "state_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexSwapLimitsAndAvailability", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "liquiditySupplyToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquiditySupplyToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityWithdrawableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liquidityBorrowableToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "utilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilUtilizationLimitToken1", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", + "type": "tuple" + } + ], + "internalType": "struct Structs.SwapLimitsAndAvailability", + "name": "limitsAndAvailability_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexTokens", + "outputs": [ + { + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexVariables2Raw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getDexVariablesRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "uint256", + "name": "index_", + "type": "uint256" + } + ], + "name": "getOracleRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getRangeShiftRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getThresholdShiftRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getTotalBorrowShares", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalDexes", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "getTotalSupplyShares", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address", + "name": "user_", + "type": "address" + } + ], + "name": "getUserBorrowData", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isAllowed", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", + "type": "tuple" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "userBorrowData_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address", + "name": "user_", + "type": "address" + } + ], + "name": "getUserBorrowDataRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address[]", + "name": "users_", + "type": "address[]" + } + ], + "name": "getUserBorrowDatas", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isAllowed", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", "type": "uint256" }, { "internalType": "uint256", - "name": "token1Debt", + "name": "borrowLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "token0RealReserves", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "token1RealReserves", + "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", - "name": "token0ImaginaryReserves", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", + "type": "tuple" + } + ], + "internalType": "struct Structs.UserBorrowData[]", + "name": "userBorrowingsData_", + "type": "tuple[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address[]", + "name": "users_", + "type": "address[]" + } + ], + "name": "getUserBorrowSupplyDatas", + "outputs": [ + { + "components": [ + { + "internalType": "bool", + "name": "isAllowed", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", "type": "uint256" }, { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "supply", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", + "type": "tuple" } ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "reserves_", - "type": "tuple" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexPricesAndExchangePrices", - "outputs": [ + "internalType": "struct Structs.UserSupplyData[]", + "name": "userSuppliesData_", + "type": "tuple[]" + }, { "components": [ { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" + "internalType": "bool", + "name": "isAllowed", + "type": "bool" }, { "internalType": "uint256", - "name": "centerPrice", + "name": "borrow", "type": "uint256" }, { "internalType": "uint256", - "name": "upperRange", + "name": "borrowLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "lowerRange", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "geometricMean", + "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", - "name": "supplyToken0ExchangePrice", + "name": "expandDuration", "type": "uint256" }, { "internalType": "uint256", - "name": "borrowToken0ExchangePrice", + "name": "baseBorrowLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "supplyToken1ExchangePrice", + "name": "maxBorrowLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "borrowToken1ExchangePrice", + "name": "borrowableUntilLimit", "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.PricesAndExchangePrice", - "name": "pex_", - "type": "tuple" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "poolId_", - "type": "uint256" - } - ], - "name": "getPool", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0_", - "type": "address" }, - { - "internalType": "address", - "name": "token1_", - "type": "address" - } - ], - "internalType": "struct Structs.Pool", - "name": "pool_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "poolId_", - "type": "uint256" - } - ], - "name": "getPoolAddress", - "outputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } - ], - "name": "getPoolConstantsView", - "outputs": [ - { - "components": [ { "internalType": "uint256", - "name": "dexId", + "name": "borrowable", "type": "uint256" }, { - "internalType": "address", - "name": "liquidity", - "type": "address" - }, - { - "internalType": "address", - "name": "factory", - "type": "address" + "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "borrow", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" + } + ], + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken0", + "type": "tuple" }, { "components": [ { - "internalType": "address", - "name": "shift", - "type": "address" + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" }, { - "internalType": "address", - "name": "admin", - "type": "address" + "internalType": "uint256", + "name": "borrow", + "type": "uint256" }, { - "internalType": "address", - "name": "colOperations", - "type": "address" + "internalType": "uint256", + "name": "borrowLimit", + "type": "uint256" }, { - "internalType": "address", - "name": "debtOperations", - "type": "address" + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" }, { - "internalType": "address", - "name": "perfectOperationsAndOracle", - "type": "address" + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxBorrowLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowable", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowLimitUtilization", + "type": "uint256" } ], - "internalType": "struct IFluidDexT1.Implementations", - "name": "implementations", + "internalType": "struct Structs.UserBorrowData", + "name": "liquidityUserBorrowDataToken1", "type": "tuple" - }, - { - "internalType": "address", - "name": "deployerContract", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "supplyToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "supplyToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken1Slot", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" } ], - "internalType": "struct IFluidDexT1.ConstantViews", - "name": "constantsView_", - "type": "tuple" + "internalType": "struct Structs.UserBorrowData[]", + "name": "userBorrowingsData_", + "type": "tuple[]" } ], "stateMutability": "view", @@ -563,277 +4975,373 @@ "inputs": [ { "internalType": "address", - "name": "pool_", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address", + "name": "user_", "type": "address" } ], - "name": "getPoolConstantsView2", + "name": "getUserSupplyData", "outputs": [ { "components": [ + { + "internalType": "bool", + "name": "isAllowed", + "type": "bool" + }, { "internalType": "uint256", - "name": "token0NumeratorPrecision", + "name": "supply", "type": "uint256" }, { "internalType": "uint256", - "name": "token0DenominatorPrecision", + "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "token1NumeratorPrecision", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "token1DenominatorPrecision", + "name": "expandPercent", "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews2", - "name": "constantsView2_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } - ], - "name": "getPoolReserves", - "outputs": [ - { - "components": [ + }, { - "internalType": "address", - "name": "pool", - "type": "address" + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" }, { - "internalType": "address", - "name": "token0_", - "type": "address" + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" }, { - "internalType": "address", - "name": "token1_", - "type": "address" + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" }, { "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, { "internalType": "uint256", - "name": "token0RealReserves", + "name": "supply", "type": "uint256" }, { "internalType": "uint256", - "name": "token1RealReserves", + "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "token0ImaginaryReserves", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "token1ImaginaryReserves", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", "type": "uint256" } ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "collateralReserves", + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", "type": "tuple" }, { "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, { "internalType": "uint256", - "name": "token0Debt", + "name": "supply", "type": "uint256" }, { "internalType": "uint256", - "name": "token1Debt", + "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "token0RealReserves", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "token1RealReserves", + "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", - "name": "token0ImaginaryReserves", + "name": "expandDuration", "type": "uint256" }, { "internalType": "uint256", - "name": "token1ImaginaryReserves", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", "type": "uint256" } ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "debtReserves", + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", "type": "tuple" } ], - "internalType": "struct Structs.PoolWithReserves", - "name": "poolReserves_", + "internalType": "struct Structs.UserSupplyData", + "name": "userSupplyData_", "type": "tuple" } ], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "pool_", - "type": "address" - } - ], - "name": "getPoolTokens", - "outputs": [ - { - "internalType": "address", - "name": "token0_", + "name": "dex_", "type": "address" }, { "internalType": "address", - "name": "token1_", + "name": "user_", "type": "address" } ], + "name": "getUserSupplyDataRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], "stateMutability": "view", "type": "function" }, { "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, { "internalType": "address[]", - "name": "pools_", + "name": "users_", "type": "address[]" } ], - "name": "getPoolsReserves", + "name": "getUserSupplyDatas", "outputs": [ { "components": [ { - "internalType": "address", - "name": "pool", - "type": "address" + "internalType": "bool", + "name": "isAllowed", + "type": "bool" }, { - "internalType": "address", - "name": "token0_", - "type": "address" + "internalType": "uint256", + "name": "supply", + "type": "uint256" }, { - "internalType": "address", - "name": "token1_", - "type": "address" + "internalType": "uint256", + "name": "withdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastUpdateTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", + "type": "uint256" }, { "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, { "internalType": "uint256", - "name": "token0RealReserves", + "name": "supply", "type": "uint256" }, { "internalType": "uint256", - "name": "token1RealReserves", + "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "token0ImaginaryReserves", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "token1ImaginaryReserves", + "name": "expandPercent", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "expandDuration", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", "type": "uint256" } ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "collateralReserves", + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken0", "type": "tuple" }, { "components": [ + { + "internalType": "bool", + "name": "modeWithInterest", + "type": "bool" + }, { "internalType": "uint256", - "name": "token0Debt", + "name": "supply", "type": "uint256" }, { "internalType": "uint256", - "name": "token1Debt", + "name": "withdrawalLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "token0RealReserves", + "name": "lastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", - "name": "token1RealReserves", + "name": "expandPercent", "type": "uint256" }, { "internalType": "uint256", - "name": "token0ImaginaryReserves", + "name": "expandDuration", "type": "uint256" }, { "internalType": "uint256", - "name": "token1ImaginaryReserves", + "name": "baseWithdrawalLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawableUntilLimit", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "withdrawable", "type": "uint256" } ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "debtReserves", + "internalType": "struct Structs.UserSupplyData", + "name": "liquidityUserSupplyDataToken1", "type": "tuple" } ], - "internalType": "struct Structs.PoolWithReserves[]", - "name": "poolsReserves_", + "internalType": "struct Structs.UserSupplyData[]", + "name": "userSuppliesData_", "type": "tuple[]" } ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "getTotalPools", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], "stateMutability": "view", "type": "function" } diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index 3692ffed7..99a14b197 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -7,16 +7,16 @@ export const FluidDexConfig: DexConfigMap = { [Network.MAINNET]: { pools: [ { - id: 'FluidDex_0x6d83f60eEac0e50A1250760151E81Db2a278e03a', // Pool identifier: `{dex_key}_{pool_address}` - address: '0x6d83f60eEac0e50A1250760151E81Db2a278e03a', // Address of the pool - debtOperations: '0xaf19a6F318b7F8f58c9F9C89Acc1eC40a3AFcdF5', - colOperations: '0x835a8E10e8F473174F937AFA0eC22fC9a7Fa504F', + id: 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a', // Pool identifier: `{dex_key}_{pool_address}` + address: '0x6d83f60eeac0e50a1250760151e81db2a278e03a', // Address of the pool + debtOperations: '0xaf19a6f318b7f8f58c9f9c89acc1ec40a3afcdf5', + colOperations: '0x835a8e10e8f473174f937afa0ec22fc9a7fa504f', perfectOperationsAndSwapOut: - '0x8Cf39E1bD5722BAaC7056E1A02eE139296B224ED', - liquidityUserModule: '0x8eC5e29eA39b2f64B21e32cB9Ff11D5059982F8C', - resolver: '0xfE1CBE632855e279601EaAF58D3cB552271BfDF5', - token0: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // wstETH - token1: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // ETH + '0x8cf39e1bd5722baac7056e1a02ee139296b224ed', + liquidityUserModule: '0x8ec5e29ea39b2f64b21e32cb9ff11d5059982f8c', + resolver: '0x8620487dd447a0d4930191f917d886cbb0664d7c', + token0: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', // wstETH + token1: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', // ETH }, ], }, diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 23d0a0caf..17b9878a5 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -70,15 +70,15 @@ function testForNetwork( // TODO: Add any direct swap contractMethod name if it exists const sideToContractMethods = new Map([ - [SwapSide.SELL, [ContractMethod.swapExactAmountIn]], + [SwapSide.SELL, ['swapIn']], // TODO: If buy is not supported remove the buy contract methods - [SwapSide.BUY, [ContractMethod.swapExactAmountOut]], + // [SwapSide.BUY, [ContractMethod.swapExactAmountOut]], ]); describe(`${network}`, () => { sideToContractMethods.forEach((contractMethods, side) => describe(`${side}`, () => { - contractMethods.forEach((contractMethod: ContractMethod) => { + contractMethods.forEach((contractMethod: string) => { describe(`${contractMethod}`, () => { it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { await testE2E( @@ -88,7 +88,7 @@ function testForNetwork( side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, side, dexKey, - contractMethod, + contractMethod as ContractMethod, network, provider, ); @@ -101,7 +101,7 @@ function testForNetwork( side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, side, dexKey, - contractMethod, + contractMethod as ContractMethod, network, provider, ); @@ -114,7 +114,7 @@ function testForNetwork( side === SwapSide.SELL ? tokenAAmount : tokenBAmount, side, dexKey, - contractMethod, + contractMethod as ContractMethod, network, provider, ); @@ -133,11 +133,11 @@ describe('FluidDex E2E', () => { const network = Network.MAINNET; // TODO: Modify the tokenASymbol, tokenBSymbol, tokenAAmount; - const tokenASymbol: string = 'tokenASymbol'; - const tokenBSymbol: string = 'tokenBSymbol'; + const tokenASymbol: string = 'wstETH'; + const tokenBSymbol: string = 'ETH'; - const tokenAAmount: string = 'tokenAAmount'; - const tokenBAmount: string = 'tokenBAmount'; + const tokenAAmount: string = '1000000000000000000'; + const tokenBAmount: string = '1000000000000000000'; const nativeTokenAmount = '1000000000000000000'; testForNetwork( diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 1c71cb982..f5c4e6b89 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -7,12 +7,14 @@ import { DummyDexHelper } from '../../dex-helper/index'; import { Network, SwapSide } from '../../constants'; import { BI_POWS } from '../../bigint-constants'; import { FluidDex } from './fluid-dex'; +import { CollateralReserves, DebtReserves } from './types'; import { checkPoolPrices, checkPoolsLiquidity, checkConstantPoolPrices, } from '../../../tests/utils'; import { Tokens } from '../../../tests/constants-e2e'; +import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; /* README @@ -40,7 +42,10 @@ function getReaderCalldata( target: exchangeAddress, callData: readerIface.encodeFunctionData(funcName, [ // TODO: Put here additional arguments to encode them + '0x6d83f60eeac0e50a1250760151e81db2a278e03a', + true, amount, + 0, ]), })); } @@ -52,8 +57,9 @@ function decodeReaderResult( ) { // TODO: Adapt this function for your needs return results.map(result => { - const parsed = readerIface.decodeFunctionResult(funcName, result); - return BigInt(parsed[0]._hex); + // const parsed = readerIface.decodeFunctionResult(funcName, result); + // console.log("result is " + BigInt(result)); + return BigInt(result); }); } @@ -64,18 +70,18 @@ async function checkOnChainPricing( prices: bigint[], amounts: bigint[], ) { - const exchangeAddress = ''; // TODO: Put here the real exchange address + const resolverAddress = '0xfe1cbe632855e279601eaaf58d3cb552271bfdf5'; // TODO: Put here the real exchange address // TODO: Replace dummy interface with the real one // Normally you can get it from fluidDex.Iface or from eventPool. // It depends on your implementation - const readerIface = new Interface(''); + const readerIface = new Interface(ResolverABI); const readerCallData = getReaderCalldata( - exchangeAddress, + resolverAddress, readerIface, amounts.slice(1), - funcName, + 'estimateSwapIn', ); const readerResult = ( await fluidDex.dexHelper.multiContract.methods @@ -87,7 +93,32 @@ async function checkOnChainPricing( decodeReaderResult(readerResult, readerIface, funcName), ); - expect(prices).toEqual(expectedPrices); + console.log('prices from getPricesVolume : ' + prices); + console.log('prices fetched from reserves : ' + expectedPrices); + + // expect(prices).toEqual(expectedPrices); + + console.log( + 'swap amount : ' + + fluidDex.swapIn( + false, + BigInt(1000000000000000000), // Convert to BigInt + { + token0RealReserves: 62488268533789980, + token1RealReserves: 2169957278960, + token0ImaginaryReserves: 73751087371915120, + token1ImaginaryReserves: 19566413072683, + }, + { + token0Debt: 16591411151470, + token1Debt: 62514322242914216, + token0RealReserves: 2169113849912, + token1RealReserves: 2560161590859, + token0ImaginaryReserves: 73781841100419650, + token1ImaginaryReserves: 19576634814289, + }, + ), + ); } async function testPricingOnNetwork( @@ -159,8 +190,8 @@ describe('FluidDex', function () { // TODO: Put here token Symbol to check against // Don't forget to update relevant tokens in constant-e2e.ts - const srcTokenSymbol = 'srcTokenSymbol'; - const destTokenSymbol = 'destTokenSymbol'; + const srcTokenSymbol = 'wstETH'; + const destTokenSymbol = 'ETH'; const amountsForSell = [ 0n, @@ -176,19 +207,19 @@ describe('FluidDex', function () { 10n * BI_POWS[tokens[srcTokenSymbol].decimals], ]; - const amountsForBuy = [ - 0n, - 1n * BI_POWS[tokens[destTokenSymbol].decimals], - 2n * BI_POWS[tokens[destTokenSymbol].decimals], - 3n * BI_POWS[tokens[destTokenSymbol].decimals], - 4n * BI_POWS[tokens[destTokenSymbol].decimals], - 5n * BI_POWS[tokens[destTokenSymbol].decimals], - 6n * BI_POWS[tokens[destTokenSymbol].decimals], - 7n * BI_POWS[tokens[destTokenSymbol].decimals], - 8n * BI_POWS[tokens[destTokenSymbol].decimals], - 9n * BI_POWS[tokens[destTokenSymbol].decimals], - 10n * BI_POWS[tokens[destTokenSymbol].decimals], - ]; + // const amountsForBuy = [ + // 0n, + // 1n * BI_POWS[tokens[destTokenSymbol].decimals], + // 2n * BI_POWS[tokens[destTokenSymbol].decimals], + // 3n * BI_POWS[tokens[destTokenSymbol].decimals], + // 4n * BI_POWS[tokens[destTokenSymbol].decimals], + // 5n * BI_POWS[tokens[destTokenSymbol].decimals], + // 6n * BI_POWS[tokens[destTokenSymbol].decimals], + // 7n * BI_POWS[tokens[destTokenSymbol].decimals], + // 8n * BI_POWS[tokens[destTokenSymbol].decimals], + // 9n * BI_POWS[tokens[destTokenSymbol].decimals], + // 10n * BI_POWS[tokens[destTokenSymbol].decimals], + // ]; beforeAll(async () => { blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); @@ -212,19 +243,19 @@ describe('FluidDex', function () { ); }); - it('getPoolIdentifiers and getPricesVolume BUY', async function () { - await testPricingOnNetwork( - fluidDex, - network, - dexKey, - blockNumber, - srcTokenSymbol, - destTokenSymbol, - SwapSide.BUY, - amountsForBuy, - '', // TODO: Put here proper function name to check pricing - ); - }); + // it('getPoolIdentifiers and getPricesVolume BUY', async function () { + // await testPricingOnNetwork( + // fluidDex, + // network, + // dexKey, + // blockNumber, + // srcTokenSymbol, + // destTokenSymbol, + // SwapSide.BUY, + // amountsForBuy, + // '', // TODO: Put here proper function name to check pricing + // ); + // }); it('getTopPoolsForToken', async function () { // We have to check without calling initializePricing, because @@ -235,7 +266,7 @@ describe('FluidDex', function () { } const poolLiquidity = await newFluidDex.getTopPoolsForToken( tokens[srcTokenSymbol].address, - 10, + 1, ); console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 33fe8410c..bce948b9a 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -4,7 +4,7 @@ import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; -import FluidDexABI from '../../abi/fluid-dex/fluid-dex.abi.json'; +import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; import { FluidDexPool, FluidDexPoolState, PoolWithReserves } from './types'; @@ -73,7 +73,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber[] = [ { target: this.pool.resolver, - callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ + callData: ResolverAbi.encodeFunctionData('getCollateralReserves', [ this.pool.address, ]), decodeFunction: await this.decodePoolWithReserves, @@ -213,10 +213,10 @@ export class FluidDexEventPool extends StatefulEventSubscriber> { - const ResolverAbi = new Interface(ResolverABI); + const ResolverAbi = new Interface(FluidDexPoolABI); const callData: MultiCallParams[] = [ { - target: this.pool.resolver, + target: this.pool.address, callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 12c2c2be2..c3afed09b 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -16,8 +16,10 @@ import { IDexHelper } from '../../dex-helper/idex-helper'; import { CollateralReserves, DebtReserves, + DexParams, FluidDexData, FluidDexPool, + FluidDexPoolState, } from './types'; import { SimpleExchange } from '../simple-exchange'; import { FluidDexConfig, Adapters, FLUID_DEX_GAS_COST } from './config'; @@ -41,15 +43,27 @@ export class FluidDex extends SimpleExchange implements IDex { readonly pools: [FluidDexPool]; + protected adapters; + constructor( readonly network: Network, readonly dexKey: string, readonly dexHelper: IDexHelper, - protected adapters = Adapters[network] || {}, // TODO: add any additional optional params to support other fork DEXes ) { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); - this.pools = FluidDexConfig[dexKey][network].pools; + this.pools = FluidDexConfig['FluidDex'][network].pools; + this.adapters = Adapters[network] || {}; // TODO: add any additional optional params to support other fork DEXes + + for (const pool of this.pools) { + this.eventPools[pool.id] = new FluidDexEventPool( + 'FluidDex', + pool, + network, + dexHelper, + this.logger, + ); + } } // Initialize pricing is called once in the start of @@ -128,6 +142,7 @@ export class FluidDex extends SimpleExchange implements IDex { return null; } + // const state = await eventPool.generateState(blockNumber); const state = await eventPool.getStateOrGenerate(blockNumber); const swap0To1: boolean = side === SwapSide.SELL; @@ -218,7 +233,57 @@ export class FluidDex extends SimpleExchange implements IDex { limit: number, ): Promise { //TODO: complete me! - return []; + let liquidityAmounts: { [id: string]: number } = {}; + for (const pool of this.pools) { + if ( + pool.token0 === tokenAddress.toLowerCase() || + pool.token1 === tokenAddress.toLowerCase() + ) { + const state: FluidDexPoolState = await this.eventPools[ + pool.id + ].getStateOrGenerate( + await this.dexHelper.provider.getBlockNumber(), + false, + ); + + liquidityAmounts[pool.id] = + pool.token0 === tokenAddress + ? state.collateralReserves.token0RealReserves + + state.debtReserves.token0RealReserves + : state.collateralReserves.token1RealReserves + + state.debtReserves.token1RealReserves; + } + } + + // console.log( + // 'Number of pools with liquidity: ' + Object.keys(liquidityAmounts).length, + // ); + + const entries = Object.entries(liquidityAmounts); + + // Sort the entries based on the values in descending order + entries.sort((a, b) => b[1] - a[1]); + + // Take the top k entries + const topKEntries = entries.slice(0, limit); + + // Convert the array back to an object + const sortedAmounts = Object.fromEntries(topKEntries); + + const poolLiquidities: PoolLiquidity[] = []; + + for (const [id, amount] of Object.entries(sortedAmounts)) { + const pool = this.pools.find(p => p.id === id); + if (!pool) continue; // Skip if pool not found + + poolLiquidities.push({ + exchange: 'FluidDex', + address: pool.address, + connectorTokens: [], + liquidityUSD: amount, + }); + } + return poolLiquidities; } // This is optional function in case if your implementation has acquired any resources From 2c85ebdc194b4143f11c8b18e3d3c27dd3cf22f9 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 30 Sep 2024 05:43:59 +0530 Subject: [PATCH 06/64] integration tests --- src/abi/fluid-dex/resolver.abi.json | 5442 ++--------------- src/dex/fluid-dex/config.ts | 2 +- .../fluid-dex/fluid-dex-integration.test.ts | 34 +- src/dex/fluid-dex/fluid-dex-pool.ts | 7 +- src/dex/fluid-dex/fluid-dex.ts | 18 +- 5 files changed, 517 insertions(+), 4986 deletions(-) diff --git a/src/abi/fluid-dex/resolver.abi.json b/src/abi/fluid-dex/resolver.abi.json index 08a2cbf87..e5be96ef0 100644 --- a/src/abi/fluid-dex/resolver.abi.json +++ b/src/abi/fluid-dex/resolver.abi.json @@ -5,39 +5,11 @@ "internalType": "address", "name": "factory_", "type": "address" - }, - { - "internalType": "address", - "name": "liquidity_", - "type": "address" - }, - { - "internalType": "address", - "name": "liquidityResolver_", - "type": "address" - }, - { - "internalType": "address", - "name": "deployer_", - "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" }, - { - "inputs": [], - "name": "DEPLOYER_CONTRACT", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "FACTORY", @@ -51,32 +23,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "LIQUIDITY", - "outputs": [ - { - "internalType": "contract IFluidLiquidity", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "LIQUIDITY_RESOLVER", - "outputs": [ - { - "internalType": "contract IFluidLiquidityResolver", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [ { @@ -85,30 +31,30 @@ "type": "address" }, { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" }, { "internalType": "uint256", - "name": "token1Amt_", + "name": "amountIn_", "type": "uint256" }, { "internalType": "uint256", - "name": "maxSharesAmt_", + "name": "amountOutMin_", "type": "uint256" } ], - "name": "estimateBorrow", + "name": "estimateSwapIn", "outputs": [ { "internalType": "uint256", - "name": "shares_", + "name": "amountOut_", "type": "uint256" } ], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -119,108 +65,177 @@ "type": "address" }, { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" + "internalType": "bool", + "name": "swap0to1_", + "type": "bool" }, { "internalType": "uint256", - "name": "minToken0Borrow_", + "name": "amountOut_", "type": "uint256" }, { "internalType": "uint256", - "name": "minToken1Borrow_", + "name": "amountInMax_", "type": "uint256" } ], - "name": "estimateBorrowPerfect", + "name": "estimateSwapOut", "outputs": [ { "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Amt_", + "name": "amountIn_", "type": "uint256" } ], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minSharesAmt_", - "type": "uint256" - } - ], - "name": "estimateDeposit", + "inputs": [], + "name": "getAllPoolAddresses", "outputs": [ { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" + "internalType": "address[]", + "name": "pools_", + "type": "address[]" } ], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxToken0Deposit_", - "type": "uint256" - }, + "inputs": [], + "name": "getAllPools", + "outputs": [ { - "internalType": "uint256", - "name": "maxToken1Deposit_", - "type": "uint256" + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + } + ], + "internalType": "struct Structs.Pool[]", + "name": "pools_", + "type": "tuple[]" } ], - "name": "estimateDepositPerfect", + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getAllPoolsReserves", "outputs": [ { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Amt_", - "type": "uint256" + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves[]", + "name": "poolsReserves_", + "type": "tuple[]" } ], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -229,71 +244,39 @@ "internalType": "address", "name": "dex_", "type": "address" - }, - { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minSharesAmt_", - "type": "uint256" } ], - "name": "estimatePayback", + "name": "getDexCollateralReserves", "outputs": [ { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxToken0Payback_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxToken1Payback_", - "type": "uint256" - } - ], - "name": "estimatePaybackPerfect", - "outputs": [ - { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Amt_", - "type": "uint256" + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "reserves_", + "type": "tuple" } ], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -302,32 +285,49 @@ "internalType": "address", "name": "dex_", "type": "address" - }, - { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxToken0_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxToken1_", - "type": "uint256" } ], - "name": "estimatePaybackPerfectInOneToken", + "name": "getDexDebtReserves", "outputs": [ { - "internalType": "uint256", - "name": "paybackAmt_", - "type": "uint256" + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "reserves_", + "type": "tuple" } ], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -336,4636 +336,239 @@ "internalType": "address", "name": "dex_", "type": "address" - }, - { - "internalType": "bool", - "name": "swap0to1_", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "amountIn_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOutMin_", - "type": "uint256" } ], - "name": "estimateSwapIn", + "name": "getDexPricesAndExchangePrices", "outputs": [ { - "internalType": "uint256", - "name": "amountOut_", - "type": "uint256" + "components": [ + { + "internalType": "uint256", + "name": "lastStoredPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "centerPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lowerRange", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "geometricMean", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken0ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "supplyToken1ExchangePrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "borrowToken1ExchangePrice", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.PricesAndExchangePrice", + "name": "pex_", + "type": "tuple" } ], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "bool", - "name": "swap0to1_", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "amountOut_", - "type": "uint256" - }, { "internalType": "uint256", - "name": "amountInMax_", + "name": "poolId_", "type": "uint256" } ], - "name": "estimateSwapOut", + "name": "getPool", "outputs": [ { - "internalType": "uint256", - "name": "amountIn_", - "type": "uint256" + "components": [ + { + "internalType": "address", + "name": "pool", + "type": "address" + }, + { + "internalType": "address", + "name": "token0", + "type": "address" + }, + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee", + "type": "uint256" + } + ], + "internalType": "struct Structs.Pool", + "name": "pool_", + "type": "tuple" } ], - "stateMutability": "payable", + "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, { "internalType": "uint256", - "name": "token1Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxSharesAmt_", + "name": "poolId_", "type": "uint256" } ], - "name": "estimateWithdraw", + "name": "getPoolAddress", "outputs": [ { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" + "internalType": "address", + "name": "pool_", + "type": "address" } ], - "stateMutability": "nonpayable", + "stateMutability": "view", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "dex_", + "name": "pool_", "type": "address" - }, - { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minToken0Withdraw_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minToken1Withdraw_", - "type": "uint256" } ], - "name": "estimateWithdrawPerfect", - "outputs": [ - { - "internalType": "uint256", - "name": "token0Amt_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Amt_", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "shares_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minToken0_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minToken1_", - "type": "uint256" - } - ], - "name": "estimateWithdrawPerfectInOneToken", - "outputs": [ - { - "internalType": "uint256", - "name": "withdrawAmt_", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "getAllDexAddresses", - "outputs": [ - { - "internalType": "address[]", - "name": "dexes_", - "type": "address[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getAllDexEntireDatas", + "name": "getPoolConstantsView", "outputs": [ { "components": [ + { + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "liquidity", + "type": "address" + }, { "internalType": "address", - "name": "dex", + "name": "factory", "type": "address" }, { "components": [ - { - "internalType": "uint256", - "name": "dexId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "liquidity", - "type": "address" - }, - { - "internalType": "address", - "name": "factory", - "type": "address" - }, - { - "components": [ - { - "internalType": "address", - "name": "shift", - "type": "address" - }, - { - "internalType": "address", - "name": "admin", - "type": "address" - }, - { - "internalType": "address", - "name": "colOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "debtOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "perfectOperationsAndOracle", - "type": "address" - } - ], - "internalType": "struct IFluidDexT1.Implementations", - "name": "implementations", - "type": "tuple" - }, { "internalType": "address", - "name": "deployerContract", + "name": "shift", "type": "address" }, { "internalType": "address", - "name": "token0", + "name": "admin", "type": "address" }, { "internalType": "address", - "name": "token1", + "name": "colOperations", "type": "address" }, - { - "internalType": "bytes32", - "name": "supplyToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "supplyToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken1Slot", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews", - "name": "constantViews", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0DenominatorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1DenominatorPrecision", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews2", - "name": "constantViews2", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isSmartCollateralEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isSmartDebtEnabled", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "revenueCut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "shiftingTime", - "type": "uint256" - }, { "internalType": "address", - "name": "centerPriceAddress", + "name": "debtOperations", "type": "address" }, { "internalType": "address", - "name": "hookAddress", + "name": "perfectOperationsAndOracle", "type": "address" - }, - { - "internalType": "uint256", - "name": "maxCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" } ], - "internalType": "struct Structs.Configs", - "name": "configs", + "internalType": "struct IFluidDexT1.Implementations", + "name": "implementations", "type": "tuple" }, { - "components": [ - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "geometricMean", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken1ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken1ExchangePrice", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.PricesAndExchangePrice", - "name": "pex", - "type": "tuple" + "internalType": "address", + "name": "deployerContract", + "type": "address" }, { - "components": [ - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "colReserves", - "type": "tuple" + "internalType": "address", + "name": "token0", + "type": "address" }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "debtReserves", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "lastToLastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastPricesTimeDiff", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleCheckPoint", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalSupplyShares", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalBorrowShares", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "isSwapAndArbitragePaused", - "type": "bool" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isRangeChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isThresholdChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isCenterPriceShiftActive", - "type": "bool" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "rangeShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "thresholdShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "shiftPercentage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - } - ], - "internalType": "struct Structs.CenterPriceShift", - "name": "centerPriceShift", - "type": "tuple" - } - ], - "internalType": "struct Structs.ShiftChanges", - "name": "shifts", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexState", - "name": "dexState", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "liquiditySupplyToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquiditySupplyToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.SwapLimitsAndAvailability", - "name": "limitsAndAvailability", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexEntireData[]", - "name": "datas_", - "type": "tuple[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getCenterPriceShiftRaw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "dexId_", - "type": "uint256" - } - ], - "name": "getDexAddress", - "outputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexCollateralReserves", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "reserves_", - "type": "tuple" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexConfigs", - "outputs": [ - { - "components": [ - { - "internalType": "bool", - "name": "isSmartCollateralEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isSmartDebtEnabled", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "revenueCut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "shiftingTime", - "type": "uint256" - }, - { - "internalType": "address", - "name": "centerPriceAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "hookAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "maxCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - } - ], - "internalType": "struct Structs.Configs", - "name": "configs_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexConstantsView", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "dexId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "liquidity", - "type": "address" - }, - { - "internalType": "address", - "name": "factory", - "type": "address" - }, - { - "components": [ - { - "internalType": "address", - "name": "shift", - "type": "address" - }, - { - "internalType": "address", - "name": "admin", - "type": "address" - }, - { - "internalType": "address", - "name": "colOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "debtOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "perfectOperationsAndOracle", - "type": "address" - } - ], - "internalType": "struct IFluidDexT1.Implementations", - "name": "implementations", - "type": "tuple" - }, - { - "internalType": "address", - "name": "deployerContract", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "supplyToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "supplyToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken1Slot", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews", - "name": "constantsView_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexConstantsView2", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "token0NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0DenominatorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1DenominatorPrecision", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews2", - "name": "constantsView2_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexDebtReserves", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "token0Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "reserves_", - "type": "tuple" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexEntireData", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "dex", - "type": "address" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "dexId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "liquidity", - "type": "address" - }, - { - "internalType": "address", - "name": "factory", - "type": "address" - }, - { - "components": [ - { - "internalType": "address", - "name": "shift", - "type": "address" - }, - { - "internalType": "address", - "name": "admin", - "type": "address" - }, - { - "internalType": "address", - "name": "colOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "debtOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "perfectOperationsAndOracle", - "type": "address" - } - ], - "internalType": "struct IFluidDexT1.Implementations", - "name": "implementations", - "type": "tuple" - }, - { - "internalType": "address", - "name": "deployerContract", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "supplyToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "supplyToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken1Slot", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews", - "name": "constantViews", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0DenominatorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1DenominatorPrecision", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews2", - "name": "constantViews2", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isSmartCollateralEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isSmartDebtEnabled", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "revenueCut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "shiftingTime", - "type": "uint256" - }, - { - "internalType": "address", - "name": "centerPriceAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "hookAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "maxCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - } - ], - "internalType": "struct Structs.Configs", - "name": "configs", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "geometricMean", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken1ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken1ExchangePrice", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.PricesAndExchangePrice", - "name": "pex", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "colReserves", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "debtReserves", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "lastToLastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastPricesTimeDiff", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleCheckPoint", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalSupplyShares", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalBorrowShares", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "isSwapAndArbitragePaused", - "type": "bool" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isRangeChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isThresholdChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isCenterPriceShiftActive", - "type": "bool" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "rangeShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "thresholdShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "shiftPercentage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - } - ], - "internalType": "struct Structs.CenterPriceShift", - "name": "centerPriceShift", - "type": "tuple" - } - ], - "internalType": "struct Structs.ShiftChanges", - "name": "shifts", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexState", - "name": "dexState", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "liquiditySupplyToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquiditySupplyToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.SwapLimitsAndAvailability", - "name": "limitsAndAvailability", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexEntireData", - "name": "data_", - "type": "tuple" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "dexes_", - "type": "address[]" - } - ], - "name": "getDexEntireDatas", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "dex", - "type": "address" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "dexId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "liquidity", - "type": "address" - }, - { - "internalType": "address", - "name": "factory", - "type": "address" - }, - { - "components": [ - { - "internalType": "address", - "name": "shift", - "type": "address" - }, - { - "internalType": "address", - "name": "admin", - "type": "address" - }, - { - "internalType": "address", - "name": "colOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "debtOperations", - "type": "address" - }, - { - "internalType": "address", - "name": "perfectOperationsAndOracle", - "type": "address" - } - ], - "internalType": "struct IFluidDexT1.Implementations", - "name": "implementations", - "type": "tuple" - }, - { - "internalType": "address", - "name": "deployerContract", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "supplyToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "supplyToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "borrowToken1Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken0Slot", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "exchangePriceToken1Slot", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews", - "name": "constantViews", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0DenominatorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1NumeratorPrecision", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1DenominatorPrecision", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.ConstantViews2", - "name": "constantViews2", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isSmartCollateralEnabled", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isSmartDebtEnabled", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "revenueCut", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerShiftThreshold", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "shiftingTime", - "type": "uint256" - }, - { - "internalType": "address", - "name": "centerPriceAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "hookAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "maxCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minCenterPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - } - ], - "internalType": "struct Structs.Configs", - "name": "configs", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "geometricMean", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken1ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken1ExchangePrice", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.PricesAndExchangePrice", - "name": "pex", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.CollateralReserves", - "name": "colReserves", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "token0Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1Debt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1RealReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token0ImaginaryReserves", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "token1ImaginaryReserves", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.DebtReserves", - "name": "debtReserves", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "lastToLastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastPricesTimeDiff", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleCheckPoint", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalSupplyShares", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalBorrowShares", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "isSwapAndArbitragePaused", - "type": "bool" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isRangeChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isThresholdChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isCenterPriceShiftActive", - "type": "bool" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "rangeShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "thresholdShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "shiftPercentage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - } - ], - "internalType": "struct Structs.CenterPriceShift", - "name": "centerPriceShift", - "type": "tuple" - } - ], - "internalType": "struct Structs.ShiftChanges", - "name": "shifts", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexState", - "name": "dexState", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "liquiditySupplyToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquiditySupplyToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.SwapLimitsAndAvailability", - "name": "limitsAndAvailability", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexEntireData[]", - "name": "datas_", - "type": "tuple[]" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexId", - "outputs": [ - { - "internalType": "uint256", - "name": "id_", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256[]", - "name": "secondsAgos_", - "type": "uint256[]" - } - ], - "name": "getDexOraclePrice", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "twap1by0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowestPrice1by0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "highestPrice1by0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "twap0by1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowestPrice0by1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "highestPrice0by1", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.Oracle[]", - "name": "twaps_", - "type": "tuple[]" - }, - { - "internalType": "uint256", - "name": "currentPrice_", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexPricesAndExchangePrices", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lowerRange", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "geometricMean", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken0ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "supplyToken1ExchangePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowToken1ExchangePrice", - "type": "uint256" - } - ], - "internalType": "struct IFluidDexT1.PricesAndExchangePrice", - "name": "pex_", - "type": "tuple" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexState", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "lastToLastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastStoredPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "centerPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastPricesTimeDiff", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleCheckPoint", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oracleMapping", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalSupplyShares", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalBorrowShares", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "isSwapAndArbitragePaused", - "type": "bool" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isRangeChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isThresholdChangeActive", - "type": "bool" - }, - { - "internalType": "bool", - "name": "isCenterPriceShiftActive", - "type": "bool" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "rangeShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "oldUpper", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldLower", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "oldTime", - "type": "uint256" - } - ], - "internalType": "struct Structs.ShiftData", - "name": "thresholdShift", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "shiftPercentage", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "duration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "startTimestamp", - "type": "uint256" - } - ], - "internalType": "struct Structs.CenterPriceShift", - "name": "centerPriceShift", - "type": "tuple" - } - ], - "internalType": "struct Structs.ShiftChanges", - "name": "shifts", - "type": "tuple" - } - ], - "internalType": "struct Structs.DexState", - "name": "state_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexSwapLimitsAndAvailability", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "liquiditySupplyToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquiditySupplyToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityWithdrawableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liquidityBorrowableToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "utilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken0", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilUtilizationLimitToken1", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.SwapLimitsAndAvailability", - "name": "limitsAndAvailability_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexTokens", - "outputs": [ - { - "internalType": "address", - "name": "token0_", - "type": "address" - }, - { - "internalType": "address", - "name": "token1_", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexVariables2Raw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getDexVariablesRaw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "uint256", - "name": "index_", - "type": "uint256" - } - ], - "name": "getOracleRaw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getRangeShiftRaw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getThresholdShiftRaw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getTotalBorrowShares", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getTotalDexes", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } - ], - "name": "getTotalSupplyShares", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "address", - "name": "user_", - "type": "address" - } - ], - "name": "getUserBorrowData", - "outputs": [ - { - "components": [ - { - "internalType": "bool", - "name": "isAllowed", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "userBorrowData_", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "address", - "name": "user_", - "type": "address" - } - ], - "name": "getUserBorrowDataRaw", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "address[]", - "name": "users_", - "type": "address[]" - } - ], - "name": "getUserBorrowDatas", - "outputs": [ - { - "components": [ - { - "internalType": "bool", - "name": "isAllowed", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.UserBorrowData[]", - "name": "userBorrowingsData_", - "type": "tuple[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "address[]", - "name": "users_", - "type": "address[]" - } - ], - "name": "getUserBorrowSupplyDatas", - "outputs": [ - { - "components": [ - { - "internalType": "bool", - "name": "isAllowed", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawable", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", - "type": "tuple" - } - ], - "internalType": "struct Structs.UserSupplyData[]", - "name": "userSuppliesData_", - "type": "tuple[]" - }, - { - "components": [ - { - "internalType": "bool", - "name": "isAllowed", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken0", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "borrow", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "baseBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxBorrowLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowableUntilLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "borrowLimitUtilization", - "type": "uint256" - } - ], - "internalType": "struct Structs.UserBorrowData", - "name": "liquidityUserBorrowDataToken1", - "type": "tuple" + { + "internalType": "address", + "name": "token1", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "supplyToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "supplyToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "borrowToken1Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken0Slot", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "exchangePriceToken1Slot", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "oracleMapping", + "type": "uint256" } ], - "internalType": "struct Structs.UserBorrowData[]", - "name": "userBorrowingsData_", - "type": "tuple[]" + "internalType": "struct IFluidDexT1.ConstantViews", + "name": "constantsView_", + "type": "tuple" } ], "stateMutability": "view", @@ -4975,196 +578,186 @@ "inputs": [ { "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "address", - "name": "user_", + "name": "pool_", "type": "address" } ], - "name": "getUserSupplyData", + "name": "getPoolConstantsView2", "outputs": [ { "components": [ - { - "internalType": "bool", - "name": "isAllowed", - "type": "bool" - }, { "internalType": "uint256", - "name": "supply", + "name": "token0NumeratorPrecision", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawalLimit", + "name": "token0DenominatorPrecision", "type": "uint256" }, { "internalType": "uint256", - "name": "lastUpdateTimestamp", + "name": "token1NumeratorPrecision", "type": "uint256" }, { "internalType": "uint256", - "name": "expandPercent", + "name": "token1DenominatorPrecision", "type": "uint256" - }, + } + ], + "internalType": "struct IFluidDexT1.ConstantViews2", + "name": "constantsView2_", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "name": "getPoolFee", + "outputs": [ + { + "internalType": "uint256", + "name": "fee_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "pool_", + "type": "address" + } + ], + "name": "getPoolReserves", + "outputs": [ + { + "components": [ { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" + "internalType": "address", + "name": "pool", + "type": "address" }, { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" + "internalType": "address", + "name": "token0", + "type": "address" }, { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" + "internalType": "address", + "name": "token1", + "type": "address" }, { "internalType": "uint256", - "name": "withdrawable", + "name": "fee", "type": "uint256" }, { "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, { "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", + "name": "token0RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "baseWithdrawalLimit", + "name": "token1RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawableUntilLimit", + "name": "token0ImaginaryReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawable", + "name": "token1ImaginaryReserves", "type": "uint256" } ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", "type": "tuple" }, { "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, { "internalType": "uint256", - "name": "lastUpdateTimestamp", + "name": "token0Debt", "type": "uint256" }, { "internalType": "uint256", - "name": "expandPercent", + "name": "token1Debt", "type": "uint256" }, { "internalType": "uint256", - "name": "expandDuration", + "name": "token0RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "baseWithdrawalLimit", + "name": "token1RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawableUntilLimit", + "name": "token0ImaginaryReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawable", + "name": "token1ImaginaryReserves", "type": "uint256" } ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", "type": "tuple" } ], - "internalType": "struct Structs.UserSupplyData", - "name": "userSupplyData_", + "internalType": "struct Structs.PoolWithReserves", + "name": "poolReserves_", "type": "tuple" } ], - "stateMutability": "view", + "stateMutability": "nonpayable", "type": "function" }, { "inputs": [ { "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "address", - "name": "user_", + "name": "pool_", "type": "address" } ], - "name": "getUserSupplyDataRaw", + "name": "getPoolTokens", "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "address", + "name": "token0_", + "type": "address" + }, + { + "internalType": "address", + "name": "token1_", + "type": "address" } ], "stateMutability": "view", @@ -5172,176 +765,119 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, { "internalType": "address[]", - "name": "users_", + "name": "pools_", "type": "address[]" } ], - "name": "getUserSupplyDatas", + "name": "getPoolsReserves", "outputs": [ { "components": [ { - "internalType": "bool", - "name": "isAllowed", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandDuration", - "type": "uint256" + "internalType": "address", + "name": "pool", + "type": "address" }, { - "internalType": "uint256", - "name": "baseWithdrawalLimit", - "type": "uint256" + "internalType": "address", + "name": "token0", + "type": "address" }, { - "internalType": "uint256", - "name": "withdrawableUntilLimit", - "type": "uint256" + "internalType": "address", + "name": "token1", + "type": "address" }, { "internalType": "uint256", - "name": "withdrawable", + "name": "fee", "type": "uint256" }, { "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "expandPercent", - "type": "uint256" - }, { "internalType": "uint256", - "name": "expandDuration", + "name": "token0RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "baseWithdrawalLimit", + "name": "token1RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawableUntilLimit", + "name": "token0ImaginaryReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawable", + "name": "token1ImaginaryReserves", "type": "uint256" } ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken0", + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", "type": "tuple" }, { "components": [ - { - "internalType": "bool", - "name": "modeWithInterest", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "supply", - "type": "uint256" - }, { "internalType": "uint256", - "name": "withdrawalLimit", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastUpdateTimestamp", + "name": "token0Debt", "type": "uint256" }, { "internalType": "uint256", - "name": "expandPercent", + "name": "token1Debt", "type": "uint256" }, { "internalType": "uint256", - "name": "expandDuration", + "name": "token0RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "baseWithdrawalLimit", + "name": "token1RealReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawableUntilLimit", + "name": "token0ImaginaryReserves", "type": "uint256" }, { "internalType": "uint256", - "name": "withdrawable", + "name": "token1ImaginaryReserves", "type": "uint256" } ], - "internalType": "struct Structs.UserSupplyData", - "name": "liquidityUserSupplyDataToken1", + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", "type": "tuple" } ], - "internalType": "struct Structs.UserSupplyData[]", - "name": "userSuppliesData_", + "internalType": "struct Structs.PoolWithReserves[]", + "name": "poolsReserves_", "type": "tuple[]" } ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getTotalPools", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], "stateMutability": "view", "type": "function" } diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index 99a14b197..8f007a4ff 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -14,7 +14,7 @@ export const FluidDexConfig: DexConfigMap = { perfectOperationsAndSwapOut: '0x8cf39e1bd5722baac7056e1a02ee139296b224ed', liquidityUserModule: '0x8ec5e29ea39b2f64b21e32cb9ff11d5059982f8c', - resolver: '0x8620487dd447a0d4930191f917d886cbb0664d7c', + resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', token0: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', // wstETH token1: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', // ETH }, diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index f5c4e6b89..e41e64b09 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -43,9 +43,9 @@ function getReaderCalldata( callData: readerIface.encodeFunctionData(funcName, [ // TODO: Put here additional arguments to encode them '0x6d83f60eeac0e50a1250760151e81db2a278e03a', - true, + funcName == 'estimateSwapIn' ? true : false, amount, - 0, + funcName == 'estimateSwapIn' ? 0 : 10 ** 30, ]), })); } @@ -70,7 +70,7 @@ async function checkOnChainPricing( prices: bigint[], amounts: bigint[], ) { - const resolverAddress = '0xfe1cbe632855e279601eaaf58d3cb552271bfdf5'; // TODO: Put here the real exchange address + const resolverAddress = '0x278166a9b88f166eb170d55801be1b1d1e576330'; // TODO: Put here the real exchange address // TODO: Replace dummy interface with the real one // Normally you can get it from fluidDex.Iface or from eventPool. @@ -81,7 +81,7 @@ async function checkOnChainPricing( resolverAddress, readerIface, amounts.slice(1), - 'estimateSwapIn', + funcName, ); const readerResult = ( await fluidDex.dexHelper.multiContract.methods @@ -97,28 +97,6 @@ async function checkOnChainPricing( console.log('prices fetched from reserves : ' + expectedPrices); // expect(prices).toEqual(expectedPrices); - - console.log( - 'swap amount : ' + - fluidDex.swapIn( - false, - BigInt(1000000000000000000), // Convert to BigInt - { - token0RealReserves: 62488268533789980, - token1RealReserves: 2169957278960, - token0ImaginaryReserves: 73751087371915120, - token1ImaginaryReserves: 19566413072683, - }, - { - token0Debt: 16591411151470, - token1Debt: 62514322242914216, - token0RealReserves: 2169113849912, - token1RealReserves: 2560161590859, - token0ImaginaryReserves: 73781841100419650, - token1ImaginaryReserves: 19576634814289, - }, - ), - ); } async function testPricingOnNetwork( @@ -239,7 +217,7 @@ describe('FluidDex', function () { destTokenSymbol, SwapSide.SELL, amountsForSell, - '', // TODO: Put here proper function name to check pricing + 'estimateSwapIn', // TODO: Put here proper function name to check pricing ); }); @@ -253,7 +231,7 @@ describe('FluidDex', function () { // destTokenSymbol, // SwapSide.BUY, // amountsForBuy, - // '', // TODO: Put here proper function name to check pricing + // 'estimateSwapOut', // TODO: Put here proper function name to check pricing // ); // }); diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index bce948b9a..cf9518186 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -198,6 +198,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber> { - const ResolverAbi = new Interface(FluidDexPoolABI); + const ResolverAbi = new Interface(ResolverABI); const callData: MultiCallParams[] = [ { - target: this.pool.address, + target: this.pool.resolver, callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), @@ -231,6 +232,8 @@ export class FluidDexEventPool extends StatefulEventSubscriber { const eventPool = this.eventPools[pool.id]; if (!eventPool) { - this.logger.error(`OSwap pool ${pool.id}: No EventPool found.`); + this.logger.error(`fluid-dex pool ${pool.id}: No EventPool found.`); return null; } // const state = await eventPool.generateState(blockNumber); const state = await eventPool.getStateOrGenerate(blockNumber); + // console.log('fluidDex - getPricesVolume : ' + state); const swap0To1: boolean = side === SwapSide.SELL; @@ -157,9 +158,22 @@ export class FluidDex extends SimpleExchange implements IDex { ), ); + // console.log('state colres is -> '); + // console.log(state.collateralReserves.token0ImaginaryReserves); + // console.log(state.collateralReserves.token0RealReserves); + // console.log(state.collateralReserves.token1ImaginaryReserves); + // console.log(state.collateralReserves.token1RealReserves); + // console.log('state debtres is -> '); + // console.log(state.debtReserves.token0Debt); + // console.log(state.debtReserves.token0ImaginaryReserves); + // console.log(state.debtReserves.token0RealReserves); + // console.log(state.debtReserves.token1Debt); + // console.log(state.debtReserves.token1ImaginaryReserves); + // console.log(state.debtReserves.token1RealReserves); + return [ { - prices: amounts, // to be done + prices: prices, // to be done unit: getBigIntPow( (side === SwapSide.SELL ? destToken : srcToken).decimals, ), // to be done From cabf53a7dbbb641ab71679ea2a45593f862c490f Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 30 Sep 2024 17:22:53 +0530 Subject: [PATCH 07/64] . --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 52 +++++++-------- src/dex/fluid-dex/fluid-dex.ts | 80 +++++++++++++++++++++-- src/dex/index.ts | 2 + src/implementations/local-paraswap-sdk.ts | 5 ++ tests/constants-e2e.ts | 2 +- tests/utils-e2e.ts | 3 + 6 files changed, 113 insertions(+), 31 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 17b9878a5..7d5398be3 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -80,19 +80,19 @@ function testForNetwork( describe(`${side}`, () => { contractMethods.forEach((contractMethod: string) => { describe(`${contractMethod}`, () => { - it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { - await testE2E( - tokens[nativeTokenSymbol], - tokens[tokenASymbol], - holders[nativeTokenSymbol], - side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, - side, - dexKey, - contractMethod as ContractMethod, - network, - provider, - ); - }); + // it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { + // await testE2E( + // tokens[nativeTokenSymbol], + // tokens[tokenASymbol], + // holders[nativeTokenSymbol], + // side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, + // side, + // dexKey, + // contractMethod as ContractMethod, + // network, + // provider, + // ); + // }); it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { await testE2E( tokens[tokenASymbol], @@ -106,19 +106,19 @@ function testForNetwork( provider, ); }); - it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { - await testE2E( - tokens[tokenASymbol], - tokens[tokenBSymbol], - holders[tokenASymbol], - side === SwapSide.SELL ? tokenAAmount : tokenBAmount, - side, - dexKey, - contractMethod as ContractMethod, - network, - provider, - ); - }); + // it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { + // await testE2E( + // tokens[tokenASymbol], + // tokens[tokenBSymbol], + // holders[tokenASymbol], + // side === SwapSide.SELL ? tokenAAmount : tokenBAmount, + // side, + // dexKey, + // contractMethod as ContractMethod, + // network, + // provider, + // ); + // }); }); }); }), diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 75f11a2e0..40043fb86 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -1,4 +1,5 @@ import { AsyncOrSync } from 'ts-essentials'; +import { Interface } from '@ethersproject/abi'; import { Token, Address, @@ -7,11 +8,12 @@ import { AdapterExchangeParam, SimpleExchangeParam, PoolLiquidity, + DexExchangeParam, Logger, } from '../../types'; import { SwapSide, Network } from '../../constants'; import * as CALLDATA_GAS_COST from '../../calldata-gas-cost'; -import { IDex } from '../../dex/idex'; +import { Context, IDex } from '../../dex/idex'; import { IDexHelper } from '../../dex-helper/idex-helper'; import { CollateralReserves, @@ -21,18 +23,23 @@ import { FluidDexPool, FluidDexPoolState, } from './types'; -import { SimpleExchange } from '../simple-exchange'; +import { + SimpleExchange, + getLocalDeadlineAsFriendlyPlaceholder, +} from '../simple-exchange'; +import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json'; import { FluidDexConfig, Adapters, FLUID_DEX_GAS_COST } from './config'; import { FluidDexEventPool } from './fluid-dex-pool'; import { applyTransferFee } from '../../lib/token-transfer-fee'; import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; +import { extractReturnAmountPosition } from '../../executor/utils'; export class FluidDex extends SimpleExchange implements IDex { readonly eventPools: { [id: string]: FluidDexEventPool } = {}; readonly hasConstantPriceLargeAmounts = false; // TODO: set true here if protocols works only with wrapped asset - readonly needWrapNative = true; + readonly needWrapNative = false; readonly isFeeOnTransferSupported = false; @@ -43,6 +50,8 @@ export class FluidDex extends SimpleExchange implements IDex { readonly pools: [FluidDexPool]; + readonly iFluidDexPool: Interface; + protected adapters; constructor( @@ -54,7 +63,7 @@ export class FluidDex extends SimpleExchange implements IDex { this.logger = dexHelper.getLogger(dexKey); this.pools = FluidDexConfig['FluidDex'][network].pools; this.adapters = Adapters[network] || {}; // TODO: add any additional optional params to support other fork DEXes - + this.iFluidDexPool = new Interface(FluidDexPoolABI); for (const pool of this.pools) { this.eventPools[pool.id] = new FluidDexEventPool( 'FluidDex', @@ -114,6 +123,27 @@ export class FluidDex extends SimpleExchange implements IDex { return null; } + getPoolByTokenPairAddress( + srcToken: Address, + destToken: Address, + ): FluidDexPool | null { + const srcAddress = srcToken.toLowerCase(); + const destAddress = destToken.toLowerCase(); + + // A pair must have 2 different tokens. + if (srcAddress === destAddress) return null; + + for (const pool of this.pools) { + if ( + (srcAddress === pool.token0 && destAddress === pool.token1) || + (srcAddress === pool.token1 && destAddress === pool.token0) + ) { + return pool; + } + } + return null; + } + // Returns pool prices for amounts. // If limitPools is defined only pools in limitPools // should be used. If limitPools is undefined then @@ -492,4 +522,46 @@ export class FluidDex extends SimpleExchange implements IDex { // Using the swap formula: (AmountIn * ReserveOut * scale) / (ReserveIn * scale + AmountIn * scale) return numerator / denominator; } + + getDexParam( + srcToken: Address, + destToken: Address, + srcAmount: string, + destAmount: string, + recipient: Address, + data: FluidDexData, + side: SwapSide, + context: Context, + executorAddress: Address, + ): AsyncOrSync { + let method: string; + let args: any; + let returnAmountPos: number | undefined = undefined; + + const deadline = getLocalDeadlineAsFriendlyPlaceholder(); + if (side === SwapSide.SELL) { + method = 'swapIn'; + returnAmountPos = extractReturnAmountPosition( + this.iFluidDexPool, + method, + 'amountOut_', + 1, + ); + args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; + } else { + method = 'swapOut'; + args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; + } + + const swapData = this.iFluidDexPool.encodeFunctionData(method, args); + + return { + needWrapNative: this.needWrapNative, + dexFuncHasRecipient: true, + exchangeData: swapData, + targetExchange: this.getPoolByTokenPairAddress(srcToken, destToken)! + .address, + returnAmountPos, + }; + } } diff --git a/src/dex/index.ts b/src/dex/index.ts index b2ba4f66f..a2b8dd139 100644 --- a/src/dex/index.ts +++ b/src/dex/index.ts @@ -84,6 +84,7 @@ import { Spark } from './spark/spark'; import { VelodromeSlipstream } from './uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream'; import { AaveV3Stata } from './aave-v3-stata/aave-v3-stata'; import { OSwap } from './oswap/oswap'; +import { FluidDex } from './fluid-dex/fluid-dex'; import { ConcentratorArusd } from './concentrator-arusd/concentrator-arusd'; import { FxProtocolRusd } from './fx-protocol-rusd/fx-protocol-rusd'; import { LitePsm } from './lite-psm/lite-psm'; @@ -169,6 +170,7 @@ const Dexes = [ ConcentratorArusd, FxProtocolRusd, LitePsm, + FluidDex, ]; export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder< diff --git a/src/implementations/local-paraswap-sdk.ts b/src/implementations/local-paraswap-sdk.ts index d8c62508f..4774ea12c 100644 --- a/src/implementations/local-paraswap-sdk.ts +++ b/src/implementations/local-paraswap-sdk.ts @@ -96,6 +96,9 @@ export class LocalParaswapSDK implements IParaSwapSDK { delete this.dexKeys[this.dexKeys.indexOf(dexKey)]; } }); + + // Remove the null entries + this.dexKeys = this.dexKeys.filter(key => key !== null); } async initializePricing() { @@ -128,6 +131,8 @@ export class LocalParaswapSDK implements IParaSwapSDK { this.dexKeys, )); + // console.log("this is pool identifiers" + JSON.stringify(poolIdentifiers, null, 2)); + const amounts = _.range(0, chunks + 1).map( i => (amount * BigInt(i)) / BigInt(chunks), ); diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index 71e4d9b8d..4d347d6b7 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -1510,7 +1510,7 @@ export const Holders: { BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a', STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18', SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a', - wstETH: '0x5fEC2f34D80ED82370F733043B6A536d7e9D7f8d', + wstETH: '0x0B925eD163218f6662a35e0f0371Ac234f9E9371', WETH: '0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44', USDT: '0xAf64555DDD61FcF7D094824dd9B4eBea165aFc5b', XAUT: '0xc4e161e8d8a4bc4ac762ab33a28bbac5474203d7', diff --git a/tests/utils-e2e.ts b/tests/utils-e2e.ts index 7c3770560..644fc238a 100644 --- a/tests/utils-e2e.ts +++ b/tests/utils-e2e.ts @@ -569,6 +569,9 @@ export async function testE2E( ); const swapTx = await ts.simulate(swapParams); + + console.log('json swap tx' + JSON.stringify(swapTx)); + // Only log gas estimate if testing against API if (useAPI) { const gasUsed = swapTx.gasUsed || '0'; From 95d4f022e7cf3729b9fc0b5fe584b8bea32c285f Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Wed, 2 Oct 2024 03:05:27 +0530 Subject: [PATCH 08/64] tests working with a few issues --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 41 ++++++++++---- .../fluid-dex/fluid-dex-integration.test.ts | 52 ++++++++--------- src/dex/fluid-dex/fluid-dex.ts | 56 ++++++++++--------- src/generic-swap-transaction-builder.ts | 2 + src/implementations/local-paraswap-sdk.ts | 3 + tests/constants-e2e.ts | 2 +- tests/utils-e2e.ts | 12 ++++ 7 files changed, 103 insertions(+), 65 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 7d5398be3..5557176ad 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -69,11 +69,7 @@ function testForNetwork( const nativeTokenSymbol = NativeTokenSymbols[network]; // TODO: Add any direct swap contractMethod name if it exists - const sideToContractMethods = new Map([ - [SwapSide.SELL, ['swapIn']], - // TODO: If buy is not supported remove the buy contract methods - // [SwapSide.BUY, [ContractMethod.swapExactAmountOut]], - ]); + const sideToContractMethods = new Map([[SwapSide.SELL, ['swapIn']]]); describe(`${network}`, () => { sideToContractMethods.forEach((contractMethods, side) => @@ -85,27 +81,48 @@ function testForNetwork( // tokens[nativeTokenSymbol], // tokens[tokenASymbol], // holders[nativeTokenSymbol], - // side === SwapSide.SELL ? nativeTokenAmount : tokenAAmount, - // side, + // tokenAAmount, + // SwapSide.BUY, // dexKey, // contractMethod as ContractMethod, // network, // provider, // ); // }); - it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { await testE2E( - tokens[tokenASymbol], tokens[nativeTokenSymbol], - holders[tokenASymbol], - side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, - side, + tokens[tokenASymbol], + holders[nativeTokenSymbol], + tokenBAmount, + SwapSide.SELL, dexKey, contractMethod as ContractMethod, network, provider, ); }); + // it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + // await testE2E( + // tokens[tokenASymbol], + // tokens[nativeTokenSymbol], + // holders[tokenASymbol], + // side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, + // side, + // dexKey, + // contractMethod as ContractMethod, + // network, + // provider, + // null, // poolIdentifiers + // undefined, // limitOrderProvider + // undefined, // transferFees + // undefined, // slippage + // undefined, // sleepMs + // undefined, // replaceTenderlyWithEstimateGas + // undefined, // forceRoute + // // '0x5F4e77A22e394B51dC7Efb8e3C78121e489E78cD',// beneficiary + // ); + // }); // it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { // await testE2E( // tokens[tokenASymbol], diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index e41e64b09..f0be09255 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -185,19 +185,19 @@ describe('FluidDex', function () { 10n * BI_POWS[tokens[srcTokenSymbol].decimals], ]; - // const amountsForBuy = [ - // 0n, - // 1n * BI_POWS[tokens[destTokenSymbol].decimals], - // 2n * BI_POWS[tokens[destTokenSymbol].decimals], - // 3n * BI_POWS[tokens[destTokenSymbol].decimals], - // 4n * BI_POWS[tokens[destTokenSymbol].decimals], - // 5n * BI_POWS[tokens[destTokenSymbol].decimals], - // 6n * BI_POWS[tokens[destTokenSymbol].decimals], - // 7n * BI_POWS[tokens[destTokenSymbol].decimals], - // 8n * BI_POWS[tokens[destTokenSymbol].decimals], - // 9n * BI_POWS[tokens[destTokenSymbol].decimals], - // 10n * BI_POWS[tokens[destTokenSymbol].decimals], - // ]; + const amountsForBuy = [ + 0n, + 1n * BI_POWS[tokens[destTokenSymbol].decimals], + 2n * BI_POWS[tokens[destTokenSymbol].decimals], + 3n * BI_POWS[tokens[destTokenSymbol].decimals], + 4n * BI_POWS[tokens[destTokenSymbol].decimals], + 5n * BI_POWS[tokens[destTokenSymbol].decimals], + 6n * BI_POWS[tokens[destTokenSymbol].decimals], + 7n * BI_POWS[tokens[destTokenSymbol].decimals], + 8n * BI_POWS[tokens[destTokenSymbol].decimals], + 9n * BI_POWS[tokens[destTokenSymbol].decimals], + 10n * BI_POWS[tokens[destTokenSymbol].decimals], + ]; beforeAll(async () => { blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); @@ -221,19 +221,19 @@ describe('FluidDex', function () { ); }); - // it('getPoolIdentifiers and getPricesVolume BUY', async function () { - // await testPricingOnNetwork( - // fluidDex, - // network, - // dexKey, - // blockNumber, - // srcTokenSymbol, - // destTokenSymbol, - // SwapSide.BUY, - // amountsForBuy, - // 'estimateSwapOut', // TODO: Put here proper function name to check pricing - // ); - // }); + it('getPoolIdentifiers and getPricesVolume BUY', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + srcTokenSymbol, + destTokenSymbol, + SwapSide.BUY, + amountsForBuy, + 'estimateSwapOut', // TODO: Put here proper function name to check pricing + ); + }); it('getTopPoolsForToken', async function () { // We have to check without calling initializePricing, because diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 40043fb86..a36d7f800 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -188,19 +188,6 @@ export class FluidDex extends SimpleExchange implements IDex { ), ); - // console.log('state colres is -> '); - // console.log(state.collateralReserves.token0ImaginaryReserves); - // console.log(state.collateralReserves.token0RealReserves); - // console.log(state.collateralReserves.token1ImaginaryReserves); - // console.log(state.collateralReserves.token1RealReserves); - // console.log('state debtres is -> '); - // console.log(state.debtReserves.token0Debt); - // console.log(state.debtReserves.token0ImaginaryReserves); - // console.log(state.debtReserves.token0RealReserves); - // console.log(state.debtReserves.token1Debt); - // console.log(state.debtReserves.token1ImaginaryReserves); - // console.log(state.debtReserves.token1RealReserves); - return [ { prices: prices, // to be done @@ -539,19 +526,36 @@ export class FluidDex extends SimpleExchange implements IDex { let returnAmountPos: number | undefined = undefined; const deadline = getLocalDeadlineAsFriendlyPlaceholder(); - if (side === SwapSide.SELL) { - method = 'swapIn'; - returnAmountPos = extractReturnAmountPosition( - this.iFluidDexPool, - method, - 'amountOut_', - 1, - ); - args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; - } else { - method = 'swapOut'; - args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; - } + + // const poolPrices = await this.pricingHelper.getPoolPrices( + // from, + // to, + // amounts, + // side, + // blockNumber, + // this.dexKeys, + // poolIdentifiers, + // transferFees, + // ); + + // console.log("pool prices : " + poolPrices); + + // const finalPrice = poolPrices[0]; + // const quoteAmount = finalPrice.prices[10]; + + method = 'swapIn'; + returnAmountPos = extractReturnAmountPosition( + this.iFluidDexPool, + method, + 'amountOut_', + 1, + ); + + // if (side == SwapSide.SELL) { + // args = [true, BigInt(srcAmount), BigInt(0), recipient]; + // } else { + args = [false, BigInt(srcAmount), BigInt(0), recipient]; + // } const swapData = this.iFluidDexPool.encodeFunctionData(method, args); diff --git a/src/generic-swap-transaction-builder.ts b/src/generic-swap-transaction-builder.ts index 4e862934e..8ccba8a03 100644 --- a/src/generic-swap-transaction-builder.ts +++ b/src/generic-swap-transaction-builder.ts @@ -33,6 +33,7 @@ import { ExecutorDetector } from './executor/ExecutorDetector'; import { ExecutorBytecodeBuilder } from './executor/ExecutorBytecodeBuilder'; import { IDexTxBuilder } from './dex/idex'; import { ParaSwapVersion, SwapSide } from '@paraswap/core'; +import { clear } from 'console'; const { utils: { hexlify, hexConcat, hexZeroPad }, @@ -253,6 +254,7 @@ export class GenericSwapTransactionBuilder { priceRoute.destToken, isSell ? priceRoute.srcAmount : minMaxAmount, isSell ? minMaxAmount : priceRoute.destAmount, + // minMaxAmount, isSell ? priceRoute.destAmount : priceRoute.srcAmount, hexConcat([ hexZeroPad(uuidToBytes16(uuid), 16), diff --git a/src/implementations/local-paraswap-sdk.ts b/src/implementations/local-paraswap-sdk.ts index 4774ea12c..094754b86 100644 --- a/src/implementations/local-paraswap-sdk.ts +++ b/src/implementations/local-paraswap-sdk.ts @@ -25,6 +25,7 @@ import { GenericSwapTransactionBuilder } from '../generic-swap-transaction-build import { AddressOrSymbol } from '@paraswap/sdk'; import { ParaSwapVersion } from '@paraswap/core'; import { TransactionBuilder } from '../transaction-builder'; +import { QuickPerps } from '../dex/quick-perps/quick-perps'; export interface IParaSwapSDK { getPrices( @@ -152,6 +153,7 @@ export class LocalParaswapSDK implements IParaSwapSDK { const finalPrice = poolPrices[0]; const quoteAmount = finalPrice.prices[chunks]; + const srcAmount = ( side === SwapSide.SELL ? amount : quoteAmount ).toString(); @@ -326,6 +328,7 @@ export class LocalParaswapSDK implements IParaSwapSDK { partnerFeePercent: '0', deadline: deadline.toString(), uuid: uuid(), + beneficiary: '0x5F4e77A22e394B51dC7Efb8e3C78121e489E78cD', // @(to be changed) }); } } diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index 4d347d6b7..a7b5296ef 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -1510,7 +1510,7 @@ export const Holders: { BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a', STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18', SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a', - wstETH: '0x0B925eD163218f6662a35e0f0371Ac234f9E9371', + wstETH: '0xC329400492c6ff2438472D4651Ad17389fCb843a', WETH: '0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44', USDT: '0xAf64555DDD61FcF7D094824dd9B4eBea165aFc5b', XAUT: '0xc4e161e8d8a4bc4ac762ab33a28bbac5474203d7', diff --git a/tests/utils-e2e.ts b/tests/utils-e2e.ts index 644fc238a..bded1c0e9 100644 --- a/tests/utils-e2e.ts +++ b/tests/utils-e2e.ts @@ -59,6 +59,7 @@ import * as util from 'util'; import { GenericSwapTransactionBuilder } from '../src/generic-swap-transaction-builder'; import { DexAdapterService, PricingHelper } from '../src'; import { v4 as uuid } from 'uuid'; +import { minBy } from 'lodash'; export const testingEndpoint = process.env.E2E_TEST_ENDPOINT; @@ -388,6 +389,7 @@ export async function testE2E( sleepMs?: number, replaceTenderlyWithEstimateGas?: boolean, forceRoute?: AddressOrSymbol[], + beneficiary: Address = NULL_ADDRESS, ) { const amount = BigInt(_amount); @@ -499,6 +501,8 @@ export async function testE2E( forceRoute, ); + console.log('price route : ' + priceRoute); + console.log('PRICE ROUTE: ', util.inspect(priceRoute, false, null, true)); expect(parseFloat(priceRoute.destAmount)).toBeGreaterThan(0); @@ -562,12 +566,20 @@ export async function testE2E( (swapSide === SwapSide.SELL ? BigInt(priceRoute.destAmount) * (10000n - BigInt(_slippage)) : BigInt(priceRoute.srcAmount) * (10000n + BigInt(_slippage))) / 10000n; + + console.log('slippage : ' + _slippage); + + console.log('original amount : ' + amount); + console.log('minmaxamount : ' + minMaxAmount); + const swapParams = await paraswap.buildTransaction( priceRoute, minMaxAmount, senderAddress, ); + console.log('these are the swap params : ' + JSON.stringify(swapParams)); + const swapTx = await ts.simulate(swapParams); console.log('json swap tx' + JSON.stringify(swapTx)); From 00542755357c85d2e5dbc4a1ca3453317f96a0aa Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Wed, 2 Oct 2024 14:11:48 +0530 Subject: [PATCH 09/64] e2e tests working --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 67 ++++++++----------------- src/dex/fluid-dex/fluid-dex.ts | 26 ++++++++-- tests/constants-e2e.ts | 2 +- 3 files changed, 42 insertions(+), 53 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 5557176ad..ad5b2b452 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -76,19 +76,6 @@ function testForNetwork( describe(`${side}`, () => { contractMethods.forEach((contractMethod: string) => { describe(`${contractMethod}`, () => { - // it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { - // await testE2E( - // tokens[nativeTokenSymbol], - // tokens[tokenASymbol], - // holders[nativeTokenSymbol], - // tokenAAmount, - // SwapSide.BUY, - // dexKey, - // contractMethod as ContractMethod, - // network, - // provider, - // ); - // }); it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { await testE2E( tokens[nativeTokenSymbol], @@ -102,40 +89,26 @@ function testForNetwork( provider, ); }); - // it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { - // await testE2E( - // tokens[tokenASymbol], - // tokens[nativeTokenSymbol], - // holders[tokenASymbol], - // side === SwapSide.SELL ? tokenAAmount : nativeTokenAmount, - // side, - // dexKey, - // contractMethod as ContractMethod, - // network, - // provider, - // null, // poolIdentifiers - // undefined, // limitOrderProvider - // undefined, // transferFees - // undefined, // slippage - // undefined, // sleepMs - // undefined, // replaceTenderlyWithEstimateGas - // undefined, // forceRoute - // // '0x5F4e77A22e394B51dC7Efb8e3C78121e489E78cD',// beneficiary - // ); - // }); - // it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { - // await testE2E( - // tokens[tokenASymbol], - // tokens[tokenBSymbol], - // holders[tokenASymbol], - // side === SwapSide.SELL ? tokenAAmount : tokenBAmount, - // side, - // dexKey, - // contractMethod as ContractMethod, - // network, - // provider, - // ); - // }); + it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[nativeTokenSymbol], + holders[tokenASymbol], + tokenAAmount, + SwapSide.SELL, + dexKey, + contractMethod as ContractMethod, + network, + provider, + null, // poolIdentifiers + undefined, // limitOrderProvider + undefined, // transferFees + undefined, // slippage + undefined, // sleepMs + undefined, // replaceTenderlyWithEstimateGas + undefined, // forceRoute + ); + }); }); }); }), diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index a36d7f800..eb4fa9dc0 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -551,11 +551,27 @@ export class FluidDex extends SimpleExchange implements IDex { 1, ); - // if (side == SwapSide.SELL) { - // args = [true, BigInt(srcAmount), BigInt(0), recipient]; - // } else { - args = [false, BigInt(srcAmount), BigInt(0), recipient]; - // } + const pool = this.getPoolByTokenPairAddress(srcToken, destToken); + + if (srcToken == '0xEeeeeEeeeeeeEeeeeeeEeeeeEeeeeeEeeeeEeeeE') { + throw new Error( + 'srcToken can not be Native ETH, try exchanging tokens and swapSide', + ); + } + + if (side == SwapSide.SELL) { + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [false, BigInt(srcAmount), BigInt(0), recipient]; + } else { + args = [true, BigInt(srcAmount), BigInt(0), recipient]; + } + } else { + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [true, BigInt(srcAmount), BigInt(0), recipient]; + } else { + args = [false, BigInt(srcAmount), BigInt(0), recipient]; + } + } const swapData = this.iFluidDexPool.encodeFunctionData(method, args); diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index a7b5296ef..9cd9a599f 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -1755,7 +1755,7 @@ export const Holders: { LINK: '0x7f1fa204bb700853d36994da19f830b6ad18455c', DMT: '0x40414f138eb2ef938e6c3629897ef99d4464d4e8', PENDLE: '0x5bdf85216ec1e38d6458c870992a69e38e03f7ef', - wstETH: '0x27edc7700f1820cb38ec3bbb84c542945f21b5a1', + wstETH: '0x3c22ec75ea5D745c78fc84762F7F1E6D82a2c5BF', EURA: '0x6dd7b830896b56812aa667bdd14b71c8b3252f8e', stEUR: '0xE588611e7A2392507879E3be80531654b85C16aA', USDA: '0xa86ff337db9107b54862d30d1a598f8be847b05e', From e3b2c14a370ae05bddd3acdd911d3b00b236ce63 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 3 Oct 2024 22:50:34 +0530 Subject: [PATCH 10/64] updated the swapIn function to include decimals and fee --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 26 +- .../fluid-dex/fluid-dex-integration.test.ts | 26 +- src/dex/fluid-dex/fluid-dex-pool.ts | 20 +- src/dex/fluid-dex/fluid-dex.ts | 501 ++++++++++++------ src/dex/fluid-dex/types.ts | 20 +- 5 files changed, 380 insertions(+), 213 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index ad5b2b452..ac234c195 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -76,19 +76,19 @@ function testForNetwork( describe(`${side}`, () => { contractMethods.forEach((contractMethod: string) => { describe(`${contractMethod}`, () => { - it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { - await testE2E( - tokens[nativeTokenSymbol], - tokens[tokenASymbol], - holders[nativeTokenSymbol], - tokenBAmount, - SwapSide.SELL, - dexKey, - contractMethod as ContractMethod, - network, - provider, - ); - }); + // it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { + // await testE2E( + // tokens[nativeTokenSymbol], + // tokens[tokenASymbol], + // holders[nativeTokenSymbol], + // tokenBAmount, + // SwapSide.SELL, + // dexKey, + // contractMethod as ContractMethod, + // network, + // provider, + // ); + // }); it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { await testE2E( tokens[tokenASymbol], diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index f0be09255..9383b276c 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -221,19 +221,19 @@ describe('FluidDex', function () { ); }); - it('getPoolIdentifiers and getPricesVolume BUY', async function () { - await testPricingOnNetwork( - fluidDex, - network, - dexKey, - blockNumber, - srcTokenSymbol, - destTokenSymbol, - SwapSide.BUY, - amountsForBuy, - 'estimateSwapOut', // TODO: Put here proper function name to check pricing - ); - }); + // it('getPoolIdentifiers and getPricesVolume BUY', async function () { + // await testPricingOnNetwork( + // fluidDex, + // network, + // dexKey, + // blockNumber, + // srcTokenSymbol, + // destTokenSymbol, + // SwapSide.BUY, + // amountsForBuy, + // 'estimateSwapOut', // TODO: Put here proper function name to check pricing + // ); + // }); it('getTopPoolsForToken', async function () { // We have to check without calling initializePricing, because diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index cf9518186..e4762437f 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -111,32 +111,32 @@ export class FluidDexEventPool extends StatefulEventSubscriber { protected adapters; + FEE_100_PERCENT = 1000000n; + constructor( readonly network: Network, readonly dexKey: string, @@ -174,7 +176,6 @@ export class FluidDex extends SimpleExchange implements IDex { // const state = await eventPool.generateState(blockNumber); const state = await eventPool.getStateOrGenerate(blockNumber); - // console.log('fluidDex - getPricesVolume : ' + state); const swap0To1: boolean = side === SwapSide.SELL; @@ -185,9 +186,15 @@ export class FluidDex extends SimpleExchange implements IDex { amount, state.collateralReserves, state.debtReserves, + srcToken.decimals, + destToken.decimals, + 0n, ), ); + // console.log('these are the prices : ' + prices); + // console.log('hehe' + swap0To1); + return [ { prices: prices, // to be done @@ -264,7 +271,7 @@ export class FluidDex extends SimpleExchange implements IDex { limit: number, ): Promise { //TODO: complete me! - let liquidityAmounts: { [id: string]: number } = {}; + let liquidityAmounts: { [id: string]: bigint } = {}; for (const pool of this.pools) { if ( pool.token0 === tokenAddress.toLowerCase() || @@ -286,14 +293,14 @@ export class FluidDex extends SimpleExchange implements IDex { } } - // console.log( - // 'Number of pools with liquidity: ' + Object.keys(liquidityAmounts).length, - // ); - const entries = Object.entries(liquidityAmounts); // Sort the entries based on the values in descending order - entries.sort((a, b) => b[1] - a[1]); + entries.sort((a, b) => { + if (b[1] > a[1]) return 1; + if (b[1] < a[1]) return -1; + return 0; + }); // Take the top k entries const topKEntries = entries.slice(0, limit); @@ -311,7 +318,7 @@ export class FluidDex extends SimpleExchange implements IDex { exchange: 'FluidDex', address: pool.address, connectorTokens: [], - liquidityUSD: amount, + liquidityUSD: Number(amount), // converted to number }); } return poolLiquidities; @@ -323,30 +330,117 @@ export class FluidDex extends SimpleExchange implements IDex { // TODO: complete me! } + getDexParam( + srcToken: Address, + destToken: Address, + srcAmount: string, + destAmount: string, + recipient: Address, + data: FluidDexData, + side: SwapSide, + context: Context, + executorAddress: Address, + ): AsyncOrSync { + let method: string; + let args: any; + let returnAmountPos: number | undefined = undefined; + + const deadline = getLocalDeadlineAsFriendlyPlaceholder(); + + method = 'swapIn'; + returnAmountPos = extractReturnAmountPosition( + this.iFluidDexPool, + method, + 'amountOut_', + 1, + ); + + const pool = this.getPoolByTokenPairAddress(srcToken, destToken); + + if (srcToken == '0xEeeeeEeeeeeeEeeeeeeEeeeeEeeeeeEeeeeEeeeE') { + throw new Error( + 'srcToken can not be Native ETH, try exchanging tokens and swapSide', + ); + } + + if (side == SwapSide.SELL) { + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [false, BigInt(srcAmount), BigInt(0), recipient]; + } else { + args = [true, BigInt(srcAmount), BigInt(0), recipient]; + } + } else { + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [true, BigInt(srcAmount), BigInt(0), recipient]; + } else { + args = [false, BigInt(srcAmount), BigInt(0), recipient]; + } + } + + const swapData = this.iFluidDexPool.encodeFunctionData(method, args); + + return { + needWrapNative: this.needWrapNative, + dexFuncHasRecipient: true, + exchangeData: swapData, + targetExchange: this.getPoolByTokenPairAddress(srcToken, destToken)! + .address, + returnAmountPos, + }; + } + /** * Calculates the output amount for a given input amount in a swap operation. - * @param {boolean} swap0To1 - Direction of the swap. True if swapping token0 for token1, false otherwise. - * @param {number} amountToSwap - The amount of input token to be swapped. - * @param {Object} colReserves - The reserves of the collateral pool. - * @param {number} colReserves.token0RealReserves - Real reserves of token0 in the collateral pool. - * @param {number} colReserves.token1RealReserves - Real reserves of token1 in the collateral pool. - * @param {number} colReserves.token0ImaginaryReserves - Imaginary reserves of token0 in the collateral pool. - * @param {number} colReserves.token1ImaginaryReserves - Imaginary reserves of token1 in the collateral pool. - * @param {Object} debtReserves - The reserves of the debt pool. - * @param {number} debtReserves.token0RealReserves - Real reserves of token0 in the debt pool. - * @param {number} debtReserves.token1RealReserves - Real reserves of token1 in the debt pool. - * @param {number} debtReserves.token0ImaginaryReserves - Imaginary reserves of token0 in the debt pool. - * @param {number} debtReserves.token1ImaginaryReserves - Imaginary reserves of token1 in the debt pool. - * @returns {Object} An object containing the input amount and the calculated output amount. - * @returns {number} amountIn - The input amount. - * @returns {number} amountOut - The calculated output amount. + * @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, + ): bigint { + if (amountIn === 0n) { + return 0n; // Return 0 if input amount is 0 + } + // console.log('amountIn : ' + amountIn); + const amountInAdjusted = + (((amountIn * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT) * + BigInt(10 ** 12)) / + BigInt(inDecimals); + // console.log('amountInAdjusted : ' + amountInAdjusted); + const amountOut = this.swapInAdjusted( + swap0To1, + amountInAdjusted, // Convert back to number for internal calculations + colReserves, + debtReserves, + ); + // console.log('amountOut : ' + amountOut); + return amountOut * BigInt(10 ** (outDecimals - 12)); + } + + /** + * 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. + */ + private swapInAdjusted( swap0To1: boolean, amountToSwap: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, - ) { + ): bigint { const { token0RealReserves, token1RealReserves, @@ -361,31 +455,35 @@ export class FluidDex extends SimpleExchange implements IDex { token1ImaginaryReserves: debtToken1ImaginaryReserves, } = debtReserves; - // Convert all reserves to BigInt + // Check if all reserves of collateral pool are greater than 0 const colPoolEnabled = - BigInt(token0RealReserves) > 0n && - BigInt(token1RealReserves) > 0n && - BigInt(token0ImaginaryReserves) > 0n && - BigInt(token1ImaginaryReserves) > 0n; + token0RealReserves > BigInt(0) && + token1RealReserves > BigInt(0) && + token0ImaginaryReserves > BigInt(0) && + token1ImaginaryReserves > BigInt(0); + // Check if all reserves of debt pool are greater than 0 const debtPoolEnabled = - BigInt(debtToken0RealReserves) > 0n && - BigInt(debtToken1RealReserves) > 0n && - BigInt(debtToken0ImaginaryReserves) > 0n && - BigInt(debtToken1ImaginaryReserves) > 0n; + debtToken0RealReserves > BigInt(0) && + debtToken1RealReserves > BigInt(0) && + debtToken0ImaginaryReserves > BigInt(0) && + debtToken1ImaginaryReserves > BigInt(0); - let colIReserveIn, colIReserveOut, debtIReserveIn, debtIReserveOut; + let colIReserveIn: bigint, + colIReserveOut: bigint, + debtIReserveIn: bigint, + debtIReserveOut: bigint; if (swap0To1) { - colIReserveIn = BigInt(token0ImaginaryReserves); - colIReserveOut = BigInt(token1ImaginaryReserves); - debtIReserveIn = BigInt(debtToken0ImaginaryReserves); - debtIReserveOut = BigInt(debtToken1ImaginaryReserves); + colIReserveIn = token0ImaginaryReserves; + colIReserveOut = token1ImaginaryReserves; + debtIReserveIn = debtToken0ImaginaryReserves; + debtIReserveOut = debtToken1ImaginaryReserves; } else { - colIReserveIn = BigInt(token1ImaginaryReserves); - colIReserveOut = BigInt(token0ImaginaryReserves); - debtIReserveIn = BigInt(debtToken1ImaginaryReserves); - debtIReserveOut = BigInt(debtToken0ImaginaryReserves); + colIReserveIn = token1ImaginaryReserves; + colIReserveOut = token0ImaginaryReserves; + debtIReserveIn = debtToken1ImaginaryReserves; + debtIReserveOut = debtToken0ImaginaryReserves; } let a: bigint; @@ -398,17 +496,17 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveIn, ); } else if (debtPoolEnabled) { - a = -1n; // Route from debt pool + a = BigInt(-1); // Route from debt pool } else if (colPoolEnabled) { - a = amountToSwap + 1n; // Route from collateral pool + a = amountToSwap + BigInt(1); // Route from collateral pool } else { throw new Error('No pools are enabled'); } - let amountOutCollateral: bigint = 0n; - let amountOutDebt: bigint = 0n; + let amountOutCollateral = BigInt(0); + let amountOutDebt = BigInt(0); - if (a <= 0n) { + if (a <= BigInt(0)) { // Entire trade routes through debt pool amountOutDebt = this.getAmountOut( amountToSwap, @@ -438,150 +536,219 @@ export class FluidDex extends SimpleExchange implements IDex { } /** - * Calculates how much of a swap should go through the collateral pool. - * @param {number} t - Total amount in. - * @param {number} x - Imaginary reserves of token out of collateral. - * @param {number} y - Imaginary reserves of token in of collateral. - * @param {number} x2 - Imaginary reserves of token out of debt. - * @param {number} y2 - Imaginary reserves of token in of debt. - * @returns {number} a - 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. + * 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. */ - swapRoutingIn( - t: bigint, - x: bigint, - y: bigint, - x2: bigint, - y2: bigint, + private getAmountOut( + amountIn: bigint, + iReserveIn: bigint, + iReserveOut: bigint, ): bigint { - const precision = BigInt(1e18); + // Both numerator and denominator are scaled to 1e6 to factor in fee scaling. + const numerator = amountIn * iReserveOut; + const denominator = iReserveIn + amountIn; - // Helper function for integer square root - const sqrtBigInt = (value: bigint): bigint => { - if (value < 0n) { - throw new Error('Square root of negative number is not allowed'); - } - if (value < 2n) { - return value; - } + // Using the swap formula: (AmountIn * iReserveY) / (iReserveX + AmountIn) + // We use division with rounding down, which is the default for bigint division + return numerator / denominator; + } - let x = value; - let y = (x + 1n) / 2n; - while (y < x) { - x = y; - y = (x + value / x) / 2n; - } - return x; - }; + /** + * Calculates the input amount for a given output amount in a swap operation. + * @param swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise. + * @param amountOut - The amount of output token to be swapped. + * @param colReserves - The reserves of the collateral pool. + * @param debtReserves - The reserves of the debt pool. + * @returns The calculated input amount required for the swap. + */ + swapOutAdjusted( + swap0to1: boolean, + amountOut: bigint, + colReserves: CollateralReserves, + debtReserves: DebtReserves, + ): bigint { + const { + token0RealReserves, + token1RealReserves, + token0ImaginaryReserves, + token1ImaginaryReserves, + } = colReserves; - const xyRoot = sqrtBigInt((x * y * precision) / precision); - const x2y2Root = sqrtBigInt((x2 * y2 * precision) / precision); + const { + token0RealReserves: debtToken0RealReserves, + token1RealReserves: debtToken1RealReserves, + token0ImaginaryReserves: debtToken0ImaginaryReserves, + token1ImaginaryReserves: debtToken1ImaginaryReserves, + } = debtReserves; - // Calculating 'a' using the given formula - const numerator = y2 * xyRoot + t * xyRoot - y * x2y2Root; - const denominator = xyRoot + x2y2Root; + // Check if all reserves of collateral pool are greater than 0 + const colPoolEnabled = + token0RealReserves > 0 && + token1RealReserves > 0 && + token0ImaginaryReserves > 0 && + token1ImaginaryReserves > 0; - // Perform the division and maintain precision - const a = (numerator * precision) / denominator / precision; + // Check if all reserves of debt pool are greater than 0 + const debtPoolEnabled = + debtToken0RealReserves > 0 && + debtToken1RealReserves > 0 && + debtToken0ImaginaryReserves > 0 && + debtToken1ImaginaryReserves > 0; + + let colIReserveIn: bigint, + colIReserveOut: bigint, + debtIReserveIn: bigint, + debtIReserveOut: bigint; + + if (swap0to1) { + colIReserveIn = token0ImaginaryReserves; + colIReserveOut = token1ImaginaryReserves; + debtIReserveIn = debtToken0ImaginaryReserves; + debtIReserveOut = debtToken1ImaginaryReserves; + } else { + colIReserveIn = token1ImaginaryReserves; + colIReserveOut = token0ImaginaryReserves; + debtIReserveIn = debtToken1ImaginaryReserves; + debtIReserveOut = debtToken0ImaginaryReserves; + } - return a; + let a: bigint; + if (colPoolEnabled && debtPoolEnabled) { + a = this.swapRoutingOut( + amountOut, + colIReserveIn, + colIReserveOut, + debtIReserveIn, + debtIReserveOut, + ); + } else if (debtPoolEnabled) { + a = BigInt(-1); // Route from debt pool + } else if (colPoolEnabled) { + a = amountOut + BigInt(1); // Route from collateral pool + } else { + throw new Error('No pools are enabled'); + } + + let amountInCollateral = BigInt(0); + let amountInDebt = BigInt(0); + + if (a <= 0) { + // Entire trade routes through debt pool + amountInDebt = this.getAmountIn( + amountOut, + debtIReserveIn, + debtIReserveOut, + ); + } else if (a >= amountOut) { + // Entire trade routes through collateral pool + amountInCollateral = this.getAmountIn( + amountOut, + colIReserveIn, + colIReserveOut, + ); + } else { + // Trade routes through both pools + amountInCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut); + amountInDebt = this.getAmountIn( + amountOut - a, + debtIReserveIn, + debtIReserveOut, + ); + } + + const totalAmountIn = amountInCollateral + amountInDebt; + + return totalAmountIn; } /** - * Given an input amount of asset and pair reserves, returns the maximum output amount of the other asset. - * @param {number} amountIn - The amount of input asset. - * @param {number} iReserveIn - Imaginary token reserve with input amount. - * @param {number} iReserveOut - Imaginary token reserve of output amount. - * @returns {number} - The maximum output amount of the other asset. + * 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. */ - getAmountOut( - amountIn: bigint, - reserveIn: bigint, - reserveOut: bigint, + private getAmountIn( + amountOut: bigint, + iReserveIn: bigint, + iReserveOut: bigint, ): bigint { // Both numerator and denominator are scaled to 1e6 to factor in fee scaling. - const scale = BigInt(1_000_000); - const numerator = amountIn * reserveOut * scale; - const denominator = reserveIn * scale + amountIn * scale; + const numerator = amountOut * iReserveIn; + const denominator = iReserveOut - amountOut; - // Using the swap formula: (AmountIn * ReserveOut * scale) / (ReserveIn * scale + AmountIn * scale) + // Using the swap formula: (AmountOut * iReserveX) / (iReserveY - AmountOut) return numerator / denominator; } - getDexParam( - srcToken: Address, - destToken: Address, - srcAmount: string, - destAmount: string, - recipient: Address, - data: FluidDexData, - side: SwapSide, - context: Context, - executorAddress: Address, - ): AsyncOrSync { - let method: string; - let args: any; - let returnAmountPos: number | undefined = undefined; - - const deadline = getLocalDeadlineAsFriendlyPlaceholder(); + /** + * 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. + */ + private swapRoutingOut( + t: bigint, + x: bigint, + y: bigint, + x2: bigint, + y2: bigint, + ): bigint { + // Adding 1e18 precision + const xyRoot = BigInt( + Math.floor(Math.sqrt(Number(x * y * BigInt(10n ** 18n)))), + ); + const x2y2Root = BigInt( + Math.floor(Math.sqrt(Number(x2 * y2 * BigInt(10n ** 18n)))), + ); - // const poolPrices = await this.pricingHelper.getPoolPrices( - // from, - // to, - // amounts, - // side, - // blockNumber, - // this.dexKeys, - // poolIdentifiers, - // transferFees, - // ); + // 1e18 precision gets cancelled out in division + const numerator = t * xyRoot + y * x2y2Root - y2 * xyRoot; + const denominator = xyRoot + x2y2Root; - // console.log("pool prices : " + poolPrices); + // Use integer division (rounds down) + const a = numerator / denominator; - // const finalPrice = poolPrices[0]; - // const quoteAmount = finalPrice.prices[10]; + return a; + } - method = 'swapIn'; - returnAmountPos = extractReturnAmountPosition( - this.iFluidDexPool, - method, - 'amountOut_', - 1, + /** + * 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 { + // Adding 1e18 precision + const xyRoot = BigInt(Math.floor(Math.sqrt(Number(x * y * BigInt(1e18))))); + const x2y2Root = BigInt( + Math.floor(Math.sqrt(Number(x2 * y2 * BigInt(1e18)))), ); - const pool = this.getPoolByTokenPairAddress(srcToken, destToken); - - if (srcToken == '0xEeeeeEeeeeeeEeeeeeeEeeeeEeeeeeEeeeeEeeeE') { - throw new Error( - 'srcToken can not be Native ETH, try exchanging tokens and swapSide', - ); - } - - if (side == SwapSide.SELL) { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [false, BigInt(srcAmount), BigInt(0), recipient]; - } else { - args = [true, BigInt(srcAmount), BigInt(0), recipient]; - } - } else { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [true, BigInt(srcAmount), BigInt(0), recipient]; - } else { - args = [false, BigInt(srcAmount), BigInt(0), recipient]; - } - } - - const swapData = this.iFluidDexPool.encodeFunctionData(method, args); + // Calculating 'a' using the given formula + const a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root); - return { - needWrapNative: this.needWrapNative, - dexFuncHasRecipient: true, - exchangeData: swapData, - targetExchange: this.getPoolByTokenPairAddress(srcToken, destToken)! - .address, - returnAmountPos, - }; + return a; } } diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 297c082a3..45339bf08 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -10,19 +10,19 @@ export type FluidDexPoolState = { }; export type CollateralReserves = { - token0RealReserves: number; // Changed from uint to number - token1RealReserves: number; // Changed from uint to number - token0ImaginaryReserves: number; // Changed from uint to number - token1ImaginaryReserves: number; // Changed from uint to number + token0RealReserves: bigint; // Changed from uint to bigint + token1RealReserves: bigint; // Changed from uint to bigint + token0ImaginaryReserves: bigint; // Changed from uint to bigint + token1ImaginaryReserves: bigint; // Changed from uint to bigint }; export type DebtReserves = { - token0Debt: number; // Changed from uint to number - token1Debt: number; // Changed from uint to number - token0RealReserves: number; // Changed from uint to number - token1RealReserves: number; // Changed from uint to number - token0ImaginaryReserves: number; // Changed from uint to number - token1ImaginaryReserves: number; // Changed from uint to number + token0Debt: bigint; // Changed from uint to bigint + token1Debt: bigint; // Changed from uint to bigint + token0RealReserves: bigint; // Changed from uint to bigint + token1RealReserves: bigint; // Changed from uint to bigint + token0ImaginaryReserves: bigint; // Changed from uint to bigint + token1ImaginaryReserves: bigint; // Changed from uint to bigint }; export interface PoolWithReserves { From 39131e0557fb8b2ffa597244ec53dd322504572e Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Fri, 4 Oct 2024 03:55:32 +0530 Subject: [PATCH 11/64] made changes --- src/dex/fluid-dex/fluid-dex.ts | 54 +++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index aa88c67d0..05d5370db 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -54,7 +54,7 @@ export class FluidDex extends SimpleExchange implements IDex { protected adapters; - FEE_100_PERCENT = 1000000n; + FEE_100_PERCENT = BigInt(1000000); constructor( readonly network: Network, @@ -181,6 +181,7 @@ export class FluidDex extends SimpleExchange implements IDex { const prices = amounts.map(amount => // this.calcPrice(pool, state, srcToken, amount, side), + this.swapIn( swap0To1, amount, @@ -192,9 +193,6 @@ export class FluidDex extends SimpleExchange implements IDex { ), ); - // console.log('these are the prices : ' + prices); - // console.log('hehe' + swap0To1); - return [ { prices: prices, // to be done @@ -408,23 +406,25 @@ export class FluidDex extends SimpleExchange implements IDex { outDecimals: number, fee: bigint, ): bigint { + // console.log('swapIn Param : ' + amountIn); + if (amountIn === 0n) { return 0n; // Return 0 if input amount is 0 } - // console.log('amountIn : ' + amountIn); const amountInAdjusted = (((amountIn * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT) * BigInt(10 ** 12)) / - BigInt(inDecimals); - // console.log('amountInAdjusted : ' + amountInAdjusted); + BigInt(10 ** inDecimals); + const amountOut = this.swapInAdjusted( swap0To1, amountInAdjusted, // Convert back to number for internal calculations colReserves, debtReserves, ); - // console.log('amountOut : ' + amountOut); - return amountOut * BigInt(10 ** (outDecimals - 12)); + const result = (amountOut * BigInt(10 ** outDecimals)) / BigInt(10 ** 12); + // console.log('this is result : ' + result); + return result; } /** @@ -529,7 +529,7 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveOut, ); } - + // console.log('this is a : ' + a); const totalAmountOut = amountOutCollateral + amountOutDebt; return totalAmountOut; @@ -553,6 +553,7 @@ export class FluidDex extends SimpleExchange implements IDex { // Using the swap formula: (AmountIn * iReserveY) / (iReserveX + AmountIn) // We use division with rounding down, which is the default for bigint division + return numerator / denominator; } @@ -632,34 +633,34 @@ export class FluidDex extends SimpleExchange implements IDex { throw new Error('No pools are enabled'); } - let amountInCollateral = BigInt(0); - let amountInDebt = BigInt(0); + let amountOutCollateral = BigInt(0); + let amountOutDebt = BigInt(0); if (a <= 0) { // Entire trade routes through debt pool - amountInDebt = this.getAmountIn( + amountOutDebt = this.getAmountIn( amountOut, debtIReserveIn, debtIReserveOut, ); } else if (a >= amountOut) { // Entire trade routes through collateral pool - amountInCollateral = this.getAmountIn( + amountOutCollateral = this.getAmountIn( amountOut, colIReserveIn, colIReserveOut, ); } else { // Trade routes through both pools - amountInCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut); - amountInDebt = this.getAmountIn( + amountOutCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut); + amountOutDebt = this.getAmountIn( amountOut - a, debtIReserveIn, debtIReserveOut, ); } - const totalAmountIn = amountInCollateral + amountInDebt; + const totalAmountIn = amountOutCollateral + amountOutDebt; return totalAmountIn; } @@ -741,14 +742,27 @@ export class FluidDex extends SimpleExchange implements IDex { y2: bigint, ): bigint { // Adding 1e18 precision + + // console.log('params of sri : ', t, x, y, x2, y2, 'prince'); + const xyRoot = BigInt(Math.floor(Math.sqrt(Number(x * y * BigInt(1e18))))); const x2y2Root = BigInt( Math.floor(Math.sqrt(Number(x2 * y2 * BigInt(1e18)))), ); // Calculating 'a' using the given formula - const a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root); - - return a; + const a = + (Number(y2) * Number(xyRoot) + + Number(t) * Number(xyRoot) - + Number(y) * Number(x2y2Root)) / + (Number(xyRoot) + Number(x2y2Root)); + + // console.log( + // 'before values : ' + (y2 * xyRoot + t * xyRoot - y * x2y2Root), + // xyRoot + x2y2Root, + // ); + + // console.log('sri values : ', xyRoot, x2y2Root, a); + return BigInt(Math.floor(a)); } } From 00d1ffecc842eec09bc40e3d821996ba7db1f524 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Fri, 4 Oct 2024 13:36:58 +0530 Subject: [PATCH 12/64] simulation prices are matching the onchain prices --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 41 ++++++++----------- .../fluid-dex/fluid-dex-integration.test.ts | 28 ++++++------- src/dex/fluid-dex/fluid-dex-pool.ts | 9 ++-- src/dex/fluid-dex/fluid-dex.ts | 15 +++---- src/dex/fluid-dex/types.ts | 2 + tests/utils-e2e.ts | 2 - 6 files changed, 46 insertions(+), 51 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index ac234c195..9acceb538 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -76,39 +76,32 @@ function testForNetwork( describe(`${side}`, () => { contractMethods.forEach((contractMethod: string) => { describe(`${contractMethod}`, () => { - // it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { - // await testE2E( - // tokens[nativeTokenSymbol], - // tokens[tokenASymbol], - // holders[nativeTokenSymbol], - // tokenBAmount, - // SwapSide.SELL, - // dexKey, - // contractMethod as ContractMethod, - // network, - // provider, - // ); - // }); - it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { await testE2E( - tokens[tokenASymbol], tokens[nativeTokenSymbol], - holders[tokenASymbol], - tokenAAmount, + tokens[tokenASymbol], + holders[nativeTokenSymbol], + tokenBAmount, SwapSide.SELL, dexKey, contractMethod as ContractMethod, network, provider, - null, // poolIdentifiers - undefined, // limitOrderProvider - undefined, // transferFees - undefined, // slippage - undefined, // sleepMs - undefined, // replaceTenderlyWithEstimateGas - undefined, // forceRoute ); }); + // it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + // await testE2E( + // tokens[tokenASymbol], + // tokens[nativeTokenSymbol], + // holders[tokenASymbol], + // tokenAAmount, + // SwapSide.SELL, + // dexKey, + // contractMethod as ContractMethod, + // network, + // provider, + // ); + // }); }); }); }), diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 9383b276c..70d05a751 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -45,7 +45,7 @@ function getReaderCalldata( '0x6d83f60eeac0e50a1250760151e81db2a278e03a', funcName == 'estimateSwapIn' ? true : false, amount, - funcName == 'estimateSwapIn' ? 0 : 10 ** 30, + funcName == 'estimateSwapIn' ? 0 : 2n * amount, ]), })); } @@ -221,19 +221,19 @@ describe('FluidDex', function () { ); }); - // it('getPoolIdentifiers and getPricesVolume BUY', async function () { - // await testPricingOnNetwork( - // fluidDex, - // network, - // dexKey, - // blockNumber, - // srcTokenSymbol, - // destTokenSymbol, - // SwapSide.BUY, - // amountsForBuy, - // 'estimateSwapOut', // TODO: Put here proper function name to check pricing - // ); - // }); + it('getPoolIdentifiers and getPricesVolume BUY', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + srcTokenSymbol, + destTokenSymbol, + SwapSide.BUY, + amountsForBuy, + 'estimateSwapOut', // TODO: Put here proper function name to check pricing + ); + }); it('getTopPoolsForToken', async function () { // We have to check without calling initializePricing, because diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index e4762437f..10979d62b 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -73,7 +73,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber[] = [ { target: this.pool.resolver, - callData: ResolverAbi.encodeFunctionData('getCollateralReserves', [ + callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), decodeFunction: await this.decodePoolWithReserves, @@ -90,6 +90,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber { state.debtReserves, srcToken.decimals, destToken.decimals, - 0n, + BigInt(state.fee), ), ); @@ -742,8 +742,7 @@ export class FluidDex extends SimpleExchange implements IDex { y2: bigint, ): bigint { // Adding 1e18 precision - - // console.log('params of sri : ', t, x, y, x2, y2, 'prince'); + // console.log('params of sri : ', t, x, y, x2, y2); const xyRoot = BigInt(Math.floor(Math.sqrt(Number(x * y * BigInt(1e18))))); const x2y2Root = BigInt( @@ -758,11 +757,13 @@ export class FluidDex extends SimpleExchange implements IDex { (Number(xyRoot) + Number(x2y2Root)); // console.log( - // 'before values : ' + (y2 * xyRoot + t * xyRoot - y * x2y2Root), - // xyRoot + x2y2Root, + // 'indepth value of a : ', + // Number(y2) * Number(xyRoot), + // Number(t) * Number(xyRoot), + // Number(y) * Number(x2y2Root), + // Number(xyRoot) + Number(x2y2Root), // ); - - // console.log('sri values : ', xyRoot, x2y2Root, a); + // console.log('xy, x2y2, a values : ', xyRoot, x2y2Root, a); return BigInt(Math.floor(a)); } } diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 45339bf08..c49e9be52 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -7,6 +7,7 @@ export type FluidDexPoolState = { // pool prices. Complete me! collateralReserves: CollateralReserves; debtReserves: DebtReserves; + fee: number; }; export type CollateralReserves = { @@ -29,6 +30,7 @@ export interface PoolWithReserves { pool: string; token0_: string; token1_: string; + fee: number; collateralReserves: CollateralReserves; debtReserves: DebtReserves; } diff --git a/tests/utils-e2e.ts b/tests/utils-e2e.ts index bded1c0e9..30c339787 100644 --- a/tests/utils-e2e.ts +++ b/tests/utils-e2e.ts @@ -501,8 +501,6 @@ export async function testE2E( forceRoute, ); - console.log('price route : ' + priceRoute); - console.log('PRICE ROUTE: ', util.inspect(priceRoute, false, null, true)); expect(parseFloat(priceRoute.destAmount)).toBeGreaterThan(0); From 1e6c838cf149e4e0bc38b68703fd6e9c33bf1fc7 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Fri, 4 Oct 2024 15:18:09 +0530 Subject: [PATCH 13/64] all tests working --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 26 +- .../fluid-dex/fluid-dex-integration.test.ts | 22 +- src/dex/fluid-dex/fluid-dex.ts | 300 +++++++++++------- 3 files changed, 208 insertions(+), 140 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 9acceb538..f5c7d4261 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -89,19 +89,19 @@ function testForNetwork( provider, ); }); - // it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { - // await testE2E( - // tokens[tokenASymbol], - // tokens[nativeTokenSymbol], - // holders[tokenASymbol], - // tokenAAmount, - // SwapSide.SELL, - // dexKey, - // contractMethod as ContractMethod, - // network, - // provider, - // ); - // }); + it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + await testE2E( + tokens[tokenASymbol], + tokens[nativeTokenSymbol], + holders[tokenASymbol], + tokenAAmount, + SwapSide.SELL, + dexKey, + contractMethod as ContractMethod, + network, + provider, + ); + }); }); }); }), diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 70d05a751..dcffb3407 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -97,6 +97,16 @@ async function checkOnChainPricing( console.log('prices fetched from reserves : ' + expectedPrices); // expect(prices).toEqual(expectedPrices); + // expect(prices).toEqual( + // expect.arrayContaining( + // expectedPrices.map(expected => ({ + // asymmetricMatch: (actual: bigint) => { + // const diff = (actual - expected) * 100n / expected; + // return diff >= -1n && diff <= 1n; + // } + // })) + // ) + // ); } async function testPricingOnNetwork( @@ -191,12 +201,12 @@ describe('FluidDex', function () { 2n * BI_POWS[tokens[destTokenSymbol].decimals], 3n * BI_POWS[tokens[destTokenSymbol].decimals], 4n * BI_POWS[tokens[destTokenSymbol].decimals], - 5n * BI_POWS[tokens[destTokenSymbol].decimals], - 6n * BI_POWS[tokens[destTokenSymbol].decimals], - 7n * BI_POWS[tokens[destTokenSymbol].decimals], - 8n * BI_POWS[tokens[destTokenSymbol].decimals], - 9n * BI_POWS[tokens[destTokenSymbol].decimals], - 10n * BI_POWS[tokens[destTokenSymbol].decimals], + // 5n * BI_POWS[tokens[destTokenSymbol].decimals], + // 6n * BI_POWS[tokens[destTokenSymbol].decimals], + // 7n * BI_POWS[tokens[destTokenSymbol].decimals], + // 8n * BI_POWS[tokens[destTokenSymbol].decimals], + // 9n * BI_POWS[tokens[destTokenSymbol].decimals], + // 10n * BI_POWS[tokens[destTokenSymbol].decimals], ]; beforeAll(async () => { diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index a70f0f53c..0b44d2492 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -179,19 +179,29 @@ export class FluidDex extends SimpleExchange implements IDex { const swap0To1: boolean = side === SwapSide.SELL; - const prices = amounts.map(amount => - // this.calcPrice(pool, state, srcToken, amount, side), - - this.swapIn( - swap0To1, - amount, - state.collateralReserves, - state.debtReserves, - srcToken.decimals, - destToken.decimals, - BigInt(state.fee), - ), - ); + const prices = amounts.map(amount => { + if (side === SwapSide.SELL) { + return this.swapIn( + srcToken.address.toLowerCase() === pool.token0.toLowerCase(), + amount, + state.collateralReserves, + state.debtReserves, + srcToken.decimals, + destToken.decimals, + BigInt(state.fee), + ); + } else { + return this.swapOut( + !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), + amount, + state.collateralReserves, + state.debtReserves, + srcToken.decimals, + destToken.decimals, + BigInt(state.fee), + ); + } + }); return [ { @@ -557,114 +567,6 @@ export class FluidDex extends SimpleExchange implements IDex { return numerator / denominator; } - /** - * Calculates the input amount for a given output amount in a swap operation. - * @param swap0to1 - Direction of the swap. True if swapping token0 for token1, false otherwise. - * @param amountOut - The amount of output token to be swapped. - * @param colReserves - The reserves of the collateral pool. - * @param debtReserves - The reserves of the debt pool. - * @returns The calculated input amount required for the swap. - */ - swapOutAdjusted( - swap0to1: boolean, - amountOut: bigint, - colReserves: CollateralReserves, - debtReserves: DebtReserves, - ): bigint { - const { - token0RealReserves, - token1RealReserves, - token0ImaginaryReserves, - token1ImaginaryReserves, - } = colReserves; - - const { - token0RealReserves: debtToken0RealReserves, - token1RealReserves: debtToken1RealReserves, - token0ImaginaryReserves: debtToken0ImaginaryReserves, - token1ImaginaryReserves: debtToken1ImaginaryReserves, - } = debtReserves; - - // Check if all reserves of collateral pool are greater than 0 - const colPoolEnabled = - token0RealReserves > 0 && - token1RealReserves > 0 && - token0ImaginaryReserves > 0 && - token1ImaginaryReserves > 0; - - // Check if all reserves of debt pool are greater than 0 - const debtPoolEnabled = - debtToken0RealReserves > 0 && - debtToken1RealReserves > 0 && - debtToken0ImaginaryReserves > 0 && - debtToken1ImaginaryReserves > 0; - - let colIReserveIn: bigint, - colIReserveOut: bigint, - debtIReserveIn: bigint, - debtIReserveOut: bigint; - - if (swap0to1) { - colIReserveIn = token0ImaginaryReserves; - colIReserveOut = token1ImaginaryReserves; - debtIReserveIn = debtToken0ImaginaryReserves; - debtIReserveOut = debtToken1ImaginaryReserves; - } else { - colIReserveIn = token1ImaginaryReserves; - colIReserveOut = token0ImaginaryReserves; - debtIReserveIn = debtToken1ImaginaryReserves; - debtIReserveOut = debtToken0ImaginaryReserves; - } - - let a: bigint; - if (colPoolEnabled && debtPoolEnabled) { - a = this.swapRoutingOut( - amountOut, - colIReserveIn, - colIReserveOut, - debtIReserveIn, - debtIReserveOut, - ); - } else if (debtPoolEnabled) { - a = BigInt(-1); // Route from debt pool - } else if (colPoolEnabled) { - a = amountOut + BigInt(1); // Route from collateral pool - } else { - throw new Error('No pools are enabled'); - } - - let amountOutCollateral = BigInt(0); - let amountOutDebt = BigInt(0); - - if (a <= 0) { - // Entire trade routes through debt pool - amountOutDebt = this.getAmountIn( - amountOut, - debtIReserveIn, - debtIReserveOut, - ); - } else if (a >= amountOut) { - // Entire trade routes through collateral pool - amountOutCollateral = this.getAmountIn( - amountOut, - colIReserveIn, - colIReserveOut, - ); - } else { - // Trade routes through both pools - amountOutCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut); - amountOutDebt = this.getAmountIn( - amountOut - a, - debtIReserveIn, - debtIReserveOut, - ); - } - - const totalAmountIn = amountOutCollateral + amountOutDebt; - - return totalAmountIn; - } - /** * 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. @@ -766,4 +668,160 @@ export class FluidDex extends SimpleExchange implements IDex { // console.log('xy, x2y2, a values : ', xyRoot, x2y2Root, a); return BigInt(Math.floor(a)); } + + /** + * 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, + ): bigint { + // console.log( + // 'this function is called ', + // swap0to1, + // amountOut, + // inDecimals, + // outDecimals, + // fee, + // ); + const amountOutAdjusted = + (amountOut * BigInt(10 ** 12)) / BigInt(10 ** outDecimals); + const amountIn = this.swapOutAdjusted( + swap0to1, + amountOutAdjusted, + colReserves, + debtReserves, + ); + + const FEE_100_PERCENT = BigInt(1e6); // Assuming this constant is defined elsewhere + + const result = + ((amountIn * FEE_100_PERCENT) / (FEE_100_PERCENT - fee)) * + BigInt(10 ** (inDecimals - 12)); + + // console.log('this is result ' + result); + + return result; + } + + /** + * 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, + ): bigint { + const { + token0RealReserves, + token1RealReserves, + token0ImaginaryReserves, + token1ImaginaryReserves, + } = colReserves; + + const { + token0RealReserves: debtToken0RealReserves, + token1RealReserves: debtToken1RealReserves, + token0ImaginaryReserves: debtToken0ImaginaryReserves, + token1ImaginaryReserves: debtToken1ImaginaryReserves, + } = debtReserves; + + // Check if all reserves of collateral pool are greater than 0 + const colPoolEnabled = + token0RealReserves > 0n && + token1RealReserves > 0n && + token0ImaginaryReserves > 0n && + token1ImaginaryReserves > 0n; + + // Check if all reserves of debt pool are greater than 0 + const debtPoolEnabled = + debtToken0RealReserves > 0n && + debtToken1RealReserves > 0n && + debtToken0ImaginaryReserves > 0n && + debtToken1ImaginaryReserves > 0n; + + let colIReserveIn: bigint, + colIReserveOut: bigint, + debtIReserveIn: bigint, + debtIReserveOut: bigint; + + if (swap0to1) { + colIReserveIn = token0ImaginaryReserves; + colIReserveOut = token1ImaginaryReserves; + debtIReserveIn = debtToken0ImaginaryReserves; + debtIReserveOut = debtToken1ImaginaryReserves; + } else { + colIReserveIn = token1ImaginaryReserves; + colIReserveOut = token0ImaginaryReserves; + debtIReserveIn = debtToken1ImaginaryReserves; + debtIReserveOut = debtToken0ImaginaryReserves; + } + + let a: bigint; + if (colPoolEnabled && debtPoolEnabled) { + a = this.swapRoutingOut( + amountOut, + colIReserveIn, + colIReserveOut, + debtIReserveIn, + debtIReserveOut, + ); + } else if (debtPoolEnabled) { + a = -1n; // Route from debt pool + } else if (colPoolEnabled) { + a = amountOut + 1n; // Route from collateral pool + } else { + throw new Error('No pools are enabled'); + } + + let amountInCollateral = 0n; + let amountInDebt = 0n; + + if (a <= 0n) { + // Entire trade routes through debt pool + amountInDebt = this.getAmountIn( + amountOut, + debtIReserveIn, + debtIReserveOut, + ); + } else if (a >= amountOut) { + // Entire trade routes through collateral pool + amountInCollateral = this.getAmountIn( + amountOut, + colIReserveIn, + colIReserveOut, + ); + } else { + // Trade routes through both pools + amountInCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut); + amountInDebt = this.getAmountIn( + amountOut - a, + debtIReserveIn, + debtIReserveOut, + ); + } + + const totalAmountIn = amountInCollateral + amountInDebt; + + return totalAmountIn; + } } From aa50aad2fe913d0b37ae8d3eaba703ee83976706 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Fri, 4 Oct 2024 23:24:33 +0530 Subject: [PATCH 14/64] added .env.example file and also reverted the irrelevant changes in main files of paraswap --- .env.example | 7 +++++++ src/generic-swap-transaction-builder.ts | 2 -- src/implementations/local-paraswap-sdk.ts | 9 +-------- src/types.ts | 1 + tests/constants-e2e.ts | 2 +- tests/utils-e2e.ts | 13 ------------- 6 files changed, 10 insertions(+), 24 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..cc27ae949 --- /dev/null +++ b/.env.example @@ -0,0 +1,7 @@ +HTTP_PROVIDER_1= +HTTP_PROVIDER_137= +HTTP_PROVIDER_43114= + +TENDERLY_TOKEN= +TENDERLY_ACCOUNT_ID= +TENDERLY_PROJECT= \ No newline at end of file diff --git a/src/generic-swap-transaction-builder.ts b/src/generic-swap-transaction-builder.ts index 8ccba8a03..4e862934e 100644 --- a/src/generic-swap-transaction-builder.ts +++ b/src/generic-swap-transaction-builder.ts @@ -33,7 +33,6 @@ import { ExecutorDetector } from './executor/ExecutorDetector'; import { ExecutorBytecodeBuilder } from './executor/ExecutorBytecodeBuilder'; import { IDexTxBuilder } from './dex/idex'; import { ParaSwapVersion, SwapSide } from '@paraswap/core'; -import { clear } from 'console'; const { utils: { hexlify, hexConcat, hexZeroPad }, @@ -254,7 +253,6 @@ export class GenericSwapTransactionBuilder { priceRoute.destToken, isSell ? priceRoute.srcAmount : minMaxAmount, isSell ? minMaxAmount : priceRoute.destAmount, - // minMaxAmount, isSell ? priceRoute.destAmount : priceRoute.srcAmount, hexConcat([ hexZeroPad(uuidToBytes16(uuid), 16), diff --git a/src/implementations/local-paraswap-sdk.ts b/src/implementations/local-paraswap-sdk.ts index 094754b86..189318f3a 100644 --- a/src/implementations/local-paraswap-sdk.ts +++ b/src/implementations/local-paraswap-sdk.ts @@ -25,7 +25,6 @@ import { GenericSwapTransactionBuilder } from '../generic-swap-transaction-build import { AddressOrSymbol } from '@paraswap/sdk'; import { ParaSwapVersion } from '@paraswap/core'; import { TransactionBuilder } from '../transaction-builder'; -import { QuickPerps } from '../dex/quick-perps/quick-perps'; export interface IParaSwapSDK { getPrices( @@ -97,9 +96,6 @@ export class LocalParaswapSDK implements IParaSwapSDK { delete this.dexKeys[this.dexKeys.indexOf(dexKey)]; } }); - - // Remove the null entries - this.dexKeys = this.dexKeys.filter(key => key !== null); } async initializePricing() { @@ -132,8 +128,6 @@ export class LocalParaswapSDK implements IParaSwapSDK { this.dexKeys, )); - // console.log("this is pool identifiers" + JSON.stringify(poolIdentifiers, null, 2)); - const amounts = _.range(0, chunks + 1).map( i => (amount * BigInt(i)) / BigInt(chunks), ); @@ -153,7 +147,6 @@ export class LocalParaswapSDK implements IParaSwapSDK { const finalPrice = poolPrices[0]; const quoteAmount = finalPrice.prices[chunks]; - const srcAmount = ( side === SwapSide.SELL ? amount : quoteAmount ).toString(); @@ -289,6 +282,7 @@ export class LocalParaswapSDK implements IParaSwapSDK { { slippageFactor, txOrigin: userAddress, + userAddress, executionContractAddress, isDirectMethod: DirectContractMethods.includes( contractMethod as ContractMethod, @@ -328,7 +322,6 @@ export class LocalParaswapSDK implements IParaSwapSDK { partnerFeePercent: '0', deadline: deadline.toString(), uuid: uuid(), - beneficiary: '0x5F4e77A22e394B51dC7Efb8e3C78121e489E78cD', // @(to be changed) }); } } diff --git a/src/types.ts b/src/types.ts index d11ac8196..ac3ffb0ea 100644 --- a/src/types.ts +++ b/src/types.ts @@ -318,6 +318,7 @@ export type ExchangeTxInfo = { export type PreprocessTransactionOptions = { slippageFactor: BigNumber; txOrigin: Address; + userAddress: Address; executionContractAddress: Address; hmac?: string; mockRfqAndLO?: boolean; diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index 9cd9a599f..aa181a6c0 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -1510,7 +1510,7 @@ export const Holders: { BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a', STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18', SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a', - wstETH: '0xC329400492c6ff2438472D4651Ad17389fCb843a', + wstETH: '0x3c22ec75ea5D745c78fc84762F7F1E6D82a2c5BF', WETH: '0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44', USDT: '0xAf64555DDD61FcF7D094824dd9B4eBea165aFc5b', XAUT: '0xc4e161e8d8a4bc4ac762ab33a28bbac5474203d7', diff --git a/tests/utils-e2e.ts b/tests/utils-e2e.ts index 30c339787..7c3770560 100644 --- a/tests/utils-e2e.ts +++ b/tests/utils-e2e.ts @@ -59,7 +59,6 @@ import * as util from 'util'; import { GenericSwapTransactionBuilder } from '../src/generic-swap-transaction-builder'; import { DexAdapterService, PricingHelper } from '../src'; import { v4 as uuid } from 'uuid'; -import { minBy } from 'lodash'; export const testingEndpoint = process.env.E2E_TEST_ENDPOINT; @@ -389,7 +388,6 @@ export async function testE2E( sleepMs?: number, replaceTenderlyWithEstimateGas?: boolean, forceRoute?: AddressOrSymbol[], - beneficiary: Address = NULL_ADDRESS, ) { const amount = BigInt(_amount); @@ -564,24 +562,13 @@ export async function testE2E( (swapSide === SwapSide.SELL ? BigInt(priceRoute.destAmount) * (10000n - BigInt(_slippage)) : BigInt(priceRoute.srcAmount) * (10000n + BigInt(_slippage))) / 10000n; - - console.log('slippage : ' + _slippage); - - console.log('original amount : ' + amount); - console.log('minmaxamount : ' + minMaxAmount); - const swapParams = await paraswap.buildTransaction( priceRoute, minMaxAmount, senderAddress, ); - console.log('these are the swap params : ' + JSON.stringify(swapParams)); - const swapTx = await ts.simulate(swapParams); - - console.log('json swap tx' + JSON.stringify(swapTx)); - // Only log gas estimate if testing against API if (useAPI) { const gasUsed = swapTx.gasUsed || '0'; From 40b2d2cde6880dedd6dfb9aa6a32fec1c469a335 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Sat, 5 Oct 2024 04:08:09 +0530 Subject: [PATCH 15/64] made changes suggested on github --- src/dex/fluid-dex/config.ts | 6 +- .../fluid-dex/fluid-dex-integration.test.ts | 52 ++--- src/dex/fluid-dex/fluid-dex-pool.ts | 46 ++--- src/dex/fluid-dex/fluid-dex.ts | 182 ++++++++++-------- src/dex/fluid-dex/types.ts | 11 +- 5 files changed, 156 insertions(+), 141 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index 8f007a4ff..0bf30a35a 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -9,11 +9,7 @@ export const FluidDexConfig: DexConfigMap = { { id: 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a', // Pool identifier: `{dex_key}_{pool_address}` address: '0x6d83f60eeac0e50a1250760151e81db2a278e03a', // Address of the pool - debtOperations: '0xaf19a6f318b7f8f58c9f9c89acc1ec40a3afcdf5', - colOperations: '0x835a8e10e8f473174f937afa0ec22fc9a7fa504f', - perfectOperationsAndSwapOut: - '0x8cf39e1bd5722baac7056e1a02ee139296b224ed', - liquidityUserModule: '0x8ec5e29ea39b2f64b21e32cb9ff11d5059982f8c', + liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497', resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', token0: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', // wstETH token1: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', // ETH diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index dcffb3407..aa6fdd18b 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -195,19 +195,19 @@ describe('FluidDex', function () { 10n * BI_POWS[tokens[srcTokenSymbol].decimals], ]; - const amountsForBuy = [ - 0n, - 1n * BI_POWS[tokens[destTokenSymbol].decimals], - 2n * BI_POWS[tokens[destTokenSymbol].decimals], - 3n * BI_POWS[tokens[destTokenSymbol].decimals], - 4n * BI_POWS[tokens[destTokenSymbol].decimals], - // 5n * BI_POWS[tokens[destTokenSymbol].decimals], - // 6n * BI_POWS[tokens[destTokenSymbol].decimals], - // 7n * BI_POWS[tokens[destTokenSymbol].decimals], - // 8n * BI_POWS[tokens[destTokenSymbol].decimals], - // 9n * BI_POWS[tokens[destTokenSymbol].decimals], - // 10n * BI_POWS[tokens[destTokenSymbol].decimals], - ]; + // const amountsForBuy = [ + // 0n, + // 1n * BI_POWS[tokens[destTokenSymbol].decimals], + // 2n * BI_POWS[tokens[destTokenSymbol].decimals], + // 3n * BI_POWS[tokens[destTokenSymbol].decimals], + // 4n * BI_POWS[tokens[destTokenSymbol].decimals], + // // 5n * BI_POWS[tokens[destTokenSymbol].decimals], + // // 6n * BI_POWS[tokens[destTokenSymbol].decimals], + // // 7n * BI_POWS[tokens[destTokenSymbol].decimals], + // // 8n * BI_POWS[tokens[destTokenSymbol].decimals], + // // 9n * BI_POWS[tokens[destTokenSymbol].decimals], + // // 10n * BI_POWS[tokens[destTokenSymbol].decimals], + // ]; beforeAll(async () => { blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); @@ -231,19 +231,19 @@ describe('FluidDex', function () { ); }); - it('getPoolIdentifiers and getPricesVolume BUY', async function () { - await testPricingOnNetwork( - fluidDex, - network, - dexKey, - blockNumber, - srcTokenSymbol, - destTokenSymbol, - SwapSide.BUY, - amountsForBuy, - 'estimateSwapOut', // TODO: Put here proper function name to check pricing - ); - }); + // it('getPoolIdentifiers and getPricesVolume BUY', async function () { + // await testPricingOnNetwork( + // fluidDex, + // network, + // dexKey, + // blockNumber, + // srcTokenSymbol, + // destTokenSymbol, + // SwapSide.BUY, + // amountsForBuy, + // 'estimateSwapOut', // TODO: Put here proper function name to check pricing + // ); + // }); it('getTopPoolsForToken', async function () { // We have to check without calling initializePricing, because diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 10979d62b..82b6accfb 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -4,17 +4,15 @@ import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; -import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; import { FluidDexPool, FluidDexPoolState, PoolWithReserves } from './types'; import { ethers } from 'ethers'; import { eachOfSeries } from 'async'; -import { USD_PRECISION } from '../woo-fi-v2/constants'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; -import { BytesLike, defaultAbiCoder } from 'ethers/lib/utils'; +import { BytesLike } from 'ethers/lib/utils'; import { Address } from '../../types'; -import { generalDecoder } from '../../lib/decoders'; +import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; export class FluidDexEventPool extends StatefulEventSubscriber { handlers: { @@ -42,7 +40,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber this.liquidityIface.parseLog(log); - this.addressesSubscribed = [pool.liquidityUserModule]; + this.addressesSubscribed = [pool.liquidityProxy]; // Add handlers this.handlers['LogOperate'] = this.handleOperate.bind(this); @@ -56,24 +54,14 @@ export class FluidDexEventPool extends StatefulEventSubscriber, log: Readonly, ): Promise | null> { - const ResolverAbi = new Interface(ResolverABI); - if ( - !( - event.args.user in - [ - this.pool.address, - this.pool.colOperations, - this.pool.debtOperations, - this.pool.perfectOperationsAndSwapOut, - ] - ) - ) { + const resolverAbi = new Interface(ResolverABI); + if (!(event.args.user in [this.pool.address])) { return null; } const callData: MultiCallParams[] = [ { target: this.pool.resolver, - callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ + callData: resolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), decodeFunction: await this.decodePoolWithReserves, @@ -87,11 +75,18 @@ export class FluidDexEventPool extends StatefulEventSubscriber | BytesLike, - ): [boolean, BytesLike] => { - return this.isMultiResult(result) - ? [result.success, result.returnData] - : [true, result]; - }; - isMultiResult = ( result: MultiResult | BytesLike, ): result is MultiResult => { @@ -200,7 +187,6 @@ export class FluidDexEventPool extends StatefulEventSubscriber> { - const ResolverAbi = new Interface(ResolverABI); + const resolverAbi = new Interface(ResolverABI); const callData: MultiCallParams[] = [ { target: this.pool.resolver, - callData: ResolverAbi.encodeFunctionData('getPoolReserves', [ + callData: resolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), decodeFunction: await this.decodePoolWithReserves, diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 0b44d2492..e8b8dfcb2 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -22,6 +22,7 @@ import { FluidDexData, FluidDexPool, FluidDexPoolState, + Pool, } from './types'; import { SimpleExchange, @@ -33,6 +34,10 @@ import { FluidDexEventPool } from './fluid-dex-pool'; import { applyTransferFee } from '../../lib/token-transfer-fee'; import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; import { extractReturnAmountPosition } from '../../executor/utils'; +import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; +import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; +import { BytesLike } from 'ethers/lib/utils'; +import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; export class FluidDex extends SimpleExchange implements IDex { readonly eventPools: { [id: string]: FluidDexEventPool } = {}; @@ -52,6 +57,10 @@ export class FluidDex extends SimpleExchange implements IDex { readonly iFluidDexPool: Interface; + // readonly liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497'; + + // readonly resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330'; + protected adapters; FEE_100_PERCENT = BigInt(1000000); @@ -82,7 +91,9 @@ export class FluidDex extends SimpleExchange implements IDex { // for pricing requests. It is optional for a DEX to // implement this function async initializePricing(blockNumber: number) { - // TODO: complete me! + Object.entries(this.eventPools).forEach(([id, eventPool]) => { + eventPool.getStateOrGenerate(blockNumber, false); + }); } // Returns the list of contract adapters (name and index) @@ -91,6 +102,39 @@ export class FluidDex extends SimpleExchange implements IDex { return this.adapters[side] ? this.adapters[side] : null; } + // async getPoolsFromResolver(){ + // const resolverAbi = new Interface(ResolverABI); + // const callData: MultiCallParams[] = [ + // { + // target: this.resolver, + // callData: resolverAbi.encodeFunctionData('getAllPools', []), + // decodeFunction: await this.decodePools, + // }, + // ]; + + // const results: Pool[] = + // await this.dexHelper.multiWrapper.aggregate( + // callData, + // await this.dexHelper.provider.getBlockNumber(), + // this.dexHelper.multiWrapper.defaultBatchSize, + // ); + // } + + decodePools = (result: MultiResult | BytesLike): Pool[] => { + return generalDecoder( + result, + ['tuple(address pool, address token0, address token1)[]'], + undefined, + decoded => { + return decoded.map((decodedPool: any) => ({ + address: decodedPool.pool, + token0: decodedPool.token0, + token1: decodedPool.token1, + })); + }, + ); + }; + // Returns list of pool identifiers that can be used // for a given swap. poolIdentifiers must be unique // across DEXes. It is recommended to use @@ -103,29 +147,11 @@ export class FluidDex extends SimpleExchange implements IDex { ): Promise { // TODO: complete me! // return []; - const pool = this.getPoolByTokenPair(srcToken, destToken); + const pool = this.getPoolByTokenPair(srcToken.address, destToken.address); return pool ? [pool.id] : []; } - getPoolByTokenPair(srcToken: Token, destToken: Token): FluidDexPool | null { - const srcAddress = srcToken.address.toLowerCase(); - const destAddress = destToken.address.toLowerCase(); - - // A pair must have 2 different tokens. - if (srcAddress === destAddress) return null; - - for (const pool of this.pools) { - if ( - (srcAddress === pool.token0 && destAddress === pool.token1) || - (srcAddress === pool.token1 && destAddress === pool.token0) - ) { - return pool; - } - } - return null; - } - - getPoolByTokenPairAddress( + getPoolByTokenPair( srcToken: Address, destToken: Address, ): FluidDexPool | null { @@ -160,7 +186,7 @@ export class FluidDex extends SimpleExchange implements IDex { ): Promise> { try { // Get the pool to use. - const pool = this.getPoolByTokenPair(srcToken, destToken); + const pool = this.getPoolByTokenPair(srcToken.address, destToken.address); if (!pool) return null; // Make sure the pool meets the optional limitPools filter. @@ -191,21 +217,23 @@ export class FluidDex extends SimpleExchange implements IDex { BigInt(state.fee), ); } else { - return this.swapOut( - !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), - amount, - state.collateralReserves, - state.debtReserves, - srcToken.decimals, - destToken.decimals, - BigInt(state.fee), - ); + return null; + + // return this.swapOut( + // !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), + // amount, + // state.collateralReserves, + // state.debtReserves, + // srcToken.decimals, + // destToken.decimals, + // BigInt(state.fee), + // ); } }); return [ { - prices: prices, // to be done + prices: prices.filter((price): price is bigint => price !== null), // to be done unit: getBigIntPow( (side === SwapSide.SELL ? destToken : srcToken).decimals, ), // to be done @@ -269,7 +297,7 @@ export class FluidDex extends SimpleExchange implements IDex { // getTopPoolsForToken. It is optional for a DEX // to implement this async updatePoolState(): Promise { - // TODO: complete me! + this.initializePricing(await this.dexHelper.provider.getBlockNumber()); } // Returns list of top pools based on liquidity. Max @@ -322,11 +350,29 @@ export class FluidDex extends SimpleExchange implements IDex { const pool = this.pools.find(p => p.id === id); if (!pool) continue; // Skip if pool not found + const state: FluidDexPoolState = await this.eventPools[ + pool.id + ].getStateOrGenerate( + await this.dexHelper.provider.getBlockNumber(), + false, + ); + + const usd0 = await this.dexHelper.getTokenUSDPrice( + { address: pool.token0, decimals: 18 }, + state.collateralReserves.token0RealReserves + + state.debtReserves.token0RealReserves, + ); + const usd1 = await this.dexHelper.getTokenUSDPrice( + { address: pool.token1, decimals: 18 }, + state.collateralReserves.token1RealReserves + + state.debtReserves.token1RealReserves, + ); + poolLiquidities.push({ exchange: 'FluidDex', address: pool.address, connectorTokens: [], - liquidityUSD: Number(amount), // converted to number + liquidityUSD: Number(usd0 + usd1), // converted to number }); } return poolLiquidities; @@ -349,40 +395,49 @@ export class FluidDex extends SimpleExchange implements IDex { context: Context, executorAddress: Address, ): AsyncOrSync { + if (srcToken == '0xEeeeeEeeeeeeEeeeeeeEeeeeEeeeeeEeeeeEeeeE') { + throw new Error( + 'srcToken can not be Native ETH, try exchanging tokens and swapSide', + ); + } + let method: string; let args: any; let returnAmountPos: number | undefined = undefined; const deadline = getLocalDeadlineAsFriendlyPlaceholder(); - method = 'swapIn'; + method = side == SwapSide.SELL ? 'swapIn' : 'swapOut'; + returnAmountPos = extractReturnAmountPosition( this.iFluidDexPool, method, - 'amountOut_', + side == SwapSide.SELL ? 'amountOut_' : 'amountIn_', 1, ); - const pool = this.getPoolByTokenPairAddress(srcToken, destToken); - - if (srcToken == '0xEeeeeEeeeeeeEeeeeeeEeeeeEeeeeeEeeeeEeeeE') { - throw new Error( - 'srcToken can not be Native ETH, try exchanging tokens and swapSide', - ); - } + const pool = this.getPoolByTokenPair(srcToken, destToken); if (side == SwapSide.SELL) { if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [false, BigInt(srcAmount), BigInt(0), recipient]; + args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; } else { - args = [true, BigInt(srcAmount), BigInt(0), recipient]; + args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; } } else { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [true, BigInt(srcAmount), BigInt(0), recipient]; - } else { - args = [false, BigInt(srcAmount), BigInt(0), recipient]; - } + return { + needWrapNative: false, + exchangeData: '', + targetExchange: 'Invalid', + dexFuncHasRecipient: false, + returnAmountPos: undefined, + }; + + // if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + // args = [true, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; + // } else { + // args = [false, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; + // } } const swapData = this.iFluidDexPool.encodeFunctionData(method, args); @@ -391,8 +446,7 @@ export class FluidDex extends SimpleExchange implements IDex { needWrapNative: this.needWrapNative, dexFuncHasRecipient: true, exchangeData: swapData, - targetExchange: this.getPoolByTokenPairAddress(srcToken, destToken)! - .address, + targetExchange: pool!.address, returnAmountPos, }; } @@ -416,8 +470,6 @@ export class FluidDex extends SimpleExchange implements IDex { outDecimals: number, fee: bigint, ): bigint { - // console.log('swapIn Param : ' + amountIn); - if (amountIn === 0n) { return 0n; // Return 0 if input amount is 0 } @@ -433,7 +485,6 @@ export class FluidDex extends SimpleExchange implements IDex { debtReserves, ); const result = (amountOut * BigInt(10 ** outDecimals)) / BigInt(10 ** 12); - // console.log('this is result : ' + result); return result; } @@ -539,7 +590,6 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveOut, ); } - // console.log('this is a : ' + a); const totalAmountOut = amountOutCollateral + amountOutDebt; return totalAmountOut; @@ -644,7 +694,6 @@ export class FluidDex extends SimpleExchange implements IDex { y2: bigint, ): bigint { // Adding 1e18 precision - // console.log('params of sri : ', t, x, y, x2, y2); const xyRoot = BigInt(Math.floor(Math.sqrt(Number(x * y * BigInt(1e18))))); const x2y2Root = BigInt( @@ -657,15 +706,6 @@ export class FluidDex extends SimpleExchange implements IDex { Number(t) * Number(xyRoot) - Number(y) * Number(x2y2Root)) / (Number(xyRoot) + Number(x2y2Root)); - - // console.log( - // 'indepth value of a : ', - // Number(y2) * Number(xyRoot), - // Number(t) * Number(xyRoot), - // Number(y) * Number(x2y2Root), - // Number(xyRoot) + Number(x2y2Root), - // ); - // console.log('xy, x2y2, a values : ', xyRoot, x2y2Root, a); return BigInt(Math.floor(a)); } @@ -689,14 +729,6 @@ export class FluidDex extends SimpleExchange implements IDex { outDecimals: number, fee: bigint, ): bigint { - // console.log( - // 'this function is called ', - // swap0to1, - // amountOut, - // inDecimals, - // outDecimals, - // fee, - // ); const amountOutAdjusted = (amountOut * BigInt(10 ** 12)) / BigInt(10 ** outDecimals); const amountIn = this.swapOutAdjusted( @@ -712,8 +744,6 @@ export class FluidDex extends SimpleExchange implements IDex { ((amountIn * FEE_100_PERCENT) / (FEE_100_PERCENT - fee)) * BigInt(10 ** (inDecimals - 12)); - // console.log('this is result ' + result); - return result; } diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index c49e9be52..30dbbeadd 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -49,10 +49,7 @@ export type FluidDexData = { export type FluidDexPool = { id: string; address: Address; - debtOperations: Address; - colOperations: Address; - perfectOperationsAndSwapOut: Address; - liquidityUserModule: Address; + liquidityProxy: Address; resolver: Address; token0: Address; token1: Address; @@ -64,3 +61,9 @@ export type DexParams = { // Complete me! pools: [FluidDexPool]; }; + +export type Pool = { + address: Address; + token0: Address; + token1: Address; +}; From 62cab435966df7091adff6ecd0d9d7a778f4f4a9 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Sat, 5 Oct 2024 04:14:51 +0530 Subject: [PATCH 16/64] added the funciton to generate the pools --- src/dex/fluid-dex/fluid-dex.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index e8b8dfcb2..50b434490 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -102,22 +102,23 @@ export class FluidDex extends SimpleExchange implements IDex { return this.adapters[side] ? this.adapters[side] : null; } - // async getPoolsFromResolver(){ + // async getPoolsFromResolver() { // const resolverAbi = new Interface(ResolverABI); // const callData: MultiCallParams[] = [ // { // target: this.resolver, // callData: resolverAbi.encodeFunctionData('getAllPools', []), - // decodeFunction: await this.decodePools, + // decodeFunction: this.decodePools, // }, // ]; - // const results: Pool[] = - // await this.dexHelper.multiWrapper.aggregate( + // const results: Pool[][] = + // await this.dexHelper.multiWrapper.aggregate( // callData, // await this.dexHelper.provider.getBlockNumber(), // this.dexHelper.multiWrapper.defaultBatchSize, // ); + // } decodePools = (result: MultiResult | BytesLike): Pool[] => { From 40cf2764b6974e048277926f5f129678ad329f41 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 7 Oct 2024 06:17:21 +0530 Subject: [PATCH 17/64] cleaned up the code --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 4 ---- src/dex/fluid-dex/fluid-dex-events.test.ts | 3 +-- src/dex/fluid-dex/fluid-dex-integration.test.ts | 13 +++---------- src/dex/fluid-dex/fluid-dex-pool.ts | 4 +--- src/dex/fluid-dex/fluid-dex.ts | 17 +---------------- src/dex/fluid-dex/types.ts | 11 ----------- 6 files changed, 6 insertions(+), 46 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index f5c7d4261..dea93b25f 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -68,7 +68,6 @@ function testForNetwork( const holders = Holders[network]; const nativeTokenSymbol = NativeTokenSymbols[network]; - // TODO: Add any direct swap contractMethod name if it exists const sideToContractMethods = new Map([[SwapSide.SELL, ['swapIn']]]); describe(`${network}`, () => { @@ -115,7 +114,6 @@ describe('FluidDex E2E', () => { describe('Mainnet', () => { const network = Network.MAINNET; - // TODO: Modify the tokenASymbol, tokenBSymbol, tokenAAmount; const tokenASymbol: string = 'wstETH'; const tokenBSymbol: string = 'ETH'; @@ -132,7 +130,5 @@ describe('FluidDex E2E', () => { tokenBAmount, nativeTokenAmount, ); - - // TODO: Add any additional test cases required to test FluidDex }); }); diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 225137a3a..6a2e6d82e 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -65,8 +65,7 @@ describe('FluidDex EventPool Mainnet', function () { // poolAddress -> EventMappings const eventsToTest: Record = { - // TODO: complete me! - [fluidDexPool.liquidityUserModule]: { + [fluidDexPool.liquidityProxy]: { LogOperate: [18917344], }, }; diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index aa6fdd18b..519ef5566 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -36,12 +36,10 @@ function getReaderCalldata( readerIface: Interface, amounts: bigint[], funcName: string, - // TODO: Put here additional arguments you need ) { return amounts.map(amount => ({ target: exchangeAddress, callData: readerIface.encodeFunctionData(funcName, [ - // TODO: Put here additional arguments to encode them '0x6d83f60eeac0e50a1250760151e81db2a278e03a', funcName == 'estimateSwapIn' ? true : false, amount, @@ -55,7 +53,6 @@ function decodeReaderResult( readerIface: Interface, funcName: string, ) { - // TODO: Adapt this function for your needs return results.map(result => { // const parsed = readerIface.decodeFunctionResult(funcName, result); // console.log("result is " + BigInt(result)); @@ -70,11 +67,8 @@ async function checkOnChainPricing( prices: bigint[], amounts: bigint[], ) { - const resolverAddress = '0x278166a9b88f166eb170d55801be1b1d1e576330'; // TODO: Put here the real exchange address + const resolverAddress = '0x278166a9b88f166eb170d55801be1b1d1e576330'; - // TODO: Replace dummy interface with the real one - // Normally you can get it from fluidDex.Iface or from eventPool. - // It depends on your implementation const readerIface = new Interface(ResolverABI); const readerCallData = getReaderCalldata( @@ -176,7 +170,6 @@ describe('FluidDex', function () { const tokens = Tokens[network]; - // TODO: Put here token Symbol to check against // Don't forget to update relevant tokens in constant-e2e.ts const srcTokenSymbol = 'wstETH'; const destTokenSymbol = 'ETH'; @@ -227,7 +220,7 @@ describe('FluidDex', function () { destTokenSymbol, SwapSide.SELL, amountsForSell, - 'estimateSwapIn', // TODO: Put here proper function name to check pricing + 'estimateSwapIn', ); }); @@ -241,7 +234,7 @@ describe('FluidDex', function () { // destTokenSymbol, // SwapSide.BUY, // amountsForBuy, - // 'estimateSwapOut', // TODO: Put here proper function name to check pricing + // 'estimateSwapOut', // ); // }); diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 82b6accfb..155672e11 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -26,7 +26,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber any; addressesSubscribed: Address[]; - protected liquidityIface = new Interface(LiquidityABI); // TODO: add any additional params required for event subscriber + protected liquidityIface = new Interface(LiquidityABI); constructor( readonly parentName: string, @@ -35,10 +35,8 @@ export class FluidDexEventPool extends StatefulEventSubscriber this.liquidityIface.parseLog(log); this.addressesSubscribed = [pool.liquidityProxy]; diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 50b434490..8c77ac015 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -41,13 +41,9 @@ import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; export class FluidDex extends SimpleExchange implements IDex { readonly eventPools: { [id: string]: FluidDexEventPool } = {}; - readonly hasConstantPriceLargeAmounts = false; - // TODO: set true here if protocols works only with wrapped asset readonly needWrapNative = false; - readonly isFeeOnTransferSupported = false; - public static dexKeysWithNetwork: { key: string; networks: Network[] }[] = getDexKeysWithNetwork(FluidDexConfig); @@ -73,7 +69,7 @@ export class FluidDex extends SimpleExchange implements IDex { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); this.pools = FluidDexConfig['FluidDex'][network].pools; - this.adapters = Adapters[network] || {}; // TODO: add any additional optional params to support other fork DEXes + this.adapters = Adapters[network] || {}; this.iFluidDexPool = new Interface(FluidDexPoolABI); for (const pool of this.pools) { this.eventPools[pool.id] = new FluidDexEventPool( @@ -146,8 +142,6 @@ export class FluidDex extends SimpleExchange implements IDex { side: SwapSide, blockNumber: number, ): Promise { - // TODO: complete me! - // return []; const pool = this.getPoolByTokenPair(srcToken.address, destToken.address); return pool ? [pool.id] : []; } @@ -263,7 +257,6 @@ export class FluidDex extends SimpleExchange implements IDex { // Returns estimated gas cost of calldata for this DEX in multiSwap getCalldataGasCost(poolPrices: PoolPrices): number | number[] { - // TODO: update if there is any payload in getAdapterParam return CALLDATA_GAS_COST.DEX_NO_PAYLOAD; } @@ -279,7 +272,6 @@ export class FluidDex extends SimpleExchange implements IDex { data: FluidDexData, side: SwapSide, ): AdapterExchangeParam { - // TODO: complete me! const { exchange } = data; // Encode here the payload for adapter @@ -307,7 +299,6 @@ export class FluidDex extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { - //TODO: complete me! let liquidityAmounts: { [id: string]: bigint } = {}; for (const pool of this.pools) { if ( @@ -379,12 +370,6 @@ export class FluidDex extends SimpleExchange implements IDex { return poolLiquidities; } - // This is optional function in case if your implementation has acquired any resources - // you need to release for graceful shutdown. For example, it may be any interval timer - releaseResources(): AsyncOrSync { - // TODO: complete me! - } - getDexParam( srcToken: Address, destToken: Address, diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 30dbbeadd..8b345d8ec 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -1,10 +1,6 @@ import { Address } from '../../types'; export type FluidDexPoolState = { - // TODO: poolState is the state of event - // subscriber. This should be the minimum - // set of parameters required to compute - // pool prices. Complete me! collateralReserves: CollateralReserves; debtReserves: DebtReserves; fee: number; @@ -36,10 +32,6 @@ export interface PoolWithReserves { } export type FluidDexData = { - // TODO: FluidDexData is the dex data that is - // returned by the API that can be used for - // tx building. The data structure should be minimal. - // Complete me! colReserves: CollateralReserves; debtReserves: DebtReserves; exchange: Address; @@ -56,9 +48,6 @@ export type FluidDexPool = { }; export type DexParams = { - // TODO: DexParams is set of parameters the can - // be used to initiate a DEX fork. - // Complete me! pools: [FluidDexPool]; }; From bf5afcba27949bd6a0fa4466311ac5b73419b353 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 8 Oct 2024 00:39:56 +0530 Subject: [PATCH 18/64] made changes --- src/dex/fluid-dex/config.ts | 16 +- src/dex/fluid-dex/fluid-dex-events.test.ts | 29 +-- src/dex/fluid-dex/fluid-dex-generate-pool.ts | 194 ++++++++++++++++++ .../fluid-dex/fluid-dex-integration.test.ts | 20 +- src/dex/fluid-dex/fluid-dex-pool.ts | 31 ++- src/dex/fluid-dex/fluid-dex.ts | 188 ++++++++++------- src/dex/fluid-dex/types.ts | 14 +- tests/constants-e2e.ts | 1 + 8 files changed, 355 insertions(+), 138 deletions(-) create mode 100644 src/dex/fluid-dex/fluid-dex-generate-pool.ts diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index 0bf30a35a..ad8a89409 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -5,16 +5,12 @@ import { Network, SwapSide } from '../../constants'; export const FluidDexConfig: DexConfigMap = { FluidDex: { [Network.MAINNET]: { - pools: [ - { - id: 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a', // Pool identifier: `{dex_key}_{pool_address}` - address: '0x6d83f60eeac0e50a1250760151e81db2a278e03a', // Address of the pool - liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497', - resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', - token0: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', // wstETH - token1: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', // ETH - }, - ], + commonAddresses: { + liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497', + resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', + dexFactory: '0x93dd426446b5370f094a1e31f19991aaa6ac0be0', + }, + pools: [], }, }, }; diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 6a2e6d82e..4d70116bc 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -49,7 +49,6 @@ async function fetchPoolState( fluidDexPool: FluidDexEventPool, blockNumber: number, ): Promise { - // TODO: complete me! return fluidDexPool.generateState(blockNumber); } @@ -62,26 +61,28 @@ describe('FluidDex EventPool Mainnet', function () { const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); const fluidDexPool: FluidDexPool = FluidDexConfig[dexKey][network].pools[0]; + const liquidityProxy: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; // poolAddress -> EventMappings const eventsToTest: Record = { - [fluidDexPool.liquidityProxy]: { - LogOperate: [18917344], + [liquidityProxy]: { + DexDeployed: [20776998], }, }; let fluidDexEventPool: FluidDexEventPool; - - beforeEach(async () => { - fluidDexEventPool = new FluidDexEventPool( - 'FluidDex', - fluidDexPool, - network, - dexHelper, - logger, - /* TODO: Put here additional constructor arguments if needed */ - ); - }); + let fluidDexCommonAddress; + + // beforeEach(async () => { + // fluidDexEventPool = new FluidDexEventPool( + // 'FluidDex', + // fluidDexPool, + // network, + // dexHelper, + // logger, + // ); + + // }); Object.entries(eventsToTest).forEach( ([poolAddress, events]: [string, EventMappings]) => { diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts new file mode 100644 index 000000000..a0794096b --- /dev/null +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -0,0 +1,194 @@ +import { Interface } from '@ethersproject/abi'; +import { DeepReadonly } from 'ts-essentials'; +import { Log, Logger } from '../../types'; +import { catchParseLogError } from '../../utils'; +import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; +import { IDexHelper } from '../../dex-helper/idex-helper'; +import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; +import DexFactoryABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; +import { + commonAddresses, + FluidDexPool, + FluidDexPoolState, + PoolWithReserves, + Pool, +} from './types'; +import { ethers } from 'ethers'; +import { eachOfSeries } from 'async'; +import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; +import { BytesLike } from 'ethers/lib/utils'; +import { Address } from '../../types'; +import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; + +export class FluidDexCommonAddresses extends StatefulEventSubscriber { + handlers: { + [event: string]: ( + event: any, + state: DeepReadonly, + log: Readonly, + ) => Promise | null>; + } = {}; + + logDecoder: (log: Log) => any; + + addressesSubscribed: Address[]; + protected dexFactoryIface = new Interface(DexFactoryABI); + + constructor( + readonly parentName: string, + // readonly pool: FluidDexPool, + readonly commonAddresses: commonAddresses, + protected network: number, + protected dexHelper: IDexHelper, + logger: Logger, + ) { + super(parentName, 'getAllPools', dexHelper, logger); + + this.logDecoder = (log: Log) => this.dexFactoryIface.parseLog(log); + this.addressesSubscribed = [commonAddresses.dexFactory]; + + // Add handlers + this.handlers['DexDeployed'] = this.handleDexDeployed.bind(this); + } + + /** + * Handle a trade rate change on the pool. + */ + async handleDexDeployed( + event: any, + state: DeepReadonly, + log: Readonly, + ): Promise | null> { + const resolverAbi = new Interface(ResolverABI); + const callData: MultiCallParams[] = [ + { + target: this.commonAddresses.resolver, + callData: resolverAbi.encodeFunctionData('getPool', [event.args.dexId]), + decodeFunction: await this.decodePool, + }, + ]; + + const results: Pool[] = await this.dexHelper.multiWrapper.aggregate( + callData, + await this.dexHelper.provider.getBlockNumber(), + this.dexHelper.multiWrapper.defaultBatchSize, + ); + + const generatedPool = { + address: results[0].address, + token0: results[0].token0, + token1: results[0].token1, + }; + + let currentPool = this.getState(0); + currentPool = currentPool == null ? [] : currentPool; + currentPool = [...currentPool, generatedPool]; + + this.setState(currentPool, await this.dexHelper.provider.getBlockNumber()); + + return currentPool; + } + + decodePool = (result: MultiResult | BytesLike): Pool => { + return generalDecoder( + result, + ['tuple(address pool, address token0, address token1, uint256 fee)'], + undefined, + decoded => { + return { + address: decoded[0].toLowerCase(), + token0: decoded[1].toLowerCase(), + token1: decoded[2].toLowerCase(), + }; + }, + ); + }; + + /** + * The function is called every time any of the subscribed + * addresses release log. The function accepts the current + * state, updates the state according to the log, and returns + * the updated state. + * @param state - Current state of event subscriber + * @param log - Log released by one of the subscribed addresses + * @returns Updates state of the event subscriber after the log + */ + async processLog( + state: DeepReadonly, + log: Readonly, + ): Promise | null> { + try { + const event = this.logDecoder(log); + if (event.name in this.handlers) { + return await this.handlers[event.name](event, state, log); + } + } catch (e) { + catchParseLogError(e, this.logger); + } + + return null; + } + + async getStateOrGenerate( + blockNumber: number, + readonly: boolean = false, + ): Promise> { + let state = this.getState(blockNumber); + if (!state) { + state = await this.generateState(blockNumber); + if (!readonly) this.setState(state, blockNumber); + } + return state; + } + + /** + * The function generates state using on-chain calls. This + * function is called to regenerate state if the event based + * system fails to fetch events and the local state is no + * more correct. + * @param blockNumber - Blocknumber for which the state should + * should be generated + * @returns state of the event subscriber at blocknumber + */ + async generateState(blockNumber: number): Promise> { + // Flatten the array of arrays into a single array + const flattenedResults: Pool[] = ( + await this.getPoolsFromResolver(blockNumber) + ).flat(); + + // Cast the result to DeepReadonly + return flattenedResults as DeepReadonly; + } + + async getPoolsFromResolver(blockNumber: number): Promise { + const resolverAbi = new Interface(ResolverABI); + const callData: MultiCallParams[] = [ + { + target: this.commonAddresses.resolver, + callData: resolverAbi.encodeFunctionData('getAllPools', []), + decodeFunction: this.decodePools, + }, + ]; + + const results: Pool[][] = await this.dexHelper.multiWrapper.aggregate< + Pool[] + >(callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize); + + return results[0]; + } + + decodePools = (result: MultiResult | BytesLike): Pool[] => { + return generalDecoder( + result, + ['tuple(address pool, address token0, address token1)[]'], + undefined, + decoded => { + return decoded.map((decodedPool: any) => ({ + address: decodedPool[0][0].toLowerCase(), + token0: decodedPool[0][1].toLowerCase(), + token1: decodedPool[0][2].toLowerCase(), + })); + }, + ); + }; +} diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 519ef5566..24d46440b 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -7,7 +7,6 @@ import { DummyDexHelper } from '../../dex-helper/index'; import { Network, SwapSide } from '../../constants'; import { BI_POWS } from '../../bigint-constants'; import { FluidDex } from './fluid-dex'; -import { CollateralReserves, DebtReserves } from './types'; import { checkPoolPrices, checkPoolsLiquidity, @@ -54,8 +53,6 @@ function decodeReaderResult( funcName: string, ) { return results.map(result => { - // const parsed = readerIface.decodeFunctionResult(funcName, result); - // console.log("result is " + BigInt(result)); return BigInt(result); }); } @@ -86,21 +83,6 @@ async function checkOnChainPricing( const expectedPrices = [0n].concat( decodeReaderResult(readerResult, readerIface, funcName), ); - - console.log('prices from getPricesVolume : ' + prices); - console.log('prices fetched from reserves : ' + expectedPrices); - - // expect(prices).toEqual(expectedPrices); - // expect(prices).toEqual( - // expect.arrayContaining( - // expectedPrices.map(expected => ({ - // asymmetricMatch: (actual: bigint) => { - // const diff = (actual - expected) * 100n / expected; - // return diff >= -1n && diff <= 1n; - // } - // })) - // ) - // ); } async function testPricingOnNetwork( @@ -242,6 +224,7 @@ describe('FluidDex', function () { // We have to check without calling initializePricing, because // pool-tracker is not calling that function const newFluidDex = new FluidDex(network, dexKey, dexHelper); + await newFluidDex.initializePricing(blockNumber); if (newFluidDex.updatePoolState) { await newFluidDex.updatePoolState(); } @@ -249,7 +232,6 @@ describe('FluidDex', function () { tokens[srcTokenSymbol].address, 1, ); - console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); if (!newFluidDex.hasConstantPriceLargeAmounts) { checkPoolsLiquidity( diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 155672e11..383a9afa0 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -6,13 +6,16 @@ import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; -import { FluidDexPool, FluidDexPoolState, PoolWithReserves } from './types'; -import { ethers } from 'ethers'; -import { eachOfSeries } from 'async'; +import { + commonAddresses, + FluidDexPool, + FluidDexPoolState, + PoolWithReserves, +} from './types'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; import { BytesLike } from 'ethers/lib/utils'; import { Address } from '../../types'; -import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; +import { generalDecoder } from '../../lib/decoders'; export class FluidDexEventPool extends StatefulEventSubscriber { handlers: { @@ -31,6 +34,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber this.liquidityIface.parseLog(log); - this.addressesSubscribed = [pool.liquidityProxy]; + this.addressesSubscribed = [commonAddresses.liquidityProxy]; // Add handlers this.handlers['LogOperate'] = this.handleOperate.bind(this); @@ -58,7 +62,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber[] = [ { - target: this.pool.resolver, + target: this.commonAddresses.resolver, callData: resolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), @@ -140,17 +144,6 @@ export class FluidDexEventPool extends StatefulEventSubscriber | BytesLike, - ): result is MultiResult => { - return ( - typeof result === 'object' && - result !== null && - 'success' in result && - 'returnData' in result - ); - }; - /** * The function is called every time any of the subscribed * addresses release log. The function accepts the current @@ -178,7 +171,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber { let state = this.getState(blockNumber); if (!state) { @@ -203,7 +196,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber[] = [ { - target: this.pool.resolver, + target: this.commonAddresses.resolver, callData: resolverAbi.encodeFunctionData('getPoolReserves', [ this.pool.address, ]), diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 8c77ac015..9c9d68f4d 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -23,6 +23,7 @@ import { FluidDexPool, FluidDexPoolState, Pool, + commonAddresses, } from './types'; import { SimpleExchange, @@ -31,13 +32,20 @@ import { import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json'; import { FluidDexConfig, Adapters, FLUID_DEX_GAS_COST } from './config'; import { FluidDexEventPool } from './fluid-dex-pool'; +import { FluidDexCommonAddresses } from './fluid-dex-generate-pool'; import { applyTransferFee } from '../../lib/token-transfer-fee'; import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; import { extractReturnAmountPosition } from '../../executor/utils'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; import { BytesLike } from 'ethers/lib/utils'; -import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; +import { + generalDecoder, + extractSuccessAndValue, + addressDecode, +} from '../../lib/decoders'; +// @ts-ignore +import { Tokens } from '../../../tests/constants-e2e'; export class FluidDex extends SimpleExchange implements IDex { readonly eventPools: { [id: string]: FluidDexEventPool } = {}; @@ -49,13 +57,11 @@ export class FluidDex extends SimpleExchange implements IDex { logger: Logger; - readonly pools: [FluidDexPool]; - - readonly iFluidDexPool: Interface; + pools: FluidDexPool[]; - // readonly liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497'; + readonly FluidCommonAddresses: FluidDexCommonAddresses; - // readonly resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330'; + readonly iFluidDexPool: Interface; protected adapters; @@ -68,17 +74,43 @@ export class FluidDex extends SimpleExchange implements IDex { ) { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); + this.FluidCommonAddresses = new FluidDexCommonAddresses( + 'FluidDex', + FluidDexConfig['FluidDex'][network].commonAddresses, + network, + dexHelper, + this.logger, + ); this.pools = FluidDexConfig['FluidDex'][network].pools; this.adapters = Adapters[network] || {}; this.iFluidDexPool = new Interface(FluidDexPoolABI); + } + + async fetchFluidDexPools(blockNumber: number): Promise { + const poolsFromResolver = + await this.FluidCommonAddresses.getStateOrGenerate(blockNumber, false); + + return poolsFromResolver.map(pool => ({ + id: `FluidDex_${pool.address}`, + address: pool.address, + token0: pool.token0, + token1: pool.token1, + })); + } + + async updatePoolAndEventPool(blockNumber: number) { + this.pools = await this.fetchFluidDexPools(blockNumber); for (const pool of this.pools) { - this.eventPools[pool.id] = new FluidDexEventPool( - 'FluidDex', - pool, - network, - dexHelper, - this.logger, - ); + if (!this.eventPools[pool.id]) { + this.eventPools[pool.id] = new FluidDexEventPool( + 'FluidDex', + pool, + this.FluidCommonAddresses.commonAddresses, + this.network, + this.dexHelper, + this.logger, + ); + } } } @@ -90,6 +122,7 @@ export class FluidDex extends SimpleExchange implements IDex { Object.entries(this.eventPools).forEach(([id, eventPool]) => { eventPool.getStateOrGenerate(blockNumber, false); }); + await this.updatePoolAndEventPool(blockNumber); } // Returns the list of contract adapters (name and index) @@ -98,25 +131,6 @@ export class FluidDex extends SimpleExchange implements IDex { return this.adapters[side] ? this.adapters[side] : null; } - // async getPoolsFromResolver() { - // const resolverAbi = new Interface(ResolverABI); - // const callData: MultiCallParams[] = [ - // { - // target: this.resolver, - // callData: resolverAbi.encodeFunctionData('getAllPools', []), - // decodeFunction: this.decodePools, - // }, - // ]; - - // const results: Pool[][] = - // await this.dexHelper.multiWrapper.aggregate( - // callData, - // await this.dexHelper.provider.getBlockNumber(), - // this.dexHelper.multiWrapper.defaultBatchSize, - // ); - - // } - decodePools = (result: MultiResult | BytesLike): Pool[] => { return generalDecoder( result, @@ -124,9 +138,9 @@ export class FluidDex extends SimpleExchange implements IDex { undefined, decoded => { return decoded.map((decodedPool: any) => ({ - address: decodedPool.pool, - token0: decodedPool.token0, - token1: decodedPool.token1, + address: decodedPool[0][0].toLowerCase(), + token0: decodedPool[0][1].toLowerCase(), + token1: decodedPool[0][2].toLowerCase(), })); }, ); @@ -142,14 +156,18 @@ export class FluidDex extends SimpleExchange implements IDex { side: SwapSide, blockNumber: number, ): Promise { - const pool = this.getPoolByTokenPair(srcToken.address, destToken.address); + await this.updatePoolAndEventPool(blockNumber); + const pool = await this.getPoolByTokenPair( + srcToken.address, + destToken.address, + ); return pool ? [pool.id] : []; } - getPoolByTokenPair( + async getPoolByTokenPair( srcToken: Address, destToken: Address, - ): FluidDexPool | null { + ): Promise { const srcAddress = srcToken.toLowerCase(); const destAddress = destToken.toLowerCase(); @@ -179,9 +197,14 @@ export class FluidDex extends SimpleExchange implements IDex { blockNumber: number, limitPools?: string[], ): Promise> { + await this.updatePoolAndEventPool(blockNumber); try { + if (side === SwapSide.BUY) throw new Error(`Buy not supported`); // Get the pool to use. - const pool = this.getPoolByTokenPair(srcToken.address, destToken.address); + const pool = await this.getPoolByTokenPair( + srcToken.address, + destToken.address, + ); if (!pool) return null; // Make sure the pool meets the optional limitPools filter. @@ -212,17 +235,15 @@ export class FluidDex extends SimpleExchange implements IDex { BigInt(state.fee), ); } else { - return null; - - // return this.swapOut( - // !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), - // amount, - // state.collateralReserves, - // state.debtReserves, - // srcToken.decimals, - // destToken.decimals, - // BigInt(state.fee), - // ); + return this.swapOut( + !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), + amount, + state.collateralReserves, + state.debtReserves, + srcToken.decimals, + destToken.decimals, + BigInt(state.fee), + ); } }); @@ -272,6 +293,7 @@ export class FluidDex extends SimpleExchange implements IDex { data: FluidDexData, side: SwapSide, ): AdapterExchangeParam { + if (side === SwapSide.BUY) throw new Error(`Buy not supported`); const { exchange } = data; // Encode here the payload for adapter @@ -299,6 +321,9 @@ export class FluidDex extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { + await this.updatePoolAndEventPool( + await this.dexHelper.provider.getBlockNumber(), + ); let liquidityAmounts: { [id: string]: bigint } = {}; for (const pool of this.pools) { if ( @@ -349,13 +374,39 @@ export class FluidDex extends SimpleExchange implements IDex { false, ); + let token0decimals: number; + for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { + let found = false; + for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { + if (tokenParams.address.toLowerCase() === pool.token0.toLowerCase()) { + token0decimals = tokenParams.decimals; + found = true; + break; + } + if (found) break; + } + } + + let token1decimals: number; + for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { + let found = false; + for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { + if (tokenParams.address.toLowerCase() === pool.token1.toLowerCase()) { + token1decimals = tokenParams.decimals; + found = true; + break; + } + if (found) break; + } + } + const usd0 = await this.dexHelper.getTokenUSDPrice( - { address: pool.token0, decimals: 18 }, + { address: pool.token0, decimals: token0decimals! }, state.collateralReserves.token0RealReserves + state.debtReserves.token0RealReserves, ); const usd1 = await this.dexHelper.getTokenUSDPrice( - { address: pool.token1, decimals: 18 }, + { address: pool.token1, decimals: token1decimals! }, state.collateralReserves.token1RealReserves + state.debtReserves.token1RealReserves, ); @@ -370,7 +421,7 @@ export class FluidDex extends SimpleExchange implements IDex { return poolLiquidities; } - getDexParam( + async getDexParam( srcToken: Address, destToken: Address, srcAmount: string, @@ -380,12 +431,11 @@ export class FluidDex extends SimpleExchange implements IDex { side: SwapSide, context: Context, executorAddress: Address, - ): AsyncOrSync { - if (srcToken == '0xEeeeeEeeeeeeEeeeeeeEeeeeEeeeeeEeeeeEeeeE') { - throw new Error( - 'srcToken can not be Native ETH, try exchanging tokens and swapSide', - ); - } + ): Promise { + const latestBlockNumber = await this.dexHelper.provider.getBlockNumber(); + await this.updatePoolAndEventPool(latestBlockNumber); + + if (side === SwapSide.BUY) throw new Error(`Buy not supported`); let method: string; let args: any; @@ -402,7 +452,7 @@ export class FluidDex extends SimpleExchange implements IDex { 1, ); - const pool = this.getPoolByTokenPair(srcToken, destToken); + const pool = await this.getPoolByTokenPair(srcToken, destToken); if (side == SwapSide.SELL) { if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { @@ -411,19 +461,11 @@ export class FluidDex extends SimpleExchange implements IDex { args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; } } else { - return { - needWrapNative: false, - exchangeData: '', - targetExchange: 'Invalid', - dexFuncHasRecipient: false, - returnAmountPos: undefined, - }; - - // if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - // args = [true, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; - // } else { - // args = [false, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; - // } + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [true, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; + } else { + args = [false, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; + } } const swapData = this.iFluidDexPool.encodeFunctionData(method, args); diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 8b345d8ec..6f8834975 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -41,14 +41,22 @@ export type FluidDexData = { export type FluidDexPool = { id: string; address: Address; - liquidityProxy: Address; - resolver: Address; token0: Address; token1: Address; }; export type DexParams = { - pools: [FluidDexPool]; + // TODO: DexParams is set of parameters the can + // be used to initiate a DEX fork. + // Complete me! + commonAddresses: commonAddresses; + pools: FluidDexPool[]; +}; + +export type commonAddresses = { + liquidityProxy: Address; + resolver: Address; + dexFactory: Address; }; export type Pool = { diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index aa181a6c0..eaed5f8c7 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -7,6 +7,7 @@ import { allowedFn, _balancesFn, _allowancesFn, + // @ts-ignore } from '../tests/smart-tokens'; import { Address } from '../src/types'; import { ETHER_ADDRESS, Network } from '../src/constants'; From b1c21386ad2f672ac4ad22a821d2fae8fa9abc5f Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Wed, 9 Oct 2024 16:15:10 +0530 Subject: [PATCH 19/64] resolved block fetching issue --- src/dex/fluid-dex/fluid-dex-generate-pool.ts | 5 ++-- src/dex/fluid-dex/fluid-dex.ts | 24 ++++++++------------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts index a0794096b..2e9043671 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -59,6 +59,7 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { state: DeepReadonly, log: Readonly, ): Promise | null> { + const blockNumber_ = await this.dexHelper.provider.getBlockNumber(); const resolverAbi = new Interface(ResolverABI); const callData: MultiCallParams[] = [ { @@ -70,7 +71,7 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { const results: Pool[] = await this.dexHelper.multiWrapper.aggregate( callData, - await this.dexHelper.provider.getBlockNumber(), + blockNumber_, this.dexHelper.multiWrapper.defaultBatchSize, ); @@ -84,7 +85,7 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { currentPool = currentPool == null ? [] : currentPool; currentPool = [...currentPool, generatedPool]; - this.setState(currentPool, await this.dexHelper.provider.getBlockNumber()); + this.setState(currentPool, blockNumber_); return currentPool; } diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 9c9d68f4d..559224ddc 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -312,7 +312,9 @@ export class FluidDex extends SimpleExchange implements IDex { // getTopPoolsForToken. It is optional for a DEX // to implement this async updatePoolState(): Promise { - this.initializePricing(await this.dexHelper.provider.getBlockNumber()); + this.initializePricing( + await this.dexHelper.web3Provider.eth.getBlockNumber(), + ); } // Returns list of top pools based on liquidity. Max @@ -321,9 +323,8 @@ export class FluidDex extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { - await this.updatePoolAndEventPool( - await this.dexHelper.provider.getBlockNumber(), - ); + const latestBlockNumber_ = + await this.dexHelper.web3Provider.eth.getBlockNumber(); let liquidityAmounts: { [id: string]: bigint } = {}; for (const pool of this.pools) { if ( @@ -332,10 +333,7 @@ export class FluidDex extends SimpleExchange implements IDex { ) { const state: FluidDexPoolState = await this.eventPools[ pool.id - ].getStateOrGenerate( - await this.dexHelper.provider.getBlockNumber(), - false, - ); + ].getStateOrGenerate(latestBlockNumber_, false); liquidityAmounts[pool.id] = pool.token0 === tokenAddress @@ -369,10 +367,7 @@ export class FluidDex extends SimpleExchange implements IDex { const state: FluidDexPoolState = await this.eventPools[ pool.id - ].getStateOrGenerate( - await this.dexHelper.provider.getBlockNumber(), - false, - ); + ].getStateOrGenerate(latestBlockNumber_, false); let token0decimals: number; for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { @@ -432,8 +427,9 @@ export class FluidDex extends SimpleExchange implements IDex { context: Context, executorAddress: Address, ): Promise { - const latestBlockNumber = await this.dexHelper.provider.getBlockNumber(); - await this.updatePoolAndEventPool(latestBlockNumber); + const latestBlockNumber_ = + await this.dexHelper.web3Provider.eth.getBlockNumber(); + await this.updatePoolAndEventPool(latestBlockNumber_); if (side === SwapSide.BUY) throw new Error(`Buy not supported`); From 141e2e5244625348b6ef5212d44bd0946211ae5e Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Wed, 9 Oct 2024 20:27:14 +0530 Subject: [PATCH 20/64] dex deployed event working --- src/dex/fluid-dex/fluid-dex-events.test.ts | 64 +++++++++++++------- src/dex/fluid-dex/fluid-dex-generate-pool.ts | 5 +- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 4d70116bc..df50a0691 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -3,12 +3,19 @@ import dotenv from 'dotenv'; dotenv.config(); import { FluidDexEventPool } from './fluid-dex-pool'; +import { FluidDexCommonAddresses } from './fluid-dex-generate-pool'; import { Network } from '../../constants'; import { Address } from '../../types'; import { DummyDexHelper } from '../../dex-helper/index'; import { testEventSubscriber } from '../../../tests/utils-events'; -import { FluidDexPool, FluidDexPoolState } from './types'; +import { + commonAddresses, + FluidDexPool, + FluidDexPoolState, + Pool, +} from './types'; import { FluidDexConfig } from './config'; +import { DeepReadonly } from 'ts-essentials'; /* README @@ -49,7 +56,14 @@ async function fetchPoolState( fluidDexPool: FluidDexEventPool, blockNumber: number, ): Promise { - return fluidDexPool.generateState(blockNumber); + return await fluidDexPool.generateState(blockNumber); +} + +async function fetchTotalPools( + fluidCommonAddresses: FluidDexCommonAddresses, + blockNumber: number, +): Promise> { + return await fluidCommonAddresses.generateState(blockNumber); } // eventName -> blockNumbers @@ -60,29 +74,31 @@ describe('FluidDex EventPool Mainnet', function () { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); - const fluidDexPool: FluidDexPool = FluidDexConfig[dexKey][network].pools[0]; - const liquidityProxy: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; + const fluidDexCommonAddressStruct: commonAddresses = + FluidDexConfig[dexKey][network].commonAddresses; + const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; + const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; // poolAddress -> EventMappings const eventsToTest: Record = { - [liquidityProxy]: { - DexDeployed: [20776998], + [dexFactory]: { + DexDeployed: [20825862], + // DexDeployed: [20776998], }, }; let fluidDexEventPool: FluidDexEventPool; - let fluidDexCommonAddress; - - // beforeEach(async () => { - // fluidDexEventPool = new FluidDexEventPool( - // 'FluidDex', - // fluidDexPool, - // network, - // dexHelper, - // logger, - // ); - - // }); + let fluidDexCommonAddress: FluidDexCommonAddresses; + + beforeEach(async () => { + fluidDexCommonAddress = new FluidDexCommonAddresses( + 'FluidDex', + fluidDexCommonAddressStruct, + network, + dexHelper, + logger, + ); + }); Object.entries(eventsToTest).forEach( ([poolAddress, events]: [string, EventMappings]) => { @@ -92,11 +108,17 @@ describe('FluidDex EventPool Mainnet', function () { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async function () { + // console.log("test1", await fetchTotalPools(fluidDexCommonAddress, 20776997)); + // const latestBlockNumber_ = (await dexHelper.web3Provider.eth.getBlockNumber()) - 102774; + // console.log(latestBlockNumber_); + // console.log("test10", await fluidDexCommonAddress.generateState(blockNumber)); + // console.log("test100", await fluidDexCommonAddress.generateState(await dexHelper.web3Provider.eth.getBlockNumber())); + await testEventSubscriber( - fluidDexEventPool, - fluidDexEventPool.addressesSubscribed, + fluidDexCommonAddress, + fluidDexCommonAddress.addressesSubscribed, (_blockNumber: number) => - fetchPoolState(fluidDexEventPool, _blockNumber), + fetchTotalPools(fluidDexCommonAddress, _blockNumber), blockNumber, `${dexKey}_${poolAddress}`, dexHelper.provider, diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts index 2e9043671..cb8ba370a 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -59,7 +59,7 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { state: DeepReadonly, log: Readonly, ): Promise | null> { - const blockNumber_ = await this.dexHelper.provider.getBlockNumber(); + const blockNumber_ = await this.dexHelper.web3Provider.eth.getBlockNumber(); const resolverAbi = new Interface(ResolverABI); const callData: MultiCallParams[] = [ { @@ -179,6 +179,9 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { } decodePools = (result: MultiResult | BytesLike): Pool[] => { + if (result === '0x') { + return []; // Return an empty array since there are no pools to decode + } return generalDecoder( result, ['tuple(address pool, address token0, address token1)[]'], From 7ea068498877c30fa5ca59504a9a51ba114dd181 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 10 Oct 2024 02:24:50 +0530 Subject: [PATCH 21/64] logOperate event half done --- src/dex/fluid-dex/fluid-dex-events.test.ts | 102 ++++++++++++++++----- src/dex/fluid-dex/fluid-dex-pool.ts | 10 +- src/dex/fluid-dex/fluid-dex.ts | 2 +- 3 files changed, 86 insertions(+), 28 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index df50a0691..cd731d22f 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -4,6 +4,7 @@ dotenv.config(); import { FluidDexEventPool } from './fluid-dex-pool'; import { FluidDexCommonAddresses } from './fluid-dex-generate-pool'; +import { FluidDex } from './fluid-dex'; import { Network } from '../../constants'; import { Address } from '../../types'; import { DummyDexHelper } from '../../dex-helper/index'; @@ -66,6 +67,23 @@ async function fetchTotalPools( return await fluidCommonAddresses.generateState(blockNumber); } +function stringifyCircular(obj: any, space?: number): string { + const seen = new WeakSet(); + return JSON.stringify( + obj, + (key, value) => { + if (typeof value === 'object' && value !== null) { + if (seen.has(value)) { + return '[Circular]'; + } + seen.add(value); + } + return value; + }, + space, + ); +} + // eventName -> blockNumbers type EventMappings = Record; @@ -79,28 +97,23 @@ describe('FluidDex EventPool Mainnet', function () { const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; - // poolAddress -> EventMappings - const eventsToTest: Record = { + const poolFetchEventsToTest: Record = { [dexFactory]: { DexDeployed: [20825862], - // DexDeployed: [20776998], + }, + }; + + // poolAddress -> EventMappings + const poolUpdateEventsToTest: Record = { + [dexFactory]: { + LogOperate: [20825862], }, }; let fluidDexEventPool: FluidDexEventPool; let fluidDexCommonAddress: FluidDexCommonAddresses; - beforeEach(async () => { - fluidDexCommonAddress = new FluidDexCommonAddresses( - 'FluidDex', - fluidDexCommonAddressStruct, - network, - dexHelper, - logger, - ); - }); - - Object.entries(eventsToTest).forEach( + Object.entries(poolUpdateEventsToTest).forEach( ([poolAddress, events]: [string, EventMappings]) => { describe(`Events for ${poolAddress}`, () => { Object.entries(events).forEach( @@ -108,17 +121,26 @@ describe('FluidDex EventPool Mainnet', function () { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async function () { - // console.log("test1", await fetchTotalPools(fluidDexCommonAddress, 20776997)); - // const latestBlockNumber_ = (await dexHelper.web3Provider.eth.getBlockNumber()) - 102774; - // console.log(latestBlockNumber_); - // console.log("test10", await fluidDexCommonAddress.generateState(blockNumber)); - // console.log("test100", await fluidDexCommonAddress.generateState(await dexHelper.web3Provider.eth.getBlockNumber())); + const fluidDex = new FluidDex(network, dexKey, dexHelper); + + // const latestBlockNumber_ = await dexHelper.web3Provider.eth.getBlockNumber(); + + await fluidDex.initializePricing(blockNumber); + + // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)); + + fluidDexEventPool = + fluidDex.eventPools[ + 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' + ]; + + console.log(fluidDexEventPool); await testEventSubscriber( - fluidDexCommonAddress, - fluidDexCommonAddress.addressesSubscribed, + fluidDexEventPool, + fluidDexEventPool.addressesSubscribed, (_blockNumber: number) => - fetchTotalPools(fluidDexCommonAddress, _blockNumber), + fetchPoolState(fluidDexEventPool, _blockNumber), blockNumber, `${dexKey}_${poolAddress}`, dexHelper.provider, @@ -131,4 +153,40 @@ describe('FluidDex EventPool Mainnet', function () { }); }, ); + + // Object.entries(poolFetchEventsToTest).forEach( + // ([poolAddress, events]: [string, EventMappings]) => { + // describe(`Events for ${poolAddress}`, () => { + // Object.entries(events).forEach( + // ([eventName, blockNumbers]: [string, number[]]) => { + // describe(`${eventName}`, () => { + // blockNumbers.forEach((blockNumber: number) => { + // it(`State after ${blockNumber}`, async function () { + + // fluidDexCommonAddress = new FluidDexCommonAddresses( + // 'FluidDex', + // fluidDexCommonAddressStruct, + // network, + // dexHelper, + // logger, + // ); + + // await testEventSubscriber( + // fluidDexCommonAddress, + // fluidDexCommonAddress.addressesSubscribed, + // (_blockNumber: number) => + // fetchTotalPools(fluidDexCommonAddress, _blockNumber), + // blockNumber, + // `${dexKey}_${poolAddress}`, + // dexHelper.provider, + // ); + + // }); + // }); + // }); + // }, + // ); + // }); + // }, + // ); }); diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 383a9afa0..a0e7c5c1c 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -33,13 +33,13 @@ export class FluidDexEventPool extends StatefulEventSubscriber this.liquidityIface.parseLog(log); this.addressesSubscribed = [commonAddresses.liquidityProxy]; @@ -57,14 +57,14 @@ export class FluidDexEventPool extends StatefulEventSubscriber, ): Promise | null> { const resolverAbi = new Interface(ResolverABI); - if (!(event.args.user in [this.pool.address])) { + if (!(event.args.user in [this.pool])) { return null; } const callData: MultiCallParams[] = [ { target: this.commonAddresses.resolver, callData: resolverAbi.encodeFunctionData('getPoolReserves', [ - this.pool.address, + this.pool, ]), decodeFunction: await this.decodePoolWithReserves, }, @@ -198,7 +198,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber { if (!this.eventPools[pool.id]) { this.eventPools[pool.id] = new FluidDexEventPool( 'FluidDex', - pool, + pool.address, this.FluidCommonAddresses.commonAddresses, this.network, this.dexHelper, From 3bf4f7f98d99f0b5ce23cb22ca95436272d49c52 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 10 Oct 2024 02:37:55 +0530 Subject: [PATCH 22/64] minor change --- src/dex/fluid-dex/fluid-dex-events.test.ts | 70 +++++++++++----------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index cd731d22f..eb0919cb0 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -127,7 +127,7 @@ describe('FluidDex EventPool Mainnet', function () { await fluidDex.initializePricing(blockNumber); - // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)); + // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)) fluidDexEventPool = fluidDex.eventPools[ @@ -154,39 +154,37 @@ describe('FluidDex EventPool Mainnet', function () { }, ); - // Object.entries(poolFetchEventsToTest).forEach( - // ([poolAddress, events]: [string, EventMappings]) => { - // describe(`Events for ${poolAddress}`, () => { - // Object.entries(events).forEach( - // ([eventName, blockNumbers]: [string, number[]]) => { - // describe(`${eventName}`, () => { - // blockNumbers.forEach((blockNumber: number) => { - // it(`State after ${blockNumber}`, async function () { - - // fluidDexCommonAddress = new FluidDexCommonAddresses( - // 'FluidDex', - // fluidDexCommonAddressStruct, - // network, - // dexHelper, - // logger, - // ); - - // await testEventSubscriber( - // fluidDexCommonAddress, - // fluidDexCommonAddress.addressesSubscribed, - // (_blockNumber: number) => - // fetchTotalPools(fluidDexCommonAddress, _blockNumber), - // blockNumber, - // `${dexKey}_${poolAddress}`, - // dexHelper.provider, - // ); - - // }); - // }); - // }); - // }, - // ); - // }); - // }, - // ); + Object.entries(poolFetchEventsToTest).forEach( + ([poolAddress, events]: [string, EventMappings]) => { + describe(`Events for ${poolAddress}`, () => { + Object.entries(events).forEach( + ([eventName, blockNumbers]: [string, number[]]) => { + describe(`${eventName}`, () => { + blockNumbers.forEach((blockNumber: number) => { + it(`State after ${blockNumber}`, async function () { + fluidDexCommonAddress = new FluidDexCommonAddresses( + 'FluidDex', + fluidDexCommonAddressStruct, + network, + dexHelper, + logger, + ); + + await testEventSubscriber( + fluidDexCommonAddress, + fluidDexCommonAddress.addressesSubscribed, + (_blockNumber: number) => + fetchTotalPools(fluidDexCommonAddress, _blockNumber), + blockNumber, + `${dexKey}_${poolAddress}`, + dexHelper.provider, + ); + }); + }); + }); + }, + ); + }); + }, + ); }); From 5c93db7780babeb247bd1ccfbfecd704ca96af22 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 10 Oct 2024 21:43:16 +0530 Subject: [PATCH 23/64] added test for logoperate function --- src/dex/fluid-dex/fluid-dex-events.test.ts | 140 +++++++++++++++------ 1 file changed, 104 insertions(+), 36 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index eb0919cb0..7a256ec2b 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -17,6 +17,11 @@ import { } from './types'; import { FluidDexConfig } from './config'; import { DeepReadonly } from 'ts-essentials'; +import { + EstimateGasSimulation, + TenderlySimulation, + TransactionSimulator, +} from '../../../tests/tenderly-simulation'; /* README @@ -84,6 +89,13 @@ function stringifyCircular(obj: any, space?: number): string { ); } +function replacer(key: string, value: any) { + if (typeof value === 'bigint') { + return value.toString(); + } + return value; +} + // eventName -> blockNumbers type EventMappings = Record; @@ -127,21 +139,77 @@ describe('FluidDex EventPool Mainnet', function () { await fluidDex.initializePricing(blockNumber); - // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)) - fluidDexEventPool = fluidDex.eventPools[ 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' ]; - console.log(fluidDexEventPool); + // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)) + + const ts: TransactionSimulator = new TenderlySimulation( + network, + ); + + await ts.setup(); + + const allowanceTxn = await ts.simulate({ + from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment + value: '0', + data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', + }); + + // console.log(allowanceTxn); + + const swapTxn = await ts.simulate({ + from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment + value: '0', + data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', + }); + + // console.log(swapTxn); + + const txnBlockNumber = swapTxn.transaction.block_number; + + console.log( + 'old values : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + txnBlockNumber - 4, + ), + replacer, + 2, + ), + ); + console.log( + 'old values : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + txnBlockNumber - 3, + ), + replacer, + 2, + ), + ); + console.log( + 'old values : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + txnBlockNumber - 2, + ), + replacer, + 2, + ), + ); + // console.log(fluidDexEventPool); await testEventSubscriber( fluidDexEventPool, fluidDexEventPool.addressesSubscribed, (_blockNumber: number) => fetchPoolState(fluidDexEventPool, _blockNumber), - blockNumber, + txnBlockNumber, `${dexKey}_${poolAddress}`, dexHelper.provider, ); @@ -154,37 +222,37 @@ describe('FluidDex EventPool Mainnet', function () { }, ); - Object.entries(poolFetchEventsToTest).forEach( - ([poolAddress, events]: [string, EventMappings]) => { - describe(`Events for ${poolAddress}`, () => { - Object.entries(events).forEach( - ([eventName, blockNumbers]: [string, number[]]) => { - describe(`${eventName}`, () => { - blockNumbers.forEach((blockNumber: number) => { - it(`State after ${blockNumber}`, async function () { - fluidDexCommonAddress = new FluidDexCommonAddresses( - 'FluidDex', - fluidDexCommonAddressStruct, - network, - dexHelper, - logger, - ); + // Object.entries(poolFetchEventsToTest).forEach( + // ([poolAddress, events]: [string, EventMappings]) => { + // describe(`Events for ${poolAddress}`, () => { + // Object.entries(events).forEach( + // ([eventName, blockNumbers]: [string, number[]]) => { + // describe(`${eventName}`, () => { + // blockNumbers.forEach((blockNumber: number) => { + // it(`State after ${blockNumber}`, async function () { + // fluidDexCommonAddress = new FluidDexCommonAddresses( + // 'FluidDex', + // fluidDexCommonAddressStruct, + // network, + // dexHelper, + // logger, + // ); - await testEventSubscriber( - fluidDexCommonAddress, - fluidDexCommonAddress.addressesSubscribed, - (_blockNumber: number) => - fetchTotalPools(fluidDexCommonAddress, _blockNumber), - blockNumber, - `${dexKey}_${poolAddress}`, - dexHelper.provider, - ); - }); - }); - }); - }, - ); - }); - }, - ); + // await testEventSubscriber( + // fluidDexCommonAddress, + // fluidDexCommonAddress.addressesSubscribed, + // (_blockNumber: number) => + // fetchTotalPools(fluidDexCommonAddress, _blockNumber), + // blockNumber, + // `${dexKey}_${poolAddress}`, + // dexHelper.provider, + // ); + // }); + // }); + // }); + // }, + // ); + // }); + // }, + // ); }); From f991071da68bb85132031b01fe42678fa83dc680 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Thu, 10 Oct 2024 22:20:50 +0530 Subject: [PATCH 24/64] written all tests --- src/dex/fluid-dex/fluid-dex-events.test.ts | 100 +++++++++------------ 1 file changed, 41 insertions(+), 59 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 7a256ec2b..5c49f0609 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -168,38 +168,20 @@ describe('FluidDex EventPool Mainnet', function () { data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', }); - // console.log(swapTxn); + console.log(swapTxn); const txnBlockNumber = swapTxn.transaction.block_number; + const txnhash = + swapTxn.transaction.transaction_info.transaction_id; + console.log(txnhash); + console.log( - 'old values : ' + - JSON.stringify( - await fluidDexEventPool.generateState( - txnBlockNumber - 4, - ), - replacer, - 2, - ), - ); - console.log( - 'old values : ' + - JSON.stringify( - await fluidDexEventPool.generateState( - txnBlockNumber - 3, - ), - replacer, - 2, - ), - ); - console.log( - 'old values : ' + + 'retreiving txn : ' + JSON.stringify( - await fluidDexEventPool.generateState( - txnBlockNumber - 2, + await dexHelper.web3Provider.eth.getTransaction( + txnhash, ), - replacer, - 2, ), ); // console.log(fluidDexEventPool); @@ -222,37 +204,37 @@ describe('FluidDex EventPool Mainnet', function () { }, ); - // Object.entries(poolFetchEventsToTest).forEach( - // ([poolAddress, events]: [string, EventMappings]) => { - // describe(`Events for ${poolAddress}`, () => { - // Object.entries(events).forEach( - // ([eventName, blockNumbers]: [string, number[]]) => { - // describe(`${eventName}`, () => { - // blockNumbers.forEach((blockNumber: number) => { - // it(`State after ${blockNumber}`, async function () { - // fluidDexCommonAddress = new FluidDexCommonAddresses( - // 'FluidDex', - // fluidDexCommonAddressStruct, - // network, - // dexHelper, - // logger, - // ); - - // await testEventSubscriber( - // fluidDexCommonAddress, - // fluidDexCommonAddress.addressesSubscribed, - // (_blockNumber: number) => - // fetchTotalPools(fluidDexCommonAddress, _blockNumber), - // blockNumber, - // `${dexKey}_${poolAddress}`, - // dexHelper.provider, - // ); - // }); - // }); - // }); - // }, - // ); - // }); - // }, - // ); + Object.entries(poolFetchEventsToTest).forEach( + ([poolAddress, events]: [string, EventMappings]) => { + describe(`Events for ${poolAddress}`, () => { + Object.entries(events).forEach( + ([eventName, blockNumbers]: [string, number[]]) => { + describe(`${eventName}`, () => { + blockNumbers.forEach((blockNumber: number) => { + it(`State after ${blockNumber}`, async function () { + fluidDexCommonAddress = new FluidDexCommonAddresses( + 'FluidDex', + fluidDexCommonAddressStruct, + network, + dexHelper, + logger, + ); + + await testEventSubscriber( + fluidDexCommonAddress, + fluidDexCommonAddress.addressesSubscribed, + (_blockNumber: number) => + fetchTotalPools(fluidDexCommonAddress, _blockNumber), + blockNumber, + `${dexKey}_${poolAddress}`, + dexHelper.provider, + ); + }); + }); + }); + }, + ); + }); + }, + ); }); From 68719465c4b80db6d8b756e32956c71a65fb4513 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Sat, 12 Oct 2024 14:30:54 +0530 Subject: [PATCH 25/64] made changes --- src/dex/fluid-dex/fluid-dex-events.test.ts | 202 ++++++++++++++++----- 1 file changed, 156 insertions(+), 46 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 5c49f0609..1f746089e 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -72,6 +72,10 @@ async function fetchTotalPools( return await fluidCommonAddresses.generateState(blockNumber); } +function delay(ms: number): Promise { + return new Promise(resolve => setTimeout(resolve, ms)); +} + function stringifyCircular(obj: any, space?: number): string { const seen = new WeakSet(); return JSON.stringify( @@ -133,25 +137,73 @@ describe('FluidDex EventPool Mainnet', function () { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async function () { + // const forkProvider = new ethers.JsonRpcProvider('https://mainnet.gateway.tenderly.co/5aa2627c-c6b9-4aa7-beec-a7352f78726b') + const fluidDex = new FluidDex(network, dexKey, dexHelper); // const latestBlockNumber_ = await dexHelper.web3Provider.eth.getBlockNumber(); await fluidDex.initializePricing(blockNumber); + // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)) + + const ts: TenderlySimulation = new TenderlySimulation( + network, + '5aa2627c-c6b9-4aa7-beec-a7352f78726b', + ); + + await ts.setup(); + + const forkId = ts.forkId; + console.log('this is ts fork id : ' + forkId); + dexHelper.replaceProviderWithRPC( + `https://rpc.tenderly.co/fork/${forkId}`, + ); + // console.log("this is fork id : ", dexHelper.web3Provider, null, 2); + console.log( + 'this is fork id : ', + JSON.stringify(dexHelper.provider, null, 2), + ); + fluidDexEventPool = fluidDex.eventPools[ 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' ]; - // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)) + // console.log("eth balance before sned : " + await dexHelper.provider.getBalance('0x1928347619834761983764191827346198723646')); - const ts: TransactionSimulator = new TenderlySimulation( - network, - ); + // const senddTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x1928347619834761983764191827346198723646', // undefined in case of contract deployment + // value: '1234', + // data: '', + // }); - await ts.setup(); + // const senddTxn2 = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x1928347619834761983764191827346198723646', // undefined in case of contract deployment + // value: '1234', + // data: '', + // }); + + // // console.log(JSON.stringify(senddTxn)); + + // console.log(JSON.stringify(ts)); + // console.log("eth balance after sned : " + await dexHelper.provider.getBalance('0x1928347619834761983764191827346198723646')); + console.log( + 'eth balance before : ' + + (await dexHelper.provider.getBalance( + '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + )), + ); + + // const allowanceTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment + // value: '0', + // data: '0x095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03a0000000000000000000000000000000000000000000000056bc75e2d63100000', + // }); const allowanceTxn = await ts.simulate({ from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment @@ -159,8 +211,14 @@ describe('FluidDex EventPool Mainnet', function () { data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', }); - // console.log(allowanceTxn); + console.log(allowanceTxn); + // const swapTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x6d83f60eeac0e50a1250760151e81db2a278e03a', // undefined in case of contract deployment + // value: '0', + // data: '0xba98fa1c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000003c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // }); const swapTxn = await ts.simulate({ from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment @@ -170,21 +228,73 @@ describe('FluidDex EventPool Mainnet', function () { console.log(swapTxn); + console.log( + 'eth balance after : ' + + (await dexHelper.provider.getBalance( + '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + )), + ); + const txnBlockNumber = swapTxn.transaction.block_number; - const txnhash = - swapTxn.transaction.transaction_info.transaction_id; - console.log(txnhash); + // const txnhash = + // swapTxn.transaction.transaction_info.transaction_id; + // console.log(txnhash); + // console.log( + // 'retreiving txn : ' + + // JSON.stringify( + // await dexHelper.provider.getTransaction( + // txnhash, + // ), + // ), + // ); + + console.log(fluidDexEventPool); + + console.log(txnBlockNumber); + + console.log( + 'state 3 blocks before : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + txnBlockNumber - 4, + ), + replacer, + 2, + ), + ); console.log( - 'retreiving txn : ' + + 'state 2 blocks before : ' + JSON.stringify( - await dexHelper.web3Provider.eth.getTransaction( - txnhash, + await fluidDexEventPool.generateState( + txnBlockNumber - 3, ), + replacer, + 2, + ), + ); + console.log( + 'state 1 block before : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + txnBlockNumber - 2, + ), + replacer, + 2, + ), + ); + + await delay(10000); + + console.log( + 'state 1 block after : ' + + JSON.stringify( + await fluidDexEventPool.generateState(txnBlockNumber), + replacer, + 2, ), ); - // console.log(fluidDexEventPool); await testEventSubscriber( fluidDexEventPool, @@ -204,37 +314,37 @@ describe('FluidDex EventPool Mainnet', function () { }, ); - Object.entries(poolFetchEventsToTest).forEach( - ([poolAddress, events]: [string, EventMappings]) => { - describe(`Events for ${poolAddress}`, () => { - Object.entries(events).forEach( - ([eventName, blockNumbers]: [string, number[]]) => { - describe(`${eventName}`, () => { - blockNumbers.forEach((blockNumber: number) => { - it(`State after ${blockNumber}`, async function () { - fluidDexCommonAddress = new FluidDexCommonAddresses( - 'FluidDex', - fluidDexCommonAddressStruct, - network, - dexHelper, - logger, - ); - - await testEventSubscriber( - fluidDexCommonAddress, - fluidDexCommonAddress.addressesSubscribed, - (_blockNumber: number) => - fetchTotalPools(fluidDexCommonAddress, _blockNumber), - blockNumber, - `${dexKey}_${poolAddress}`, - dexHelper.provider, - ); - }); - }); - }); - }, - ); - }); - }, - ); + // Object.entries(poolFetchEventsToTest).forEach( + // ([poolAddress, events]: [string, EventMappings]) => { + // describe(`Events for ${poolAddress}`, () => { + // Object.entries(events).forEach( + // ([eventName, blockNumbers]: [string, number[]]) => { + // describe(`${eventName}`, () => { + // blockNumbers.forEach((blockNumber: number) => { + // it(`State after ${blockNumber}`, async function () { + // fluidDexCommonAddress = new FluidDexCommonAddresses( + // 'FluidDex', + // fluidDexCommonAddressStruct, + // network, + // dexHelper, + // logger, + // ); + + // await testEventSubscriber( + // fluidDexCommonAddress, + // fluidDexCommonAddress.addressesSubscribed, + // (_blockNumber: number) => + // fetchTotalPools(fluidDexCommonAddress, _blockNumber), + // blockNumber, + // `${dexKey}_${poolAddress}`, + // dexHelper.provider, + // ); + // }); + // }); + // }); + // }, + // ); + // }); + // }, + // ); }); From 1e09cb9bc645523e12a7fdf56a3a37d84ce86705 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Sun, 13 Oct 2024 13:31:10 +0530 Subject: [PATCH 26/64] events test working --- src/dex/fluid-dex/fluid-dex-events.test.ts | 163 +++++---------------- src/dex/fluid-dex/fluid-dex-pool.ts | 102 ++++++++----- 2 files changed, 101 insertions(+), 164 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 1f746089e..af02ff7b2 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -137,60 +137,30 @@ describe('FluidDex EventPool Mainnet', function () { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async function () { - // const forkProvider = new ethers.JsonRpcProvider('https://mainnet.gateway.tenderly.co/5aa2627c-c6b9-4aa7-beec-a7352f78726b') - const fluidDex = new FluidDex(network, dexKey, dexHelper); - // const latestBlockNumber_ = await dexHelper.web3Provider.eth.getBlockNumber(); - await fluidDex.initializePricing(blockNumber); - // console.log(stringifyCircular(Object.keys(fluidDex.eventPools).length)) - const ts: TenderlySimulation = new TenderlySimulation( network, - '5aa2627c-c6b9-4aa7-beec-a7352f78726b', ); await ts.setup(); const forkId = ts.forkId; - console.log('this is ts fork id : ' + forkId); dexHelper.replaceProviderWithRPC( `https://rpc.tenderly.co/fork/${forkId}`, ); - // console.log("this is fork id : ", dexHelper.web3Provider, null, 2); - console.log( - 'this is fork id : ', - JSON.stringify(dexHelper.provider, null, 2), - ); + + console.log(forkId); fluidDexEventPool = fluidDex.eventPools[ 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' ]; - // console.log("eth balance before sned : " + await dexHelper.provider.getBalance('0x1928347619834761983764191827346198723646')); - - // const senddTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x1928347619834761983764191827346198723646', // undefined in case of contract deployment - // value: '1234', - // data: '', - // }); + console.log(fluidDexEventPool.dexHelper.provider); - // const senddTxn2 = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x1928347619834761983764191827346198723646', // undefined in case of contract deployment - // value: '1234', - // data: '', - // }); - - // // console.log(JSON.stringify(senddTxn)); - - // console.log(JSON.stringify(ts)); - - // console.log("eth balance after sned : " + await dexHelper.provider.getBalance('0x1928347619834761983764191827346198723646')); console.log( 'eth balance before : ' + (await dexHelper.provider.getBalance( @@ -198,12 +168,6 @@ describe('FluidDex EventPool Mainnet', function () { )), ); - // const allowanceTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment - // value: '0', - // data: '0x095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03a0000000000000000000000000000000000000000000000056bc75e2d63100000', - // }); const allowanceTxn = await ts.simulate({ from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment @@ -211,14 +175,10 @@ describe('FluidDex EventPool Mainnet', function () { data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', }); - console.log(allowanceTxn); + console.log( + 'allowance txn (isSuccess?) : ' + allowanceTxn.success, + ); - // const swapTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x6d83f60eeac0e50a1250760151e81db2a278e03a', // undefined in case of contract deployment - // value: '0', - // data: '0xba98fa1c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000003c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // }); const swapTxn = await ts.simulate({ from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment @@ -226,7 +186,7 @@ describe('FluidDex EventPool Mainnet', function () { data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', }); - console.log(swapTxn); + console.log('swap txn (isSuccess?) : ' + swapTxn.success); console.log( 'eth balance after : ' + @@ -237,71 +197,58 @@ describe('FluidDex EventPool Mainnet', function () { const txnBlockNumber = swapTxn.transaction.block_number; - // const txnhash = - // swapTxn.transaction.transaction_info.transaction_id; - // console.log(txnhash); - - // console.log( - // 'retreiving txn : ' + - // JSON.stringify( - // await dexHelper.provider.getTransaction( - // txnhash, - // ), - // ), - // ); - - console.log(fluidDexEventPool); - - console.log(txnBlockNumber); - + await delay(30000); console.log( - 'state 3 blocks before : ' + - JSON.stringify( - await fluidDexEventPool.generateState( - txnBlockNumber - 4, - ), - replacer, - 2, - ), - ); - console.log( - 'state 2 blocks before : ' + + 'state 1 block after : ' + JSON.stringify( await fluidDexEventPool.generateState( - txnBlockNumber - 3, + txnBlockNumber - 2, ), replacer, 2, ), ); console.log( - 'state 1 block before : ' + + 'state 1 block after : ' + JSON.stringify( await fluidDexEventPool.generateState( - txnBlockNumber - 2, + await dexHelper.provider.getBlockNumber(), ), replacer, 2, ), ); + }); + }); + }); + }, + ); + }); + }, + ); - await delay(10000); - - console.log( - 'state 1 block after : ' + - JSON.stringify( - await fluidDexEventPool.generateState(txnBlockNumber), - replacer, - 2, - ), + Object.entries(poolFetchEventsToTest).forEach( + ([poolAddress, events]: [string, EventMappings]) => { + describe(`Events for ${poolAddress}`, () => { + Object.entries(events).forEach( + ([eventName, blockNumbers]: [string, number[]]) => { + describe(`${eventName}`, () => { + blockNumbers.forEach((blockNumber: number) => { + it(`State after ${blockNumber}`, async function () { + fluidDexCommonAddress = new FluidDexCommonAddresses( + 'FluidDex', + fluidDexCommonAddressStruct, + network, + dexHelper, + logger, ); await testEventSubscriber( - fluidDexEventPool, - fluidDexEventPool.addressesSubscribed, + fluidDexCommonAddress, + fluidDexCommonAddress.addressesSubscribed, (_blockNumber: number) => - fetchPoolState(fluidDexEventPool, _blockNumber), - txnBlockNumber, + fetchTotalPools(fluidDexCommonAddress, _blockNumber), + blockNumber, `${dexKey}_${poolAddress}`, dexHelper.provider, ); @@ -313,38 +260,4 @@ describe('FluidDex EventPool Mainnet', function () { }); }, ); - - // Object.entries(poolFetchEventsToTest).forEach( - // ([poolAddress, events]: [string, EventMappings]) => { - // describe(`Events for ${poolAddress}`, () => { - // Object.entries(events).forEach( - // ([eventName, blockNumbers]: [string, number[]]) => { - // describe(`${eventName}`, () => { - // blockNumbers.forEach((blockNumber: number) => { - // it(`State after ${blockNumber}`, async function () { - // fluidDexCommonAddress = new FluidDexCommonAddresses( - // 'FluidDex', - // fluidDexCommonAddressStruct, - // network, - // dexHelper, - // logger, - // ); - - // await testEventSubscriber( - // fluidDexCommonAddress, - // fluidDexCommonAddress.addressesSubscribed, - // (_blockNumber: number) => - // fetchTotalPools(fluidDexCommonAddress, _blockNumber), - // blockNumber, - // `${dexKey}_${poolAddress}`, - // dexHelper.provider, - // ); - // }); - // }); - // }); - // }, - // ); - // }); - // }, - // ); }); diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index a0e7c5c1c..0cc1efa90 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -8,14 +8,16 @@ import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; import { commonAddresses, - FluidDexPool, FluidDexPoolState, PoolWithReserves, + CollateralReserves, + DebtReserves, } from './types'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; import { BytesLike } from 'ethers/lib/utils'; import { Address } from '../../types'; import { generalDecoder } from '../../lib/decoders'; +import { Contract } from 'ethers'; export class FluidDexEventPool extends StatefulEventSubscriber { handlers: { @@ -36,7 +38,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber[] = [ + const resolverContract = new Contract( + this.commonAddresses.resolver, + ResolverABI, + this.dexHelper.provider, + ); + const rawResult = await resolverContract.callStatic.getPoolReserves( + this.pool, { - target: this.commonAddresses.resolver, - callData: resolverAbi.encodeFunctionData('getPoolReserves', [ - this.pool, - ]), - decodeFunction: await this.decodePoolWithReserves, + blockTag: await this.dexHelper.provider, }, - ]; - - const results: PoolWithReserves[] = - await this.dexHelper.multiWrapper.aggregate( - callData, - await this.dexHelper.provider.getBlockNumber(), - this.dexHelper.multiWrapper.defaultBatchSize, - ); - - const generatedState = { - collateralReserves: results[0].collateralReserves, - debtReserves: results[0].debtReserves, - fee: results[0].fee, - }; + ); + + const generatedState = this.convertToFluidDexPoolState(rawResult); this.setState( generatedState, @@ -181,6 +174,13 @@ export class FluidDexEventPool extends StatefulEventSubscriber> { - const resolverAbi = new Interface(ResolverABI); - const callData: MultiCallParams[] = [ + const resolverContract = new Contract( + this.commonAddresses.resolver, + ResolverABI, + this.dexHelper.provider, + ); + const rawResult = await resolverContract.callStatic.getPoolReserves( + this.pool, { - target: this.commonAddresses.resolver, - callData: resolverAbi.encodeFunctionData('getPoolReserves', [ - this.pool, - ]), - decodeFunction: await this.decodePoolWithReserves, + blockTag: blockNumber, }, - ]; + ); + + const convertedResult = this.convertToFluidDexPoolState(rawResult); + + return convertedResult; + } + + convertToFluidDexPoolState(input: any[]): FluidDexPoolState { + // Ignore the first three addresses + const [, , , feeHex, collateralReservesHex, debtReservesHex] = input; + // // Convert fee from hex to number + const fee = feeHex; + // console.log("converted fee : " + fee); + + // Convert collateral reserves + const collateralReserves: CollateralReserves = { + token0RealReserves: collateralReservesHex[0], + token1RealReserves: collateralReservesHex[1], + token0ImaginaryReserves: collateralReservesHex[2], + token1ImaginaryReserves: collateralReservesHex[3], + }; - const results: PoolWithReserves[] = - await this.dexHelper.multiWrapper.aggregate( - callData, - blockNumber, - this.dexHelper.multiWrapper.defaultBatchSize, - ); + // Convert debt reserves + const debtReserves: DebtReserves = { + token0Debt: debtReservesHex[0], + token1Debt: debtReservesHex[1], + token0RealReserves: debtReservesHex[2], + token1RealReserves: debtReservesHex[3], + token0ImaginaryReserves: debtReservesHex[4], + token1ImaginaryReserves: debtReservesHex[5], + }; return { - collateralReserves: results[0].collateralReserves, - debtReserves: results[0].debtReserves, - fee: results[0].fee, + collateralReserves, + debtReserves, + fee, }; } } From 22e0e530018cfacd414d34869d2db83dbb8f7748 Mon Sep 17 00:00:00 2001 From: bergben Date: Sun, 13 Oct 2024 17:02:21 +0200 Subject: [PATCH 27/64] feat(fluid): cleanup --- src/dex/fluid-dex/config.ts | 7 +- src/dex/fluid-dex/fluid-dex-generate-pool.ts | 35 +++--- src/dex/fluid-dex/fluid-dex-pool.ts | 76 ++----------- src/dex/fluid-dex/fluid-dex.ts | 107 ++++++------------- src/dex/fluid-dex/types.ts | 31 +++--- 5 files changed, 73 insertions(+), 183 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index ad8a89409..bbd30ccd1 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -18,7 +18,8 @@ export const FluidDexConfig: DexConfigMap = { export const FLUID_DEX_GAS_COST = 160_000; export const Adapters: Record = { - // TODO: add adapters for each chain - // This is an example to copy - [Network.MAINNET]: { [SwapSide.SELL]: [{ name: '', index: 0 }] }, + [Network.MAINNET]: { + // TODO: set index? + [SwapSide.SELL]: [{ name: 'Adapter03', index: 0 }], + }, }; diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts index cb8ba370a..9492a4631 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -1,4 +1,5 @@ import { Interface } from '@ethersproject/abi'; +import { BytesLike } from 'ethers/lib/utils'; import { DeepReadonly } from 'ts-essentials'; import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; @@ -6,19 +7,10 @@ import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import DexFactoryABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; -import { - commonAddresses, - FluidDexPool, - FluidDexPoolState, - PoolWithReserves, - Pool, -} from './types'; -import { ethers } from 'ethers'; -import { eachOfSeries } from 'async'; +import { CommonAddresses, Pool } from './types'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; -import { BytesLike } from 'ethers/lib/utils'; import { Address } from '../../types'; -import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; +import { generalDecoder } from '../../lib/decoders'; export class FluidDexCommonAddresses extends StatefulEventSubscriber { handlers: { @@ -33,11 +25,11 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { addressesSubscribed: Address[]; protected dexFactoryIface = new Interface(DexFactoryABI); + protected resolverIface = new Interface(ResolverABI); constructor( readonly parentName: string, - // readonly pool: FluidDexPool, - readonly commonAddresses: commonAddresses, + readonly commonAddresses: CommonAddresses, protected network: number, protected dexHelper: IDexHelper, logger: Logger, @@ -60,12 +52,13 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { log: Readonly, ): Promise | null> { const blockNumber_ = await this.dexHelper.web3Provider.eth.getBlockNumber(); - const resolverAbi = new Interface(ResolverABI); const callData: MultiCallParams[] = [ { target: this.commonAddresses.resolver, - callData: resolverAbi.encodeFunctionData('getPool', [event.args.dexId]), - decodeFunction: await this.decodePool, + callData: this.resolverIface.encodeFunctionData('getPool', [ + event.args.dexId, + ]), + decodeFunction: this.decodePool, }, ]; @@ -81,13 +74,13 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { token1: results[0].token1, }; - let currentPool = this.getState(0); - currentPool = currentPool == null ? [] : currentPool; - currentPool = [...currentPool, generatedPool]; + let currentPools = this.getState(0); + currentPools = currentPools == null ? [] : currentPools; + currentPools = [...currentPools, generatedPool]; - this.setState(currentPool, blockNumber_); + this.setState(currentPools, blockNumber_); - return currentPool; + return currentPools; } decodePool = (result: MultiResult | BytesLike): Pool => { diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 0cc1efa90..f03d75693 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -1,5 +1,6 @@ import { Interface } from '@ethersproject/abi'; import { DeepReadonly } from 'ts-essentials'; +import { BytesLike } from 'ethers/lib/utils'; import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; @@ -7,14 +8,13 @@ import { IDexHelper } from '../../dex-helper/idex-helper'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; import { - commonAddresses, + CommonAddresses, FluidDexPoolState, PoolWithReserves, CollateralReserves, DebtReserves, } from './types'; -import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; -import { BytesLike } from 'ethers/lib/utils'; +import { MultiResult } from '../../lib/multi-wrapper'; import { Address } from '../../types'; import { generalDecoder } from '../../lib/decoders'; import { Contract } from 'ethers'; @@ -36,7 +36,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber, log: Readonly, ): Promise | null> { - const resolverAbi = new Interface(ResolverABI); if (!(event.args.user in [this.pool])) { return null; } @@ -70,7 +69,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber | BytesLike, - ): PoolWithReserves => { - return generalDecoder( - result, - [ - 'tuple(address pool, address token0_, address token1_, uint256 fee,' + - 'tuple(uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) collateralReserves, ' + - 'tuple(uint256 token0Debt, uint256 token1Debt, uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) debtReserves)', - ], - undefined, - decoded => { - const [decodedResult] = decoded; - return { - pool: decodedResult.pool, - token0_: decodedResult.token0_, - token1_: decodedResult.token1_, - fee: decodedResult.fee, - collateralReserves: { - token0RealReserves: BigInt( - decodedResult.collateralReserves.token0RealReserves, - ), - token1RealReserves: BigInt( - decodedResult.collateralReserves.token1RealReserves, - ), - token0ImaginaryReserves: BigInt( - decodedResult.collateralReserves.token0ImaginaryReserves, - ), - token1ImaginaryReserves: BigInt( - decodedResult.collateralReserves.token1ImaginaryReserves, - ), - }, - debtReserves: { - token0Debt: BigInt(decodedResult.debtReserves.token0Debt), - token1Debt: BigInt(decodedResult.debtReserves.token1Debt), - token0RealReserves: BigInt( - decodedResult.debtReserves.token0RealReserves, - ), - token1RealReserves: BigInt( - decodedResult.debtReserves.token1RealReserves, - ), - token0ImaginaryReserves: BigInt( - decodedResult.debtReserves.token0ImaginaryReserves, - ), - token1ImaginaryReserves: BigInt( - decodedResult.debtReserves.token1ImaginaryReserves, - ), - }, - }; - }, - ); - }; - /** * The function is called every time any of the subscribed * addresses release log. The function accepts the current @@ -174,13 +120,6 @@ export class FluidDexEventPool extends StatefulEventSubscriber { pools: FluidDexPool[]; - readonly FluidCommonAddresses: FluidDexCommonAddresses; + readonly fluidCommonAddresses: FluidDexCommonAddresses; - readonly iFluidDexPool: Interface; + readonly fluidDexPoolIface: Interface; protected adapters; @@ -74,7 +61,7 @@ export class FluidDex extends SimpleExchange implements IDex { ) { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); - this.FluidCommonAddresses = new FluidDexCommonAddresses( + this.fluidCommonAddresses = new FluidDexCommonAddresses( 'FluidDex', FluidDexConfig['FluidDex'][network].commonAddresses, network, @@ -83,12 +70,14 @@ export class FluidDex extends SimpleExchange implements IDex { ); this.pools = FluidDexConfig['FluidDex'][network].pools; this.adapters = Adapters[network] || {}; - this.iFluidDexPool = new Interface(FluidDexPoolABI); + this.fluidDexPoolIface = new Interface(FluidDexPoolABI); } - async fetchFluidDexPools(blockNumber: number): Promise { + private async fetchFluidDexPools( + blockNumber: number, + ): Promise { const poolsFromResolver = - await this.FluidCommonAddresses.getStateOrGenerate(blockNumber, false); + await this.fluidCommonAddresses.getStateOrGenerate(blockNumber, false); return poolsFromResolver.map(pool => ({ id: `FluidDex_${pool.address}`, @@ -105,7 +94,7 @@ export class FluidDex extends SimpleExchange implements IDex { this.eventPools[pool.id] = new FluidDexEventPool( 'FluidDex', pool.address, - this.FluidCommonAddresses.commonAddresses, + this.fluidCommonAddresses.commonAddresses, this.network, this.dexHelper, this.logger, @@ -218,41 +207,24 @@ export class FluidDex extends SimpleExchange implements IDex { return null; } - // const state = await eventPool.generateState(blockNumber); const state = await eventPool.getStateOrGenerate(blockNumber); - const swap0To1: boolean = side === SwapSide.SELL; - const prices = amounts.map(amount => { - if (side === SwapSide.SELL) { - return this.swapIn( - srcToken.address.toLowerCase() === pool.token0.toLowerCase(), - amount, - state.collateralReserves, - state.debtReserves, - srcToken.decimals, - destToken.decimals, - BigInt(state.fee), - ); - } else { - return this.swapOut( - !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), - amount, - state.collateralReserves, - state.debtReserves, - srcToken.decimals, - destToken.decimals, - BigInt(state.fee), - ); - } + return this.swapIn( + srcToken.address.toLowerCase() === pool.token0.toLowerCase(), + amount, + state.collateralReserves, + state.debtReserves, + srcToken.decimals, + destToken.decimals, + BigInt(state.fee), + ); }); return [ { prices: prices.filter((price): price is bigint => price !== null), // to be done - unit: getBigIntPow( - (side === SwapSide.SELL ? destToken : srcToken).decimals, - ), // to be done + unit: getBigIntPow(destToken.decimals), data: { colReserves: state.collateralReserves, debtReserves: state.debtReserves, @@ -433,38 +405,27 @@ export class FluidDex extends SimpleExchange implements IDex { if (side === SwapSide.BUY) throw new Error(`Buy not supported`); - let method: string; let args: any; let returnAmountPos: number | undefined = undefined; - const deadline = getLocalDeadlineAsFriendlyPlaceholder(); - - method = side == SwapSide.SELL ? 'swapIn' : 'swapOut'; + const method = 'swapIn'; returnAmountPos = extractReturnAmountPosition( - this.iFluidDexPool, + this.fluidDexPoolIface, method, - side == SwapSide.SELL ? 'amountOut_' : 'amountIn_', + 'amountOut_', 1, ); const pool = await this.getPoolByTokenPair(srcToken, destToken); - if (side == SwapSide.SELL) { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; - } else { - args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; - } + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; } else { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [true, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; - } else { - args = [false, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; - } + args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; } - const swapData = this.iFluidDexPool.encodeFunctionData(method, args); + const swapData = this.fluidDexPoolIface.encodeFunctionData(method, args); return { needWrapNative: this.needWrapNative, @@ -485,7 +446,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @param outDecimals - The number of decimals for the output token. * @returns The calculated output amount (as a BigInt). */ - swapIn( + private swapIn( swap0To1: boolean, amountIn: bigint, colReserves: CollateralReserves, @@ -710,7 +671,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @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( + private swapRoutingIn( t: bigint, x: bigint, y: bigint, @@ -744,7 +705,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @param {number} fee - The fee for the swap. 1e4 = 1% * @returns {bigint} amountIn - The calculated input amount required for the swap. */ - swapOut( + private swapOut( swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, @@ -779,7 +740,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @param {DebtReserves} debtReserves - The reserves of the debt pool. * @returns {bigint} The calculated input amount required for the swap. */ - swapOutAdjusted( + private swapOutAdjusted( swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 6f8834975..0660d23ac 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -7,25 +7,25 @@ export type FluidDexPoolState = { }; export type CollateralReserves = { - token0RealReserves: bigint; // Changed from uint to bigint - token1RealReserves: bigint; // Changed from uint to bigint - token0ImaginaryReserves: bigint; // Changed from uint to bigint - token1ImaginaryReserves: bigint; // Changed from uint to bigint + token0RealReserves: bigint; + token1RealReserves: bigint; + token0ImaginaryReserves: bigint; + token1ImaginaryReserves: bigint; }; export type DebtReserves = { - token0Debt: bigint; // Changed from uint to bigint - token1Debt: bigint; // Changed from uint to bigint - token0RealReserves: bigint; // Changed from uint to bigint - token1RealReserves: bigint; // Changed from uint to bigint - token0ImaginaryReserves: bigint; // Changed from uint to bigint - token1ImaginaryReserves: bigint; // Changed from uint to bigint + token0Debt: bigint; + token1Debt: bigint; + token0RealReserves: bigint; + token1RealReserves: bigint; + token0ImaginaryReserves: bigint; + token1ImaginaryReserves: bigint; }; export interface PoolWithReserves { pool: string; - token0_: string; - token1_: string; + token0: string; + token1: string; fee: number; collateralReserves: CollateralReserves; debtReserves: DebtReserves; @@ -46,14 +46,11 @@ export type FluidDexPool = { }; export type DexParams = { - // TODO: DexParams is set of parameters the can - // be used to initiate a DEX fork. - // Complete me! - commonAddresses: commonAddresses; + commonAddresses: CommonAddresses; pools: FluidDexPool[]; }; -export type commonAddresses = { +export type CommonAddresses = { liquidityProxy: Address; resolver: Address; dexFactory: Address; From 992c9c821c07512174048d949affcb9a7eaed52c Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 14 Oct 2024 16:56:59 +0530 Subject: [PATCH 28/64] made the changes --- src/dex/fluid-dex/fluid-dex-pool.ts | 53 ++++++++++++++++++++++------- src/dex/fluid-dex/fluid-dex.ts | 15 ++++---- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 0cc1efa90..ecda7e27d 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -214,25 +214,24 @@ export class FluidDexEventPool extends StatefulEventSubscriber { - readonly eventPools: { [id: string]: FluidDexEventPool } = {}; + eventPools: { [id: string]: FluidDexEventPool } = {}; readonly hasConstantPriceLargeAmounts = false; readonly needWrapNative = false; readonly isFeeOnTransferSupported = false; @@ -119,9 +119,9 @@ export class FluidDex extends SimpleExchange implements IDex { // for pricing requests. It is optional for a DEX to // implement this function async initializePricing(blockNumber: number) { - Object.entries(this.eventPools).forEach(([id, eventPool]) => { - eventPool.getStateOrGenerate(blockNumber, false); - }); + // Object.entries(this.eventPools).forEach(([id, eventPool]) => { + // eventPool.getStateOrGenerate(blockNumber, false); + // }); await this.updatePoolAndEventPool(blockNumber); } @@ -249,7 +249,7 @@ export class FluidDex extends SimpleExchange implements IDex { return [ { - prices: prices.filter((price): price is bigint => price !== null), // to be done + prices: prices, unit: getBigIntPow( (side === SwapSide.SELL ? destToken : srcToken).decimals, ), // to be done @@ -312,9 +312,7 @@ export class FluidDex extends SimpleExchange implements IDex { // getTopPoolsForToken. It is optional for a DEX // to implement this async updatePoolState(): Promise { - this.initializePricing( - await this.dexHelper.web3Provider.eth.getBlockNumber(), - ); + this.initializePricing(await this.dexHelper.provider.getBlockNumber()); } // Returns list of top pools based on liquidity. Max @@ -400,6 +398,7 @@ export class FluidDex extends SimpleExchange implements IDex { state.collateralReserves.token0RealReserves + state.debtReserves.token0RealReserves, ); + const usd1 = await this.dexHelper.getTokenUSDPrice( { address: pool.token1, decimals: token1decimals! }, state.collateralReserves.token1RealReserves + From d1c0921dbcc4db735fb3c43ebd4ac857c12139df Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 14 Oct 2024 16:59:09 +0530 Subject: [PATCH 29/64] changed web3provider to provider --- src/dex/fluid-dex/fluid-dex-generate-pool.ts | 2 +- src/dex/fluid-dex/fluid-dex-integration.test.ts | 2 +- src/dex/fluid-dex/fluid-dex.ts | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts index cb8ba370a..2d1e640dc 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -59,7 +59,7 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { state: DeepReadonly, log: Readonly, ): Promise | null> { - const blockNumber_ = await this.dexHelper.web3Provider.eth.getBlockNumber(); + const blockNumber_ = await this.dexHelper.provider.getBlockNumber(); const resolverAbi = new Interface(ResolverABI); const callData: MultiCallParams[] = [ { diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 24d46440b..fd7d8fe11 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -185,7 +185,7 @@ describe('FluidDex', function () { // ]; beforeAll(async () => { - blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); + blockNumber = await dexHelper.provider.getBlockNumber(); fluidDex = new FluidDex(network, dexKey, dexHelper); if (fluidDex.initializePricing) { await fluidDex.initializePricing(blockNumber); diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index d9ee77d03..c6607f92f 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -321,8 +321,7 @@ export class FluidDex extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { - const latestBlockNumber_ = - await this.dexHelper.web3Provider.eth.getBlockNumber(); + const latestBlockNumber_ = await this.dexHelper.provider.getBlockNumber(); let liquidityAmounts: { [id: string]: bigint } = {}; for (const pool of this.pools) { if ( @@ -426,8 +425,7 @@ export class FluidDex extends SimpleExchange implements IDex { context: Context, executorAddress: Address, ): Promise { - const latestBlockNumber_ = - await this.dexHelper.web3Provider.eth.getBlockNumber(); + const latestBlockNumber_ = await this.dexHelper.provider.getBlockNumber(); await this.updatePoolAndEventPool(latestBlockNumber_); if (side === SwapSide.BUY) throw new Error(`Buy not supported`); From 37885ecfe6223b4565e3117576362d0f2465f7b8 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 14 Oct 2024 17:25:37 +0530 Subject: [PATCH 30/64] . --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f96f6d322..b601e2d07 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,10 @@ tests/states.json tests/configs.json .idea/ local-scripts -tests/debug-price-route.json \ No newline at end of file +tests/debug-price-route.json +tests/constants-e2e.d.ts +tests/constants-e2e.js +tests/constants-e2e.js.map +tests/smart-tokens.d.ts +tests/smart-tokens.js +tests/smart-tokens.js.map \ No newline at end of file From 813b6ae1d735d4c5772bb26e888026db086d2cfa Mon Sep 17 00:00:00 2001 From: bergben Date: Mon, 14 Oct 2024 14:43:51 +0200 Subject: [PATCH 31/64] tests: minor cleanup --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 3 ++- src/dex/fluid-dex/fluid-dex-events.test.ts | 15 +++------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index dea93b25f..ca91f8543 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -2,6 +2,8 @@ import dotenv from 'dotenv'; dotenv.config(); +import { StaticJsonRpcProvider } from '@ethersproject/providers'; + import { testE2E } from '../../../tests/utils-e2e'; import { Tokens, @@ -9,7 +11,6 @@ import { NativeTokenSymbols, } from '../../../tests/constants-e2e'; import { Network, ContractMethod, SwapSide } from '../../constants'; -import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { generateConfig } from '../../config'; /* diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index af02ff7b2..2e4016101 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -9,19 +9,10 @@ import { Network } from '../../constants'; import { Address } from '../../types'; import { DummyDexHelper } from '../../dex-helper/index'; import { testEventSubscriber } from '../../../tests/utils-events'; -import { - commonAddresses, - FluidDexPool, - FluidDexPoolState, - Pool, -} from './types'; +import { CommonAddresses, FluidDexPoolState, Pool } from './types'; import { FluidDexConfig } from './config'; import { DeepReadonly } from 'ts-essentials'; -import { - EstimateGasSimulation, - TenderlySimulation, - TransactionSimulator, -} from '../../../tests/tenderly-simulation'; +import { TenderlySimulation } from '../../../tests/tenderly-simulation'; /* README @@ -108,7 +99,7 @@ describe('FluidDex EventPool Mainnet', function () { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); - const fluidDexCommonAddressStruct: commonAddresses = + const fluidDexCommonAddressStruct: CommonAddresses = FluidDexConfig[dexKey][network].commonAddresses; const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; From 728113392c2ed9b2234f7868a2ccaacbf0f5386b Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 14 Oct 2024 18:19:09 +0530 Subject: [PATCH 32/64] removed commented out code --- .../fluid-dex/fluid-dex-integration.test.ts | 28 ----------------- src/dex/fluid-dex/fluid-dex-pool.ts | 30 ------------------- 2 files changed, 58 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index fd7d8fe11..d89aaed81 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -170,20 +170,6 @@ describe('FluidDex', function () { 10n * BI_POWS[tokens[srcTokenSymbol].decimals], ]; - // const amountsForBuy = [ - // 0n, - // 1n * BI_POWS[tokens[destTokenSymbol].decimals], - // 2n * BI_POWS[tokens[destTokenSymbol].decimals], - // 3n * BI_POWS[tokens[destTokenSymbol].decimals], - // 4n * BI_POWS[tokens[destTokenSymbol].decimals], - // // 5n * BI_POWS[tokens[destTokenSymbol].decimals], - // // 6n * BI_POWS[tokens[destTokenSymbol].decimals], - // // 7n * BI_POWS[tokens[destTokenSymbol].decimals], - // // 8n * BI_POWS[tokens[destTokenSymbol].decimals], - // // 9n * BI_POWS[tokens[destTokenSymbol].decimals], - // // 10n * BI_POWS[tokens[destTokenSymbol].decimals], - // ]; - beforeAll(async () => { blockNumber = await dexHelper.provider.getBlockNumber(); fluidDex = new FluidDex(network, dexKey, dexHelper); @@ -206,20 +192,6 @@ describe('FluidDex', function () { ); }); - // it('getPoolIdentifiers and getPricesVolume BUY', async function () { - // await testPricingOnNetwork( - // fluidDex, - // network, - // dexKey, - // blockNumber, - // srcTokenSymbol, - // destTokenSymbol, - // SwapSide.BUY, - // amountsForBuy, - // 'estimateSwapOut', - // ); - // }); - it('getTopPoolsForToken', async function () { // We have to check without calling initializePricing, because // pool-tracker is not calling that function diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index ecda7e27d..056099a19 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -240,34 +240,4 @@ export class FluidDexEventPool extends StatefulEventSubscriber Date: Tue, 15 Oct 2024 03:55:57 +0530 Subject: [PATCH 33/64] event catching debugged --- src/abi/fluid-dex/dexFactory.abi.json | 506 +++++++++++++++++++ src/dex/fluid-dex/fluid-dex-events.test.ts | 84 +++ src/dex/fluid-dex/fluid-dex-generate-pool.ts | 103 +--- src/dex/fluid-dex/fluid-dex-pool.ts | 66 +-- src/dex/fluid-dex/fluid-dex.ts | 16 +- src/dex/fluid-dex/types.ts | 3 - 6 files changed, 629 insertions(+), 149 deletions(-) create mode 100644 src/abi/fluid-dex/dexFactory.abi.json diff --git a/src/abi/fluid-dex/dexFactory.abi.json b/src/abi/fluid-dex/dexFactory.abi.json new file mode 100644 index 000000000..7ed784ad6 --- /dev/null +++ b/src/abi/fluid-dex/dexFactory.abi.json @@ -0,0 +1,506 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "owner_", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "errorId_", + "type": "uint256" + } + ], + "name": "FluidDexError", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "errorId_", + "type": "uint256" + } + ], + "name": "FluidDexFactoryError", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "shares_", + "type": "uint256" + } + ], + "name": "FluidDexLiquidityOutput", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "token0Amt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Amt", + "type": "uint256" + } + ], + "name": "FluidDexPerfectLiquidityOutput", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tokenAmt", + "type": "uint256" + } + ], + "name": "FluidDexSingleTokenOutput", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountOut", + "type": "uint256" + } + ], + "name": "FluidDexSwapResult", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "dex", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "dexId", + "type": "uint256" + } + ], + "name": "DexDeployed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "deployer", + "type": "address" + }, + { + "indexed": true, + "internalType": "bool", + "name": "allowed", + "type": "bool" + } + ], + "name": "LogSetDeployer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "dexAuth", + "type": "address" + }, + { + "indexed": true, + "internalType": "bool", + "name": "allowed", + "type": "bool" + }, + { + "indexed": true, + "internalType": "address", + "name": "dex", + "type": "address" + } + ], + "name": "LogSetDexAuth", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "dexDeploymentLogic", + "type": "address" + }, + { + "indexed": true, + "internalType": "bool", + "name": "allowed", + "type": "bool" + } + ], + "name": "LogSetDexDeploymentLogic", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "globalAuth", + "type": "address" + }, + { + "indexed": true, + "internalType": "bool", + "name": "allowed", + "type": "bool" + } + ], + "name": "LogSetGlobalAuth", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "user", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dexDeploymentLogic_", + "type": "address" + }, + { + "internalType": "bytes", + "name": "dexDeploymentData_", + "type": "bytes" + } + ], + "name": "deployDex", + "outputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "dexId_", + "type": "uint256" + } + ], + "name": "getDexAddress", + "outputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "deployer_", + "type": "address" + } + ], + "name": "isDeployer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + } + ], + "name": "isDex", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address", + "name": "dexAuth_", + "type": "address" + } + ], + "name": "isDexAuth", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dexDeploymentLogic_", + "type": "address" + } + ], + "name": "isDexDeploymentLogic", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "globalAuth_", + "type": "address" + } + ], + "name": "isGlobalAuth", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "slot_", + "type": "bytes32" + } + ], + "name": "readFromStorage", + "outputs": [ + { + "internalType": "uint256", + "name": "result_", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "deployer_", + "type": "address" + }, + { + "internalType": "bool", + "name": "allowed_", + "type": "bool" + } + ], + "name": "setDeployer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "dex_", + "type": "address" + }, + { + "internalType": "address", + "name": "dexAuth_", + "type": "address" + }, + { + "internalType": "bool", + "name": "allowed_", + "type": "bool" + } + ], + "name": "setDexAuth", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "deploymentLogic_", + "type": "address" + }, + { + "internalType": "bool", + "name": "allowed_", + "type": "bool" + } + ], + "name": "setDexDeploymentLogic", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "globalAuth_", + "type": "address" + }, + { + "internalType": "bool", + "name": "allowed_", + "type": "bool" + } + ], + "name": "setGlobalAuth", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target_", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data_", + "type": "bytes" + } + ], + "name": "spell", + "outputs": [ + { + "internalType": "bytes", + "name": "response_", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "totalDexes", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index af02ff7b2..09928ee68 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -136,6 +136,90 @@ describe('FluidDex EventPool Mainnet', function () { ([eventName, blockNumbers]: [string, number[]]) => { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { + // it(`State after ${blockNumber}`, async function () { + // const fluidDex = new FluidDex(network, dexKey, dexHelper); + + // await fluidDex.initializePricing(blockNumber); + + // const ts: TenderlySimulation = new TenderlySimulation( + // network, + // ); + + // await ts.setup(); + + // const forkId = ts.forkId; + // dexHelper.replaceProviderWithRPC( + // `https://rpc.tenderly.co/fork/${forkId}`, + // ); + + // console.log(forkId); + + // fluidDexEventPool = + // fluidDex.eventPools[ + // 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' + // ]; + + // console.log(fluidDexEventPool.dexHelper.provider); + + // console.log( + // 'eth balance before : ' + + // (await dexHelper.provider.getBalance( + // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // )), + // ); + + // const allowanceTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment + // value: '0', + // data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', + // }); + + // console.log( + // 'allowance txn (isSuccess?) : ' + allowanceTxn.success, + // ); + + // const swapTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment + // value: '0', + // data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', + // }); + + // console.log('swap txn (isSuccess?) : ' + swapTxn.success); + + // console.log( + // 'eth balance after : ' + + // (await dexHelper.provider.getBalance( + // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // )), + // ); + + // const txnBlockNumber = swapTxn.transaction.block_number; + + // await delay(30000); + // console.log( + // 'state 1 block after : ' + + // JSON.stringify( + // await fluidDexEventPool.generateState( + // txnBlockNumber - 2, + // ), + // replacer, + // 2, + // ), + // ); + // console.log( + // 'state 1 block after : ' + + // JSON.stringify( + // await fluidDexEventPool.generateState( + // await dexHelper.provider.getBlockNumber(), + // ), + // replacer, + // 2, + // ), + // ); + // }); + it(`State after ${blockNumber}`, async function () { const fluidDex = new FluidDex(network, dexKey, dexHelper); diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts index 2d1e640dc..69b6111bf 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -5,20 +5,13 @@ import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; -import DexFactoryABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; -import { - commonAddresses, - FluidDexPool, - FluidDexPoolState, - PoolWithReserves, - Pool, -} from './types'; -import { ethers } from 'ethers'; -import { eachOfSeries } from 'async'; +import DexFactoryABI from '../../abi/fluid-dex/dexFactory.abi.json'; +import { commonAddresses, Pool } from './types'; import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; import { BytesLike } from 'ethers/lib/utils'; import { Address } from '../../types'; import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; +import { Contract } from 'ethers'; export class FluidDexCommonAddresses extends StatefulEventSubscriber { handlers: { @@ -60,34 +53,7 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { log: Readonly, ): Promise | null> { const blockNumber_ = await this.dexHelper.provider.getBlockNumber(); - const resolverAbi = new Interface(ResolverABI); - const callData: MultiCallParams[] = [ - { - target: this.commonAddresses.resolver, - callData: resolverAbi.encodeFunctionData('getPool', [event.args.dexId]), - decodeFunction: await this.decodePool, - }, - ]; - - const results: Pool[] = await this.dexHelper.multiWrapper.aggregate( - callData, - blockNumber_, - this.dexHelper.multiWrapper.defaultBatchSize, - ); - - const generatedPool = { - address: results[0].address, - token0: results[0].token0, - token1: results[0].token1, - }; - - let currentPool = this.getState(0); - currentPool = currentPool == null ? [] : currentPool; - currentPool = [...currentPool, generatedPool]; - - this.setState(currentPool, blockNumber_); - - return currentPool; + return this.getStateOrGenerate(blockNumber_, false); } decodePool = (result: MultiResult | BytesLike): Pool => { @@ -119,7 +85,12 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { log: Readonly, ): Promise | null> { try { - const event = this.logDecoder(log); + let event; + try { + event = this.logDecoder(log); + } catch (e) { + return null; + } if (event.name in this.handlers) { return await this.handlers[event.name](event, state, log); } @@ -152,47 +123,21 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { * @returns state of the event subscriber at blocknumber */ async generateState(blockNumber: number): Promise> { - // Flatten the array of arrays into a single array - const flattenedResults: Pool[] = ( - await this.getPoolsFromResolver(blockNumber) - ).flat(); - - // Cast the result to DeepReadonly - return flattenedResults as DeepReadonly; - } - - async getPoolsFromResolver(blockNumber: number): Promise { - const resolverAbi = new Interface(ResolverABI); - const callData: MultiCallParams[] = [ - { - target: this.commonAddresses.resolver, - callData: resolverAbi.encodeFunctionData('getAllPools', []), - decodeFunction: this.decodePools, - }, - ]; + const resolverContract = new Contract( + this.commonAddresses.resolver, + ResolverABI, + this.dexHelper.provider, + ); + const rawResult = await resolverContract.callStatic.getAllPools({ + blockTag: blockNumber, + }); - const results: Pool[][] = await this.dexHelper.multiWrapper.aggregate< - Pool[] - >(callData, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize); + const pools: Pool[] = rawResult.map((result: any) => ({ + address: result[0], + token0: result[1], + token1: result[2], + })); - return results[0]; + return pools; } - - decodePools = (result: MultiResult | BytesLike): Pool[] => { - if (result === '0x') { - return []; // Return an empty array since there are no pools to decode - } - return generalDecoder( - result, - ['tuple(address pool, address token0, address token1)[]'], - undefined, - decoded => { - return decoded.map((decodedPool: any) => ({ - address: decodedPool[0][0].toLowerCase(), - token0: decodedPool[0][1].toLowerCase(), - token1: decodedPool[0][2].toLowerCase(), - })); - }, - ); - }; } diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 056099a19..51f431249 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -9,14 +9,10 @@ import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; import { commonAddresses, FluidDexPoolState, - PoolWithReserves, CollateralReserves, DebtReserves, } from './types'; -import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; -import { BytesLike } from 'ethers/lib/utils'; import { Address } from '../../types'; -import { generalDecoder } from '../../lib/decoders'; import { Contract } from 'ethers'; export class FluidDexEventPool extends StatefulEventSubscriber { @@ -50,6 +46,15 @@ export class FluidDexEventPool extends StatefulEventSubscriber | BytesLike, - ): PoolWithReserves => { - return generalDecoder( - result, - [ - 'tuple(address pool, address token0_, address token1_, uint256 fee,' + - 'tuple(uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) collateralReserves, ' + - 'tuple(uint256 token0Debt, uint256 token1Debt, uint256 token0RealReserves, uint256 token1RealReserves, uint256 token0ImaginaryReserves, uint256 token1ImaginaryReserves) debtReserves)', - ], - undefined, - decoded => { - const [decodedResult] = decoded; - return { - pool: decodedResult.pool, - token0_: decodedResult.token0_, - token1_: decodedResult.token1_, - fee: decodedResult.fee, - collateralReserves: { - token0RealReserves: BigInt( - decodedResult.collateralReserves.token0RealReserves, - ), - token1RealReserves: BigInt( - decodedResult.collateralReserves.token1RealReserves, - ), - token0ImaginaryReserves: BigInt( - decodedResult.collateralReserves.token0ImaginaryReserves, - ), - token1ImaginaryReserves: BigInt( - decodedResult.collateralReserves.token1ImaginaryReserves, - ), - }, - debtReserves: { - token0Debt: BigInt(decodedResult.debtReserves.token0Debt), - token1Debt: BigInt(decodedResult.debtReserves.token1Debt), - token0RealReserves: BigInt( - decodedResult.debtReserves.token0RealReserves, - ), - token1RealReserves: BigInt( - decodedResult.debtReserves.token1RealReserves, - ), - token0ImaginaryReserves: BigInt( - decodedResult.debtReserves.token0ImaginaryReserves, - ), - token1ImaginaryReserves: BigInt( - decodedResult.debtReserves.token1ImaginaryReserves, - ), - }, - }; - }, - ); - }; - /** * The function is called every time any of the subscribed * addresses release log. The function accepts the current diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index c6607f92f..355aef2c3 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -89,12 +89,11 @@ export class FluidDex extends SimpleExchange implements IDex { async fetchFluidDexPools(blockNumber: number): Promise { const poolsFromResolver = await this.FluidCommonAddresses.getStateOrGenerate(blockNumber, false); - return poolsFromResolver.map(pool => ({ - id: `FluidDex_${pool.address}`, - address: pool.address, - token0: pool.token0, - token1: pool.token1, + id: `FluidDex_${pool.address.toLowerCase()}`, + address: pool.address.toLowerCase(), + token0: pool.token0.toLowerCase(), + token1: pool.token1.toLowerCase(), })); } @@ -119,9 +118,6 @@ export class FluidDex extends SimpleExchange implements IDex { // for pricing requests. It is optional for a DEX to // implement this function async initializePricing(blockNumber: number) { - // Object.entries(this.eventPools).forEach(([id, eventPool]) => { - // eventPool.getStateOrGenerate(blockNumber, false); - // }); await this.updatePoolAndEventPool(blockNumber); } @@ -252,7 +248,7 @@ export class FluidDex extends SimpleExchange implements IDex { prices: prices, unit: getBigIntPow( (side === SwapSide.SELL ? destToken : srcToken).decimals, - ), // to be done + ), data: { colReserves: state.collateralReserves, debtReserves: state.debtReserves, @@ -260,7 +256,7 @@ export class FluidDex extends SimpleExchange implements IDex { }, exchange: this.dexKey, poolIdentifier: pool.id, - gasCost: FLUID_DEX_GAS_COST, // to be done + gasCost: FLUID_DEX_GAS_COST, poolAddresses: [pool.address], }, ]; diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 6f8834975..8eb7711a1 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -46,9 +46,6 @@ export type FluidDexPool = { }; export type DexParams = { - // TODO: DexParams is set of parameters the can - // be used to initiate a DEX fork. - // Complete me! commonAddresses: commonAddresses; pools: FluidDexPool[]; }; From 102d020f528e3d2d769202a917bf83f13aacb9c3 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 15 Oct 2024 14:12:18 +0530 Subject: [PATCH 34/64] removed commenting --- src/dex/fluid-dex/fluid-dex-events.test.ts | 99 +----------------- src/dex/fluid-dex/fluid-dex-generate-pool.ts | 12 +-- src/dex/fluid-dex/fluid-dex-pool.ts | 19 ++-- src/dex/fluid-dex/fluid-dex.ts | 103 ++++++------------- src/dex/fluid-dex/types.ts | 28 ++--- 5 files changed, 62 insertions(+), 199 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 09928ee68..2e4016101 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -9,19 +9,10 @@ import { Network } from '../../constants'; import { Address } from '../../types'; import { DummyDexHelper } from '../../dex-helper/index'; import { testEventSubscriber } from '../../../tests/utils-events'; -import { - commonAddresses, - FluidDexPool, - FluidDexPoolState, - Pool, -} from './types'; +import { CommonAddresses, FluidDexPoolState, Pool } from './types'; import { FluidDexConfig } from './config'; import { DeepReadonly } from 'ts-essentials'; -import { - EstimateGasSimulation, - TenderlySimulation, - TransactionSimulator, -} from '../../../tests/tenderly-simulation'; +import { TenderlySimulation } from '../../../tests/tenderly-simulation'; /* README @@ -108,7 +99,7 @@ describe('FluidDex EventPool Mainnet', function () { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); - const fluidDexCommonAddressStruct: commonAddresses = + const fluidDexCommonAddressStruct: CommonAddresses = FluidDexConfig[dexKey][network].commonAddresses; const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; @@ -136,90 +127,6 @@ describe('FluidDex EventPool Mainnet', function () { ([eventName, blockNumbers]: [string, number[]]) => { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { - // it(`State after ${blockNumber}`, async function () { - // const fluidDex = new FluidDex(network, dexKey, dexHelper); - - // await fluidDex.initializePricing(blockNumber); - - // const ts: TenderlySimulation = new TenderlySimulation( - // network, - // ); - - // await ts.setup(); - - // const forkId = ts.forkId; - // dexHelper.replaceProviderWithRPC( - // `https://rpc.tenderly.co/fork/${forkId}`, - // ); - - // console.log(forkId); - - // fluidDexEventPool = - // fluidDex.eventPools[ - // 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' - // ]; - - // console.log(fluidDexEventPool.dexHelper.provider); - - // console.log( - // 'eth balance before : ' + - // (await dexHelper.provider.getBalance( - // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // )), - // ); - - // const allowanceTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment - // value: '0', - // data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', - // }); - - // console.log( - // 'allowance txn (isSuccess?) : ' + allowanceTxn.success, - // ); - - // const swapTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment - // value: '0', - // data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', - // }); - - // console.log('swap txn (isSuccess?) : ' + swapTxn.success); - - // console.log( - // 'eth balance after : ' + - // (await dexHelper.provider.getBalance( - // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // )), - // ); - - // const txnBlockNumber = swapTxn.transaction.block_number; - - // await delay(30000); - // console.log( - // 'state 1 block after : ' + - // JSON.stringify( - // await fluidDexEventPool.generateState( - // txnBlockNumber - 2, - // ), - // replacer, - // 2, - // ), - // ); - // console.log( - // 'state 1 block after : ' + - // JSON.stringify( - // await fluidDexEventPool.generateState( - // await dexHelper.provider.getBlockNumber(), - // ), - // replacer, - // 2, - // ), - // ); - // }); - it(`State after ${blockNumber}`, async function () { const fluidDex = new FluidDex(network, dexKey, dexHelper); diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-generate-pool.ts index 69b6111bf..f41e8f4ed 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-generate-pool.ts @@ -1,4 +1,5 @@ import { Interface } from '@ethersproject/abi'; +import { BytesLike } from 'ethers/lib/utils'; import { DeepReadonly } from 'ts-essentials'; import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; @@ -6,11 +7,10 @@ import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; import { IDexHelper } from '../../dex-helper/idex-helper'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import DexFactoryABI from '../../abi/fluid-dex/dexFactory.abi.json'; -import { commonAddresses, Pool } from './types'; -import { MultiResult, MultiCallParams } from '../../lib/multi-wrapper'; -import { BytesLike } from 'ethers/lib/utils'; +import { CommonAddresses, Pool } from './types'; +import { MultiResult } from '../../lib/multi-wrapper'; import { Address } from '../../types'; -import { generalDecoder, extractSuccessAndValue } from '../../lib/decoders'; +import { generalDecoder } from '../../lib/decoders'; import { Contract } from 'ethers'; export class FluidDexCommonAddresses extends StatefulEventSubscriber { @@ -26,11 +26,11 @@ export class FluidDexCommonAddresses extends StatefulEventSubscriber { addressesSubscribed: Address[]; protected dexFactoryIface = new Interface(DexFactoryABI); + protected resolverIface = new Interface(ResolverABI); constructor( readonly parentName: string, - // readonly pool: FluidDexPool, - readonly commonAddresses: commonAddresses, + readonly commonAddresses: CommonAddresses, protected network: number, protected dexHelper: IDexHelper, logger: Logger, diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 51f431249..12b4d03c1 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -1,5 +1,6 @@ import { Interface } from '@ethersproject/abi'; import { DeepReadonly } from 'ts-essentials'; +import { BytesLike } from 'ethers/lib/utils'; import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; @@ -7,7 +8,7 @@ import { IDexHelper } from '../../dex-helper/idex-helper'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; import LiquidityABI from '../../abi/fluid-dex/liquidityUserModule.abi.json'; import { - commonAddresses, + CommonAddresses, FluidDexPoolState, CollateralReserves, DebtReserves, @@ -32,7 +33,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber, log: Readonly, ): Promise | null> { - const resolverAbi = new Interface(ResolverABI); if (!(event.args.user in [this.pool])) { return null; } @@ -75,7 +75,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber { pools: FluidDexPool[]; - readonly FluidCommonAddresses: FluidDexCommonAddresses; + readonly fluidCommonAddresses: FluidDexCommonAddresses; - readonly iFluidDexPool: Interface; + readonly fluidDexPoolIface: Interface; protected adapters; @@ -74,7 +61,7 @@ export class FluidDex extends SimpleExchange implements IDex { ) { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); - this.FluidCommonAddresses = new FluidDexCommonAddresses( + this.fluidCommonAddresses = new FluidDexCommonAddresses( 'FluidDex', FluidDexConfig['FluidDex'][network].commonAddresses, network, @@ -83,12 +70,14 @@ export class FluidDex extends SimpleExchange implements IDex { ); this.pools = FluidDexConfig['FluidDex'][network].pools; this.adapters = Adapters[network] || {}; - this.iFluidDexPool = new Interface(FluidDexPoolABI); + this.fluidDexPoolIface = new Interface(FluidDexPoolABI); } - async fetchFluidDexPools(blockNumber: number): Promise { + private async fetchFluidDexPools( + blockNumber: number, + ): Promise { const poolsFromResolver = - await this.FluidCommonAddresses.getStateOrGenerate(blockNumber, false); + await this.fluidCommonAddresses.getStateOrGenerate(blockNumber, false); return poolsFromResolver.map(pool => ({ id: `FluidDex_${pool.address.toLowerCase()}`, address: pool.address.toLowerCase(), @@ -104,7 +93,7 @@ export class FluidDex extends SimpleExchange implements IDex { this.eventPools[pool.id] = new FluidDexEventPool( 'FluidDex', pool.address, - this.FluidCommonAddresses.commonAddresses, + this.fluidCommonAddresses.commonAddresses, this.network, this.dexHelper, this.logger, @@ -214,33 +203,18 @@ export class FluidDex extends SimpleExchange implements IDex { return null; } - // const state = await eventPool.generateState(blockNumber); const state = await eventPool.getStateOrGenerate(blockNumber); - const swap0To1: boolean = side === SwapSide.SELL; - const prices = amounts.map(amount => { - if (side === SwapSide.SELL) { - return this.swapIn( - srcToken.address.toLowerCase() === pool.token0.toLowerCase(), - amount, - state.collateralReserves, - state.debtReserves, - srcToken.decimals, - destToken.decimals, - BigInt(state.fee), - ); - } else { - return this.swapOut( - !(srcToken.address.toLowerCase() === pool.token0.toLowerCase()), - amount, - state.collateralReserves, - state.debtReserves, - srcToken.decimals, - destToken.decimals, - BigInt(state.fee), - ); - } + return this.swapIn( + srcToken.address.toLowerCase() === pool.token0.toLowerCase(), + amount, + state.collateralReserves, + state.debtReserves, + srcToken.decimals, + destToken.decimals, + BigInt(state.fee), + ); }); return [ @@ -426,38 +400,27 @@ export class FluidDex extends SimpleExchange implements IDex { if (side === SwapSide.BUY) throw new Error(`Buy not supported`); - let method: string; let args: any; let returnAmountPos: number | undefined = undefined; - const deadline = getLocalDeadlineAsFriendlyPlaceholder(); - - method = side == SwapSide.SELL ? 'swapIn' : 'swapOut'; + const method = 'swapIn'; returnAmountPos = extractReturnAmountPosition( - this.iFluidDexPool, + this.fluidDexPoolIface, method, - side == SwapSide.SELL ? 'amountOut_' : 'amountIn_', + 'amountOut_', 1, ); const pool = await this.getPoolByTokenPair(srcToken, destToken); - if (side == SwapSide.SELL) { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; - } else { - args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; - } + if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; } else { - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { - args = [true, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; - } else { - args = [false, BigInt(srcAmount), 2n * BigInt(srcAmount), recipient]; - } + args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; } - const swapData = this.iFluidDexPool.encodeFunctionData(method, args); + const swapData = this.fluidDexPoolIface.encodeFunctionData(method, args); return { needWrapNative: this.needWrapNative, @@ -478,7 +441,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @param outDecimals - The number of decimals for the output token. * @returns The calculated output amount (as a BigInt). */ - swapIn( + private swapIn( swap0To1: boolean, amountIn: bigint, colReserves: CollateralReserves, @@ -703,7 +666,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @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( + private swapRoutingIn( t: bigint, x: bigint, y: bigint, @@ -737,7 +700,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @param {number} fee - The fee for the swap. 1e4 = 1% * @returns {bigint} amountIn - The calculated input amount required for the swap. */ - swapOut( + private swapOut( swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, @@ -772,7 +735,7 @@ export class FluidDex extends SimpleExchange implements IDex { * @param {DebtReserves} debtReserves - The reserves of the debt pool. * @returns {bigint} The calculated input amount required for the swap. */ - swapOutAdjusted( + private swapOutAdjusted( swap0to1: boolean, amountOut: bigint, colReserves: CollateralReserves, diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 8eb7711a1..0660d23ac 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -7,25 +7,25 @@ export type FluidDexPoolState = { }; export type CollateralReserves = { - token0RealReserves: bigint; // Changed from uint to bigint - token1RealReserves: bigint; // Changed from uint to bigint - token0ImaginaryReserves: bigint; // Changed from uint to bigint - token1ImaginaryReserves: bigint; // Changed from uint to bigint + token0RealReserves: bigint; + token1RealReserves: bigint; + token0ImaginaryReserves: bigint; + token1ImaginaryReserves: bigint; }; export type DebtReserves = { - token0Debt: bigint; // Changed from uint to bigint - token1Debt: bigint; // Changed from uint to bigint - token0RealReserves: bigint; // Changed from uint to bigint - token1RealReserves: bigint; // Changed from uint to bigint - token0ImaginaryReserves: bigint; // Changed from uint to bigint - token1ImaginaryReserves: bigint; // Changed from uint to bigint + token0Debt: bigint; + token1Debt: bigint; + token0RealReserves: bigint; + token1RealReserves: bigint; + token0ImaginaryReserves: bigint; + token1ImaginaryReserves: bigint; }; export interface PoolWithReserves { pool: string; - token0_: string; - token1_: string; + token0: string; + token1: string; fee: number; collateralReserves: CollateralReserves; debtReserves: DebtReserves; @@ -46,11 +46,11 @@ export type FluidDexPool = { }; export type DexParams = { - commonAddresses: commonAddresses; + commonAddresses: CommonAddresses; pools: FluidDexPool[]; }; -export type commonAddresses = { +export type CommonAddresses = { liquidityProxy: Address; resolver: Address; dexFactory: Address; From 32598ffdeec7608d9c687d7c88f3fac6826a81ee Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 15 Oct 2024 14:14:27 +0530 Subject: [PATCH 35/64] removed irrelevant padto32bytes function --- src/dex/fluid-dex/fluid-dex-pool.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 12b4d03c1..6257634dc 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -1,6 +1,5 @@ import { Interface } from '@ethersproject/abi'; import { DeepReadonly } from 'ts-essentials'; -import { BytesLike } from 'ethers/lib/utils'; import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; @@ -47,15 +46,6 @@ export class FluidDexEventPool extends StatefulEventSubscriber Date: Tue, 15 Oct 2024 14:24:47 +0530 Subject: [PATCH 36/64] changed the blocknumber when dexis deployed --- src/dex/fluid-dex/fluid-dex-events.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 2e4016101..9388de7d2 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -106,7 +106,7 @@ describe('FluidDex EventPool Mainnet', function () { const poolFetchEventsToTest: Record = { [dexFactory]: { - DexDeployed: [20825862], + DexDeployed: [20776998], }, }; From c98001601fa253586ee8434b9e4cd79e50ee56ab Mon Sep 17 00:00:00 2001 From: 0xprinc <0xprinc@gmail.com> Date: Tue, 15 Oct 2024 14:36:42 +0530 Subject: [PATCH 37/64] Update fluid-dex-events.test.ts --- src/dex/fluid-dex/fluid-dex-events.test.ts | 101 +-------------------- 1 file changed, 4 insertions(+), 97 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 09928ee68..9388de7d2 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -9,19 +9,10 @@ import { Network } from '../../constants'; import { Address } from '../../types'; import { DummyDexHelper } from '../../dex-helper/index'; import { testEventSubscriber } from '../../../tests/utils-events'; -import { - commonAddresses, - FluidDexPool, - FluidDexPoolState, - Pool, -} from './types'; +import { CommonAddresses, FluidDexPoolState, Pool } from './types'; import { FluidDexConfig } from './config'; import { DeepReadonly } from 'ts-essentials'; -import { - EstimateGasSimulation, - TenderlySimulation, - TransactionSimulator, -} from '../../../tests/tenderly-simulation'; +import { TenderlySimulation } from '../../../tests/tenderly-simulation'; /* README @@ -108,14 +99,14 @@ describe('FluidDex EventPool Mainnet', function () { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); - const fluidDexCommonAddressStruct: commonAddresses = + const fluidDexCommonAddressStruct: CommonAddresses = FluidDexConfig[dexKey][network].commonAddresses; const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; const poolFetchEventsToTest: Record = { [dexFactory]: { - DexDeployed: [20825862], + DexDeployed: [20776998], }, }; @@ -136,90 +127,6 @@ describe('FluidDex EventPool Mainnet', function () { ([eventName, blockNumbers]: [string, number[]]) => { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { - // it(`State after ${blockNumber}`, async function () { - // const fluidDex = new FluidDex(network, dexKey, dexHelper); - - // await fluidDex.initializePricing(blockNumber); - - // const ts: TenderlySimulation = new TenderlySimulation( - // network, - // ); - - // await ts.setup(); - - // const forkId = ts.forkId; - // dexHelper.replaceProviderWithRPC( - // `https://rpc.tenderly.co/fork/${forkId}`, - // ); - - // console.log(forkId); - - // fluidDexEventPool = - // fluidDex.eventPools[ - // 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' - // ]; - - // console.log(fluidDexEventPool.dexHelper.provider); - - // console.log( - // 'eth balance before : ' + - // (await dexHelper.provider.getBalance( - // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // )), - // ); - - // const allowanceTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment - // value: '0', - // data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', - // }); - - // console.log( - // 'allowance txn (isSuccess?) : ' + allowanceTxn.success, - // ); - - // const swapTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment - // value: '0', - // data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', - // }); - - // console.log('swap txn (isSuccess?) : ' + swapTxn.success); - - // console.log( - // 'eth balance after : ' + - // (await dexHelper.provider.getBalance( - // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // )), - // ); - - // const txnBlockNumber = swapTxn.transaction.block_number; - - // await delay(30000); - // console.log( - // 'state 1 block after : ' + - // JSON.stringify( - // await fluidDexEventPool.generateState( - // txnBlockNumber - 2, - // ), - // replacer, - // 2, - // ), - // ); - // console.log( - // 'state 1 block after : ' + - // JSON.stringify( - // await fluidDexEventPool.generateState( - // await dexHelper.provider.getBlockNumber(), - // ), - // replacer, - // 2, - // ), - // ); - // }); - it(`State after ${blockNumber}`, async function () { const fluidDex = new FluidDex(network, dexKey, dexHelper); From fd000cdd537e5361e61c617238ea4435846ec3ae Mon Sep 17 00:00:00 2001 From: 0xprinc <0xprinc@gmail.com> Date: Tue, 15 Oct 2024 14:37:25 +0530 Subject: [PATCH 38/64] Update fluid-dex-pool.ts --- src/dex/fluid-dex/fluid-dex-pool.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 12b4d03c1..6257634dc 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -1,6 +1,5 @@ import { Interface } from '@ethersproject/abi'; import { DeepReadonly } from 'ts-essentials'; -import { BytesLike } from 'ethers/lib/utils'; import { Log, Logger } from '../../types'; import { catchParseLogError } from '../../utils'; import { StatefulEventSubscriber } from '../../stateful-event-subscriber'; @@ -47,15 +46,6 @@ export class FluidDexEventPool extends StatefulEventSubscriber Date: Tue, 15 Oct 2024 14:39:37 +0530 Subject: [PATCH 39/64] Update config.ts From 917f6e21965a6c9492503bf211daf664bbb5b66b Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 15 Oct 2024 18:35:20 +0530 Subject: [PATCH 40/64] . --- src/dex/fluid-dex/config.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index ad8a89409..bbd30ccd1 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -18,7 +18,8 @@ export const FluidDexConfig: DexConfigMap = { export const FLUID_DEX_GAS_COST = 160_000; export const Adapters: Record = { - // TODO: add adapters for each chain - // This is an example to copy - [Network.MAINNET]: { [SwapSide.SELL]: [{ name: '', index: 0 }] }, + [Network.MAINNET]: { + // TODO: set index? + [SwapSide.SELL]: [{ name: 'Adapter03', index: 0 }], + }, }; From 04bcd3df43689a5a05dd6c722189369ce497691e Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 15 Oct 2024 19:33:29 +0530 Subject: [PATCH 41/64] . --- src/dex/fluid-dex/fluid-dex-events.test.ts | 194 ++++++++++----------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 9388de7d2..93bf898de 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -120,103 +120,103 @@ describe('FluidDex EventPool Mainnet', function () { let fluidDexEventPool: FluidDexEventPool; let fluidDexCommonAddress: FluidDexCommonAddresses; - Object.entries(poolUpdateEventsToTest).forEach( - ([poolAddress, events]: [string, EventMappings]) => { - describe(`Events for ${poolAddress}`, () => { - Object.entries(events).forEach( - ([eventName, blockNumbers]: [string, number[]]) => { - describe(`${eventName}`, () => { - blockNumbers.forEach((blockNumber: number) => { - it(`State after ${blockNumber}`, async function () { - const fluidDex = new FluidDex(network, dexKey, dexHelper); - - await fluidDex.initializePricing(blockNumber); - - const ts: TenderlySimulation = new TenderlySimulation( - network, - ); - - await ts.setup(); - - const forkId = ts.forkId; - dexHelper.replaceProviderWithRPC( - `https://rpc.tenderly.co/fork/${forkId}`, - ); - - console.log(forkId); - - fluidDexEventPool = - fluidDex.eventPools[ - 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' - ]; - - console.log(fluidDexEventPool.dexHelper.provider); - - console.log( - 'eth balance before : ' + - (await dexHelper.provider.getBalance( - '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - )), - ); - - const allowanceTxn = await ts.simulate({ - from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment - value: '0', - data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', - }); - - console.log( - 'allowance txn (isSuccess?) : ' + allowanceTxn.success, - ); - - const swapTxn = await ts.simulate({ - from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment - value: '0', - data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', - }); - - console.log('swap txn (isSuccess?) : ' + swapTxn.success); - - console.log( - 'eth balance after : ' + - (await dexHelper.provider.getBalance( - '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - )), - ); - - const txnBlockNumber = swapTxn.transaction.block_number; - - await delay(30000); - console.log( - 'state 1 block after : ' + - JSON.stringify( - await fluidDexEventPool.generateState( - txnBlockNumber - 2, - ), - replacer, - 2, - ), - ); - console.log( - 'state 1 block after : ' + - JSON.stringify( - await fluidDexEventPool.generateState( - await dexHelper.provider.getBlockNumber(), - ), - replacer, - 2, - ), - ); - }); - }); - }); - }, - ); - }); - }, - ); + // Object.entries(poolUpdateEventsToTest).forEach( + // ([poolAddress, events]: [string, EventMappings]) => { + // describe(`Events for ${poolAddress}`, () => { + // Object.entries(events).forEach( + // ([eventName, blockNumbers]: [string, number[]]) => { + // describe(`${eventName}`, () => { + // blockNumbers.forEach((blockNumber: number) => { + // it(`State after ${blockNumber}`, async function () { + // const fluidDex = new FluidDex(network, dexKey, dexHelper); + + // await fluidDex.initializePricing(blockNumber); + + // const ts: TenderlySimulation = new TenderlySimulation( + // network, + // ); + + // await ts.setup(); + + // const forkId = ts.forkId; + // dexHelper.replaceProviderWithRPC( + // `https://rpc.tenderly.co/fork/${forkId}`, + // ); + + // console.log(forkId); + + // fluidDexEventPool = + // fluidDex.eventPools[ + // 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' + // ]; + + // console.log(fluidDexEventPool.dexHelper.provider); + + // console.log( + // 'eth balance before : ' + + // (await dexHelper.provider.getBalance( + // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // )), + // ); + + // const allowanceTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment + // value: '0', + // data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', + // }); + + // console.log( + // 'allowance txn (isSuccess?) : ' + allowanceTxn.success, + // ); + + // const swapTxn = await ts.simulate({ + // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment + // value: '0', + // data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', + // }); + + // console.log('swap txn (isSuccess?) : ' + swapTxn.success); + + // console.log( + // 'eth balance after : ' + + // (await dexHelper.provider.getBalance( + // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + // )), + // ); + + // const txnBlockNumber = swapTxn.transaction.block_number; + + // await delay(30000); + // console.log( + // 'state 1 block after : ' + + // JSON.stringify( + // await fluidDexEventPool.generateState( + // txnBlockNumber - 2, + // ), + // replacer, + // 2, + // ), + // ); + // console.log( + // 'state 1 block after : ' + + // JSON.stringify( + // await fluidDexEventPool.generateState( + // await dexHelper.provider.getBlockNumber(), + // ), + // replacer, + // 2, + // ), + // ); + // }); + // }); + // }); + // }, + // ); + // }); + // }, + // ); Object.entries(poolFetchEventsToTest).forEach( ([poolAddress, events]: [string, EventMappings]) => { From ee5b27f67136b7c65931cb645705fb497daa364e Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Tue, 15 Oct 2024 19:38:41 +0530 Subject: [PATCH 42/64] . --- src/dex/fluid-dex/fluid-dex-events.test.ts | 194 ++++++++++----------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 93bf898de..9388de7d2 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -120,103 +120,103 @@ describe('FluidDex EventPool Mainnet', function () { let fluidDexEventPool: FluidDexEventPool; let fluidDexCommonAddress: FluidDexCommonAddresses; - // Object.entries(poolUpdateEventsToTest).forEach( - // ([poolAddress, events]: [string, EventMappings]) => { - // describe(`Events for ${poolAddress}`, () => { - // Object.entries(events).forEach( - // ([eventName, blockNumbers]: [string, number[]]) => { - // describe(`${eventName}`, () => { - // blockNumbers.forEach((blockNumber: number) => { - // it(`State after ${blockNumber}`, async function () { - // const fluidDex = new FluidDex(network, dexKey, dexHelper); - - // await fluidDex.initializePricing(blockNumber); - - // const ts: TenderlySimulation = new TenderlySimulation( - // network, - // ); - - // await ts.setup(); - - // const forkId = ts.forkId; - // dexHelper.replaceProviderWithRPC( - // `https://rpc.tenderly.co/fork/${forkId}`, - // ); - - // console.log(forkId); - - // fluidDexEventPool = - // fluidDex.eventPools[ - // 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' - // ]; - - // console.log(fluidDexEventPool.dexHelper.provider); - - // console.log( - // 'eth balance before : ' + - // (await dexHelper.provider.getBalance( - // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // )), - // ); - - // const allowanceTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment - // value: '0', - // data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', - // }); - - // console.log( - // 'allowance txn (isSuccess?) : ' + allowanceTxn.success, - // ); - - // const swapTxn = await ts.simulate({ - // from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment - // value: '0', - // data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', - // }); - - // console.log('swap txn (isSuccess?) : ' + swapTxn.success); - - // console.log( - // 'eth balance after : ' + - // (await dexHelper.provider.getBalance( - // '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', - // )), - // ); - - // const txnBlockNumber = swapTxn.transaction.block_number; - - // await delay(30000); - // console.log( - // 'state 1 block after : ' + - // JSON.stringify( - // await fluidDexEventPool.generateState( - // txnBlockNumber - 2, - // ), - // replacer, - // 2, - // ), - // ); - // console.log( - // 'state 1 block after : ' + - // JSON.stringify( - // await fluidDexEventPool.generateState( - // await dexHelper.provider.getBlockNumber(), - // ), - // replacer, - // 2, - // ), - // ); - // }); - // }); - // }); - // }, - // ); - // }); - // }, - // ); + Object.entries(poolUpdateEventsToTest).forEach( + ([poolAddress, events]: [string, EventMappings]) => { + describe(`Events for ${poolAddress}`, () => { + Object.entries(events).forEach( + ([eventName, blockNumbers]: [string, number[]]) => { + describe(`${eventName}`, () => { + blockNumbers.forEach((blockNumber: number) => { + it(`State after ${blockNumber}`, async function () { + const fluidDex = new FluidDex(network, dexKey, dexHelper); + + await fluidDex.initializePricing(blockNumber); + + const ts: TenderlySimulation = new TenderlySimulation( + network, + ); + + await ts.setup(); + + const forkId = ts.forkId; + dexHelper.replaceProviderWithRPC( + `https://rpc.tenderly.co/fork/${forkId}`, + ); + + console.log(forkId); + + fluidDexEventPool = + fluidDex.eventPools[ + 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' + ]; + + console.log(fluidDexEventPool.dexHelper.provider); + + console.log( + 'eth balance before : ' + + (await dexHelper.provider.getBalance( + '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + )), + ); + + const allowanceTxn = await ts.simulate({ + from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment + value: '0', + data: '0x095ea7b30000000000000000000000006a000f20005980200259b80c51020030400010680000000000000000000000000000000000000000000000056bc75e2d63100000', + }); + + console.log( + 'allowance txn (isSuccess?) : ' + allowanceTxn.success, + ); + + const swapTxn = await ts.simulate({ + from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment + value: '0', + data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', + }); + + console.log('swap txn (isSuccess?) : ' + swapTxn.success); + + console.log( + 'eth balance after : ' + + (await dexHelper.provider.getBalance( + '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', + )), + ); + + const txnBlockNumber = swapTxn.transaction.block_number; + + await delay(30000); + console.log( + 'state 1 block after : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + txnBlockNumber - 2, + ), + replacer, + 2, + ), + ); + console.log( + 'state 1 block after : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + await dexHelper.provider.getBlockNumber(), + ), + replacer, + 2, + ), + ); + }); + }); + }); + }, + ); + }); + }, + ); Object.entries(poolFetchEventsToTest).forEach( ([poolAddress, events]: [string, EventMappings]) => { From 5fe1de8956ede27b0285d74c68c241c9d7e42b45 Mon Sep 17 00:00:00 2001 From: 0xprinc <0xprinc@gmail.com> Date: Tue, 15 Oct 2024 19:51:52 +0530 Subject: [PATCH 43/64] changed blocknumber of dexdeployed event --- src/dex/fluid-dex/fluid-dex-events.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 9388de7d2..2e4016101 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -106,7 +106,7 @@ describe('FluidDex EventPool Mainnet', function () { const poolFetchEventsToTest: Record = { [dexFactory]: { - DexDeployed: [20776998], + DexDeployed: [20825862], }, }; From 04c267496a911b7e6d3439b941f02152e460d5d1 Mon Sep 17 00:00:00 2001 From: bergben Date: Fri, 18 Oct 2024 18:07:38 +0200 Subject: [PATCH 44/64] feat(fluid-dex): update addresses to production deployment --- src/dex/fluid-dex/config.ts | 6 +++--- src/dex/fluid-dex/fluid-dex-events.test.ts | 2 +- src/dex/fluid-dex/fluid-dex-integration.test.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index bbd30ccd1..fa1402d24 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -7,15 +7,15 @@ export const FluidDexConfig: DexConfigMap = { [Network.MAINNET]: { commonAddresses: { liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497', - resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', - dexFactory: '0x93dd426446b5370f094a1e31f19991aaa6ac0be0', + resolver: '0x90bFebd5Ac2d6787028DC8A58d0b5EE07b16E06F', + dexFactory: '0xF9b539Cd37Fc81bBEA1F078240d16b988BBae073', }, pools: [], }, }, }; -export const FLUID_DEX_GAS_COST = 160_000; +export const FLUID_DEX_GAS_COST = 150_000; export const Adapters: Record = { [Network.MAINNET]: { diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 2e4016101..20a7718f6 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -102,7 +102,7 @@ describe('FluidDex EventPool Mainnet', function () { const fluidDexCommonAddressStruct: CommonAddresses = FluidDexConfig[dexKey][network].commonAddresses; const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; - const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; + const dexFactory: Address = '0xF9b539Cd37Fc81bBEA1F078240d16b988BBae073'; const poolFetchEventsToTest: Record = { [dexFactory]: { diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index d89aaed81..65d14272b 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -64,7 +64,7 @@ async function checkOnChainPricing( prices: bigint[], amounts: bigint[], ) { - const resolverAddress = '0x278166a9b88f166eb170d55801be1b1d1e576330'; + const resolverAddress = '0x90bFebd5Ac2d6787028DC8A58d0b5EE07b16E06F'; const readerIface = new Interface(ResolverABI); From b1058db8ca1a47e9574cdff86fa7e952976c7f14 Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Sat, 19 Oct 2024 02:32:17 +0530 Subject: [PATCH 45/64] made the tests work --- src/dex/fluid-dex/config.ts | 6 +- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 6 +- src/dex/fluid-dex/fluid-dex-events.test.ts | 66 +++++++++++++++---- .../fluid-dex/fluid-dex-integration.test.ts | 2 +- 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index bbd30ccd1..aa31cbc6e 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -7,15 +7,15 @@ export const FluidDexConfig: DexConfigMap = { [Network.MAINNET]: { commonAddresses: { liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497', - resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', - dexFactory: '0x93dd426446b5370f094a1e31f19991aaa6ac0be0', + resolver: '0x90bfebd5ac2d6787028dc8a58d0b5ee07b16e06f', + dexFactory: '0xf9b539cd37fc81bbea1f078240d16b988bbae073', }, pools: [], }, }, }; -export const FLUID_DEX_GAS_COST = 160_000; +export const FLUID_DEX_GAS_COST = 150_000; export const Adapters: Record = { [Network.MAINNET]: { diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index dea93b25f..61df541db 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -117,9 +117,9 @@ describe('FluidDex E2E', () => { const tokenASymbol: string = 'wstETH'; const tokenBSymbol: string = 'ETH'; - const tokenAAmount: string = '1000000000000000000'; - const tokenBAmount: string = '1000000000000000000'; - const nativeTokenAmount = '1000000000000000000'; + const tokenAAmount: string = '100000000000000'; + const tokenBAmount: string = '100000000000000'; + const nativeTokenAmount = '100000000000000'; testForNetwork( network, diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 9388de7d2..8f316ab49 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -63,8 +63,12 @@ async function fetchTotalPools( return await fluidCommonAddresses.generateState(blockNumber); } -function delay(ms: number): Promise { - return new Promise(resolve => setTimeout(resolve, ms)); +async function delay(seconds: number): Promise { + for (let i = seconds; i > 0; i--) { + process.stdout.write(`\r${i} second${i !== 1 ? 's' : ''} left`); + await new Promise(resolve => setTimeout(resolve, 1000)); + } + process.stdout.write("\rTime's up! \n"); } function stringifyCircular(obj: any, space?: number): string { @@ -102,18 +106,18 @@ describe('FluidDex EventPool Mainnet', function () { const fluidDexCommonAddressStruct: CommonAddresses = FluidDexConfig[dexKey][network].commonAddresses; const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; - const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; + const dexFactory: Address = '0xf9b539cd37fc81bbea1f078240d16b988bbae073'; const poolFetchEventsToTest: Record = { [dexFactory]: { - DexDeployed: [20776998], + DexDeployed: [20982078], }, }; // poolAddress -> EventMappings const poolUpdateEventsToTest: Record = { [dexFactory]: { - LogOperate: [20825862], + LogOperate: [20982078], }, }; @@ -131,6 +135,7 @@ describe('FluidDex EventPool Mainnet', function () { const fluidDex = new FluidDex(network, dexKey, dexHelper); await fluidDex.initializePricing(blockNumber); + console.log('hello'); const ts: TenderlySimulation = new TenderlySimulation( network, @@ -145,12 +150,32 @@ describe('FluidDex EventPool Mainnet', function () { console.log(forkId); - fluidDexEventPool = - fluidDex.eventPools[ - 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' - ]; + const pools = + fluidDex.fluidCommonAddresses.getState(blockNumber); + let pool: string | undefined; + + if (pools) { + for (let i = 0; i < pools.length; i++) { + if ( + pools[i].token0.toLowerCase() === + '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0' && + pools[i].token1.toLowerCase() === + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' + ) { + pool = pools[i].address.toLowerCase(); + break; + } + } + } else { + console.error('Pools data is null or undefined'); + } + + fluidDexEventPool = fluidDex.eventPools[`FluidDex_${pool}`]; + console.log( + `this is the dex key that i fetched from writing the for loop FluidDex_${pool}`, + ); - console.log(fluidDexEventPool.dexHelper.provider); + // console.log(fluidDexEventPool.dexHelper.provider); console.log( 'eth balance before : ' + @@ -159,6 +184,17 @@ describe('FluidDex EventPool Mainnet', function () { )), ); + console.log( + 'state 1 block after : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + await dexHelper.provider.getBlockNumber(), + ), + replacer, + 2, + ), + ); + const allowanceTxn = await ts.simulate({ from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment @@ -174,7 +210,7 @@ describe('FluidDex EventPool Mainnet', function () { from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment value: '0', - data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', + data: '0xe3ead59e000000000000000000000000000010036c0190e009a000d0fc3541100a07380a0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000006a6b745e1dd000000000000000000000000000000000000000000000000000006b7ea416a9c0a47d24fdc9fd475bb1cc320a468c050100000000000000000000000001405b6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b300000000000000000000000025f0a3b25cbc0ca0417770f686209628323ff901ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff25f0a3b25cbc0ca0417770f686209628323ff901000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', }); console.log('swap txn (isSuccess?) : ' + swapTxn.success); @@ -188,9 +224,13 @@ describe('FluidDex EventPool Mainnet', function () { const txnBlockNumber = swapTxn.transaction.block_number; - await delay(30000); + console.log(txnBlockNumber); + console.log(await dexHelper.provider.getBlockNumber()); + + await delay(30); + console.log( - 'state 1 block after : ' + + 'state 1 block before : ' + JSON.stringify( await fluidDexEventPool.generateState( txnBlockNumber - 2, diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index d89aaed81..11474ca76 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -64,7 +64,7 @@ async function checkOnChainPricing( prices: bigint[], amounts: bigint[], ) { - const resolverAddress = '0x278166a9b88f166eb170d55801be1b1d1e576330'; + const resolverAddress = '0x90bfebd5ac2d6787028dc8a58d0b5ee07b16e06f'; const readerIface = new Interface(ResolverABI); From 7a74e6c45a7b4629d654cbc768d55e9801da0e0a Mon Sep 17 00:00:00 2001 From: 0xprinc <0xprinc@gmail.com> Date: Sat, 19 Oct 2024 02:47:44 +0530 Subject: [PATCH 46/64] Update fluid-dex.ts --- src/dex/fluid-dex/fluid-dex.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index ab82a896b..06189c037 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -453,6 +453,12 @@ export class FluidDex extends SimpleExchange implements IDex { if (amountIn === 0n) { return 0n; // Return 0 if input amount is 0 } + if ( + colReserves.token0RealReserves + debtReserves.token0RealReserves == 0n && + colReserves.token1RealReserves + debtReserves.token1RealReserves == 0n + ) { + return 0n; + } const amountInAdjusted = (((amountIn * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT) * BigInt(10 ** 12)) / From 96ffcd240d04b7adffe056761f7db2da2f80922a Mon Sep 17 00:00:00 2001 From: bergben Date: Sun, 20 Oct 2024 17:31:55 +0200 Subject: [PATCH 47/64] feat(fluid): finalize gas cost constant --- src/dex/fluid-dex/config.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index aa31cbc6e..367cb4b49 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -15,7 +15,10 @@ export const FluidDexConfig: DexConfigMap = { }, }; -export const FLUID_DEX_GAS_COST = 150_000; +// Uniswap takes total gas of 125k = 21k base gas & 104k swap (this is when user has token balance) +// Fluid takes total gas of 175k = 21k base gas & 154k swap (this is when user has token balance), +// with ETH swaps costing less (because no WETH conversion) +export const FLUID_DEX_GAS_COST = 154_000; export const Adapters: Record = { [Network.MAINNET]: { From 54923901b7bd9068214592e1e75325f5d92e2b1d Mon Sep 17 00:00:00 2001 From: 0xprinc Date: Mon, 28 Oct 2024 20:35:27 +0530 Subject: [PATCH 48/64] reoslved the issue --- src/abi/fluid-dex/resolver.abi.json | 643 +++++++++++------- src/dex/fluid-dex/config.ts | 4 +- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 7 +- src/dex/fluid-dex/fluid-dex-events.test.ts | 67 +- .../fluid-dex/fluid-dex-integration.test.ts | 34 +- src/dex/fluid-dex/fluid-dex-pool.ts | 4 +- src/dex/fluid-dex/fluid-dex.ts | 48 +- 7 files changed, 509 insertions(+), 298 deletions(-) diff --git a/src/abi/fluid-dex/resolver.abi.json b/src/abi/fluid-dex/resolver.abi.json index e5be96ef0..44a0251af 100644 --- a/src/abi/fluid-dex/resolver.abi.json +++ b/src/abi/fluid-dex/resolver.abi.json @@ -1,11 +1,7 @@ [ { "inputs": [ - { - "internalType": "address", - "name": "factory_", - "type": "address" - } + { "internalType": "address", "name": "factory_", "type": "address" } ], "stateMutability": "nonpayable", "type": "constructor" @@ -25,68 +21,28 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "bool", - "name": "swap0to1_", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "amountIn_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountOutMin_", - "type": "uint256" - } + { "internalType": "address", "name": "dex_", "type": "address" }, + { "internalType": "bool", "name": "swap0to1_", "type": "bool" }, + { "internalType": "uint256", "name": "amountIn_", "type": "uint256" }, + { "internalType": "uint256", "name": "amountOutMin_", "type": "uint256" } ], "name": "estimateSwapIn", "outputs": [ - { - "internalType": "uint256", - "name": "amountOut_", - "type": "uint256" - } + { "internalType": "uint256", "name": "amountOut_", "type": "uint256" } ], "stateMutability": "payable", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - }, - { - "internalType": "bool", - "name": "swap0to1_", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "amountOut_", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amountInMax_", - "type": "uint256" - } + { "internalType": "address", "name": "dex_", "type": "address" }, + { "internalType": "bool", "name": "swap0to1_", "type": "bool" }, + { "internalType": "uint256", "name": "amountOut_", "type": "uint256" }, + { "internalType": "uint256", "name": "amountInMax_", "type": "uint256" } ], "name": "estimateSwapOut", "outputs": [ - { - "internalType": "uint256", - "name": "amountIn_", - "type": "uint256" - } + { "internalType": "uint256", "name": "amountIn_", "type": "uint256" } ], "stateMutability": "payable", "type": "function" @@ -95,11 +51,7 @@ "inputs": [], "name": "getAllPoolAddresses", "outputs": [ - { - "internalType": "address[]", - "name": "pools_", - "type": "address[]" - } + { "internalType": "address[]", "name": "pools_", "type": "address[]" } ], "stateMutability": "view", "type": "function" @@ -110,26 +62,10 @@ "outputs": [ { "components": [ - { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - } + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" } ], "internalType": "struct Structs.Pool[]", "name": "pools_", @@ -145,26 +81,93 @@ "outputs": [ { "components": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" }, { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" }, { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves[]", + "name": "poolsReserves_", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getAllPoolsReservesAdjusted", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "components": [ { @@ -240,11 +243,7 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "dex_", - "type": "address" - } + { "internalType": "address", "name": "dex_", "type": "address" } ], "name": "getDexCollateralReserves", "outputs": [ @@ -281,12 +280,45 @@ }, { "inputs": [ + { "internalType": "address", "name": "dex_", "type": "address" } + ], + "name": "getDexCollateralReservesAdjusted", + "outputs": [ { - "internalType": "address", - "name": "dex_", - "type": "address" + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "reserves_", + "type": "tuple" } ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "dex_", "type": "address" } + ], "name": "getDexDebtReserves", "outputs": [ { @@ -332,12 +364,55 @@ }, { "inputs": [ + { "internalType": "address", "name": "dex_", "type": "address" } + ], + "name": "getDexDebtReservesAdjusted", + "outputs": [ { - "internalType": "address", - "name": "dex_", - "type": "address" + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "reserves_", + "type": "tuple" } ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "dex_", "type": "address" } + ], "name": "getDexPricesAndExchangePrices", "outputs": [ { @@ -398,36 +473,16 @@ }, { "inputs": [ - { - "internalType": "uint256", - "name": "poolId_", - "type": "uint256" - } + { "internalType": "uint256", "name": "poolId_", "type": "uint256" } ], "name": "getPool", "outputs": [ { "components": [ - { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, - { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - } + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" } ], "internalType": "struct Structs.Pool", "name": "pool_", @@ -439,62 +494,30 @@ }, { "inputs": [ - { - "internalType": "uint256", - "name": "poolId_", - "type": "uint256" - } + { "internalType": "uint256", "name": "poolId_", "type": "uint256" } ], "name": "getPoolAddress", "outputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } + { "internalType": "address", "name": "pool_", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } + { "internalType": "address", "name": "pool_", "type": "address" } ], "name": "getPoolConstantsView", "outputs": [ { "components": [ - { - "internalType": "uint256", - "name": "dexId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "liquidity", - "type": "address" - }, - { - "internalType": "address", - "name": "factory", - "type": "address" - }, + { "internalType": "uint256", "name": "dexId", "type": "uint256" }, + { "internalType": "address", "name": "liquidity", "type": "address" }, + { "internalType": "address", "name": "factory", "type": "address" }, { "components": [ - { - "internalType": "address", - "name": "shift", - "type": "address" - }, - { - "internalType": "address", - "name": "admin", - "type": "address" - }, + { "internalType": "address", "name": "shift", "type": "address" }, + { "internalType": "address", "name": "admin", "type": "address" }, { "internalType": "address", "name": "colOperations", @@ -520,16 +543,8 @@ "name": "deployerContract", "type": "address" }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" - }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, { "internalType": "bytes32", "name": "supplyToken0Slot", @@ -576,11 +591,7 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } + { "internalType": "address", "name": "pool_", "type": "address" } ], "name": "getPoolConstantsView2", "outputs": [ @@ -617,55 +628,112 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } + { "internalType": "address", "name": "pool_", "type": "address" } ], "name": "getPoolFee", "outputs": [ - { - "internalType": "uint256", - "name": "fee_", - "type": "uint256" - } + { "internalType": "uint256", "name": "fee_", "type": "uint256" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } + { "internalType": "address", "name": "pool_", "type": "address" } ], "name": "getPoolReserves", "outputs": [ { "components": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" }, { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" }, { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves", + "name": "poolReserves_", + "type": "tuple" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "pool_", "type": "address" } + ], + "name": "getPoolReservesAdjusted", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "components": [ { @@ -741,60 +809,113 @@ }, { "inputs": [ - { - "internalType": "address", - "name": "pool_", - "type": "address" - } + { "internalType": "address", "name": "pool_", "type": "address" } ], "name": "getPoolTokens", "outputs": [ - { - "internalType": "address", - "name": "token0_", - "type": "address" - }, - { - "internalType": "address", - "name": "token1_", - "type": "address" - } + { "internalType": "address", "name": "token0_", "type": "address" }, + { "internalType": "address", "name": "token1_", "type": "address" } ], "stateMutability": "view", "type": "function" }, { "inputs": [ - { - "internalType": "address[]", - "name": "pools_", - "type": "address[]" - } + { "internalType": "address[]", "name": "pools_", "type": "address[]" } ], "name": "getPoolsReserves", "outputs": [ { "components": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" }, { - "internalType": "address", - "name": "pool", - "type": "address" - }, - { - "internalType": "address", - "name": "token0", - "type": "address" - }, - { - "internalType": "address", - "name": "token1", - "type": "address" + "components": [ + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.CollateralReserves", + "name": "collateralReserves", + "type": "tuple" }, { - "internalType": "uint256", - "name": "fee", - "type": "uint256" - }, + "components": [ + { + "internalType": "uint256", + "name": "token0Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1Debt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1RealReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token0ImaginaryReserves", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "token1ImaginaryReserves", + "type": "uint256" + } + ], + "internalType": "struct IFluidDexT1.DebtReserves", + "name": "debtReserves", + "type": "tuple" + } + ], + "internalType": "struct Structs.PoolWithReserves[]", + "name": "poolsReserves_", + "type": "tuple[]" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address[]", "name": "pools_", "type": "address[]" } + ], + "name": "getPoolsReservesAdjusted", + "outputs": [ + { + "components": [ + { "internalType": "address", "name": "pool", "type": "address" }, + { "internalType": "address", "name": "token0", "type": "address" }, + { "internalType": "address", "name": "token1", "type": "address" }, + { "internalType": "uint256", "name": "fee", "type": "uint256" }, { "components": [ { @@ -871,13 +992,7 @@ { "inputs": [], "name": "getTotalPools", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" } diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index bbd30ccd1..eb73dc603 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -7,8 +7,8 @@ export const FluidDexConfig: DexConfigMap = { [Network.MAINNET]: { commonAddresses: { liquidityProxy: '0x52aa899454998be5b000ad077a46bbe360f4e497', - resolver: '0x278166a9b88f166eb170d55801be1b1d1e576330', - dexFactory: '0x93dd426446b5370f094a1e31f19991aaa6ac0be0', + resolver: '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13', + dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085', }, pools: [], }, diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index dea93b25f..303c52846 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -11,6 +11,7 @@ import { import { Network, ContractMethod, SwapSide } from '../../constants'; import { StaticJsonRpcProvider } from '@ethersproject/providers'; import { generateConfig } from '../../config'; +import { DummyDexHelper } from '../../dex-helper'; /* README @@ -117,9 +118,9 @@ describe('FluidDex E2E', () => { const tokenASymbol: string = 'wstETH'; const tokenBSymbol: string = 'ETH'; - const tokenAAmount: string = '1000000000000000000'; - const tokenBAmount: string = '1000000000000000000'; - const nativeTokenAmount = '1000000000000000000'; + const tokenAAmount: string = '100000000000000'; + const tokenBAmount: string = '100000000000000'; + const nativeTokenAmount = '100000000000000'; testForNetwork( network, diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 2e4016101..f05e69703 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -63,8 +63,12 @@ async function fetchTotalPools( return await fluidCommonAddresses.generateState(blockNumber); } -function delay(ms: number): Promise { - return new Promise(resolve => setTimeout(resolve, ms)); +async function delay(seconds: number): Promise { + for (let i = seconds; i > 0; i--) { + process.stdout.write(`\r${i} second${i !== 1 ? 's' : ''} left`); + await new Promise(resolve => setTimeout(resolve, 1000)); + } + process.stdout.write("\rTime's up! \n"); } function stringifyCircular(obj: any, space?: number): string { @@ -102,18 +106,18 @@ describe('FluidDex EventPool Mainnet', function () { const fluidDexCommonAddressStruct: CommonAddresses = FluidDexConfig[dexKey][network].commonAddresses; const liquidityProxy: Address = '0x52aa899454998be5b000ad077a46bbe360f4e497'; - const dexFactory: Address = '0x93dd426446b5370f094a1e31f19991aaa6ac0be0'; + const dexFactory: Address = '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085'; const poolFetchEventsToTest: Record = { [dexFactory]: { - DexDeployed: [20825862], + DexDeployed: [21063272], }, }; // poolAddress -> EventMappings const poolUpdateEventsToTest: Record = { [dexFactory]: { - LogOperate: [20825862], + LogOperate: [21063272], }, }; @@ -145,12 +149,32 @@ describe('FluidDex EventPool Mainnet', function () { console.log(forkId); - fluidDexEventPool = - fluidDex.eventPools[ - 'FluidDex_0x6d83f60eeac0e50a1250760151e81db2a278e03a' - ]; + const pools = + fluidDex.fluidCommonAddresses.getState(blockNumber); + let pool: string | undefined; + + if (pools) { + for (let i = 0; i < pools.length; i++) { + if ( + pools[i].token0.toLowerCase() === + '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0' && + pools[i].token1.toLowerCase() === + '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' + ) { + pool = pools[i].address.toLowerCase(); + break; + } + } + } else { + console.error('Pools data is null or undefined'); + } + + fluidDexEventPool = fluidDex.eventPools[`FluidDex_${pool}`]; + console.log( + `this is the dex key that i fetched from writing the for loop FluidDex_${pool}`, + ); - console.log(fluidDexEventPool.dexHelper.provider); + console.log('this is pool : ' + pool); console.log( 'eth balance before : ' + @@ -159,6 +183,17 @@ describe('FluidDex EventPool Mainnet', function () { )), ); + console.log( + 'state 1 block before : ' + + JSON.stringify( + await fluidDexEventPool.generateState( + await dexHelper.provider.getBlockNumber(), + ), + replacer, + 2, + ), + ); + const allowanceTxn = await ts.simulate({ from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', // undefined in case of contract deployment @@ -174,7 +209,7 @@ describe('FluidDex EventPool Mainnet', function () { from: '0x3c22ec75ea5d745c78fc84762f7f1e6d82a2c5bf', to: '0x6a000f20005980200259b80c5102003040001068', // undefined in case of contract deployment value: '0', - data: '0xe3ead59e000000000000000000000000a600910b670804230e00a100000d28000ae005c00000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000103ab964e9ceb0100000000000000000000000000000000000000000000000001064b0ec65b454c0ae160924eed54e7abfa6d4ced59c2447000000000000000000000000013f7447000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000006d83f60eeac0e50a1250760151e81db2a278e03affffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6d83f60eeac0e50a1250760151e81db2a278e03a000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', + data: '0xe3ead59e000000000000000000000000000010036c0190e009a000d0fc3541100a07380a0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee00000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000006a6b745e1dd000000000000000000000000000000000000000000000000000006b7ea416a9c0a47d24fdc9fd475bb1cc320a468c050100000000000000000000000001405b6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001807f39c581f595b53c5cb19bd0b3f8da6c935e2ca00000006000000044ff00000000000000000000000000000000000000000000000000000000000000095ea7b30000000000000000000000000b1a513ee24972daef112bc777a5610d4325c9e7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0b1a513ee24972daef112bc777a5610d4325c9e7000000a00024000000000007000000000000000000000000000000000000000000000000000000002668dfaa000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006a000f20005980200259b80c5102003040001068', }); console.log('swap txn (isSuccess?) : ' + swapTxn.success); @@ -186,11 +221,17 @@ describe('FluidDex EventPool Mainnet', function () { )), ); + // console.log(JSON.stringify(swapTxn)); + const txnBlockNumber = swapTxn.transaction.block_number; - await delay(30000); + console.log(txnBlockNumber); + console.log(await dexHelper.provider.getBlockNumber()); + + await delay(30); + console.log( - 'state 1 block after : ' + + 'state 1 block before : ' + JSON.stringify( await fluidDexEventPool.generateState( txnBlockNumber - 2, diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index d89aaed81..5cb9f9879 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -39,7 +39,7 @@ function getReaderCalldata( return amounts.map(amount => ({ target: exchangeAddress, callData: readerIface.encodeFunctionData(funcName, [ - '0x6d83f60eeac0e50a1250760151e81db2a278e03a', + '0x0b1a513ee24972daef112bc777a5610d4325c9e7', funcName == 'estimateSwapIn' ? true : false, amount, funcName == 'estimateSwapIn' ? 0 : 2n * amount, @@ -64,7 +64,7 @@ async function checkOnChainPricing( prices: bigint[], amounts: bigint[], ) { - const resolverAddress = '0x278166a9b88f166eb170d55801be1b1d1e576330'; + const resolverAddress = '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13'; const readerIface = new Interface(ResolverABI); @@ -123,7 +123,15 @@ async function testPricingOnNetwork( `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `, poolPrices, ); - + console.log( + 'logged params : ', + networkTokens[srcTokenSymbol], + networkTokens[destTokenSymbol], + amounts, + side, + blockNumber, + pools, + ); expect(poolPrices).not.toBeNull(); if (fluidDex.hasConstantPriceLargeAmounts) { checkConstantPoolPrices(poolPrices!, amounts, dexKey); @@ -158,16 +166,16 @@ describe('FluidDex', function () { const amountsForSell = [ 0n, - 1n * BI_POWS[tokens[srcTokenSymbol].decimals], - 2n * BI_POWS[tokens[srcTokenSymbol].decimals], - 3n * BI_POWS[tokens[srcTokenSymbol].decimals], - 4n * BI_POWS[tokens[srcTokenSymbol].decimals], - 5n * BI_POWS[tokens[srcTokenSymbol].decimals], - 6n * BI_POWS[tokens[srcTokenSymbol].decimals], - 7n * BI_POWS[tokens[srcTokenSymbol].decimals], - 8n * BI_POWS[tokens[srcTokenSymbol].decimals], - 9n * BI_POWS[tokens[srcTokenSymbol].decimals], - 10n * BI_POWS[tokens[srcTokenSymbol].decimals], + 1n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 2n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 3n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 4n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 5n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 6n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 7n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 8n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 9n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], + 10n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], ]; beforeAll(async () => { diff --git a/src/dex/fluid-dex/fluid-dex-pool.ts b/src/dex/fluid-dex/fluid-dex-pool.ts index 6257634dc..a00740307 100644 --- a/src/dex/fluid-dex/fluid-dex-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-pool.ts @@ -62,7 +62,7 @@ export class FluidDexEventPool extends StatefulEventSubscriber { BigInt(state.fee), ); }); - return [ { prices: prices, @@ -453,6 +452,12 @@ export class FluidDex extends SimpleExchange implements IDex { if (amountIn === 0n) { return 0n; // Return 0 if input amount is 0 } + if ( + colReserves.token0RealReserves + debtReserves.token0RealReserves == 0n && + colReserves.token1RealReserves + debtReserves.token1RealReserves == 0n + ) { + return 0n; + } const amountInAdjusted = (((amountIn * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT) * BigInt(10 ** 12)) / @@ -510,19 +515,31 @@ export class FluidDex extends SimpleExchange implements IDex { debtToken0ImaginaryReserves > BigInt(0) && debtToken1ImaginaryReserves > BigInt(0); + let colReserveIn: bigint, + colReserveOut: bigint, + debtReserveIn: bigint, + debtReserveOut: bigint; let colIReserveIn: bigint, colIReserveOut: bigint, debtIReserveIn: bigint, debtIReserveOut: bigint; if (swap0To1) { + colReserveIn = token0RealReserves; + colReserveOut = token1RealReserves; colIReserveIn = token0ImaginaryReserves; colIReserveOut = token1ImaginaryReserves; + debtReserveIn = debtToken0RealReserves; + debtReserveOut = debtToken1RealReserves; debtIReserveIn = debtToken0ImaginaryReserves; debtIReserveOut = debtToken1ImaginaryReserves; } else { + colReserveIn = token1RealReserves; + colReserveOut = token0RealReserves; colIReserveIn = token1ImaginaryReserves; colIReserveOut = token0ImaginaryReserves; + debtReserveIn = debtToken1RealReserves; + debtReserveOut = debtToken0RealReserves; debtIReserveIn = debtToken1ImaginaryReserves; debtIReserveOut = debtToken0ImaginaryReserves; } @@ -570,6 +587,14 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveOut, ); } + + if (amountOutDebt > debtReserveOut) { + return 0n; + } + + if (amountOutCollateral > colReserveOut) { + return 0n; + } const totalAmountOut = amountOutCollateral + amountOutDebt; return totalAmountOut; @@ -769,19 +794,31 @@ export class FluidDex extends SimpleExchange implements IDex { debtToken0ImaginaryReserves > 0n && debtToken1ImaginaryReserves > 0n; + let colReserveIn: bigint, + colReserveOut: bigint, + debtReserveIn: bigint, + debtReserveOut: bigint; let colIReserveIn: bigint, colIReserveOut: bigint, debtIReserveIn: bigint, debtIReserveOut: bigint; if (swap0to1) { + colReserveIn = token0RealReserves; + colReserveOut = token1RealReserves; colIReserveIn = token0ImaginaryReserves; colIReserveOut = token1ImaginaryReserves; + debtReserveIn = debtToken0RealReserves; + debtReserveOut = debtToken1RealReserves; debtIReserveIn = debtToken0ImaginaryReserves; debtIReserveOut = debtToken1ImaginaryReserves; } else { + colReserveIn = token1RealReserves; + colReserveOut = token0RealReserves; colIReserveIn = token1ImaginaryReserves; colIReserveOut = token0ImaginaryReserves; + debtReserveIn = debtToken1RealReserves; + debtReserveOut = debtToken0RealReserves; debtIReserveIn = debtToken1ImaginaryReserves; debtIReserveOut = debtToken0ImaginaryReserves; } @@ -813,6 +850,9 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveIn, debtIReserveOut, ); + if (amountOut > debtReserveOut) { + return 2n ** 64n - 1n; // BigInt max value + } } else if (a >= amountOut) { // Entire trade routes through collateral pool amountInCollateral = this.getAmountIn( @@ -820,6 +860,9 @@ export class FluidDex extends SimpleExchange implements IDex { colIReserveIn, colIReserveOut, ); + if (amountOut > colReserveOut) { + return 2n ** 64n - 1n; // BigInt max value + } } else { // Trade routes through both pools amountInCollateral = this.getAmountIn(a, colIReserveIn, colIReserveOut); @@ -828,6 +871,9 @@ export class FluidDex extends SimpleExchange implements IDex { debtIReserveIn, debtIReserveOut, ); + if (amountOut - a > debtReserveOut || a > debtReserveOut) { + return 2n ** 64n - 1n; // BigInt max value + } } const totalAmountIn = amountInCollateral + amountInDebt; From 5b02437d17f0121adacb48f2d4a55e4bce732a82 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 11:54:03 +0300 Subject: [PATCH 49/64] remove adapters --- src/dex/fluid-dex/config.ts | 7 ------- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 4 +++- src/dex/fluid-dex/fluid-dex.ts | 11 +++-------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index 11f8462b1..6a619309b 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -19,10 +19,3 @@ export const FluidDexConfig: DexConfigMap = { // Fluid takes total gas of 175k = 21k base gas & 154k swap (this is when user has token balance), // with ETH swaps costing less (because no WETH conversion) export const FLUID_DEX_GAS_COST = 154_000; - -export const Adapters: Record = { - [Network.MAINNET]: { - // TODO: set index? - [SwapSide.SELL]: [{ name: 'Adapter03', index: 0 }], - }, -}; diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 3f54871bb..0e3dfa86e 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -70,7 +70,9 @@ function testForNetwork( const holders = Holders[network]; const nativeTokenSymbol = NativeTokenSymbols[network]; - const sideToContractMethods = new Map([[SwapSide.SELL, ['swapIn']]]); + const sideToContractMethods = new Map([ + [SwapSide.SELL, [ContractMethod.swapExactAmountIn]], + ]); describe(`${network}`, () => { sideToContractMethods.forEach((contractMethods, side) => diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index f7930cbd6..1236bf5b0 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -24,7 +24,7 @@ import { } from './types'; import { SimpleExchange } from '../simple-exchange'; import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json'; -import { FluidDexConfig, Adapters, FLUID_DEX_GAS_COST } from './config'; +import { FluidDexConfig, FLUID_DEX_GAS_COST } from './config'; import { FluidDexEventPool } from './fluid-dex-pool'; import { FluidDexCommonAddresses } from './fluid-dex-generate-pool'; import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; @@ -50,8 +50,6 @@ export class FluidDex extends SimpleExchange implements IDex { readonly fluidDexPoolIface: Interface; - protected adapters; - FEE_100_PERCENT = BigInt(1000000); constructor( @@ -69,7 +67,6 @@ export class FluidDex extends SimpleExchange implements IDex { this.logger, ); this.pools = FluidDexConfig['FluidDex'][network].pools; - this.adapters = Adapters[network] || {}; this.fluidDexPoolIface = new Interface(FluidDexPoolABI); } @@ -110,10 +107,8 @@ export class FluidDex extends SimpleExchange implements IDex { await this.updatePoolAndEventPool(blockNumber); } - // Returns the list of contract adapters (name and index) - // for a buy/sell. Return null if there are no adapters. - getAdapters(side: SwapSide): { name: string; index: number }[] | null { - return this.adapters[side] ? this.adapters[side] : null; + getAdapters(side: SwapSide) { + return null; } decodePools = (result: MultiResult | BytesLike): Pool[] => { From ced8c6c017cb539c63e5db1ea56fce2a1f4bce73 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 11:56:14 +0300 Subject: [PATCH 50/64] 3.9.7-fluid-dex.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 477bbd6b9..d2d348091 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.9.6", + "version": "3.9.7-fluid-dex.0", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 0b6559d49a5f80ac91d3403cb890785a941fa8ea Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 13:26:25 +0300 Subject: [PATCH 51/64] disable getTopPoolsForToken --- .gitignore | 6 - src/dex/fluid-dex/config.ts | 4 +- src/dex/fluid-dex/fluid-dex.ts | 186 +-- tests/constants-e2e.d.ts | 22 + tests/constants-e2e.js | 1942 ++++++++++++++++++++++++++++++++ tests/constants-e2e.js.map | 1 + tests/constants-e2e.ts | 1 - tests/smart-tokens.d.ts | 36 + tests/smart-tokens.js | 64 ++ tests/smart-tokens.js.map | 1 + 10 files changed, 2161 insertions(+), 102 deletions(-) create mode 100644 tests/constants-e2e.d.ts create mode 100644 tests/constants-e2e.js create mode 100644 tests/constants-e2e.js.map create mode 100644 tests/smart-tokens.d.ts create mode 100644 tests/smart-tokens.js create mode 100644 tests/smart-tokens.js.map diff --git a/.gitignore b/.gitignore index b601e2d07..bea819f62 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,3 @@ tests/configs.json .idea/ local-scripts tests/debug-price-route.json -tests/constants-e2e.d.ts -tests/constants-e2e.js -tests/constants-e2e.js.map -tests/smart-tokens.d.ts -tests/smart-tokens.js -tests/smart-tokens.js.map \ No newline at end of file diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index 6a619309b..dc87730f8 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -1,6 +1,6 @@ import { DexParams } from './types'; -import { DexConfigMap, AdapterMappings } from '../../types'; -import { Network, SwapSide } from '../../constants'; +import { DexConfigMap } from '../../types'; +import { Network } from '../../constants'; export const FluidDexConfig: DexConfigMap = { FluidDex: { diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 1236bf5b0..b76b27d90 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -31,8 +31,6 @@ import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; import { extractReturnAmountPosition } from '../../executor/utils'; import { MultiResult } from '../../lib/multi-wrapper'; import { generalDecoder } from '../../lib/decoders'; -// @ts-ignore -import { Tokens } from '../../../tests/constants-e2e'; export class FluidDex extends SimpleExchange implements IDex { eventPools: { [id: string]: FluidDexEventPool } = {}; @@ -285,97 +283,99 @@ export class FluidDex extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { - const latestBlockNumber_ = await this.dexHelper.provider.getBlockNumber(); - let liquidityAmounts: { [id: string]: bigint } = {}; - for (const pool of this.pools) { - if ( - pool.token0 === tokenAddress.toLowerCase() || - pool.token1 === tokenAddress.toLowerCase() - ) { - const state: FluidDexPoolState = await this.eventPools[ - pool.id - ].getStateOrGenerate(latestBlockNumber_, false); - - liquidityAmounts[pool.id] = - pool.token0 === tokenAddress - ? state.collateralReserves.token0RealReserves + - state.debtReserves.token0RealReserves - : state.collateralReserves.token1RealReserves + - state.debtReserves.token1RealReserves; - } - } - - const entries = Object.entries(liquidityAmounts); - - // Sort the entries based on the values in descending order - entries.sort((a, b) => { - if (b[1] > a[1]) return 1; - if (b[1] < a[1]) return -1; - return 0; - }); - - // Take the top k entries - const topKEntries = entries.slice(0, limit); - - // Convert the array back to an object - const sortedAmounts = Object.fromEntries(topKEntries); - - const poolLiquidities: PoolLiquidity[] = []; - - for (const [id, amount] of Object.entries(sortedAmounts)) { - const pool = this.pools.find(p => p.id === id); - if (!pool) continue; // Skip if pool not found - - const state: FluidDexPoolState = await this.eventPools[ - pool.id - ].getStateOrGenerate(latestBlockNumber_, false); - - let token0decimals: number; - for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { - let found = false; - for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { - if (tokenParams.address.toLowerCase() === pool.token0.toLowerCase()) { - token0decimals = tokenParams.decimals; - found = true; - break; - } - if (found) break; - } - } - - let token1decimals: number; - for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { - let found = false; - for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { - if (tokenParams.address.toLowerCase() === pool.token1.toLowerCase()) { - token1decimals = tokenParams.decimals; - found = true; - break; - } - if (found) break; - } - } - - const usd0 = await this.dexHelper.getTokenUSDPrice( - { address: pool.token0, decimals: token0decimals! }, - state.collateralReserves.token0RealReserves + - state.debtReserves.token0RealReserves, - ); - - const usd1 = await this.dexHelper.getTokenUSDPrice( - { address: pool.token1, decimals: token1decimals! }, - state.collateralReserves.token1RealReserves + - state.debtReserves.token1RealReserves, - ); - - poolLiquidities.push({ - exchange: 'FluidDex', - address: pool.address, - connectorTokens: [], - liquidityUSD: Number(usd0 + usd1), // converted to number - }); - } - return poolLiquidities; + // const latestBlockNumber_ = await this.dexHelper.provider.getBlockNumber(); + // let liquidityAmounts: { [id: string]: bigint } = {}; + // for (const pool of this.pools) { + // if ( + // pool.token0 === tokenAddress.toLowerCase() || + // pool.token1 === tokenAddress.toLowerCase() + // ) { + // const state: FluidDexPoolState = await this.eventPools[ + // pool.id + // ].getStateOrGenerate(latestBlockNumber_, false); + // + // liquidityAmounts[pool.id] = + // pool.token0 === tokenAddress + // ? state.collateralReserves.token0RealReserves + + // state.debtReserves.token0RealReserves + // : state.collateralReserves.token1RealReserves + + // state.debtReserves.token1RealReserves; + // } + // } + // + // const entries = Object.entries(liquidityAmounts); + // + // // Sort the entries based on the values in descending order + // entries.sort((a, b) => { + // if (b[1] > a[1]) return 1; + // if (b[1] < a[1]) return -1; + // return 0; + // }); + // + // // Take the top k entries + // const topKEntries = entries.slice(0, limit); + // + // // Convert the array back to an object + // const sortedAmounts = Object.fromEntries(topKEntries); + // + // const poolLiquidities: PoolLiquidity[] = []; + // + // for (const [id, amount] of Object.entries(sortedAmounts)) { + // const pool = this.pools.find(p => p.id === id); + // if (!pool) continue; // Skip if pool not found + // + // const state: FluidDexPoolState = await this.eventPools[ + // pool.id + // ].getStateOrGenerate(latestBlockNumber_, false); + // + // // let token0decimals: number; + // // for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { + // // let found = false; + // // for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { + // // if (tokenParams.address.toLowerCase() === pool.token0.toLowerCase()) { + // // token0decimals = tokenParams.decimals; + // // found = true; + // // break; + // // } + // // if (found) break; + // // } + // // } + // // + // // let token1decimals: number; + // // for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { + // // let found = false; + // // for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { + // // if (tokenParams.address.toLowerCase() === pool.token1.toLowerCase()) { + // // token1decimals = tokenParams.decimals; + // // found = true; + // // break; + // // } + // // if (found) break; + // // } + // // } + // + // const usd0 = await this.dexHelper.getTokenUSDPrice( + // { address: pool.token0, decimals: token0decimals! }, + // state.collateralReserves.token0RealReserves + + // state.debtReserves.token0RealReserves, + // ); + // + // const usd1 = await this.dexHelper.getTokenUSDPrice( + // { address: pool.token1, decimals: token1decimals! }, + // state.collateralReserves.token1RealReserves + + // state.debtReserves.token1RealReserves, + // ); + // + // poolLiquidities.push({ + // exchange: 'FluidDex', + // address: pool.address, + // connectorTokens: [], + // liquidityUSD: Number(usd0 + usd1), // converted to number + // }); + // } + // return poolLiquidities; + + return []; } async getDexParam( diff --git a/tests/constants-e2e.d.ts b/tests/constants-e2e.d.ts new file mode 100644 index 000000000..4934d92b2 --- /dev/null +++ b/tests/constants-e2e.d.ts @@ -0,0 +1,22 @@ +import { SmartTokenParams, SmartToken } from '../tests/smart-tokens'; +import { Address } from '../src/types'; +export declare const GIFTER_ADDRESS = "0xb22fC4eC94D555A5049593ca4552c810Fb8a6d00"; +export declare const GENERIC_ADDR1 = "0xbe9317f6711e2da074fe1f168fd9c402bc0a9d1b"; +export declare const GENERIC_ADDR2 = "0x230a1ac45690b9ae1176389434610b9526d2f21b"; +export declare const Tokens: { + [network: number]: { + [symbol: string]: SmartTokenParams; + }; +}; +export declare const Holders: { + [network: number]: { + [tokenAddress: string]: Address; + }; +}; +export declare const SmartTokens: Record>; +export declare const NativeTokenSymbols: { + [network: number]: string; +}; +export declare const WrappedNativeTokenSymbols: { + [network: number]: string; +}; diff --git a/tests/constants-e2e.js b/tests/constants-e2e.js new file mode 100644 index 000000000..5e3a3326d --- /dev/null +++ b/tests/constants-e2e.js @@ -0,0 +1,1942 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.WrappedNativeTokenSymbols = exports.NativeTokenSymbols = exports.SmartTokens = exports.Holders = exports.Tokens = exports.GENERIC_ADDR2 = exports.GENERIC_ADDR1 = exports.GIFTER_ADDRESS = void 0; +const smart_tokens_1 = require("../tests/smart-tokens"); +const constants_1 = require("../src/constants"); +exports.GIFTER_ADDRESS = '0xb22fC4eC94D555A5049593ca4552c810Fb8a6d00'; +exports.GENERIC_ADDR1 = '0xbe9317f6711e2da074fe1f168fd9c402bc0a9d1b'; +exports.GENERIC_ADDR2 = '0x230a1ac45690b9ae1176389434610b9526d2f21b'; +exports.Tokens = { + [constants_1.Network.MAINNET]: { + sUSDS: { + address: '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD', + decimals: 18, + }, + USDS: { + address: '0xdC035D45d973E3EC169d2276DDab16f1e407384F', + decimals: 18, + }, + SKY: { + address: '0x56072C95FAA701256059aa122697B133aDEd9279', + decimals: 18, + }, + MKR: { + address: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', + decimals: 18, + }, + AA_wstETH: { + decimals: 18, + address: '0x2688fc68c4eac90d9e5e1b94776cf14eade8d877', + }, + 'AA_idle_cpPOR-USDC': { + decimals: 18, + address: '0x9cacd44cfdf22731bc99facf3531c809d56bd4a2', + }, + 'BB_idle_cpFAS-USDT': { + decimals: 18, + address: '0x3eb6318b8d9f362a0e1d99f6032edb1c4c602500', + }, + AA_steakUSDC: { + decimals: 18, + address: '0x2b0e31b8ee653d2077db86dea3acf3f34ae9d5d2', + }, + BB_steakUSDC: { + decimals: 18, + address: '0x7b713b1cb6eafd4061064581579ffccf7df21545', + }, + AA_Re7WETH: { + decimals: 18, + address: '0x454bb3cb427b21e1c052a080e21a57753cd6969e', + }, + BB_Re7WETH: { + decimals: 18, + address: '0x20aa3cd83044d2903181f7ef5c2b498a017d1c4a', + }, + BB_dUSDCV3: { + decimals: 18, + address: '0x2a84a042db06222c486bcb815e961f26599d0df6', + }, + AA_sUSDe: { + decimals: 18, + address: '0xf3188697bd35df73e4293d04a07ebaaf1ffc4018', + }, + BB_sUSDe: { + decimals: 18, + address: '0xb8d0be502a8f12cc5213733285b430a43d07349d', + }, + AA_iETHv2: { + decimals: 18, + address: '0xdf17c739b666B259DA3416d01f0310a6e429f592', + }, + BB_iETHv2: { + decimals: 18, + address: '0x990b3aF34dDB502715E1070CE6778d8eB3c8Ea82', + }, + USDE: { + address: '0x4c9edd5852cd905f086c759e8383e09bff1e68b3', + decimals: 18, + }, + ETH: { + address: constants_1.ETHER_ADDRESS, + decimals: 18, + }, + SWETH: { + address: '0xf951e335afb289353dc249e82926178eac7ded78', + decimals: 18, + }, + BAT: { + address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef', + decimals: 18, + }, + rswETH: { + address: '0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0', + decimals: 18, + }, + REQ: { + address: '0x8f8221aFbB33998d8584A2B05749bA73c37a938a', + decimals: 18, + }, + eETH: { + address: '0x35fA164735182de50811E8e2E824cFb9B6118ac2', + decimals: 18, + }, + weETH: { + address: '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee', + decimals: 18, + }, + AMPL: { + address: '0xd46ba6d942050d489dbd938a2c909a5d5039a161', + decimals: 9, + }, + USDC: { + address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', + decimals: 6, + symbol: 'USDC', + addBalance: smart_tokens_1.balancesFn, + addAllowance: smart_tokens_1.allowedFn, + }, + aEthUSDC: { + address: '0x98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c', + decimals: 6, + }, + aEthWETH: { + address: '0x4d5f47fa6a74757f35c14fd3a6ef8e3c9bc514e8', + decimals: 18, + }, + MAV: { + address: '0x7448c7456a97769f6cd04f1e83a4a23ccdc46abd', + decimals: 18, + }, + SUSHI: { + address: '0x6b3595068778dd592e39a122f4f5a5cf09c90fe2', + decimals: 18, + }, + CUSDC: { + address: '0x39AA39c021dfbaE8faC545936693aC917d5E7563', + decimals: 8, + }, + TUSD: { + address: '0x0000000000085d4780b73119b644ae5ecd22b376', + decimals: 18, + }, + WBTC: { + address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', + decimals: 8, + addBalance: smart_tokens_1.balancesFn, + addAllowance: smart_tokens_1.allowedFn, + }, + sBTC: { + address: '0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6', + decimals: 18, + }, + tBTCv2: { + address: '0x18084fbA666a33d37592fA2633fD49a74DD93a88', + decimals: 18, + }, + BADGER: { + address: '0x3472A5A71965499acd81997a54BBA8D852C6E53d', + decimals: 18, + }, + USDT: { + address: '0xdac17f958d2ee523a2206206994597c13d831ec7', + decimals: 6, + addBalance: smart_tokens_1.balancesFn, + addAllowance: smart_tokens_1.allowedFn, + }, + STETH: { + address: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', + decimals: 18, + }, + SDEX: { + address: '0x5DE8ab7E27f6E7A1fFf3E5B337584Aa43961BEeF', + decimals: 18, + }, + wstETH: { + address: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', + decimals: 18, + }, + USDM: { + address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', + decimals: 18, + }, + wUSDM: { + address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', + decimals: 18, + }, + frxETH: { + address: '0x5E8422345238F34275888049021821E8E08CAa1f', + decimals: 18, + }, + WETH: { + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + decimals: 18, + addBalance: smart_tokens_1.balanceOfFn, + addAllowance: smart_tokens_1.allowanceFn, + }, + PSP: { + address: '0xcafe001067cdef266afb7eb5a286dcfd277f3de5', + decimals: 18, + }, + SETH: { + address: '0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb', + decimals: 18, + }, + LINK: { + address: '0x514910771af9ca656af840dff83e8264ecf986ca', + decimals: 18, + }, + DAI: { + address: '0x6b175474e89094c44da98b954eedeac495271d0f', + decimals: 18, + addBalance: smart_tokens_1.balanceOfFn, + addAllowance: smart_tokens_1.allowanceFn, + }, + MLN: { + address: '0xec67005c4e498ec7f55e092bd1d35cbc47c91892', + decimals: 18, + }, + SENT: { + address: '0xa44E5137293E855B1b7bC7E2C6f8cD796fFCB037', + decimals: 8, + }, + oldFRAX: { + address: '0x853d955acef822db058eb8505911ed77f175b99e', + decimals: 18, + }, + aDAI: { + address: '0x028171bCA77440897B824Ca71D1c56caC55b68A3', + decimals: 18, + }, + aUSDT: { + address: '0x3Ed3B47Dd13ECAURA9a98b44e6204A523E766B225811', + decimals: 6, + }, + waUSDT: { + address: '0xf8Fd466F12e236f4c96F7Cce6c79EAdB819abF58', + decimals: 6, + }, + ALUSD: { + address: '0xbc6da0fe9ad5f3b0d58160288917aa56653660e9', + decimals: 18, + }, + BAL: { + address: '0xba100000625a3754423978a60c9317c58a424e3D', + decimals: 18, + }, + OHM: { + address: '0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5', + decimals: 9, + }, + AURA: { + address: '0xc0c293ce456ff0ed870add98a0828dd4d2903dbf', + decimals: 18, + }, + WISE: { + address: '0x66a0f676479cee1d7373f3dc2e2952778bff5bd6', + decimals: 18, + }, + DDIM: { + address: '0xFbEEa1C75E4c4465CB2FCCc9c6d6afe984558E20', + decimals: 18, + }, + DODO: { + address: '0x43Dfc4159D86F3A37A5A4B3D4580b888ad7d4DDd', + decimals: 18, + }, + STG: { + address: '0xAf5191B0De278C7286d6C7CC6ab6BB8A73bA2Cd6', + decimals: 18, + }, + ADAI: { + address: '0x028171bca77440897b824ca71d1c56cac55b68a3', + decimals: 18, + }, + AWETH: { + address: '0x030ba81f1c18d280636f32af80b9aad02cf0854e', + decimals: 18, + }, + ALPHA: { + address: '0xa1faa113cbe53436df28ff0aee54275c13b40975', + decimals: 18, + }, + CRV: { + address: '0xd533a949740bb3306d119cc777fa900ba034cd52', + decimals: 18, + }, + INCH: { + address: '0x111111111117dC0aa78b770fA6A738034120C302', + decimals: 18, + }, + mUSD: { + address: '0xe2f2a5c287993345a840db3b0845fbc70f5935a5', + decimals: 18, + }, + mBTC: { + address: '0x945facb997494cc2570096c74b5f66a3507330a1', + decimals: 18, + }, + renBTC: { + address: '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D', + decimals: 8, + }, + HBTC: { + address: '0x0316EB71485b0Ab14103307bf65a021042c6d380', + decimals: 18, + }, + tBTC: { + address: '0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa', + decimals: 18, + }, + BUSD: { + address: '0x4fabb145d64652a948d72533023f6e7a623c7c53', + decimals: 18, + }, + GUSD: { + address: '0x056fd409e1d7a124bd7017459dfea2f387b6d5cd', + decimals: 2, + }, + ADAIv1: { + address: '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d', + decimals: 18, + }, + CETH: { + address: '0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5', + decimals: 8, + }, + CDAI: { + address: '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', + decimals: 8, + }, + MIM: { + address: '0x99D8a9C45b2ecA8864373A26D1459e3Dff1e17F3', + decimals: 18, + }, + AnkETH: { + address: '0xE95A203B1a91a908F9B9CE46459d101078c2c3cb', + decimals: 18, + }, + EURS: { + address: '0xdB25f211AB05b1c97D595516F45794528a807ad8', + decimals: 2, + }, + EURT: { + address: '0xC581b735A1688071A1746c968e0798D642EDE491', + decimals: 6, + }, + jEUR: { + address: '0x0f17bc9a994b87b5225cfb6a2cd4d667adb4f20b', + decimals: 18, + }, + jCHF: { + address: '0x53dfea0a8cc2a2a2e425e1c174bc162999723ea0', + decimals: 18, + }, + jGBP: { + address: '0x7409856cae628f5d578b285b45669b36e7005283', + decimals: 18, + }, + XAUT: { + address: '0x68749665FF8D2d112Fa859AA293F07A622782F38', + decimals: 6, + }, + CVX: { + address: '0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B', + decimals: 18, + }, + UST: { + address: '0xa47c8bf37f92abed4a126bda807a7b7498661acd', + decimals: 18, + }, + SAITAMA: { + address: '0x8b3192f5eebd8579568a2ed41e6feb402f93f73f', + decimals: 9, + }, + BBAUSDT: { + // bpt of USDT Linear Pool + address: '0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c', + decimals: 18, + }, + BBADAI: { + // bpt of DAI Linear Pool + address: '0x804cdb9116a10bb78768d3252355a1b18067bf8f', + decimals: 18, + }, + BBAUSD: { + address: '0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2', + decimals: 18, + }, + BBFDAI: { + address: '0x8f4063446f5011bc1c9f79a819efe87776f23704', + decimals: 18, + }, + FEI: { + address: '0x956F47F50A910163D8BF957Cf5846D573E7f87CA', + decimals: 18, + }, + newFRAX: { + address: '0x853d955aCEf822Db058eb8505911ED77F175b99e', + decimals: 18, + }, + sETH: { + address: '0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb', + decimals: 18, + }, + sUSD: { + address: '0x57Ab1ec28D129707052df4dF418D58a2D46d5f51', + decimals: 18, + }, + USDD: { + address: '0x0c10bf8fcb7bf5412187a595ab97a3609160b5c6', + decimals: 18, + }, + alETH: { + address: '0x0100546f2cd4c9d97f798ffc9755e47865ff7ee6', + decimals: 18, + }, + SHIBA: { + address: '0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE', + decimals: 18, + }, + dUSDC: { + address: '0xc411db5f5eb3f7d552f9b8454b2d74097ccde6e3', + decimals: 6, + }, + EURA: { + address: '0x1a7e4e63778b4f12a199c062f3efdd288afcbce8', + decimals: 18, + symbol: 'EURA', + }, + EUROC: { + address: '0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c', + decimals: 6, + symbol: 'EUROC', + }, + bERNX: { + address: '0x3f95AA88dDbB7D9D484aa3D482bf0a80009c52c9', + decimals: 18, + symbol: 'bERNX', + }, + bC3M: { + address: '0x2F123cF3F37CE3328CC9B5b8415f9EC5109b45e7', + decimals: 18, + symbol: 'bC3M', + }, + stEUR: { + address: '0x004626a008b1acdc4c74ab51644093b155e59a23', + decimals: 18, + }, + USDA: { + address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', + decimals: 18, + symbol: 'USDA', + }, + bIB01: { + address: '0xCA30c93B02514f86d5C86a6e375E3A330B435Fb5', + decimals: 18, + symbol: 'bIB01', + }, + steakUSDC: { + address: '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB', + decimals: 18, + symbol: 'steakUSDC', + }, + stUSD: { + address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + decimals: 18, + }, + GHO: { + address: '0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f', + decimals: 18, + }, + stkGHO: { + address: '0x1a88Df1cFe15Af22B3c4c783D4e6F7F9e0C1885d', + decimals: 18, + }, + USDe: { + address: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3', + decimals: 18, + }, + crvUSD: { + address: '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E', + decimals: 18, + }, + wibBTC: { + address: '0x8751d4196027d4e6da63716fa7786b5174f04c15', + decimals: 18, + }, + MATIC: { + address: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', + decimals: 18, + }, + POL: { + address: '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6', + decimals: 19, + }, + GYD: { + address: '0xe07f9d810a48ab5c3c914ba3ca53af14e4491e8a', + decimals: 18, + }, + LUSD: { + address: '0x5f98805a4e8be255a32880fdec7f6728c6568ba0', + decimals: 18, + }, + BNT: { + address: '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c', + decimals: 18, + }, + sDAI: { + address: '0x83f20f44975d03b1b09e64809b757c47f942beea', + decimals: 18, + }, + stataUSDT: { + address: '0x862c57d48becb45583aeba3f489696d22466ca1b', + decimals: 6, + }, + aaveUSDT: { + address: '0x23878914efe38d27c4d67ab83ed1b93a74d4086a', + decimals: 6, + }, + rUSD: { + address: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18', + decimals: 18, + }, + arUSD: { + address: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a', + decimals: 18, + }, + USD0: { + address: '0x73A15FeD60Bf67631dC6cd7Bc5B6e8da8190aCF5', + decimals: 18, + symbol: 'USD0', + }, + 'USD0++': { + address: '0x35D8949372D46B7a3D5A56006AE77B215fc69bC0', + decimals: 18, + symbol: 'USD0++', + }, + }, + [constants_1.Network.POLYGON]: { + jGBP: { + address: '0x767058f11800fba6a682e73a6e79ec5eb74fac8c', + decimals: 18, + }, + DAI: { + address: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', + decimals: 18, + }, + // native bridged wormhole + USDCe: { + address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', + decimals: 6, + addBalance: smart_tokens_1._balancesFn, + addAllowance: smart_tokens_1._allowancesFn, + }, + TEL: { + address: '0xdf7837de1f2fa4631d716cf2502f8b230f1dcc32', + decimals: 2, + }, + // wormhole + USDC: { + address: '0x576Cf361711cd940CD9C397BB98C4C896cBd38De', + decimals: 6, + }, + // circle issued usdc + USDCn: { + address: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', + decimals: 6, + }, + stataUSDCn: { + address: '0x2dCa80061632f3F87c9cA28364d1d0c30cD79a19', + decimals: 6, + }, + aaveUSDCn: { + address: '0xa4d94019934d8333ef880abffbf2fdd611c762bd', + decimals: 6, + }, + POPS: { + address: '0xa92A1576D11dB45c53be71d59245ac97ce0d8147', + decimals: 18, + }, + CRV: { + address: '0x172370d5cd63279efa6d502dab29171933a610af', + decimals: 18, + }, + BAL: { + address: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3', + decimals: 18, + }, + AAVE: { + address: '0xd6df932a45c0f255f85145f286ea0b292b21c90b', + decimals: 18, + }, + PSP: { + address: '0x42d61d766b85431666b39b89c43011f24451bff6', + decimals: 18, + }, + WETH: { + address: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', + decimals: 18, + }, + crvUSD: { + address: '0xc4ce1d6f5d98d65ee25cf85e9f2e9dcfee6cb5d6', + decimals: 18, + }, + WMATIC: { + address: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', + decimals: 18, + addBalance: smart_tokens_1.balanceOfFn, + addAllowance: smart_tokens_1.allowanceFn, + }, + AMWMATIC: { + address: '0x8dF3aad3a84da6b69A4DA8aeC3eA40d9091B2Ac4', + decimals: 18, + }, + aPolWMATIC: { + address: '0x6d80113e533a2c0fe82eabd35f1875dcea89ea97', + decimals: 18, + }, + MUST: { + address: '0x9C78EE466D6Cb57A4d01Fd887D2b5dFb2D46288f', + decimals: 18, + }, + AMDAI: { + address: '0x27F8D03b3a2196956ED754baDc28D73be8830A6e', + decimals: 18, + }, + BTU: { + address: '0xfdc26cda2d2440d0e83cd1dee8e8be48405806dc', + decimals: 18, + }, + USDT: { + address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', + decimals: 6, + }, + WBTC: { + address: '0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6', + decimals: 8, + }, + MATIC: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + mUSD: { + address: '0xe840b73e5287865eec17d250bfb1536704b43b21', + decimals: 18, + }, + AMWETH: { + address: '0x28424507fefb6f7f8e9d3860f56504e4e5f5f390', + decimals: 18, + }, + AMWBTC: { + address: '0x5c2ed810328349100a66b82b78a1791b101c9d61', + decimals: 8, + }, + KNC: { + address: '0x1c954e8fe737f99f68fa1ccda3e51ebdb291948c', + decimals: 18, + }, + jEUR: { + address: '0x4e3decbb3645551b8a19f0ea1678079fcb33fb4c', + decimals: 18, + }, + jGPB: { + address: '0x767058f11800fba6a682e73a6e79ec5eb74fac8c', + decimals: 18, + }, + jCHF: { + address: '0xbd1463f02f61676d53fd183c2b19282bff93d099', + decimals: 18, + }, + RADIO: { + address: '0x613a489785C95afEB3b404CC41565cCff107B6E0', + decimals: 18, + }, + HANZO: { + address: '0x37eb60f78e06c4bb2a5f836b0fc6bccbbaa995b3', + decimals: 9, + }, + RVLT: { + address: '0xf0f9d895aca5c8678f706fb8216fa22957685a13', + decimals: 18, + }, + stMATIC: { + address: '0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4', + decimals: 18, + }, + axlUSDC: { + address: '0x750e4c4984a9e0f12978ea6742bc1c5d248f40ed', + decimals: 6, + }, + deUSDC: { + address: '0x1ddcaa4ed761428ae348befc6718bcb12e63bfaa', + decimals: 6, + }, + amUSDT: { + address: '0x60d55f02a771d515e077c9c2403a1ef324885cec', + decimals: 6, + }, + amUSDC: { + address: '0x1a13F4Ca1d028320A707D99520AbFefca3998b7F', + decimals: 6, + }, + MAI: { + address: '0xa3fa99a148fa48d14ed51d610c367c61876997f1', + decimals: 18, + }, + EURA: { + address: '0xe0b52e49357fd4daf2c15e02058dce6bc0057db4', + decimals: 18, + symbol: 'EURA', + }, + USDM: { + address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', + decimals: 18, + }, + wUSDM: { + address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', + decimals: 18, + }, + stEUR: { + address: '0x004626a008b1acdc4c74ab51644093b155e59a23', + decimals: 18, + }, + USDA: { + address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', + decimals: 18, + symbol: 'USDA', + }, + stUSD: { + address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + decimals: 18, + }, + BUSD: { + address: '0x9C9e5fD8bbc25984B178FdCE6117Defa39d2db39', + decimals: 18, + }, + TUSD: { + address: '0x2e1ad108ff1d8c782fcbbb89aad783ac49586756', + decimals: 18, + }, + SDEX: { + address: '0x6899fAcE15c14348E1759371049ab64A3a06bFA6', + decimals: 18, + }, + MATICX: { + address: '0xfa68fb4628dff1028cfec22b4162fccd0d45efb6', + decimals: 18, + }, + SUSHI: { + address: '0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a', + decimals: 18, + }, + TRYB: { + address: '0x4fb71290ac171e1d144f7221d882becac7196eb5', + decimals: 6, + }, + }, + [constants_1.Network.FANTOM]: { + FTM: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + SOLID: { + address: '0x777cf5ba9c291a1a8f57ff14836f6f9dc5c0f9dd', + decimals: 18, + }, + WFTM: { + address: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83', + decimals: 18, + }, + DAI: { + address: '0x8d11ec38a3eb5e956b052f67da8bdc9bef8abf3e', + decimals: 18, + }, + USDC: { + address: '0x04068DA6C83AFCFA0e13ba15A6696662335D5B75', + decimals: 6, + }, + FUSDT: { + address: '0x049d68029688eabf473097a2fc38ef61633a3c7a', + decimals: 6, + }, + LQDR: { + address: '0x10b620b2dbac4faa7d7ffd71da486f5d44cd86f9', + decimals: 18, + }, + EQUAL: { + address: '0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6', + decimals: 18, + }, + beFTM: { + address: '0x7381ed41f6de418dde5e84b55590422a57917886', + decimals: 18, + }, + POPS: { + address: '0x9dE4b40bDcE50Ec6a1A668bF85997BbBD324069a', + decimals: 18, + }, + MIM: { + address: '0x82f0b8b456c1a451378467398982d4834b6829c1', + decimals: 18, + }, + FRAX: { + address: '0xdc301622e621166BD8E82f2cA0A26c13Ad0BE355', + decimals: 18, + }, + nETH: { + address: '0x67C10C397dD0Ba417329543c1a40eb48AAa7cd00', + decimals: 18, + }, + WETH: { + address: '0x74b23882a30290451A17c44f4F05243b6b58C76d', + decimals: 18, + }, + SPIRIT: { + address: '0x5cc61a78f164885776aa610fb0fe1257df78e59b', + decimals: 18, + }, + wBOMB: { + address: '0xc09a82ad5075b3067d80f54f05e1e22229699cc1', + decimals: 18, + }, + TOR: { + address: '0x74e23df9110aa9ea0b6ff2faee01e740ca1c642e', + decimals: 18, + }, + BOO: { + address: '0x841fad6eae12c286d1fd18d1d525dffa75c7effe', + decimals: 18, + }, + ETH: { + address: '0x74b23882a30290451A17c44f4F05243b6b58C76d', + decimals: 18, + }, + GDAI: { + address: '0x07E6332dD090D287d3489245038daF987955DCFB', + decimals: 18, + }, + GUSDC: { + address: '0xe578C856933D8e1082740bf7661e379Aa2A30b26', + decimals: 6, + }, + axlUSDC: { + address: '0x1B6382DBDEa11d97f24495C9A90b7c88469134a4', + decimals: 6, + }, + lzUSDC: { + address: '0x28a92dde19D9989F39A49905d7C9C2FAc7799bDf', + decimals: 6, + }, + FVM: { + address: '0x07BB65fAaC502d4996532F834A1B7ba5dC32Ff96', + decimals: 18, + }, + USDCe: { + address: '0x2f733095b80a04b38b0d10cc884524a3d09b836a', + decimals: 6, + }, + scrvUSDC_e: { + address: '0x0cf1aa18ab7020973705aa9c46bbec6150e2782b', + decimals: 18, + }, + scrvUSDC_p: { + address: '0x8b697f95d8c9fbbcc597a89223b10b80369490a1', + decimals: 18, + }, + }, + [constants_1.Network.BSC]: { + POPS: { + address: '0xa1051433EC7b5cc249c75Fdd5b96BF423f2f4A32', + decimals: 18, + }, + DAI: { + address: '0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3', + decimals: 18, + }, + WBNB: { + address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', + decimals: 18, + }, + BNBx: { + address: '0x1bdd3Cf7F79cfB8EdbB955f20ad99211551BA275', + decimals: 18, + }, + BUSD: { + address: '0xe9e7cea3dedca5984780bafc599bd69add087d56', + decimals: 18, + }, + USDT: { + address: '0x55d398326f99059ff775485246999027b3197955', + decimals: 18, + }, + ETH: { + address: '0x2170ed0880ac9a755fd29b2688956bd959f933f8', + decimals: 18, + }, + UST: { + address: '0x23396cf899ca06c4472205fc903bdb4de249d6fc', + decimals: 18, + }, + USDC: { + address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', + decimals: 18, + }, + RADIO: { + address: '0x30807D3b851A31d62415B8bb7Af7dCa59390434a', + decimals: 18, + }, + BNB: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + bBTC: { + address: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', + decimals: 18, + }, + anyBTC: { + address: '0x54261774905f3e6E9718f2ABb10ed6555cae308a', + decimals: 8, + }, + nUSD: { + address: '0x23b891e5C62E0955ae2bD185990103928Ab817b3', + decimals: 18, + }, + CONE: { + address: '0xA60205802E1B5C6EC1CAFA3cAcd49dFeECe05AC9', + decimals: 18, + }, + axlUSD: { + address: '0x4268B8F0B87b6Eae5d897996E6b845ddbD99Adf3', + decimals: 6, + }, + FRAX: { + address: '0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40', + decimals: 18, + }, + frxETH: { + address: '0x64048A7eEcF3a2F1BA9e144aAc3D7dB6e58F555e', + decimals: 18, + }, + USDFI: { + address: '0x11A38e06699b238D6D9A0C7A01f3AC63a07ad318', + decimals: 18, + }, + XRP: { + address: '0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe', + decimals: 18, + }, + SDEX: { + address: '0xFdc66A08B0d0Dc44c17bbd471B88f49F50CdD20F', + decimals: 18, + }, + EURA: { + address: '0x12f31B73D812C6Bb0d735a218c086d44D5fe5f89', + decimals: 18, + symbol: 'EURA', + }, + USDA: { + address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', + decimals: 18, + symbol: 'USDA', + }, + stUSD: { + address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + decimals: 18, + }, + stataUSDT: { + address: '0x0471d185cc7be61e154277cab2396cd397663da6', + decimals: 18, + }, + aaveUSDT: { + address: '0xa9251ca9de909cb71783723713b21e4233fbf1b1', + decimals: 18, + }, + }, + [constants_1.Network.AVALANCHE]: { + LINKe: { + address: '0x5947bb275c521040051d82396192181b413227a3', + decimals: 18, + }, + PHAR: { + address: '0xAAAB9D12A30504559b0C5a9A5977fEE4A6081c6b', + decimals: 18, + }, + USDCe: { + address: '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664', + decimals: 6, + }, + USDC: { + address: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', + decimals: 6, + }, + USDTe: { + address: '0xc7198437980c041c805A1EDcbA50c1Ce5db95118', + decimals: 6, + }, + USDT: { + address: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7', + decimals: 6, + addAllowance: smart_tokens_1._allowancesFn, + addBalance: smart_tokens_1.balanceOfFn, + }, + POPS: { + address: '0x240248628B7B6850352764C5dFa50D1592A033A8', + decimals: 18, + }, + WAVAX: { + address: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', + decimals: 18, + addAllowance: smart_tokens_1.allowanceFn, + addBalance: smart_tokens_1.balanceOfFn, + }, + sAVAX: { + address: '0x2b2C81e08f1Af8835a78Bb2A90AE924ACE0eA4bE', + decimals: 18, + }, + WETHe: { + address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', + decimals: 18, + }, + ETH: { + address: '0xf20d962a6c8f70c731bd838a3a388D7d48fA6e15', + decimals: 18, + }, + WBTC: { + address: '0x408D4cD0ADb7ceBd1F1A1C33A0Ba2098E1295bAB', + decimals: 8, + }, + WETH: { + address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', + decimals: 18, + }, + TUSD: { + address: '0x1c20e891bab6b1727d14da358fae2984ed9b59eb', + decimals: 18, + }, + oldFRAX: { + address: '0xdc42728b0ea910349ed3c6e1c9dc06b5fb591f98', + decimals: 18, + }, + newFRAX: { + address: '0xd24c2ad096400b6fbcd2ad8b24e7acbc21a1da64', + decimals: 18, + }, + DAIE: { + address: '0xd586e7f844cea2f87f50152665bcbc2c279d8d70', + decimals: 18, + }, + PNG: { + address: '0x60781c2586d68229fde47564546784ab3faca982', + decimals: 18, + }, + SHIBX: { + address: '0x440aBbf18c54b2782A4917b80a1746d3A2c2Cce1', + decimals: 18, + }, + wBTC: { + address: '0x50b7545627a5162F82A992c33b87aDc75187B218', + decimals: 8, + }, + renBTC: { + address: '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501', + decimals: 8, + }, + BTCb: { + address: '0x152b9d0FdC40C096757F570A51E494bd4b943E50', + decimals: 8, + }, + ADAI: { + address: '0x47AFa96Cdc9fAb46904A55a6ad4bf6660B53c38a', + decimals: 18, + }, + avWAVAX: { + address: '0xDFE521292EcE2A4f44242efBcD66Bc594CA9714B', + decimals: 18, + }, + MIM: { + address: '0x130966628846BFd36ff31a822705796e8cb8C18D', + decimals: 18, + }, + TSD: { + address: '0x4fbf0429599460D327BD5F55625E30E4fC066095', + decimals: 18, + }, + avUSDT: { + address: '0x532e6537fea298397212f09a61e03311686f548e', + decimals: 6, + }, + THO: { + address: '0xAE4AA155D2987B454C29450ef4f862CF00907B61', + decimals: 18, + }, + AVAX: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + aETH: { + address: '0x3a3A65aAb0dd2A17E3F1947bA16138cd37d08c04', + decimals: 18, + }, + aUSDT: { + address: '0x71fc860f7d3a592a4a98740e39db31d25db65ae8', + decimals: 6, + }, + YUSD: { + address: '0x111111111111ed1D73f860F57b2798b683f2d325', + decimals: 18, + }, + H2O: { + address: '0x026187BdbC6b751003517bcb30Ac7817D5B766f8', + decimals: 18, + }, + MONEY: { + address: '0x0f577433Bf59560Ef2a79c124E9Ff99fCa258948', + decimals: 18, + }, + nETH: { + address: '0x19E1ae0eE35c0404f835521146206595d37981ae', + decimals: 18, + }, + avWETH: { + address: '0x53f7c5869a859F0AeC3D334ee8B4Cf01E3492f21', + decimals: 18, + }, + nUSD: { + address: '0xCFc37A6AB183dd4aED08C204D1c2773c0b1BDf46', + decimals: 18, + }, + BETS: { + address: '0x94025780a1ab58868d9b2dbbb775f44b32e8e6e5', + decimals: 18, + }, + HATCHY: { + address: '0x502580fc390606b47fc3b741d6d49909383c28a9', + decimals: 18, + }, + AMPL: { + address: '0x027dbcA046ca156De9622cD1e2D907d375e53aa7', + decimals: 9, + }, + stataUSDT: { + address: '0x5525ee69bc1e354b356864187de486fab5ad67d7', + decimals: 6, + }, + aaveUSDT: { + address: '0x6ab707aca953edaefbc4fd23ba73294241490620', + decimals: 6, + }, + }, + [constants_1.Network.ARBITRUM]: { + SEN: { + address: '0x154388a4650D63acC823e06Ef9e47C1eDdD3cBb2', + decimals: 18, + }, + BAL: { + address: '0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8', + decimals: 18, + }, + DAI: { + address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', + decimals: 18, + }, + ARB: { + address: '0x912ce59144191c1204e64559fe8253a0e49e6548', + decimals: 18, + }, + WETH: { + address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', + decimals: 18, + addBalance: smart_tokens_1._balancesFn, + addAllowance: smart_tokens_1._allowancesFn, + }, + ETH: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + USDCe: { + address: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', + decimals: 6, + }, + USDC: { + address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', + decimals: 6, + symbol: 'USDC', + addBalance: smart_tokens_1.balanceAndBlacklistStatesFn, + addAllowance: smart_tokens_1.allowedFn, + }, + SUSHI: { + address: '0xd4d42F0b6DEF4CE0383636770eF773390d85c61A', + decimals: 18, + }, + crvUSD: { + address: '0x498bf2b1e120fed3ad3d42ea2165e9b73f99c1e5', + decimals: 18, + }, + OHM: { + address: '0xf0cb2dc0db5e6c66b9a70ac27b06b878da017028', + decimals: 9, + }, + RDNT: { + address: '0x3082cc23568ea640225c2467653db90e9250aaa0', + decimals: 18, + }, + USDT: { + address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', + decimals: 6, + addBalance: smart_tokens_1._balancesFn, + addAllowance: smart_tokens_1._allowancesFn, + }, + FRAX: { + address: '0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F', + decimals: 18, + }, + nUSD: { + address: '0x2913E812Cf0dcCA30FB28E6Cac3d2DCFF4497688', + decimals: 18, + }, + nETH: { + address: '0x3ea9B0ab55F34Fb188824Ee288CeaEfC63cf908e', + decimals: 18, + }, + EURS: { + address: '0xd22a58f79e9481d1a88e00c343885a588b34b68b', + decimals: 2, + }, + AAVE: { + address: '0xba5ddd1f9d7f570dc94a51479a000e3bce967196', + decimals: 18, + }, + MIM: { + address: '0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A', + decimals: 18, + }, + VST: { + address: '0x64343594ab9b56e99087bfa6f2335db24c2d1f17', + decimals: 18, + }, + POPS: { + address: '0xa0b20DecBc557E3f68E140eD5a0c69bc865F865A', + decimals: 18, + }, + ZYB: { + address: '0x3B475F6f2f41853706afc9Fa6a6b8C5dF1a2724c', + decimals: 18, + }, + WBTC: { + address: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', + decimals: 8, + }, + LEX: { + address: '0x6bB7A17AcC227fd1F6781D1EEDEAE01B42047eE0', + decimals: 18, + }, + EURA: { + address: '0xfa5ed56a203466cbbc2430a43c66b9d8723528e7', + decimals: 18, + symbol: 'EURA', + }, + stEUR: { + address: '0x004626a008b1acdc4c74ab51644093b155e59a23', + decimals: 18, + }, + USDA: { + address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', + decimals: 18, + symbol: 'USDA', + }, + USDM: { + address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', + decimals: 18, + }, + wUSDM: { + address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', + decimals: 18, + }, + stUSD: { + address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + decimals: 18, + }, + GRAIL: { + address: '0x3d9907f9a368ad0a51be60f7da3b97cf940982d8', + decimals: 18, + }, + AURY: { + address: '0x11bf4f05eb28b802ed3ab672594decb20ffe2313', + decimals: 9, + }, + wstETH: { + address: '0x5979D7b546E38E414F7E9822514be443A4800529', + decimals: 18, + }, + RDPX: { + address: '0x32eb7902d4134bf98a28b963d26de779af92a212', + decimals: 18, + }, + SDEX: { + address: '0xabD587f2607542723b17f14d00d99b987C29b074', + decimals: 18, + }, + LINK: { + address: '0xf97f4df75117a78c1a5a0dbb814af92458539fb4', + decimals: 18, + }, + DMT: { + address: '0x8b0e6f19ee57089f7649a455d89d7bc6314d04e8', + decimals: 18, + }, + PENDLE: { + address: '0x0c880f6761f1af8d9aa9c466984b80dab9a8c9e8', + decimals: 18, + }, + stataUSDT: { + address: '0xb165a74407fe1e519d6bcbdec1ed3202b35a4140', + decimals: 6, + }, + aaveUSDT: { + address: '0x6ab707aca953edaefbc4fd23ba73294241490620', + decimals: 6, + }, + GHO: { + address: '0x7dff72693f6a4149b17e7c6314655f6a9f7c8b33', + decimals: 18, + }, + }, + [constants_1.Network.OPTIMISM]: { + DAI: { + address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', + decimals: 18, + }, + WETH: { + address: '0x4200000000000000000000000000000000000006', + decimals: 18, + addBalance: smart_tokens_1.balanceOfFn, + addAllowance: smart_tokens_1.allowanceFn, + }, + ETH: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + USDCe: { + address: '0x7F5c764cBc14f9669B88837ca1490cCa17c31607', + decimals: 6, + }, + USDC: { + address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', + decimals: 6, + }, + USDT: { + address: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58', + decimals: 6, + }, + PSTAKE: { + address: '0x023550adde4fa2f90d63a41d9282bee0294c04cd', + decimals: 18, + }, + GRAIN: { + address: '0xfd389dc9533717239856190f42475d3f263a270d', + decimals: 18, + }, + tBTC: { + address: '0x6c84a8f1c29108f47a79964b5fe888d4f4d0de40', + decimals: 18, + }, + GRAI: { + address: '0x894134a25a5fac1c2c26f1d8fbf05111a3cb9487', + decimals: 18, + }, + LUSD: { + address: '0xc40f949f8a4e094d1b49a23ea9241d289b7b2819', + decimals: 18, + }, + POPS: { + address: '0x3D51a9fB5dCc87F7B237B04975559b920a9a56Ff', + decimals: 18, + }, + crvUSD: { + address: '0xc52d7f23a2e460248db6ee192cb23dd12bddcbf6', + decimals: 18, + }, + OP: { + address: '0x4200000000000000000000000000000000000042', + decimals: 18, + }, + sETH: { + address: '0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49', + decimals: 18, + }, + sUSD: { + address: '0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9', + decimals: 18, + }, + wstETH: { + address: '0x1f32b1c2345538c0c6f582fcb022739c4a194ebb', + decimals: 18, + }, + rETH: { + address: '0x9bcef72be871e61ed4fbbc7630889bee758eb81d', + decimals: 18, + }, + MAI: { + address: '0xdfa46478f9e5ea86d57387849598dbfb2e964b02', + decimals: 18, + }, + WBTC: { + address: '0x68f180fcCe6836688e9084f035309E29Bf0A2095', + decimals: 8, + }, + EURA: { + address: '0x9485aca5bbbe1667ad97c7fe7c4531a624c8b1ed', + decimals: 18, + symbol: 'EURA', + }, + USDM: { + address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', + decimals: 18, + }, + wUSDM: { + address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', + decimals: 18, + }, + stEUR: { + address: '0x004626a008b1acdc4c74ab51644093b155e59a23', + decimals: 18, + }, + USDA: { + address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', + decimals: 18, + symbol: 'USDA', + }, + stUSD: { + address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + decimals: 18, + }, + frxETH: { + address: '0x6806411765Af15Bddd26f8f544A34cC40cb9838B', + decimals: 18, + }, + stataUSDT: { + address: '0x035c93db04e5aaea54e6cd0261c492a3e0638b37', + decimals: 6, + }, + aaveUSDT: { + address: '0x6ab707aca953edaefbc4fd23ba73294241490620', + decimals: 6, + }, + }, + [constants_1.Network.ZKEVM]: { + ETH: { + address: constants_1.ETHER_ADDRESS, + decimals: 18, + }, + WETH: { + address: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9', + decimals: 18, + }, + MATIC: { + address: '0xa2036f0538221a77a3937f1379699f44945018d0', + decimals: 18, + }, + WBTC: { + address: '0xea034fb02eb1808c2cc3adbc15f447b93cbe08e1', + decimals: 8, + }, + USDC: { + address: '0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035', + decimals: 6, + }, + }, + [constants_1.Network.BASE]: { + wstETH: { + address: `0xc1cba3fcea344f92d9239c08c0568f6f2f0ee452`, + decimals: 18, + }, + PRIME: { + address: '0xfA980cEd6895AC314E7dE34Ef1bFAE90a5AdD21b', + decimals: 18, + }, + WETH: { + address: '0x4200000000000000000000000000000000000006', + decimals: 18, + }, + MAV: { + address: '0x64b88c73A5DfA78D1713fE1b4c69a22d7E0faAa7', + decimals: 18, + }, + crvUSD: { + address: '0x417ac0e078398c154edfadd9ef675d30be60af93', + decimals: 18, + }, + USDC: { + address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', + symbol: 'USDC', + decimals: 6, + }, + USDM: { + address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', + decimals: 18, + }, + wUSDM: { + address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', + decimals: 18, + }, + USDbC: { + address: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', + decimals: 6, + }, + DOG: { + address: '0xAfb89a09D82FBDE58f18Ac6437B3fC81724e4dF6', + decimals: 18, + }, + cbETH: { + address: '0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22', + decimals: 18, + }, + tBTC: { + address: '0x236aa50979d5f3de3bd1eeb40e81137f22ab794b', + decimals: 18, + }, + DAI: { + address: '0x50c5725949a6f0c72e6c4a641f24049a917db0cb', + decimals: 18, + }, + ALB: { + address: '0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4', + decimals: 18, + }, + BAL: { + address: '0x4158734d47fc9692176b5085e0f52ee0da5d47f1', + decimals: 18, + }, + GOLD: { + address: '0xbeFD5C25A59ef2C1316c5A4944931171F30Cd3E4', + decimals: 18, + }, + SDEX: { + address: '0xFd4330b0312fdEEC6d4225075b82E00493FF2e3f', + decimals: 18, + }, + EURA: { + address: '0xA61BeB4A3d02decb01039e378237032B351125B4', + decimals: 18, + symbol: 'EURA', + }, + USDA: { + address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', + decimals: 18, + symbol: 'USDA', + }, + stUSD: { + address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + decimals: 18, + }, + ETH: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, + AERO: { + address: '0x940181a94A35A4569E4529A3CDfB74e38FD98631', + decimals: 18, + }, + stataUSDC: { + address: '0x4ea71a20e655794051d1ee8b6e4a3269b13ccacc', + decimals: 6, + }, + aaveUSDC: { + address: '0x4e65fe4dba92790696d040ac24aa414708f5c0ab', + decimals: 6, + }, + }, +}; +exports.Holders = { + [constants_1.Network.MAINNET]: { + USDS: '0xB1796E8f1eEcF23027c1E3C00fE303629A189d10', + sUSDS: '0xd564B3aE673CAa49D054Bf185bD72a6853763eE7', + SKY: '0x0ddda327A6614130CCb20bc0097313A282176A01', + MKR: '0xe9aAA7A9DDc0877626C1779AbC29993aD89A6c1f', + // Idle tokens + AA_wstETH: '0xd7C1b48877A7dFA7D51cf1144c89C0A3F134F935', + 'AA_idle_cpPOR-USDC': '0x085c8eaccA6911fE60aE3f8FbAe5F3012E3A05Ec', + 'BB_idle_cpFAS-USDT': '0xFDAD59EF0686C3Da702b7D651a3bD35a539c8Bc4', + AA_steakUSDC: '0x28C1eCF5B0f16E1D85B9D2677EfB79d68167cAf2', + BB_steakUSDC: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300', + AA_Re7WETH: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb', + BB_Re7WETH: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300', + BB_dUSDCV3: '0xFb3bD022D5DAcF95eE28a6B07825D4Ff9C5b3814', + AA_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4', + BB_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4', + AA_iETHv2: '0xA118aD79E2152b9a3c7Df8B8791887762b0f1D49', + BB_iETHv2: '0x15079cBAa74C1df2a602fAc88Bd5b98B08FfE6A4', + ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132', + USDC: '0x7713974908be4bed47172370115e8b1219f4a5f0', + USDE: '0x8707f238936c12c309bfc2B9959C35828AcFc512', + AMPL: '0x223592a191ECfC7FDC38a9256c3BD96E771539A9', + WBTC: '0x6daB3bCbFb336b29d06B9C793AEF7eaA57888922', + tBTCv2: '0x84eA3907b9206427F45c7b2614925a2B86D12611', + sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195', + TUSD: '0x88369cB14F9893aEA737F61ad31Bc6d018af7985', + aEthUSDC: '0x42EFD1E0DB4ADa762cc5092ECBD052dE7c6e72E2', + MAV: '0x92582aa69BB6117903a01eDdfe6EFfDDe564A69f', + BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a', + STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18', + SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a', + wstETH: '0x3c22ec75ea5D745c78fc84762F7F1E6D82a2c5BF', + WETH: '0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44', + USDT: '0xAf64555DDD61FcF7D094824dd9B4eBea165aFc5b', + XAUT: '0xc4e161e8d8a4bc4ac762ab33a28bbac5474203d7', + R: '0xBfe4c9D3235475C138a61f62e9e72FaD94A3303b', + sDAI: '0x4C612E3B15b96Ff9A6faED838F8d07d479a8dD4c', + CVX: '0x0aCA67Fa70B142A3b9bF2eD89A81B40ff85dACdC', + MIM: '0xa046a8660e66d178ee07ec97c585eeb6aa18c26c', + AnkETH: '0xF7260D4ADc48fEefd5a19a9Eb23f9747CeE15C92', + DAI: '0xd1668fb5f690c59ab4b0cabad0f8c1617895052b', + oldFRAX: '0x183d0dc5867c01bfb1dbbc41d6a9d3de6e044626', + newFRAX: '0x183d0dc5867c01bfb1dbbc41d6a9d3de6e044626', + FEI: '0x19c549357034d10db8d75ed812b45be1dd8a7218', + BAL: '0x0659FB78b5139eE5bC9238b2C85944a112A7b591', + OHM: '0x3D7FEAB5cfab1c7De8ab2b7D5B260E76fD88BC78', + AURA: '0xBB19053E031D9B2B364351B21a8ed3568b21399b', + WISE: '0x25c315e0758beeab30ee048a4e2080e7084b64b3', + DDIM: '0x229cbd1955fee93ab6e7876c1b17f6d0b859e953', + DODO: '0x3e19d726ed435afd3a42967551426b3a47c0f5b7', + ADAI: '0x826c3064d4f5b9507152f5cb440ca9326e1ec8fa', + AWETH: '0xa433105e7396070a5e1fdd7e2b2338f1bfa0de68', + BUSD: '0xf977814e90da44bfa03b6295a0616a897441acec', + INCH: '0x4ee7c0f5480eb1edd8902a5e8b991ed52992d5f5', + mUSD: '0x3aD1D5CFCF9169Da73C23D85d5f2Bf53bC9d39dF', + mBTC: '0x15A295e9BCFcF93a8721DCb9A19330fc59771271', + renBTC: '0xAaE0633E15200bc9C50d45cD762477D268E126BD', + tBTC: '0xC25099792E9349C7DD09759744ea681C7de2cb66', + HBTC: '0x52885fF60Cd7Ae081e0665968C457DdACF888C90', + GUSD: '0x550Def3DB74F583c7A1eDf2DFFE84a7398850D0c', + LINK: '0x8d4169cCf3aD88EaFBB09580e7441D3eD2b4B922', + ADAIv1: '0x3021026e4ff227571a5a563ad19ea657c7027e59', + CETH: '0x712d0f306956a6a4b4f9319ad9b9de48c5345996', + CDAI: '0xab4ce310054a11328685ece1043211b68ba5d082', + CUSDC: '0xC2F61a6eEEC48d686901D325CDE9233b81c793F3', + EURS: '0xC1056Adeb61a01964Ea265cA95EffB7016f9Ed78', + EURT: '0x6914FC70fAC4caB20a8922E900C4BA57fEECf8E1', + CRV: '0x7a16fF8270133F063aAb6C9977183D9e72835428', + jEUR: '0x937Df4e3d6dB229A10ff0098ab3A1bCC40C33ea4', + UST: '0xf16e9b0d03470827a95cdfd0cb8a8a3b46969b91', + SAITAMA: '0x763d5d93f27615aac852b70549f5877b92193864', + aETH: '0xc03c4476fbe25138bf724fa1b95551c6e6b8fd2c', + aWETH: '0x3ddfa8ec3052539b6c9549f12cea2c295cff5296', + aUSDT: '0x4aef720f7bbe98f916221bbc2fb5a15efe6d2cb8', + BBAUSD: '0x4361b7425cff39b1be9bf12cee2ef32f89656cda', + sETH: '0x274d9E726844AB52E351e8F1272e7fc3f58B7E5F', + sUSD: '0xcb68110C43C97b6051FEd5e2Bacc2814aDaD1688', + USDD: '0xf89d7b9c864f589bbf53a82105107622b35eaa40', + alETH: '0xBD28e1B15EcbE72706A445f77bd17FCd8Fe6f652', + SHIBA: '0x73af3bcf944a6559933396c1577b257e2054d935', + aEthWETH: '0x931433324E6B0b5B04E3460ef3fb3f78dda3c721', + dUSDC: '0x2FC2F705110A7F46Ce85F701d7217EF1018f01A3', + PSP: '0xE5E5440a1CE69C5cf67BFFA74d185e57c31b43E5', + EUROC: '0x64AE5802620398143FC7113037769175F74825Ea', + bC3M: '0x5f9F41497f9e11fd7D4c4B067413199682eE2CFF', + bERNX: '0x5F7A4c11bde4f218f0025Ef444c369d838ffa2aD', + bIB01: '0x5F7A4c11bde4f218f0025Ef444c369d838ffa2aD', + steakUSDC: '0xC977d218Fde6A39c7aCE71C8243545c276B48931', + EURA: '0xa116f421ff82a9704428259fd8cc63347127b777', + stEUR: '0xdC7Aa225964267c7E0EfB35f4931426209E90312', + USDA: '0x2686bC6A56D205010637CE1DF124b20Cb19E4054', + stUSD: '0x4e83c0a323b68E3Bc7CC8a4E35326Fd0544A291E', + crvUSD: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635', + GHO: '0x0F11640BF66e2D9352d9c41434A5C6E597c5e4c8', + wibBTC: '0xFbdCA68601f835b27790D98bbb8eC7f05FDEaA9B', + MATIC: '0x7073783eee7e9b3e6e4ddac4d7f49dc46044dd9a', + POL: '0x05A47D9f589a001C15E38D068dCc5DaE6D96a2eb', + SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058', + frxETH: '0x9df2322bdAEC46627100C999E6dDdD27837fec6e', + LUSD: '0xEd279fDD11cA84bEef15AF5D39BB4d4bEE23F0cA', + BNT: '0xf727e20e081aAE428E7c6bE07b156bB21ab587a7', + USDe: '0x74e6c48e667d698a4cf90665b6960a5bae39e603', + eETH: '0x0f1DfeF1a40557d279d0de6E49aB306891A638b8', + stataUSDT: '0x6803364AceD5181877abC11E865FB27cB654a426', + aaveUSDT: '0x32c98a981Fe7C333Bd4e8E7630E8e0CF5ce20987', + weETH: '0x267ed5f71EE47D3E45Bb1569Aa37889a2d10f91e', + rUSD: '0xEC2eda1C4F981E468ABF62424a10B69B738b498E', + arUSD: '0xeFc24206053a452e2299BF3b8f964512b041Db4C', + USD0: '0x6A5d5Af0E266a24648a9d7E8D388EAEc7AbD8433', + 'USD0++': '0x2227b6806339906707b43F36a1f07B52FF7Fa776', + USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', + wUSDM: '0x3B95bC951EE0f553ba487327278cAc44f29715E5', + }, + [constants_1.Network.POLYGON]: { + jGBP: '0x02aa0B826c7BA6386DdBE04C0a8715A1c0A16B24', + MATIC: '0xfCbB9e5BB354B6F9fd40362Cee043F510dd3028D', + DAI: '0x98F911D496Cf46bf9FF9CdD7039Cf579B26F01B9', + WETH: '0x62ac55b745f9b08f1a81dcbbe630277095cf4be1', + WMATIC: '0x0AFF6665bB45bF349489B20E225A6c5D78E2280F', + AMWMATIC: '0x975779102B2A82384f872EE759801DB5204CE331', + USDC: '0xf89d7b9c864f589bbf53a82105107622b35eaa40', + BAL: '0xF1CFf6380D9A15dB33Eed0309541E254fC7dE695', + AAVE: '0x256e063f7fb60a3004D13e1D09e7A9D200A5C5bA', + PSP: '0xa902c6a26bcaC4c62Eb8667E3Ef9368f78421dB5', + POPS: '0x2693b57ee51f4e2a26dfb339a911fa8731061f49', + MUST: '0x9f2a409848fb9b7bd058b24a23e8dbf1e166a109', + AMDAI: '0xFA0DCe8280FCDf369a4cbFc1830d3302789307a6', + mUSD: '0x5084f622cbDf1E22E473d66d97916524745B9b6e', + USDT: '0x2D55eccD5F50D325ee3CE192322911f87113bCd3', + WBTC: '0xdc9232e2df177d7a12fdff6ecbab114e2231198d', + AMWETH: '0x6f1c28c40b5fed4fb546f85959ae2f7c16365cad', + KNC: '0x41Af7fd16dFC29bdA8D8aAA4CeFfC0E8046992eC', + jEUR: '0x807B465fC3f72aF3AAfda74480CA7E4E55964cd3', + aUSDT: '0x027ffd3c119567e85998f4e6b9c3d83d5702660c', + aPolUSDT: '0x941da3d6759147736456cee36647213183079337', + aPolWMATIC: '0xfB3C01F90B4629DBD4Fd5310E995Ef3FE2e7AbeE', + RADIO: '0x60531b9c3645546d864604ee0fc5b7d6adc81cc2', + HANZO: '0x8a151b6ec99c7b90b342ab401d511b480309b220', + RVLT: '0x815f87ca3db2b9491115a7769aeacb140361c5a9', + stMATIC: '0x7C8963BddC17095aDbc9387Cc6cdcCaA798feA52', + axlUSDC: '0x9298F93ee0393a823C242D80F1a4aDf4c8a3Feef', + deUSDC: '0x94d5ead1f80cf0b4d3480ab59dff16d47c93e9fe', + amUSDT: '0x832b11846a27b3ba25d68ae80c39fab155d18c49', + amUSDC: '0x6e7f19cd23049c7118e14470e2bf85d2e26ee0ae', + MAI: '0x9a8cf02f3e56c664ce75e395d0e4f3dc3dafe138', + SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058', + CRV: '0x2151578e1fEc29361bB0481312Ea6b935014D636', + SUSHI: '0x1605CE87dD176b38a17d30e8926370ffD5268bf6', + EURA: '0x9A760aa1Fe631fD9aC0Aee0965736121c7c132cc', + stEUR: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', + USDA: '0x741383AbD73891b40822A069f14d6fc5b5685020', + stUSD: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', + stataUSDCn: '0xFAB1420c84fF5E058B8AD12604D24247e268f362', + aaveUSDCn: '0xEBA9C3C1B41A846431F970aCA5Eee10f55969B76', + crvUSD: '0x61aE20E0292a5E6CF2F017236755246BB9e0f57a', + USDCe: '0xA67EFB69A4f58F568aAB1b9d51110102985835b0', + USDCn: '0x4B6f17856215eab57c29ebfA18B0a0F74A3627bb', + USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', + wUSDM: '0x76272a79F7e529247b663fC8857BD69244b0d412', + TRYB: '0xD05007f1BD1304bFAEb370Ec5EbD18fD02a581e6', + }, + [constants_1.Network.FANTOM]: { + DAI: '0x370f4b2dcf75c94d8d4450b493661a9c6170d0b5', + FTM: '0x431e81E5dfB5A24541b5Ff8762bDEF3f32F96354', + WFTM: '0xB7D0fB518a5b7bf8dc7ea19A715E8FD8BD983e27', + USDC: '0xf53feaeb035361c046e5669745695e450ebb4028', + USDCe: '0x305fa2FB5AF034D490A9C9be8bcd9b01902480BF', + FUSDT: '0x9ade1c17d25246c405604344f89E8F23F8c1c632', + POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', + aFanUSDT: '0x8EBc96fF91A30059E447bFC7C0a7394f8A5793E6', + aFanWFTM: '0x935AD0fBea9572bB24138F23A69e314f0BDbdDbE', + MIM: '0xbcab7d083cf6a01e0dda9ed7f8a02b47d125e682', + FRAX: '0x4423ac71f53ca92e2f2be5917a9c2468e7412f4a', + nETH: '0x16b658270ac50c0063940ed287c401b3df7ccf70', + WETH: '0x7b7b957c284c2c227c980d6e2f804311947b84d0', + SPIRIT: '0x0d0707963952f2fba59dd06f2b425ace40b492fe', + wBOMB: '0x28aa4f9ffe21365473b64c161b566c3cdead0108', + TOR: '0x70de4b5ed310fd93da3c0bae824fb99cb4d44dd8', + BOO: '0xf778f4d7a14a8cb73d5261f9c61970ef4e7d7842', + ETH: '0xf48883940b4056801de30f12b934dcea90133ee6', + GUSDC: '0x894d774a293f8aa3d23d67815d4cadb5319c1094', + GDAI: '0x0e2ed73f9c1409e2b36fe6c46e60d4557b7c2ac0', + EQUAL: '0x8b187ea19c93091a4d6b426b71871648182b5fac', + FVM: '0x07BB65fAaC502d4996532F834A1B7ba5dC32Ff96', + lzUSDC: '0x06F1C4A56357bF3971C79063f2B58E58c547BC0B', + axlUSDC: '0xccf932cd565c21d2e516c8ff3a4f244eea27e09a', + SOLID: '0xddf169bf228e6d6e701180e2e6f290739663a784', + scrvUSDC_e: '0xb8c1dAb69724da9d3225F14bfD76Ae97bB92BFda', + scrvUSDC_p: '0x74796478d7755a77807fADd2389A18DF1baf9e7c', + }, + [constants_1.Network.BSC]: { + DAI: '0xf68a4b64162906eff0ff6ae34e2bb1cd42fef62d', + WBNB: '0x59d779bed4db1e734d3fda3172d45bc3063ecd69', + BUSD: '0x0D0707963952f2fBA59dD06f2b425ace40b492Fe', + POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', + BNB: '0xf68a4b64162906eff0ff6ae34e2bb1cd42fef62d', + USDT: '0xf89d7b9c864f589bbf53a82105107622b35eaa40', + ETH: '0xefdca55e4bce6c1d535cb2d0687b5567eef2ae83', + USDC: '0x554b52bf57b387fd09d6644368c5a8aacaaf5ae0', + RADIO: '0x75b3efed620e2d6750d88263cd4d7a27b0d7d3c5', + bBTC: '0x72a53cdbbcc1b9efa39c834a540550e23463aacb', + anyBTC: '0x4ffef8e8a75c20ab0ddf96c50d2457277d27923c', + nUSD: '0x28ec0b36f0819ecb5005cab836f4ed5a2eca4d13', + axlUSD: '0xc03fbeda9069b22a120ae6a09349a0b5eea5570a', + FRAX: '0xEB4576fE753DAB07635c0Bb6c8f0A355e1Db5d31', + frxETH: '0xf324adC872005197A6f7DAE214d3b63aa0C3625F', + USDFI: '0x2E00D722e091836B39Db3e4dcE6eE51c90c5B221', + SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058', + BNBx: '0xFF4606bd3884554CDbDabd9B6e25E2faD4f6fc54', + EURA: '0x4A5362ef534FFB27510E4E4C9A215BB5436377C2', + USDA: '0x230c1f68aBE6033Cba3Fe0D2C0D7097e9923C3bC', + stUSD: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', + stataUSDT: '', + aaveUSDT: '0x5DE3c5BE52D7aDbdC3aEFe2eA061A2ECE0C7d766', + }, + [constants_1.Network.AVALANCHE]: { + LINKe: '0x9efa0A617C0552F1558c95993aA8b8A68b3e709C', + AVAX: '0xD6216fC19DB775Df9774a6E33526131dA7D19a2c', + avWAVAX: '0xc5ed2333f8a2C351fCA35E5EBAdb2A82F5d254C3', + WAVAX: '0x5CfCd7E6D055Ba4f7B998914336254aDE3F69f26', + sAVAX: '0xC73DF1e68FC203F6E4b6270240D6f82A850e8D38', + BETS: '0x8cc2284c90d05578633418f9cde104f402375a65', + HATCHY: '0x14ec295ec8def851ec6e2959df872dd24e422631', + USDCe: '0x3a2434c698f8d79af1f5a9e43013157ca8b11a66', + USDC: '0xcc2da711D621A4491b338CAC88B9C0954db3e75B', + USDTe: '0x84d34f4f83a87596cd3fb6887cff8f17bf5a7b83', + WETHe: '0x9bdB521a97E95177BF252C253E256A60C3e14447', + POPS: '0x5268c2331658cb0b2858cfa9db27d8f22f5434bc', + ETH: '0x9852e84b5AA485683d8AeE7B0332e42442763b75', + DAIE: '0xED2a7edd7413021d440b09D654f3b87712abAB66', + TUSD: '0x5Db946411F08f15300f23D9bde4A407B07D56C03', + PNG: '0x348b11CF986e8E1CdA10c4A7E375aA252b47fc55', + SHIBX: '0xfE5ADf65BE1a46b83EF3d352A8F9258A039f3050', + wBTC: '0xbB2BD754A45f400A01158A8b3C89DE085D58ABF1', + renBTC: '0xb8D1D22609D10078Db36915fc4610F8674b44319', + ADAI: '0xc5ed2333f8a2C351fCA35E5EBAdb2A82F5d254C3', + MIM: '0x64cb3f5aada07d831b8db6c6d9c715c53c251ef3', + TSD: '0x691A89db352B72dDb249bFe16503494eC0D920A4', + THO: '0xc40d16c47394a506d451475c8a7c46c1175c1da1', + aAvaUSDT: '0x50B1Ba98Cf117c9682048D56628B294ebbAA4ec2', + USDT: '0x0d0707963952f2fba59dd06f2b425ace40b492fe', + aAvaWAVAX: '0x1B18Df70863636AEe4BfBAb6F7C70ceBCA9bA404', + oldFRAX: '0x4e3376018add04ebe4c46bf6f924ddec8c67aa7b', + newFRAX: '0x4e3376018add04ebe4c46bf6f924ddec8c67aa7b', + nETH: '0xcf2ef00e75558512ae735679ea5df62ad2056786', + avWETH: '0x92d78e32b990d10aeca0875dc5585f1a6f958179', + YUSD: '0x86D0c0e4B8CC5409144f66E6E76b904bb9ce9cDb', + BTCb: '0x2446bEb3905CfFbd2c5eB18F1f9c2996B05257c4', + AMPL: '0xfcaA5ea7F8eb0631BcA72C345025C0A5a6D93f0E', + PHAR: '0x654296D56532f62B7d91d335791d3c364a9385b5', + stataUSDT: '', + aaveUSDT: '0xB2d3ad6e99D2A043EF77e3812461Ad2D4Ae3da8B', + }, + [constants_1.Network.ARBITRUM]: { + SEN: '0x76d39045d856caf9bfae12ba611ca4a94449a4f1', + RDPX: '0x115b818593c00da4f9d1d8f5ce7d7f88cce48bee', + ARB: '0xb65edba80a3d81903ecd499c8eb9cf0e19096bd0', + ETH: '0xfa0a32e5c33b6123122b6b68099001d9371d14e9', + DAI: '0x2d070ed1321871841245d8ee5b84bd2712644322', + WETH: '0x3368e17064c9ba5d6f1f93c4c678bea00cc78555', + BAL: '0x7b7b957c284c2c227c980d6e2f804311947b84d0', + USDCe: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', + USDC: '0xb38e8c17e38363af6ebdcb3dae12e0243582891d', + OHM: '0xebce5f29ff5ca9aa330ebdf7ec6b5f474bff271e', + USDT: '0xf977814e90da44bfa03b6295a0616a897441acec', + POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', + FRAX: '0x59bf0545fca0e5ad48e13da269facd2e8c886ba4', + nUSD: '0x9dd329f5411466d9e0c488ff72519ca9fef0cb40', + nETH: '0xa067668661c84476afcdc6fa5d758c4c01c34352', + AAVE: '0x8D2876aD4D2A994C529F19D846CA541015dc3f05', + aArbAAVE: '0x439901eCaB06F75B14bC25fD60d53bB3A3b9e277', + EURS: '0x251aeE4A9eB1d8251485D1A9b3bE68975B39EC33', + aArbEURS: '0xD2BC982A2035dB0E1Be7c2C1a9f87E31794C653e', + MIM: '0xf46bb6dda9709c49efb918201d97f6474eac5aea', + VST: '0x59bf0545fca0e5ad48e13da269facd2e8c886ba4', + aArbUSDC: '0x048BF2F5908e95976CeAD0E47D805b3803E286e2', + ZYB: '0x3ec0eddcd1e25025077327886a78133589082fb2', + WBTC: '0xd9d611c6943585bc0e18e51034af8fa28778f7da', + RDNT: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', + SDEX: '0xb0470cf15b22a6a32c49a7c20e3821b944a76058', + LINK: '0x7f1fa204bb700853d36994da19f830b6ad18455c', + DMT: '0x40414f138eb2ef938e6c3629897ef99d4464d4e8', + PENDLE: '0x5bdf85216ec1e38d6458c870992a69e38e03f7ef', + wstETH: '0x3c22ec75ea5D745c78fc84762F7F1E6D82a2c5BF', + EURA: '0x6dd7b830896b56812aa667bdd14b71c8b3252f8e', + stEUR: '0xE588611e7A2392507879E3be80531654b85C16aA', + USDA: '0xa86ff337db9107b54862d30d1a598f8be847b05e', + stUSD: '0xBa511aAd739358b2F34285f9E2d5344017b7DcaD', + stataUSDT: '0xc5042f9d9a18e95547864438455c8f05b4987399', + aaveUSDT: '0xAfa788fab589fe61C23DF76905558f4734444D67', + crvUSD: '0x9755e99bdb99495d3d31d953785d993c6df8552e', + GHO: '0xda39E48523770197EF3CbB70C1bf1cCCF9B4b1E7', + USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', + wUSDM: '0x12c9cE6b155c8aaC74004732A621B64bC669bb79', + }, + [constants_1.Network.OPTIMISM]: { + ETH: '0xF6D4E5a7c5215F91f59a95065190CCa24bf64554', + DAI: '0x1337bedc9d22ecbe766df105c9623922a27963ec', + WETH: '0x86bb63148d17d445ed5398ef26aa05bf76dd5b59', + POPS: '0x3cbd9044aaabef08ce93a68448e093cff405ad76', + USDCe: '0xdecc0c09c3b5f6e92ef4184125d5648a66e35298', + USDC: '0x8aF3827a41c26C7F32C81E93bb66e837e0210D5c', + USDT: '0xf977814e90da44bfa03b6295a0616a897441acec', + OP: '0xEBb8EA128BbdFf9a1780A4902A9380022371d466', + aOptWETH: '0x7B7D80C40415F744864f051B806b466e2fbB8E68', + aOptUSDC: '0x8c0Fcf914E90fF5d7f2D02c1576BF4245FaD2B7F', + sBTC: '0xbbb33d2e7bd7ddc722e53da9ca8ee97df41cfabf', + sETH: '0xce3850927d0e631b6082f9d45a6391a3794c51eb', + sUSD: '0xa5f7a39e55d7878bc5bd754ee5d6bd7a7662355b', + wstETH: '0x63f6D9E7d3953106bCaf98832BD9C88A54AfCc9D', + rETH: '0x4c2e69e58b14de9afedfb94319519ce34e087283', + WBTC: '0xb9c8f0d3254007ee4b98970b94544e473cd610ec', + frxETH: '0x4d4edf8291d169f975b99914b6ab3326abb45938', + EURA: '0x9A760aa1Fe631fD9aC0Aee0965736121c7c132cc', + stEUR: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', + USDA: '0x7dFf12833a6f0e88f610E79E11E9506848cCF187', + stUSD: '0xC98b0729695A25152B8D5b6B95709070605A7F60', + crvUSD: '0x7a16fF8270133F063aAb6C9977183D9e72835428', + LUSD: '0xf0a9abb11958a071e168f2ee5bcbacf1abbde9cf', + GRAI: '0x92b051204816DC4fbA7AC1A68a2cf319A9a387CB', + stataUSDT: '0xd55263b84685Ced7e10a77607C7fFD763D495B6e', + aaveUSDT: '0x1Fd458C52fEb7Bb35097ebd9566DB6C269341FDD', + tBTC: '0xf7b4531e52211CC44379102F719cad29411dB053', + PSTAKE: '0xc45398444B83183b2018e0224B3D332b42D492Af', + USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', + wUSDM: '0x1Ab0b1A5A239B524702EcE9cCe77E096d4daE75B', + }, + [constants_1.Network.ZKEVM]: { + ETH: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9', + WETH: '0xc44b0378e400a9958219ec8f294c23b9976e3c5d', + MATIC: '0x8f2a1450c040b3c19efe9676165d8f30d8280019', + WBTC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c', + USDC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c', + }, + [constants_1.Network.BASE]: { + WETH: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28', + PRIME: '0xe3879b7359695f802d6FD56Bb76fD82C362Dafd6', + ETH: '0xd34ea7278e6bd48defe656bbe263aef11101469c', + MAV: '0xf977814e90da44bfa03b6295a0616a897441acec', + USDC: '0x21bD501F86A0B5cE0907651Df3368DA905B300A9', + USDbC: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28', + DAI: '0x20f03e26968b179025f65c1f4afadfd3959c8d03', + BAL: '0x854b004700885a61107b458f11ecc169a019b764', + GOLD: '0x1374c25b3710758c326ee0c70ec48b595d5ccf8c', + SDEX: '0xa5d378c05192e3f1f365d6298921879c4d51c5a3', + EURA: '0x5b5614b9fffab7c751799eb12d5cb9165c8c40ad', + stEUR: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', + USDA: '0x7FE4b2632f5AE6d930677D662AF26Bc0a06672b3', + stUSD: '0x8deeffb6047b8ee91b09334eb2a4ca120f43f596', + ALB: '0x365c6d588e8611125de3bea5b9280c304fa54113', + AERO: '0x807877258b55bfefabdd469da1c72731c5070839', + tBTC: '0x9f1920d0cbb63ed03376a1e09fd2851d601234c8', + DOG: '0xbe3ab8a87730684ef1e476064c2e43c3e982f8e8', + stataUSDC: '0x88Cac91ADDE2208039A227B373C2A692C0700547', + aaveUSDC: '0x5DE3c5BE52D7aDbdC3aEFe2eA061A2ECE0C7d766', + USDM: '0x426c4966fC76Bf782A663203c023578B744e4C5E', + crvUSD: '0xBbAbDB1385deA5285113581A7024d6DC04131101', + cbETH: '0x50e011dD1e2b4906F1534623cD134B30422bb11E', + wUSDM: '0xe30965Acd0Ee1CE2e0Cd0AcBFB3596bD6fC78A51', + }, +}; +exports.SmartTokens = Object.keys(exports.Tokens).reduce((acc, _network) => { + const network = parseInt(_network, 10); + acc[+network] = Object.keys(exports.Tokens[network]).reduce((_acc, tokenName) => { + const token = exports.Tokens[network][tokenName]; + if (token.addAllowance && token.addBalance) { + _acc[tokenName] = new smart_tokens_1.SmartToken(token); + } + return _acc; + }, {}); + return acc; +}, {}); +exports.NativeTokenSymbols = { + [constants_1.Network.MAINNET]: 'ETH', + [constants_1.Network.POLYGON]: 'MATIC', + [constants_1.Network.BSC]: 'BNB', + [constants_1.Network.AVALANCHE]: 'AVAX', + [constants_1.Network.FANTOM]: 'FTM', + [constants_1.Network.ARBITRUM]: 'ETH', + [constants_1.Network.OPTIMISM]: 'ETH', + [constants_1.Network.BASE]: 'ETH', +}; +exports.WrappedNativeTokenSymbols = { + [constants_1.Network.MAINNET]: 'WETH', + [constants_1.Network.POLYGON]: 'WMATIC', + [constants_1.Network.BSC]: 'WBNB', + [constants_1.Network.AVALANCHE]: 'WAVAX', + [constants_1.Network.FANTOM]: 'WFTM', + [constants_1.Network.ARBITRUM]: 'WETH', + [constants_1.Network.OPTIMISM]: 'WETH', + [constants_1.Network.BASE]: 'WETH', +}; +//# sourceMappingURL=constants-e2e.js.map \ No newline at end of file diff --git a/tests/constants-e2e.js.map b/tests/constants-e2e.js.map new file mode 100644 index 000000000..0f77ff873 --- /dev/null +++ b/tests/constants-e2e.js.map @@ -0,0 +1 @@ +{"version":3,"file":"constants-e2e.js","sourceRoot":"","sources":["constants-e2e.ts"],"names":[],"mappings":";;;AAAA,wDAU+B;AAE/B,gDAA0D;AAE7C,QAAA,cAAc,GAAG,4CAA4C,CAAC;AAC9D,QAAA,aAAa,GAAG,4CAA4C,CAAC;AAC7D,QAAA,aAAa,GAAG,4CAA4C,CAAC;AAE7D,QAAA,MAAM,GAEf;IACF,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;QACjB,KAAK,EAAE;YACL,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,IAAI,EAAE;YACJ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,GAAG,EAAE;YACH,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,GAAG,EAAE;YACH,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,SAAS,EAAE;YACT,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,4CAA4C;SACtD;QACD,oBAAoB,EAAE;YACpB,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,4CAA4C;SACtD;QACD,oBAAoB,EAAE;YACpB,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,4CAA4C;SACtD;QACD,YAAY,EAAE;YACZ,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,4CAA4C;SACtD;QACD,YAAY,EAAE;YACZ,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,4CAA4C;SACtD;QACD,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,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,yBAAU,CAAC,KAAK,CAAC,CAAC;SACzC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAgC,CAAC,CAAC;IACrC,OAAO,GAAG,CAAC;AACb,CAAC,EAAE,EAAgD,CAAC,CAAC;AAExC,QAAA,kBAAkB,GAAkC;IAC/D,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,KAAK;IACxB,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,OAAO;IAC1B,CAAC,mBAAO,CAAC,GAAG,CAAC,EAAE,KAAK;IACpB,CAAC,mBAAO,CAAC,SAAS,CAAC,EAAE,MAAM;IAC3B,CAAC,mBAAO,CAAC,MAAM,CAAC,EAAE,KAAK;IACvB,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,KAAK;IACzB,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,KAAK;IACzB,CAAC,mBAAO,CAAC,IAAI,CAAC,EAAE,KAAK;CACtB,CAAC;AAEW,QAAA,yBAAyB,GAAkC;IACtE,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,MAAM;IACzB,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,QAAQ;IAC3B,CAAC,mBAAO,CAAC,GAAG,CAAC,EAAE,MAAM;IACrB,CAAC,mBAAO,CAAC,SAAS,CAAC,EAAE,OAAO;IAC5B,CAAC,mBAAO,CAAC,MAAM,CAAC,EAAE,MAAM;IACxB,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;IAC1B,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;IAC1B,CAAC,mBAAO,CAAC,IAAI,CAAC,EAAE,MAAM;CACvB,CAAC"} \ No newline at end of file diff --git a/tests/constants-e2e.ts b/tests/constants-e2e.ts index 6ef5ec065..7c7be8743 100644 --- a/tests/constants-e2e.ts +++ b/tests/constants-e2e.ts @@ -8,7 +8,6 @@ import { _balancesFn, _allowancesFn, balanceAndBlacklistStatesFn, - // @ts-ignore } from '../tests/smart-tokens'; import { Address } from '../src/types'; import { ETHER_ADDRESS, Network } from '../src/constants'; diff --git a/tests/smart-tokens.d.ts b/tests/smart-tokens.d.ts new file mode 100644 index 000000000..1ba9d1d0f --- /dev/null +++ b/tests/smart-tokens.d.ts @@ -0,0 +1,36 @@ +import { Address, Token } from '../src/types'; +export declare type StateOverride = { + value: Record; +}; +export declare type StateSimulateApiOverride = { + storage: { + value: Record; + }; +}; +export declare type StateOverrides = { + networkID: string; + stateOverrides: Record; +}; +export declare type AddBalanceFn = (address: Address, amount: string) => Record; +export declare type AddAllowanceFn = (address: Address, spender: Address, amount: string) => Record; +export declare const balanceOfFn: AddBalanceFn; +export declare const balancesFn: AddBalanceFn; +export declare const balanceAndBlacklistStatesFn: AddBalanceFn; +export declare const _balancesFn: AddBalanceFn; +export declare const allowanceFn: AddAllowanceFn; +export declare const _allowancesFn: AddAllowanceFn; +export declare const allowedFn: AddAllowanceFn; +export declare type SmartTokenParams = Token & { + addBalance?: AddBalanceFn; + addAllowance?: AddAllowanceFn; +}; +export declare class SmartToken { + private params; + private value; + constructor(params: SmartTokenParams); + get address(): string; + get token(): Token; + addBalance(address: Address, amount: string): SmartToken; + addAllowance(address: Address, spender: string, amount: string): SmartToken; + applyOverrides(overrides: StateOverrides): void; +} diff --git a/tests/smart-tokens.js b/tests/smart-tokens.js new file mode 100644 index 000000000..ddd01ca43 --- /dev/null +++ b/tests/smart-tokens.js @@ -0,0 +1,64 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SmartToken = exports.allowedFn = exports._allowancesFn = exports.allowanceFn = exports._balancesFn = exports.balanceAndBlacklistStatesFn = exports.balancesFn = exports.balanceOfFn = void 0; +const constructAddBalanceFn = (varName) => { + return (address, amount) => { + return { + [`${varName}[${address}]`]: amount, + }; + }; +}; +const constructAddBAllowanceFn = (varName) => { + return (address, spender, amount) => { + return { + [`${varName}[${address}][${spender}]`]: amount, + }; + }; +}; +exports.balanceOfFn = constructAddBalanceFn('balanceOf'); +exports.balancesFn = constructAddBalanceFn('balances'); +exports.balanceAndBlacklistStatesFn = constructAddBalanceFn('balanceAndBlacklistStates'); +exports._balancesFn = constructAddBalanceFn('_balances'); +exports.allowanceFn = constructAddBAllowanceFn('allowance'); +exports._allowancesFn = constructAddBAllowanceFn('_allowances'); +exports.allowedFn = constructAddBAllowanceFn('allowed'); +class SmartToken { + constructor(params) { + this.params = params; + this.value = {}; + if (!params.addBalance) { + throw new Error(`${params.address} ${params.symbol} needs to provide addBalance fn`); + } + if (!params.addAllowance) { + throw new Error(`${params.address} ${params.symbol} needs to provide addAllowance fn`); + } + } + get address() { + return this.params.address; + } + get token() { + return { + address: this.params.address, + decimals: this.params.decimals, + symbol: this.params.symbol, + type: this.params.type, + }; + } + addBalance(address, amount) { + const [key, value] = Object.entries(this.params.addBalance(address, amount))[0]; + this.value[key] = value; + return this; + } + addAllowance(address, spender, amount) { + const [key, value] = Object.entries(this.params.addAllowance(address, spender, amount))[0]; + this.value[key] = value; + return this; + } + applyOverrides(overrides) { + overrides.stateOverrides[this.params.address] = { + value: this.value, + }; + } +} +exports.SmartToken = SmartToken; +//# sourceMappingURL=smart-tokens.js.map \ No newline at end of file diff --git a/tests/smart-tokens.js.map b/tests/smart-tokens.js.map new file mode 100644 index 000000000..0673066e4 --- /dev/null +++ b/tests/smart-tokens.js.map @@ -0,0 +1 @@ +{"version":3,"file":"smart-tokens.js","sourceRoot":"","sources":["smart-tokens.ts"],"names":[],"mappings":";;;AA2BA,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAgB,EAAE;IAC9D,OAAO,CAAC,OAAgB,EAAE,MAAc,EAAE,EAAE;QAC1C,OAAO;YACL,CAAC,GAAG,OAAO,IAAI,OAAO,GAAG,CAAC,EAAE,MAAM;SACnC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,wBAAwB,GAAG,CAAC,OAAe,EAAkB,EAAE;I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AAC,MAAM,CAAC,MAAM;YAC1B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;SACvB,CAAC;IACJ,CAAC;IAEM,UAAU,CAAC,OAAgB,EAAE,MAAc;QAChD,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CACjC,IAAI,CAAC,MAAM,CAAC,UAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CACzC,CAAC,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,YAAY,CACjB,OAAgB,EAChB,OAAe,EACf,MAAc;QAEd,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,OAAO,CACjC,IAAI,CAAC,MAAM,CAAC,YAAa,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CACpD,CAAC,CAAC,CAAC,CAAC;QACL,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,cAAc,CAAC,SAAyB;QAC7C,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG;YAC9C,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC;CACF;AAvDD,gCAuDC"} \ No newline at end of file From 90970b0a08a82e060a98254bdbbf21fc65e43271 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 13:26:55 +0300 Subject: [PATCH 52/64] 3.9.7-fluid-dex.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d2d348091..7cbdb8c31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.9.7-fluid-dex.0", + "version": "3.9.7-fluid-dex.1", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From f13a9220b1fd42593c14e37ba3387782f67a78ec Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 14:59:15 +0300 Subject: [PATCH 53/64] add fixes --- src/dex/fluid-dex/config.ts | 1 - src/dex/fluid-dex/fluid-dex-e2e.test.ts | 64 +++--- .../fluid-dex/fluid-dex-integration.test.ts | 185 +++++++++++++----- src/dex/fluid-dex/fluid-dex.ts | 119 +---------- src/dex/fluid-dex/types.ts | 1 - 5 files changed, 181 insertions(+), 189 deletions(-) diff --git a/src/dex/fluid-dex/config.ts b/src/dex/fluid-dex/config.ts index dc87730f8..a2e738ac2 100644 --- a/src/dex/fluid-dex/config.ts +++ b/src/dex/fluid-dex/config.ts @@ -10,7 +10,6 @@ export const FluidDexConfig: DexConfigMap = { resolver: '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13', dexFactory: '0x91716C4EDA1Fb55e84Bf8b4c7085f84285c19085', }, - pools: [], }, }, }; diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index 0e3dfa86e..c9d101329 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -60,7 +60,6 @@ function testForNetwork( tokenBSymbol: string, tokenAAmount: string, tokenBAmount: string, - nativeTokenAmount: string, ) { const provider = new StaticJsonRpcProvider( generateConfig(network).privateHttpProvider, @@ -79,11 +78,11 @@ function testForNetwork( describe(`${side}`, () => { contractMethods.forEach((contractMethod: string) => { describe(`${contractMethod}`, () => { - it(`${nativeTokenSymbol} -> ${tokenASymbol}`, async () => { + it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => { await testE2E( - tokens[nativeTokenSymbol], tokens[tokenASymbol], - holders[nativeTokenSymbol], + tokens[tokenBSymbol], + holders[tokenASymbol], tokenBAmount, SwapSide.SELL, dexKey, @@ -92,12 +91,12 @@ function testForNetwork( provider, ); }); - it(`${tokenASymbol} -> ${nativeTokenSymbol}`, async () => { + it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => { await testE2E( + tokens[tokenBSymbol], tokens[tokenASymbol], - tokens[nativeTokenSymbol], - holders[tokenASymbol], - tokenAAmount, + holders[tokenBSymbol], + tokenBAmount, SwapSide.SELL, dexKey, contractMethod as ContractMethod, @@ -118,21 +117,38 @@ describe('FluidDex E2E', () => { describe('Mainnet', () => { const network = Network.MAINNET; - const tokenASymbol: string = 'wstETH'; - const tokenBSymbol: string = 'ETH'; - - const tokenAAmount: string = '100000000000000'; - const tokenBAmount: string = '100000000000000'; - const nativeTokenAmount = '100000000000000'; - - testForNetwork( - network, - dexKey, - tokenASymbol, - tokenBSymbol, - tokenAAmount, - tokenBAmount, - nativeTokenAmount, - ); + describe('ETH -> wstETH', () => { + const tokenASymbol: string = 'wstETH'; + const tokenBSymbol: string = 'ETH'; + + const tokenAAmount: string = '100000000000000'; + const tokenBAmount: string = '100000000000000'; + + testForNetwork( + network, + dexKey, + tokenASymbol, + tokenBSymbol, + tokenAAmount, + tokenBAmount, + ); + }); + + describe('USDC -> USDT', () => { + const tokenASymbol: string = 'USDC'; + const tokenBSymbol: string = 'USDT'; + + const tokenAAmount: string = '1000000'; + const tokenBAmount: string = '100000000'; + + testForNetwork( + network, + dexKey, + tokenASymbol, + tokenBSymbol, + tokenAAmount, + tokenBAmount, + ); + }); }); }); diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 5cb9f9879..2f012d359 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -133,11 +133,6 @@ async function testPricingOnNetwork( pools, ); expect(poolPrices).not.toBeNull(); - if (fluidDex.hasConstantPriceLargeAmounts) { - checkConstantPoolPrices(poolPrices!, amounts, dexKey); - } else { - checkPoolPrices(poolPrices!, amounts, side, dexKey); - } // Check if onchain pricing equals to calculated ones await checkOnChainPricing( @@ -160,24 +155,6 @@ describe('FluidDex', function () { const tokens = Tokens[network]; - // Don't forget to update relevant tokens in constant-e2e.ts - const srcTokenSymbol = 'wstETH'; - const destTokenSymbol = 'ETH'; - - const amountsForSell = [ - 0n, - 1n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 2n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 3n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 4n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 5n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 6n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 7n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 8n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 9n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - 10n * BI_POWS[tokens[srcTokenSymbol].decimals - 10], - ]; - beforeAll(async () => { blockNumber = await dexHelper.provider.getBlockNumber(); fluidDex = new FluidDex(network, dexKey, dexHelper); @@ -186,40 +163,142 @@ describe('FluidDex', function () { } }); - it('getPoolIdentifiers and getPricesVolume SELL', async function () { - await testPricingOnNetwork( - fluidDex, - network, - dexKey, - blockNumber, - srcTokenSymbol, - destTokenSymbol, - SwapSide.SELL, - amountsForSell, - 'estimateSwapIn', - ); + describe('wstETH -> ETH', () => { + const tokenASymbol = 'wstETH'; + const tokenBSymbol = 'ETH'; + + const amountsForSell = [ + 0n, + 1n * BI_POWS[8], + 2n * BI_POWS[8], + 3n * BI_POWS[8], + 4n * BI_POWS[8], + 5n * BI_POWS[8], + 6n * BI_POWS[8], + 7n * BI_POWS[8], + 8n * BI_POWS[8], + 9n * BI_POWS[8], + 10n * BI_POWS[8], + ]; + + it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume SELL', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + tokenASymbol, + tokenBSymbol, + SwapSide.SELL, + amountsForSell, + 'estimateSwapIn', + ); + }); + + it('ETH -> wstETH, getPoolIdentifiers and getPricesVolume SELL', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + tokenBSymbol, + tokenASymbol, + SwapSide.SELL, + amountsForSell, + 'estimateSwapIn', + ); + }); + + it.skip('getTopPoolsForToken', async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + const newFluidDex = new FluidDex(network, dexKey, dexHelper); + await newFluidDex.initializePricing(blockNumber); + if (newFluidDex.updatePoolState) { + await newFluidDex.updatePoolState(); + } + const poolLiquidity = await newFluidDex.getTopPoolsForToken( + tokens[tokenASymbol].address, + 1, + ); + + if (!newFluidDex.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][tokenASymbol].address, + dexKey, + ); + } + }); }); - it('getTopPoolsForToken', async function () { - // We have to check without calling initializePricing, because - // pool-tracker is not calling that function - const newFluidDex = new FluidDex(network, dexKey, dexHelper); - await newFluidDex.initializePricing(blockNumber); - if (newFluidDex.updatePoolState) { - await newFluidDex.updatePoolState(); - } - const poolLiquidity = await newFluidDex.getTopPoolsForToken( - tokens[srcTokenSymbol].address, - 1, - ); - - if (!newFluidDex.hasConstantPriceLargeAmounts) { - checkPoolsLiquidity( - poolLiquidity, - Tokens[network][srcTokenSymbol].address, + describe('USDC -> USDT', () => { + const tokenASymbol = 'USDC'; + const tokenBSymbol = 'USDT'; + + const amountsForSell = [ + 0n, + 1n * BI_POWS[6], + 2n * BI_POWS[6], + 3n * BI_POWS[6], + 4n * BI_POWS[6], + 5n * BI_POWS[6], + 6n * BI_POWS[6], + 7n * BI_POWS[6], + 8n * BI_POWS[6], + 9n * BI_POWS[6], + 10n * BI_POWS[6], + ]; + + it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () { + await testPricingOnNetwork( + fluidDex, + network, dexKey, + blockNumber, + tokenASymbol, + tokenBSymbol, + SwapSide.SELL, + amountsForSell, + 'estimateSwapIn', ); - } + }); + + it('USDT -> USDC getPoolIdentifiers and getPricesVolume SELL', async function () { + await testPricingOnNetwork( + fluidDex, + network, + dexKey, + blockNumber, + tokenBSymbol, + tokenASymbol, + SwapSide.SELL, + amountsForSell, + 'estimateSwapIn', + ); + }); + + it.skip('getTopPoolsForToken', async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + const newFluidDex = new FluidDex(network, dexKey, dexHelper); + await newFluidDex.initializePricing(blockNumber); + if (newFluidDex.updatePoolState) { + await newFluidDex.updatePoolState(); + } + const poolLiquidity = await newFluidDex.getTopPoolsForToken( + tokens[tokenASymbol].address, + 1, + ); + + if (!newFluidDex.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][tokenASymbol].address, + dexKey, + ); + } + }); }); }); }); diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index b76b27d90..e26076f4d 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -42,7 +42,7 @@ export class FluidDex extends SimpleExchange implements IDex { logger: Logger; - pools: FluidDexPool[]; + pools: FluidDexPool[] = []; readonly fluidCommonAddresses: FluidDexCommonAddresses; @@ -64,7 +64,6 @@ export class FluidDex extends SimpleExchange implements IDex { dexHelper, this.logger, ); - this.pools = FluidDexConfig['FluidDex'][network].pools; this.fluidDexPoolIface = new Interface(FluidDexPoolABI); } @@ -81,7 +80,11 @@ export class FluidDex extends SimpleExchange implements IDex { })); } - async updatePoolAndEventPool(blockNumber: number) { + // Initialize pricing is called once in the start of + // pricing service. It is intended to setup the integration + // for pricing requests. It is optional for a DEX to + // implement this function + async initializePricing(blockNumber: number) { this.pools = await this.fetchFluidDexPools(blockNumber); for (const pool of this.pools) { if (!this.eventPools[pool.id]) { @@ -97,14 +100,6 @@ export class FluidDex extends SimpleExchange implements IDex { } } - // Initialize pricing is called once in the start of - // pricing service. It is intended to setup the integration - // for pricing requests. It is optional for a DEX to - // implement this function - async initializePricing(blockNumber: number) { - await this.updatePoolAndEventPool(blockNumber); - } - getAdapters(side: SwapSide) { return null; } @@ -134,7 +129,6 @@ export class FluidDex extends SimpleExchange implements IDex { side: SwapSide, blockNumber: number, ): Promise { - await this.updatePoolAndEventPool(blockNumber); const pool = await this.getPoolByTokenPair( srcToken.address, destToken.address, @@ -175,7 +169,6 @@ export class FluidDex extends SimpleExchange implements IDex { blockNumber: number, limitPools?: string[], ): Promise> { - await this.updatePoolAndEventPool(blockNumber); try { if (side === SwapSide.BUY) throw new Error(`Buy not supported`); // Get the pool to use. @@ -283,98 +276,7 @@ export class FluidDex extends SimpleExchange implements IDex { tokenAddress: Address, limit: number, ): Promise { - // const latestBlockNumber_ = await this.dexHelper.provider.getBlockNumber(); - // let liquidityAmounts: { [id: string]: bigint } = {}; - // for (const pool of this.pools) { - // if ( - // pool.token0 === tokenAddress.toLowerCase() || - // pool.token1 === tokenAddress.toLowerCase() - // ) { - // const state: FluidDexPoolState = await this.eventPools[ - // pool.id - // ].getStateOrGenerate(latestBlockNumber_, false); - // - // liquidityAmounts[pool.id] = - // pool.token0 === tokenAddress - // ? state.collateralReserves.token0RealReserves + - // state.debtReserves.token0RealReserves - // : state.collateralReserves.token1RealReserves + - // state.debtReserves.token1RealReserves; - // } - // } - // - // const entries = Object.entries(liquidityAmounts); - // - // // Sort the entries based on the values in descending order - // entries.sort((a, b) => { - // if (b[1] > a[1]) return 1; - // if (b[1] < a[1]) return -1; - // return 0; - // }); - // - // // Take the top k entries - // const topKEntries = entries.slice(0, limit); - // - // // Convert the array back to an object - // const sortedAmounts = Object.fromEntries(topKEntries); - // - // const poolLiquidities: PoolLiquidity[] = []; - // - // for (const [id, amount] of Object.entries(sortedAmounts)) { - // const pool = this.pools.find(p => p.id === id); - // if (!pool) continue; // Skip if pool not found - // - // const state: FluidDexPoolState = await this.eventPools[ - // pool.id - // ].getStateOrGenerate(latestBlockNumber_, false); - // - // // let token0decimals: number; - // // for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { - // // let found = false; - // // for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { - // // if (tokenParams.address.toLowerCase() === pool.token0.toLowerCase()) { - // // token0decimals = tokenParams.decimals; - // // found = true; - // // break; - // // } - // // if (found) break; - // // } - // // } - // // - // // let token1decimals: number; - // // for (const [networkStr, symbolMapping] of Object.entries(Tokens)) { - // // let found = false; - // // for (const [symbol, tokenParams] of Object.entries(symbolMapping)) { - // // if (tokenParams.address.toLowerCase() === pool.token1.toLowerCase()) { - // // token1decimals = tokenParams.decimals; - // // found = true; - // // break; - // // } - // // if (found) break; - // // } - // // } - // - // const usd0 = await this.dexHelper.getTokenUSDPrice( - // { address: pool.token0, decimals: token0decimals! }, - // state.collateralReserves.token0RealReserves + - // state.debtReserves.token0RealReserves, - // ); - // - // const usd1 = await this.dexHelper.getTokenUSDPrice( - // { address: pool.token1, decimals: token1decimals! }, - // state.collateralReserves.token1RealReserves + - // state.debtReserves.token1RealReserves, - // ); - // - // poolLiquidities.push({ - // exchange: 'FluidDex', - // address: pool.address, - // connectorTokens: [], - // liquidityUSD: Number(usd0 + usd1), // converted to number - // }); - // } - // return poolLiquidities; - + //@TODO return []; } @@ -389,13 +291,10 @@ export class FluidDex extends SimpleExchange implements IDex { context: Context, executorAddress: Address, ): Promise { - const latestBlockNumber_ = await this.dexHelper.provider.getBlockNumber(); - await this.updatePoolAndEventPool(latestBlockNumber_); - if (side === SwapSide.BUY) throw new Error(`Buy not supported`); let args: any; - let returnAmountPos: number | undefined = undefined; + let returnAmountPos: number | undefined; const method = 'swapIn'; @@ -408,7 +307,7 @@ export class FluidDex extends SimpleExchange implements IDex { const pool = await this.getPoolByTokenPair(srcToken, destToken); - if (pool!.token0.toLowerCase() != srcToken.toLowerCase()) { + if (pool!.token0.toLowerCase() !== srcToken.toLowerCase()) { args = [false, BigInt(srcAmount), BigInt(destAmount), recipient]; } else { args = [true, BigInt(srcAmount), BigInt(destAmount), recipient]; diff --git a/src/dex/fluid-dex/types.ts b/src/dex/fluid-dex/types.ts index 0660d23ac..5efbe4dcd 100644 --- a/src/dex/fluid-dex/types.ts +++ b/src/dex/fluid-dex/types.ts @@ -47,7 +47,6 @@ export type FluidDexPool = { export type DexParams = { commonAddresses: CommonAddresses; - pools: FluidDexPool[]; }; export type CommonAddresses = { From 58104dca4b2dade34b4446be4177a21c18251e32 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 15:01:47 +0300 Subject: [PATCH 54/64] update gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index bea819f62..c7b020006 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,3 @@ tests/states.json tests/configs.json .idea/ local-scripts -tests/debug-price-route.json From f4457a4b7a7bd5d90b5c06337d58f04c795f85b3 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 15:04:44 +0300 Subject: [PATCH 55/64] add fixes --- src/dex/fluid-dex/fluid-dex.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index e26076f4d..2594a8cd8 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -170,6 +170,9 @@ export class FluidDex extends SimpleExchange implements IDex { limitPools?: string[], ): Promise> { try { + if (srcToken.address.toLowerCase() === destToken.address.toLowerCase()) + return null; + if (side === SwapSide.BUY) throw new Error(`Buy not supported`); // Get the pool to use. const pool = await this.getPoolByTokenPair( From c18993246e4e0e593bfe027c61f6e33b0f1988d4 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 15:05:48 +0300 Subject: [PATCH 56/64] 3.9.7-fluid-dex.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7cbdb8c31..94145f01b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.9.7-fluid-dex.1", + "version": "3.9.7-fluid-dex.2", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From 20ee97744a54df3033cf172f828f17d148ada25d Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 18:08:17 +0300 Subject: [PATCH 57/64] add fixes --- src/dex/fluid-dex/fluid-dex-events.test.ts | 19 ++++---- ...-generate-pool.ts => fluid-dex-factory.ts} | 2 +- .../fluid-dex/fluid-dex-integration.test.ts | 44 ------------------- src/dex/fluid-dex/fluid-dex.ts | 34 +++++++------- 4 files changed, 28 insertions(+), 71 deletions(-) rename src/dex/fluid-dex/{fluid-dex-generate-pool.ts => fluid-dex-factory.ts} (98%) diff --git a/src/dex/fluid-dex/fluid-dex-events.test.ts b/src/dex/fluid-dex/fluid-dex-events.test.ts index 4a80876cc..5a3de2ec5 100644 --- a/src/dex/fluid-dex/fluid-dex-events.test.ts +++ b/src/dex/fluid-dex/fluid-dex-events.test.ts @@ -3,7 +3,7 @@ import dotenv from 'dotenv'; dotenv.config(); import { FluidDexEventPool } from './fluid-dex-pool'; -import { FluidDexCommonAddresses } from './fluid-dex-generate-pool'; +import { FluidDexFactory } from './fluid-dex-factory'; import { FluidDex } from './fluid-dex'; import { Network } from '../../constants'; import { Address } from '../../types'; @@ -57,10 +57,10 @@ async function fetchPoolState( } async function fetchTotalPools( - fluidCommonAddresses: FluidDexCommonAddresses, + factory: FluidDexFactory, blockNumber: number, ): Promise> { - return await fluidCommonAddresses.generateState(blockNumber); + return await factory.generateState(blockNumber); } async function delay(seconds: number): Promise { @@ -122,7 +122,7 @@ describe('FluidDex EventPool Mainnet', function () { }; let fluidDexEventPool: FluidDexEventPool; - let fluidDexCommonAddress: FluidDexCommonAddresses; + let factory: FluidDexFactory; Object.entries(poolUpdateEventsToTest).forEach( ([poolAddress, events]: [string, EventMappings]) => { @@ -150,8 +150,7 @@ describe('FluidDex EventPool Mainnet', function () { console.log(forkId); - const pools = - fluidDex.fluidCommonAddresses.getState(blockNumber); + const pools = fluidDex.factory.getState(blockNumber); let pool: string | undefined; if (pools) { @@ -266,7 +265,7 @@ describe('FluidDex EventPool Mainnet', function () { describe(`${eventName}`, () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async function () { - fluidDexCommonAddress = new FluidDexCommonAddresses( + factory = new FluidDexFactory( 'FluidDex', fluidDexCommonAddressStruct, network, @@ -275,10 +274,10 @@ describe('FluidDex EventPool Mainnet', function () { ); await testEventSubscriber( - fluidDexCommonAddress, - fluidDexCommonAddress.addressesSubscribed, + factory, + factory.addressesSubscribed, (_blockNumber: number) => - fetchTotalPools(fluidDexCommonAddress, _blockNumber), + fetchTotalPools(factory, _blockNumber), blockNumber, `${dexKey}_${poolAddress}`, dexHelper.provider, diff --git a/src/dex/fluid-dex/fluid-dex-generate-pool.ts b/src/dex/fluid-dex/fluid-dex-factory.ts similarity index 98% rename from src/dex/fluid-dex/fluid-dex-generate-pool.ts rename to src/dex/fluid-dex/fluid-dex-factory.ts index f41e8f4ed..cdfbce849 100644 --- a/src/dex/fluid-dex/fluid-dex-generate-pool.ts +++ b/src/dex/fluid-dex/fluid-dex-factory.ts @@ -13,7 +13,7 @@ import { Address } from '../../types'; import { generalDecoder } from '../../lib/decoders'; import { Contract } from 'ethers'; -export class FluidDexCommonAddresses extends StatefulEventSubscriber { +export class FluidDexFactory extends StatefulEventSubscriber { handlers: { [event: string]: ( event: any, diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 2f012d359..3eb0b7741 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -208,28 +208,6 @@ describe('FluidDex', function () { 'estimateSwapIn', ); }); - - it.skip('getTopPoolsForToken', async function () { - // We have to check without calling initializePricing, because - // pool-tracker is not calling that function - const newFluidDex = new FluidDex(network, dexKey, dexHelper); - await newFluidDex.initializePricing(blockNumber); - if (newFluidDex.updatePoolState) { - await newFluidDex.updatePoolState(); - } - const poolLiquidity = await newFluidDex.getTopPoolsForToken( - tokens[tokenASymbol].address, - 1, - ); - - if (!newFluidDex.hasConstantPriceLargeAmounts) { - checkPoolsLiquidity( - poolLiquidity, - Tokens[network][tokenASymbol].address, - dexKey, - ); - } - }); }); describe('USDC -> USDT', () => { @@ -277,28 +255,6 @@ describe('FluidDex', function () { 'estimateSwapIn', ); }); - - it.skip('getTopPoolsForToken', async function () { - // We have to check without calling initializePricing, because - // pool-tracker is not calling that function - const newFluidDex = new FluidDex(network, dexKey, dexHelper); - await newFluidDex.initializePricing(blockNumber); - if (newFluidDex.updatePoolState) { - await newFluidDex.updatePoolState(); - } - const poolLiquidity = await newFluidDex.getTopPoolsForToken( - tokens[tokenASymbol].address, - 1, - ); - - if (!newFluidDex.hasConstantPriceLargeAmounts) { - checkPoolsLiquidity( - poolLiquidity, - Tokens[network][tokenASymbol].address, - dexKey, - ); - } - }); }); }); }); diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 2594a8cd8..9884d8b33 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -26,7 +26,7 @@ import { SimpleExchange } from '../simple-exchange'; import FluidDexPoolABI from '../../abi/fluid-dex/fluid-dex.abi.json'; import { FluidDexConfig, FLUID_DEX_GAS_COST } from './config'; import { FluidDexEventPool } from './fluid-dex-pool'; -import { FluidDexCommonAddresses } from './fluid-dex-generate-pool'; +import { FluidDexFactory } from './fluid-dex-factory'; import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; import { extractReturnAmountPosition } from '../../executor/utils'; import { MultiResult } from '../../lib/multi-wrapper'; @@ -44,7 +44,7 @@ export class FluidDex extends SimpleExchange implements IDex { pools: FluidDexPool[] = []; - readonly fluidCommonAddresses: FluidDexCommonAddresses; + readonly factory: FluidDexFactory; readonly fluidDexPoolIface: Interface; @@ -57,7 +57,7 @@ export class FluidDex extends SimpleExchange implements IDex { ) { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); - this.fluidCommonAddresses = new FluidDexCommonAddresses( + this.factory = new FluidDexFactory( 'FluidDex', FluidDexConfig['FluidDex'][network].commonAddresses, network, @@ -70,8 +70,10 @@ export class FluidDex extends SimpleExchange implements IDex { private async fetchFluidDexPools( blockNumber: number, ): Promise { - const poolsFromResolver = - await this.fluidCommonAddresses.getStateOrGenerate(blockNumber, false); + const poolsFromResolver = await this.factory.getStateOrGenerate( + blockNumber, + false, + ); return poolsFromResolver.map(pool => ({ id: `FluidDex_${pool.address.toLowerCase()}`, address: pool.address.toLowerCase(), @@ -85,19 +87,27 @@ export class FluidDex extends SimpleExchange implements IDex { // for pricing requests. It is optional for a DEX to // implement this function async initializePricing(blockNumber: number) { + await this.factory.initialize(blockNumber); this.pools = await this.fetchFluidDexPools(blockNumber); + for (const pool of this.pools) { if (!this.eventPools[pool.id]) { this.eventPools[pool.id] = new FluidDexEventPool( 'FluidDex', pool.address, - this.fluidCommonAddresses.commonAddresses, + this.factory.commonAddresses, this.network, this.dexHelper, this.logger, ); } } + + await Promise.all( + Object.values(this.eventPools).map(async eventPool => { + return eventPool.initialize(blockNumber); + }), + ); } getAdapters(side: SwapSide) { @@ -192,7 +202,8 @@ export class FluidDex extends SimpleExchange implements IDex { return null; } - const state = await eventPool.getStateOrGenerate(blockNumber); + const state = await eventPool.getState(blockNumber); + if (!state) return null; const prices = amounts.map(amount => { return this.swapIn( @@ -264,15 +275,6 @@ export class FluidDex extends SimpleExchange implements IDex { }; } - // This is called once before getTopPoolsForToken is - // called for multiple tokens. This can be helpful to - // update common state required for calculating - // getTopPoolsForToken. It is optional for a DEX - // to implement this - async updatePoolState(): Promise { - this.initializePricing(await this.dexHelper.provider.getBlockNumber()); - } - // Returns list of top pools based on liquidity. Max // limit number pools should be returned. async getTopPoolsForToken( From 1002e30b077b7cafd52f5ab090fe2fd1dfae6825 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Tue, 29 Oct 2024 18:10:14 +0300 Subject: [PATCH 58/64] remove extra files --- .gitignore | 1 + tests/constants-e2e.d.ts | 22 - tests/constants-e2e.js | 1942 ------------------------------------ tests/constants-e2e.js.map | 1 - tests/smart-tokens.d.ts | 36 - tests/smart-tokens.js | 64 -- tests/smart-tokens.js.map | 1 - 7 files changed, 1 insertion(+), 2066 deletions(-) delete mode 100644 tests/constants-e2e.d.ts delete mode 100644 tests/constants-e2e.js delete mode 100644 tests/constants-e2e.js.map delete mode 100644 tests/smart-tokens.d.ts delete mode 100644 tests/smart-tokens.js delete mode 100644 tests/smart-tokens.js.map diff --git a/.gitignore b/.gitignore index c7b020006..bea819f62 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ tests/states.json tests/configs.json .idea/ local-scripts +tests/debug-price-route.json diff --git a/tests/constants-e2e.d.ts b/tests/constants-e2e.d.ts deleted file mode 100644 index 4934d92b2..000000000 --- a/tests/constants-e2e.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { SmartTokenParams, SmartToken } from '../tests/smart-tokens'; -import { Address } from '../src/types'; -export declare const GIFTER_ADDRESS = "0xb22fC4eC94D555A5049593ca4552c810Fb8a6d00"; -export declare const GENERIC_ADDR1 = "0xbe9317f6711e2da074fe1f168fd9c402bc0a9d1b"; -export declare const GENERIC_ADDR2 = "0x230a1ac45690b9ae1176389434610b9526d2f21b"; -export declare const Tokens: { - [network: number]: { - [symbol: string]: SmartTokenParams; - }; -}; -export declare const Holders: { - [network: number]: { - [tokenAddress: string]: Address; - }; -}; -export declare const SmartTokens: Record>; -export declare const NativeTokenSymbols: { - [network: number]: string; -}; -export declare const WrappedNativeTokenSymbols: { - [network: number]: string; -}; diff --git a/tests/constants-e2e.js b/tests/constants-e2e.js deleted file mode 100644 index 5e3a3326d..000000000 --- a/tests/constants-e2e.js +++ /dev/null @@ -1,1942 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.WrappedNativeTokenSymbols = exports.NativeTokenSymbols = exports.SmartTokens = exports.Holders = exports.Tokens = exports.GENERIC_ADDR2 = exports.GENERIC_ADDR1 = exports.GIFTER_ADDRESS = void 0; -const smart_tokens_1 = require("../tests/smart-tokens"); -const constants_1 = require("../src/constants"); -exports.GIFTER_ADDRESS = '0xb22fC4eC94D555A5049593ca4552c810Fb8a6d00'; -exports.GENERIC_ADDR1 = '0xbe9317f6711e2da074fe1f168fd9c402bc0a9d1b'; -exports.GENERIC_ADDR2 = '0x230a1ac45690b9ae1176389434610b9526d2f21b'; -exports.Tokens = { - [constants_1.Network.MAINNET]: { - sUSDS: { - address: '0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD', - decimals: 18, - }, - USDS: { - address: '0xdC035D45d973E3EC169d2276DDab16f1e407384F', - decimals: 18, - }, - SKY: { - address: '0x56072C95FAA701256059aa122697B133aDEd9279', - decimals: 18, - }, - MKR: { - address: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', - decimals: 18, - }, - AA_wstETH: { - decimals: 18, - address: '0x2688fc68c4eac90d9e5e1b94776cf14eade8d877', - }, - 'AA_idle_cpPOR-USDC': { - decimals: 18, - address: '0x9cacd44cfdf22731bc99facf3531c809d56bd4a2', - }, - 'BB_idle_cpFAS-USDT': { - decimals: 18, - address: '0x3eb6318b8d9f362a0e1d99f6032edb1c4c602500', - }, - AA_steakUSDC: { - decimals: 18, - address: '0x2b0e31b8ee653d2077db86dea3acf3f34ae9d5d2', - }, - BB_steakUSDC: { - decimals: 18, - address: '0x7b713b1cb6eafd4061064581579ffccf7df21545', - }, - AA_Re7WETH: { - decimals: 18, - address: '0x454bb3cb427b21e1c052a080e21a57753cd6969e', - }, - BB_Re7WETH: { - decimals: 18, - address: '0x20aa3cd83044d2903181f7ef5c2b498a017d1c4a', - }, - BB_dUSDCV3: { - decimals: 18, - address: '0x2a84a042db06222c486bcb815e961f26599d0df6', - }, - AA_sUSDe: { - decimals: 18, - address: '0xf3188697bd35df73e4293d04a07ebaaf1ffc4018', - }, - BB_sUSDe: { - decimals: 18, - address: '0xb8d0be502a8f12cc5213733285b430a43d07349d', - }, - AA_iETHv2: { - decimals: 18, - address: '0xdf17c739b666B259DA3416d01f0310a6e429f592', - }, - BB_iETHv2: { - decimals: 18, - address: '0x990b3aF34dDB502715E1070CE6778d8eB3c8Ea82', - }, - USDE: { - address: '0x4c9edd5852cd905f086c759e8383e09bff1e68b3', - decimals: 18, - }, - ETH: { - address: constants_1.ETHER_ADDRESS, - decimals: 18, - }, - SWETH: { - address: '0xf951e335afb289353dc249e82926178eac7ded78', - decimals: 18, - }, - BAT: { - address: '0x0d8775f648430679a709e98d2b0cb6250d2887ef', - decimals: 18, - }, - rswETH: { - address: '0xFAe103DC9cf190eD75350761e95403b7b8aFa6c0', - decimals: 18, - }, - REQ: { - address: '0x8f8221aFbB33998d8584A2B05749bA73c37a938a', - decimals: 18, - }, - eETH: { - address: '0x35fA164735182de50811E8e2E824cFb9B6118ac2', - decimals: 18, - }, - weETH: { - address: '0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee', - decimals: 18, - }, - AMPL: { - address: '0xd46ba6d942050d489dbd938a2c909a5d5039a161', - decimals: 9, - }, - USDC: { - address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', - decimals: 6, - symbol: 'USDC', - addBalance: smart_tokens_1.balancesFn, - addAllowance: smart_tokens_1.allowedFn, - }, - aEthUSDC: { - address: '0x98c23e9d8f34fefb1b7bd6a91b7ff122f4e16f5c', - decimals: 6, - }, - aEthWETH: { - address: '0x4d5f47fa6a74757f35c14fd3a6ef8e3c9bc514e8', - decimals: 18, - }, - MAV: { - address: '0x7448c7456a97769f6cd04f1e83a4a23ccdc46abd', - decimals: 18, - }, - SUSHI: { - address: '0x6b3595068778dd592e39a122f4f5a5cf09c90fe2', - decimals: 18, - }, - CUSDC: { - address: '0x39AA39c021dfbaE8faC545936693aC917d5E7563', - decimals: 8, - }, - TUSD: { - address: '0x0000000000085d4780b73119b644ae5ecd22b376', - decimals: 18, - }, - WBTC: { - address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', - decimals: 8, - addBalance: smart_tokens_1.balancesFn, - addAllowance: smart_tokens_1.allowedFn, - }, - sBTC: { - address: '0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6', - decimals: 18, - }, - tBTCv2: { - address: '0x18084fbA666a33d37592fA2633fD49a74DD93a88', - decimals: 18, - }, - BADGER: { - address: '0x3472A5A71965499acd81997a54BBA8D852C6E53d', - decimals: 18, - }, - USDT: { - address: '0xdac17f958d2ee523a2206206994597c13d831ec7', - decimals: 6, - addBalance: smart_tokens_1.balancesFn, - addAllowance: smart_tokens_1.allowedFn, - }, - STETH: { - address: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', - decimals: 18, - }, - SDEX: { - address: '0x5DE8ab7E27f6E7A1fFf3E5B337584Aa43961BEeF', - decimals: 18, - }, - wstETH: { - address: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', - decimals: 18, - }, - USDM: { - address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', - decimals: 18, - }, - wUSDM: { - address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', - decimals: 18, - }, - frxETH: { - address: '0x5E8422345238F34275888049021821E8E08CAa1f', - decimals: 18, - }, - WETH: { - address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', - decimals: 18, - addBalance: smart_tokens_1.balanceOfFn, - addAllowance: smart_tokens_1.allowanceFn, - }, - PSP: { - address: '0xcafe001067cdef266afb7eb5a286dcfd277f3de5', - decimals: 18, - }, - SETH: { - address: '0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb', - decimals: 18, - }, - LINK: { - address: '0x514910771af9ca656af840dff83e8264ecf986ca', - decimals: 18, - }, - DAI: { - address: '0x6b175474e89094c44da98b954eedeac495271d0f', - decimals: 18, - addBalance: smart_tokens_1.balanceOfFn, - addAllowance: smart_tokens_1.allowanceFn, - }, - MLN: { - address: '0xec67005c4e498ec7f55e092bd1d35cbc47c91892', - decimals: 18, - }, - SENT: { - address: '0xa44E5137293E855B1b7bC7E2C6f8cD796fFCB037', - decimals: 8, - }, - oldFRAX: { - address: '0x853d955acef822db058eb8505911ed77f175b99e', - decimals: 18, - }, - aDAI: { - address: '0x028171bCA77440897B824Ca71D1c56caC55b68A3', - decimals: 18, - }, - aUSDT: { - address: '0x3Ed3B47Dd13ECAURA9a98b44e6204A523E766B225811', - decimals: 6, - }, - waUSDT: { - address: '0xf8Fd466F12e236f4c96F7Cce6c79EAdB819abF58', - decimals: 6, - }, - ALUSD: { - address: '0xbc6da0fe9ad5f3b0d58160288917aa56653660e9', - decimals: 18, - }, - BAL: { - address: '0xba100000625a3754423978a60c9317c58a424e3D', - decimals: 18, - }, - OHM: { - address: '0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5', - decimals: 9, - }, - AURA: { - address: '0xc0c293ce456ff0ed870add98a0828dd4d2903dbf', - decimals: 18, - }, - WISE: { - address: '0x66a0f676479cee1d7373f3dc2e2952778bff5bd6', - decimals: 18, - }, - DDIM: { - address: '0xFbEEa1C75E4c4465CB2FCCc9c6d6afe984558E20', - decimals: 18, - }, - DODO: { - address: '0x43Dfc4159D86F3A37A5A4B3D4580b888ad7d4DDd', - decimals: 18, - }, - STG: { - address: '0xAf5191B0De278C7286d6C7CC6ab6BB8A73bA2Cd6', - decimals: 18, - }, - ADAI: { - address: '0x028171bca77440897b824ca71d1c56cac55b68a3', - decimals: 18, - }, - AWETH: { - address: '0x030ba81f1c18d280636f32af80b9aad02cf0854e', - decimals: 18, - }, - ALPHA: { - address: '0xa1faa113cbe53436df28ff0aee54275c13b40975', - decimals: 18, - }, - CRV: { - address: '0xd533a949740bb3306d119cc777fa900ba034cd52', - decimals: 18, - }, - INCH: { - address: '0x111111111117dC0aa78b770fA6A738034120C302', - decimals: 18, - }, - mUSD: { - address: '0xe2f2a5c287993345a840db3b0845fbc70f5935a5', - decimals: 18, - }, - mBTC: { - address: '0x945facb997494cc2570096c74b5f66a3507330a1', - decimals: 18, - }, - renBTC: { - address: '0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D', - decimals: 8, - }, - HBTC: { - address: '0x0316EB71485b0Ab14103307bf65a021042c6d380', - decimals: 18, - }, - tBTC: { - address: '0x8dAEBADE922dF735c38C80C7eBD708Af50815fAa', - decimals: 18, - }, - BUSD: { - address: '0x4fabb145d64652a948d72533023f6e7a623c7c53', - decimals: 18, - }, - GUSD: { - address: '0x056fd409e1d7a124bd7017459dfea2f387b6d5cd', - decimals: 2, - }, - ADAIv1: { - address: '0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d', - decimals: 18, - }, - CETH: { - address: '0x4ddc2d193948926d02f9b1fe9e1daa0718270ed5', - decimals: 8, - }, - CDAI: { - address: '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', - decimals: 8, - }, - MIM: { - address: '0x99D8a9C45b2ecA8864373A26D1459e3Dff1e17F3', - decimals: 18, - }, - AnkETH: { - address: '0xE95A203B1a91a908F9B9CE46459d101078c2c3cb', - decimals: 18, - }, - EURS: { - address: '0xdB25f211AB05b1c97D595516F45794528a807ad8', - decimals: 2, - }, - EURT: { - address: '0xC581b735A1688071A1746c968e0798D642EDE491', - decimals: 6, - }, - jEUR: { - address: '0x0f17bc9a994b87b5225cfb6a2cd4d667adb4f20b', - decimals: 18, - }, - jCHF: { - address: '0x53dfea0a8cc2a2a2e425e1c174bc162999723ea0', - decimals: 18, - }, - jGBP: { - address: '0x7409856cae628f5d578b285b45669b36e7005283', - decimals: 18, - }, - XAUT: { - address: '0x68749665FF8D2d112Fa859AA293F07A622782F38', - decimals: 6, - }, - CVX: { - address: '0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B', - decimals: 18, - }, - UST: { - address: '0xa47c8bf37f92abed4a126bda807a7b7498661acd', - decimals: 18, - }, - SAITAMA: { - address: '0x8b3192f5eebd8579568a2ed41e6feb402f93f73f', - decimals: 9, - }, - BBAUSDT: { - // bpt of USDT Linear Pool - address: '0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c', - decimals: 18, - }, - BBADAI: { - // bpt of DAI Linear Pool - address: '0x804cdb9116a10bb78768d3252355a1b18067bf8f', - decimals: 18, - }, - BBAUSD: { - address: '0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2', - decimals: 18, - }, - BBFDAI: { - address: '0x8f4063446f5011bc1c9f79a819efe87776f23704', - decimals: 18, - }, - FEI: { - address: '0x956F47F50A910163D8BF957Cf5846D573E7f87CA', - decimals: 18, - }, - newFRAX: { - address: '0x853d955aCEf822Db058eb8505911ED77F175b99e', - decimals: 18, - }, - sETH: { - address: '0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb', - decimals: 18, - }, - sUSD: { - address: '0x57Ab1ec28D129707052df4dF418D58a2D46d5f51', - decimals: 18, - }, - USDD: { - address: '0x0c10bf8fcb7bf5412187a595ab97a3609160b5c6', - decimals: 18, - }, - alETH: { - address: '0x0100546f2cd4c9d97f798ffc9755e47865ff7ee6', - decimals: 18, - }, - SHIBA: { - address: '0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE', - decimals: 18, - }, - dUSDC: { - address: '0xc411db5f5eb3f7d552f9b8454b2d74097ccde6e3', - decimals: 6, - }, - EURA: { - address: '0x1a7e4e63778b4f12a199c062f3efdd288afcbce8', - decimals: 18, - symbol: 'EURA', - }, - EUROC: { - address: '0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c', - decimals: 6, - symbol: 'EUROC', - }, - bERNX: { - address: '0x3f95AA88dDbB7D9D484aa3D482bf0a80009c52c9', - decimals: 18, - symbol: 'bERNX', - }, - bC3M: { - address: '0x2F123cF3F37CE3328CC9B5b8415f9EC5109b45e7', - decimals: 18, - symbol: 'bC3M', - }, - stEUR: { - address: '0x004626a008b1acdc4c74ab51644093b155e59a23', - decimals: 18, - }, - USDA: { - address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', - decimals: 18, - symbol: 'USDA', - }, - bIB01: { - address: '0xCA30c93B02514f86d5C86a6e375E3A330B435Fb5', - decimals: 18, - symbol: 'bIB01', - }, - steakUSDC: { - address: '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB', - decimals: 18, - symbol: 'steakUSDC', - }, - stUSD: { - address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - decimals: 18, - }, - GHO: { - address: '0x40d16fc0246ad3160ccc09b8d0d3a2cd28ae6c2f', - decimals: 18, - }, - stkGHO: { - address: '0x1a88Df1cFe15Af22B3c4c783D4e6F7F9e0C1885d', - decimals: 18, - }, - USDe: { - address: '0x4c9EDD5852cd905f086C759E8383e09bff1E68B3', - decimals: 18, - }, - crvUSD: { - address: '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E', - decimals: 18, - }, - wibBTC: { - address: '0x8751d4196027d4e6da63716fa7786b5174f04c15', - decimals: 18, - }, - MATIC: { - address: '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', - decimals: 18, - }, - POL: { - address: '0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6', - decimals: 19, - }, - GYD: { - address: '0xe07f9d810a48ab5c3c914ba3ca53af14e4491e8a', - decimals: 18, - }, - LUSD: { - address: '0x5f98805a4e8be255a32880fdec7f6728c6568ba0', - decimals: 18, - }, - BNT: { - address: '0x1f573d6fb3f13d689ff844b4ce37794d79a7ff1c', - decimals: 18, - }, - sDAI: { - address: '0x83f20f44975d03b1b09e64809b757c47f942beea', - decimals: 18, - }, - stataUSDT: { - address: '0x862c57d48becb45583aeba3f489696d22466ca1b', - decimals: 6, - }, - aaveUSDT: { - address: '0x23878914efe38d27c4d67ab83ed1b93a74d4086a', - decimals: 6, - }, - rUSD: { - address: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18', - decimals: 18, - }, - arUSD: { - address: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a', - decimals: 18, - }, - USD0: { - address: '0x73A15FeD60Bf67631dC6cd7Bc5B6e8da8190aCF5', - decimals: 18, - symbol: 'USD0', - }, - 'USD0++': { - address: '0x35D8949372D46B7a3D5A56006AE77B215fc69bC0', - decimals: 18, - symbol: 'USD0++', - }, - }, - [constants_1.Network.POLYGON]: { - jGBP: { - address: '0x767058f11800fba6a682e73a6e79ec5eb74fac8c', - decimals: 18, - }, - DAI: { - address: '0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', - decimals: 18, - }, - // native bridged wormhole - USDCe: { - address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', - decimals: 6, - addBalance: smart_tokens_1._balancesFn, - addAllowance: smart_tokens_1._allowancesFn, - }, - TEL: { - address: '0xdf7837de1f2fa4631d716cf2502f8b230f1dcc32', - decimals: 2, - }, - // wormhole - USDC: { - address: '0x576Cf361711cd940CD9C397BB98C4C896cBd38De', - decimals: 6, - }, - // circle issued usdc - USDCn: { - address: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', - decimals: 6, - }, - stataUSDCn: { - address: '0x2dCa80061632f3F87c9cA28364d1d0c30cD79a19', - decimals: 6, - }, - aaveUSDCn: { - address: '0xa4d94019934d8333ef880abffbf2fdd611c762bd', - decimals: 6, - }, - POPS: { - address: '0xa92A1576D11dB45c53be71d59245ac97ce0d8147', - decimals: 18, - }, - CRV: { - address: '0x172370d5cd63279efa6d502dab29171933a610af', - decimals: 18, - }, - BAL: { - address: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3', - decimals: 18, - }, - AAVE: { - address: '0xd6df932a45c0f255f85145f286ea0b292b21c90b', - decimals: 18, - }, - PSP: { - address: '0x42d61d766b85431666b39b89c43011f24451bff6', - decimals: 18, - }, - WETH: { - address: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', - decimals: 18, - }, - crvUSD: { - address: '0xc4ce1d6f5d98d65ee25cf85e9f2e9dcfee6cb5d6', - decimals: 18, - }, - WMATIC: { - address: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', - decimals: 18, - addBalance: smart_tokens_1.balanceOfFn, - addAllowance: smart_tokens_1.allowanceFn, - }, - AMWMATIC: { - address: '0x8dF3aad3a84da6b69A4DA8aeC3eA40d9091B2Ac4', - decimals: 18, - }, - aPolWMATIC: { - address: '0x6d80113e533a2c0fe82eabd35f1875dcea89ea97', - decimals: 18, - }, - MUST: { - address: '0x9C78EE466D6Cb57A4d01Fd887D2b5dFb2D46288f', - decimals: 18, - }, - AMDAI: { - address: '0x27F8D03b3a2196956ED754baDc28D73be8830A6e', - decimals: 18, - }, - BTU: { - address: '0xfdc26cda2d2440d0e83cd1dee8e8be48405806dc', - decimals: 18, - }, - USDT: { - address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f', - decimals: 6, - }, - WBTC: { - address: '0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6', - decimals: 8, - }, - MATIC: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - mUSD: { - address: '0xe840b73e5287865eec17d250bfb1536704b43b21', - decimals: 18, - }, - AMWETH: { - address: '0x28424507fefb6f7f8e9d3860f56504e4e5f5f390', - decimals: 18, - }, - AMWBTC: { - address: '0x5c2ed810328349100a66b82b78a1791b101c9d61', - decimals: 8, - }, - KNC: { - address: '0x1c954e8fe737f99f68fa1ccda3e51ebdb291948c', - decimals: 18, - }, - jEUR: { - address: '0x4e3decbb3645551b8a19f0ea1678079fcb33fb4c', - decimals: 18, - }, - jGPB: { - address: '0x767058f11800fba6a682e73a6e79ec5eb74fac8c', - decimals: 18, - }, - jCHF: { - address: '0xbd1463f02f61676d53fd183c2b19282bff93d099', - decimals: 18, - }, - RADIO: { - address: '0x613a489785C95afEB3b404CC41565cCff107B6E0', - decimals: 18, - }, - HANZO: { - address: '0x37eb60f78e06c4bb2a5f836b0fc6bccbbaa995b3', - decimals: 9, - }, - RVLT: { - address: '0xf0f9d895aca5c8678f706fb8216fa22957685a13', - decimals: 18, - }, - stMATIC: { - address: '0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4', - decimals: 18, - }, - axlUSDC: { - address: '0x750e4c4984a9e0f12978ea6742bc1c5d248f40ed', - decimals: 6, - }, - deUSDC: { - address: '0x1ddcaa4ed761428ae348befc6718bcb12e63bfaa', - decimals: 6, - }, - amUSDT: { - address: '0x60d55f02a771d515e077c9c2403a1ef324885cec', - decimals: 6, - }, - amUSDC: { - address: '0x1a13F4Ca1d028320A707D99520AbFefca3998b7F', - decimals: 6, - }, - MAI: { - address: '0xa3fa99a148fa48d14ed51d610c367c61876997f1', - decimals: 18, - }, - EURA: { - address: '0xe0b52e49357fd4daf2c15e02058dce6bc0057db4', - decimals: 18, - symbol: 'EURA', - }, - USDM: { - address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', - decimals: 18, - }, - wUSDM: { - address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', - decimals: 18, - }, - stEUR: { - address: '0x004626a008b1acdc4c74ab51644093b155e59a23', - decimals: 18, - }, - USDA: { - address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', - decimals: 18, - symbol: 'USDA', - }, - stUSD: { - address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - decimals: 18, - }, - BUSD: { - address: '0x9C9e5fD8bbc25984B178FdCE6117Defa39d2db39', - decimals: 18, - }, - TUSD: { - address: '0x2e1ad108ff1d8c782fcbbb89aad783ac49586756', - decimals: 18, - }, - SDEX: { - address: '0x6899fAcE15c14348E1759371049ab64A3a06bFA6', - decimals: 18, - }, - MATICX: { - address: '0xfa68fb4628dff1028cfec22b4162fccd0d45efb6', - decimals: 18, - }, - SUSHI: { - address: '0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a', - decimals: 18, - }, - TRYB: { - address: '0x4fb71290ac171e1d144f7221d882becac7196eb5', - decimals: 6, - }, - }, - [constants_1.Network.FANTOM]: { - FTM: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - SOLID: { - address: '0x777cf5ba9c291a1a8f57ff14836f6f9dc5c0f9dd', - decimals: 18, - }, - WFTM: { - address: '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83', - decimals: 18, - }, - DAI: { - address: '0x8d11ec38a3eb5e956b052f67da8bdc9bef8abf3e', - decimals: 18, - }, - USDC: { - address: '0x04068DA6C83AFCFA0e13ba15A6696662335D5B75', - decimals: 6, - }, - FUSDT: { - address: '0x049d68029688eabf473097a2fc38ef61633a3c7a', - decimals: 6, - }, - LQDR: { - address: '0x10b620b2dbac4faa7d7ffd71da486f5d44cd86f9', - decimals: 18, - }, - EQUAL: { - address: '0x3fd3a0c85b70754efc07ac9ac0cbbdce664865a6', - decimals: 18, - }, - beFTM: { - address: '0x7381ed41f6de418dde5e84b55590422a57917886', - decimals: 18, - }, - POPS: { - address: '0x9dE4b40bDcE50Ec6a1A668bF85997BbBD324069a', - decimals: 18, - }, - MIM: { - address: '0x82f0b8b456c1a451378467398982d4834b6829c1', - decimals: 18, - }, - FRAX: { - address: '0xdc301622e621166BD8E82f2cA0A26c13Ad0BE355', - decimals: 18, - }, - nETH: { - address: '0x67C10C397dD0Ba417329543c1a40eb48AAa7cd00', - decimals: 18, - }, - WETH: { - address: '0x74b23882a30290451A17c44f4F05243b6b58C76d', - decimals: 18, - }, - SPIRIT: { - address: '0x5cc61a78f164885776aa610fb0fe1257df78e59b', - decimals: 18, - }, - wBOMB: { - address: '0xc09a82ad5075b3067d80f54f05e1e22229699cc1', - decimals: 18, - }, - TOR: { - address: '0x74e23df9110aa9ea0b6ff2faee01e740ca1c642e', - decimals: 18, - }, - BOO: { - address: '0x841fad6eae12c286d1fd18d1d525dffa75c7effe', - decimals: 18, - }, - ETH: { - address: '0x74b23882a30290451A17c44f4F05243b6b58C76d', - decimals: 18, - }, - GDAI: { - address: '0x07E6332dD090D287d3489245038daF987955DCFB', - decimals: 18, - }, - GUSDC: { - address: '0xe578C856933D8e1082740bf7661e379Aa2A30b26', - decimals: 6, - }, - axlUSDC: { - address: '0x1B6382DBDEa11d97f24495C9A90b7c88469134a4', - decimals: 6, - }, - lzUSDC: { - address: '0x28a92dde19D9989F39A49905d7C9C2FAc7799bDf', - decimals: 6, - }, - FVM: { - address: '0x07BB65fAaC502d4996532F834A1B7ba5dC32Ff96', - decimals: 18, - }, - USDCe: { - address: '0x2f733095b80a04b38b0d10cc884524a3d09b836a', - decimals: 6, - }, - scrvUSDC_e: { - address: '0x0cf1aa18ab7020973705aa9c46bbec6150e2782b', - decimals: 18, - }, - scrvUSDC_p: { - address: '0x8b697f95d8c9fbbcc597a89223b10b80369490a1', - decimals: 18, - }, - }, - [constants_1.Network.BSC]: { - POPS: { - address: '0xa1051433EC7b5cc249c75Fdd5b96BF423f2f4A32', - decimals: 18, - }, - DAI: { - address: '0x1af3f329e8be154074d8769d1ffa4ee058b1dbc3', - decimals: 18, - }, - WBNB: { - address: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', - decimals: 18, - }, - BNBx: { - address: '0x1bdd3Cf7F79cfB8EdbB955f20ad99211551BA275', - decimals: 18, - }, - BUSD: { - address: '0xe9e7cea3dedca5984780bafc599bd69add087d56', - decimals: 18, - }, - USDT: { - address: '0x55d398326f99059ff775485246999027b3197955', - decimals: 18, - }, - ETH: { - address: '0x2170ed0880ac9a755fd29b2688956bd959f933f8', - decimals: 18, - }, - UST: { - address: '0x23396cf899ca06c4472205fc903bdb4de249d6fc', - decimals: 18, - }, - USDC: { - address: '0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', - decimals: 18, - }, - RADIO: { - address: '0x30807D3b851A31d62415B8bb7Af7dCa59390434a', - decimals: 18, - }, - BNB: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - bBTC: { - address: '0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c', - decimals: 18, - }, - anyBTC: { - address: '0x54261774905f3e6E9718f2ABb10ed6555cae308a', - decimals: 8, - }, - nUSD: { - address: '0x23b891e5C62E0955ae2bD185990103928Ab817b3', - decimals: 18, - }, - CONE: { - address: '0xA60205802E1B5C6EC1CAFA3cAcd49dFeECe05AC9', - decimals: 18, - }, - axlUSD: { - address: '0x4268B8F0B87b6Eae5d897996E6b845ddbD99Adf3', - decimals: 6, - }, - FRAX: { - address: '0x90C97F71E18723b0Cf0dfa30ee176Ab653E89F40', - decimals: 18, - }, - frxETH: { - address: '0x64048A7eEcF3a2F1BA9e144aAc3D7dB6e58F555e', - decimals: 18, - }, - USDFI: { - address: '0x11A38e06699b238D6D9A0C7A01f3AC63a07ad318', - decimals: 18, - }, - XRP: { - address: '0x1d2f0da169ceb9fc7b3144628db156f3f6c60dbe', - decimals: 18, - }, - SDEX: { - address: '0xFdc66A08B0d0Dc44c17bbd471B88f49F50CdD20F', - decimals: 18, - }, - EURA: { - address: '0x12f31B73D812C6Bb0d735a218c086d44D5fe5f89', - decimals: 18, - symbol: 'EURA', - }, - USDA: { - address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', - decimals: 18, - symbol: 'USDA', - }, - stUSD: { - address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - decimals: 18, - }, - stataUSDT: { - address: '0x0471d185cc7be61e154277cab2396cd397663da6', - decimals: 18, - }, - aaveUSDT: { - address: '0xa9251ca9de909cb71783723713b21e4233fbf1b1', - decimals: 18, - }, - }, - [constants_1.Network.AVALANCHE]: { - LINKe: { - address: '0x5947bb275c521040051d82396192181b413227a3', - decimals: 18, - }, - PHAR: { - address: '0xAAAB9D12A30504559b0C5a9A5977fEE4A6081c6b', - decimals: 18, - }, - USDCe: { - address: '0xA7D7079b0FEaD91F3e65f86E8915Cb59c1a4C664', - decimals: 6, - }, - USDC: { - address: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', - decimals: 6, - }, - USDTe: { - address: '0xc7198437980c041c805A1EDcbA50c1Ce5db95118', - decimals: 6, - }, - USDT: { - address: '0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7', - decimals: 6, - addAllowance: smart_tokens_1._allowancesFn, - addBalance: smart_tokens_1.balanceOfFn, - }, - POPS: { - address: '0x240248628B7B6850352764C5dFa50D1592A033A8', - decimals: 18, - }, - WAVAX: { - address: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', - decimals: 18, - addAllowance: smart_tokens_1.allowanceFn, - addBalance: smart_tokens_1.balanceOfFn, - }, - sAVAX: { - address: '0x2b2C81e08f1Af8835a78Bb2A90AE924ACE0eA4bE', - decimals: 18, - }, - WETHe: { - address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', - decimals: 18, - }, - ETH: { - address: '0xf20d962a6c8f70c731bd838a3a388D7d48fA6e15', - decimals: 18, - }, - WBTC: { - address: '0x408D4cD0ADb7ceBd1F1A1C33A0Ba2098E1295bAB', - decimals: 8, - }, - WETH: { - address: '0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', - decimals: 18, - }, - TUSD: { - address: '0x1c20e891bab6b1727d14da358fae2984ed9b59eb', - decimals: 18, - }, - oldFRAX: { - address: '0xdc42728b0ea910349ed3c6e1c9dc06b5fb591f98', - decimals: 18, - }, - newFRAX: { - address: '0xd24c2ad096400b6fbcd2ad8b24e7acbc21a1da64', - decimals: 18, - }, - DAIE: { - address: '0xd586e7f844cea2f87f50152665bcbc2c279d8d70', - decimals: 18, - }, - PNG: { - address: '0x60781c2586d68229fde47564546784ab3faca982', - decimals: 18, - }, - SHIBX: { - address: '0x440aBbf18c54b2782A4917b80a1746d3A2c2Cce1', - decimals: 18, - }, - wBTC: { - address: '0x50b7545627a5162F82A992c33b87aDc75187B218', - decimals: 8, - }, - renBTC: { - address: '0xDBf31dF14B66535aF65AaC99C32e9eA844e14501', - decimals: 8, - }, - BTCb: { - address: '0x152b9d0FdC40C096757F570A51E494bd4b943E50', - decimals: 8, - }, - ADAI: { - address: '0x47AFa96Cdc9fAb46904A55a6ad4bf6660B53c38a', - decimals: 18, - }, - avWAVAX: { - address: '0xDFE521292EcE2A4f44242efBcD66Bc594CA9714B', - decimals: 18, - }, - MIM: { - address: '0x130966628846BFd36ff31a822705796e8cb8C18D', - decimals: 18, - }, - TSD: { - address: '0x4fbf0429599460D327BD5F55625E30E4fC066095', - decimals: 18, - }, - avUSDT: { - address: '0x532e6537fea298397212f09a61e03311686f548e', - decimals: 6, - }, - THO: { - address: '0xAE4AA155D2987B454C29450ef4f862CF00907B61', - decimals: 18, - }, - AVAX: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - aETH: { - address: '0x3a3A65aAb0dd2A17E3F1947bA16138cd37d08c04', - decimals: 18, - }, - aUSDT: { - address: '0x71fc860f7d3a592a4a98740e39db31d25db65ae8', - decimals: 6, - }, - YUSD: { - address: '0x111111111111ed1D73f860F57b2798b683f2d325', - decimals: 18, - }, - H2O: { - address: '0x026187BdbC6b751003517bcb30Ac7817D5B766f8', - decimals: 18, - }, - MONEY: { - address: '0x0f577433Bf59560Ef2a79c124E9Ff99fCa258948', - decimals: 18, - }, - nETH: { - address: '0x19E1ae0eE35c0404f835521146206595d37981ae', - decimals: 18, - }, - avWETH: { - address: '0x53f7c5869a859F0AeC3D334ee8B4Cf01E3492f21', - decimals: 18, - }, - nUSD: { - address: '0xCFc37A6AB183dd4aED08C204D1c2773c0b1BDf46', - decimals: 18, - }, - BETS: { - address: '0x94025780a1ab58868d9b2dbbb775f44b32e8e6e5', - decimals: 18, - }, - HATCHY: { - address: '0x502580fc390606b47fc3b741d6d49909383c28a9', - decimals: 18, - }, - AMPL: { - address: '0x027dbcA046ca156De9622cD1e2D907d375e53aa7', - decimals: 9, - }, - stataUSDT: { - address: '0x5525ee69bc1e354b356864187de486fab5ad67d7', - decimals: 6, - }, - aaveUSDT: { - address: '0x6ab707aca953edaefbc4fd23ba73294241490620', - decimals: 6, - }, - }, - [constants_1.Network.ARBITRUM]: { - SEN: { - address: '0x154388a4650D63acC823e06Ef9e47C1eDdD3cBb2', - decimals: 18, - }, - BAL: { - address: '0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8', - decimals: 18, - }, - DAI: { - address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', - decimals: 18, - }, - ARB: { - address: '0x912ce59144191c1204e64559fe8253a0e49e6548', - decimals: 18, - }, - WETH: { - address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', - decimals: 18, - addBalance: smart_tokens_1._balancesFn, - addAllowance: smart_tokens_1._allowancesFn, - }, - ETH: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - USDCe: { - address: '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8', - decimals: 6, - }, - USDC: { - address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831', - decimals: 6, - symbol: 'USDC', - addBalance: smart_tokens_1.balanceAndBlacklistStatesFn, - addAllowance: smart_tokens_1.allowedFn, - }, - SUSHI: { - address: '0xd4d42F0b6DEF4CE0383636770eF773390d85c61A', - decimals: 18, - }, - crvUSD: { - address: '0x498bf2b1e120fed3ad3d42ea2165e9b73f99c1e5', - decimals: 18, - }, - OHM: { - address: '0xf0cb2dc0db5e6c66b9a70ac27b06b878da017028', - decimals: 9, - }, - RDNT: { - address: '0x3082cc23568ea640225c2467653db90e9250aaa0', - decimals: 18, - }, - USDT: { - address: '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', - decimals: 6, - addBalance: smart_tokens_1._balancesFn, - addAllowance: smart_tokens_1._allowancesFn, - }, - FRAX: { - address: '0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F', - decimals: 18, - }, - nUSD: { - address: '0x2913E812Cf0dcCA30FB28E6Cac3d2DCFF4497688', - decimals: 18, - }, - nETH: { - address: '0x3ea9B0ab55F34Fb188824Ee288CeaEfC63cf908e', - decimals: 18, - }, - EURS: { - address: '0xd22a58f79e9481d1a88e00c343885a588b34b68b', - decimals: 2, - }, - AAVE: { - address: '0xba5ddd1f9d7f570dc94a51479a000e3bce967196', - decimals: 18, - }, - MIM: { - address: '0xFEa7a6a0B346362BF88A9e4A88416B77a57D6c2A', - decimals: 18, - }, - VST: { - address: '0x64343594ab9b56e99087bfa6f2335db24c2d1f17', - decimals: 18, - }, - POPS: { - address: '0xa0b20DecBc557E3f68E140eD5a0c69bc865F865A', - decimals: 18, - }, - ZYB: { - address: '0x3B475F6f2f41853706afc9Fa6a6b8C5dF1a2724c', - decimals: 18, - }, - WBTC: { - address: '0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', - decimals: 8, - }, - LEX: { - address: '0x6bB7A17AcC227fd1F6781D1EEDEAE01B42047eE0', - decimals: 18, - }, - EURA: { - address: '0xfa5ed56a203466cbbc2430a43c66b9d8723528e7', - decimals: 18, - symbol: 'EURA', - }, - stEUR: { - address: '0x004626a008b1acdc4c74ab51644093b155e59a23', - decimals: 18, - }, - USDA: { - address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', - decimals: 18, - symbol: 'USDA', - }, - USDM: { - address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', - decimals: 18, - }, - wUSDM: { - address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', - decimals: 18, - }, - stUSD: { - address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - decimals: 18, - }, - GRAIL: { - address: '0x3d9907f9a368ad0a51be60f7da3b97cf940982d8', - decimals: 18, - }, - AURY: { - address: '0x11bf4f05eb28b802ed3ab672594decb20ffe2313', - decimals: 9, - }, - wstETH: { - address: '0x5979D7b546E38E414F7E9822514be443A4800529', - decimals: 18, - }, - RDPX: { - address: '0x32eb7902d4134bf98a28b963d26de779af92a212', - decimals: 18, - }, - SDEX: { - address: '0xabD587f2607542723b17f14d00d99b987C29b074', - decimals: 18, - }, - LINK: { - address: '0xf97f4df75117a78c1a5a0dbb814af92458539fb4', - decimals: 18, - }, - DMT: { - address: '0x8b0e6f19ee57089f7649a455d89d7bc6314d04e8', - decimals: 18, - }, - PENDLE: { - address: '0x0c880f6761f1af8d9aa9c466984b80dab9a8c9e8', - decimals: 18, - }, - stataUSDT: { - address: '0xb165a74407fe1e519d6bcbdec1ed3202b35a4140', - decimals: 6, - }, - aaveUSDT: { - address: '0x6ab707aca953edaefbc4fd23ba73294241490620', - decimals: 6, - }, - GHO: { - address: '0x7dff72693f6a4149b17e7c6314655f6a9f7c8b33', - decimals: 18, - }, - }, - [constants_1.Network.OPTIMISM]: { - DAI: { - address: '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1', - decimals: 18, - }, - WETH: { - address: '0x4200000000000000000000000000000000000006', - decimals: 18, - addBalance: smart_tokens_1.balanceOfFn, - addAllowance: smart_tokens_1.allowanceFn, - }, - ETH: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - USDCe: { - address: '0x7F5c764cBc14f9669B88837ca1490cCa17c31607', - decimals: 6, - }, - USDC: { - address: '0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85', - decimals: 6, - }, - USDT: { - address: '0x94b008aA00579c1307B0EF2c499aD98a8ce58e58', - decimals: 6, - }, - PSTAKE: { - address: '0x023550adde4fa2f90d63a41d9282bee0294c04cd', - decimals: 18, - }, - GRAIN: { - address: '0xfd389dc9533717239856190f42475d3f263a270d', - decimals: 18, - }, - tBTC: { - address: '0x6c84a8f1c29108f47a79964b5fe888d4f4d0de40', - decimals: 18, - }, - GRAI: { - address: '0x894134a25a5fac1c2c26f1d8fbf05111a3cb9487', - decimals: 18, - }, - LUSD: { - address: '0xc40f949f8a4e094d1b49a23ea9241d289b7b2819', - decimals: 18, - }, - POPS: { - address: '0x3D51a9fB5dCc87F7B237B04975559b920a9a56Ff', - decimals: 18, - }, - crvUSD: { - address: '0xc52d7f23a2e460248db6ee192cb23dd12bddcbf6', - decimals: 18, - }, - OP: { - address: '0x4200000000000000000000000000000000000042', - decimals: 18, - }, - sETH: { - address: '0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49', - decimals: 18, - }, - sUSD: { - address: '0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9', - decimals: 18, - }, - wstETH: { - address: '0x1f32b1c2345538c0c6f582fcb022739c4a194ebb', - decimals: 18, - }, - rETH: { - address: '0x9bcef72be871e61ed4fbbc7630889bee758eb81d', - decimals: 18, - }, - MAI: { - address: '0xdfa46478f9e5ea86d57387849598dbfb2e964b02', - decimals: 18, - }, - WBTC: { - address: '0x68f180fcCe6836688e9084f035309E29Bf0A2095', - decimals: 8, - }, - EURA: { - address: '0x9485aca5bbbe1667ad97c7fe7c4531a624c8b1ed', - decimals: 18, - symbol: 'EURA', - }, - USDM: { - address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', - decimals: 18, - }, - wUSDM: { - address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', - decimals: 18, - }, - stEUR: { - address: '0x004626a008b1acdc4c74ab51644093b155e59a23', - decimals: 18, - }, - USDA: { - address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', - decimals: 18, - symbol: 'USDA', - }, - stUSD: { - address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - decimals: 18, - }, - frxETH: { - address: '0x6806411765Af15Bddd26f8f544A34cC40cb9838B', - decimals: 18, - }, - stataUSDT: { - address: '0x035c93db04e5aaea54e6cd0261c492a3e0638b37', - decimals: 6, - }, - aaveUSDT: { - address: '0x6ab707aca953edaefbc4fd23ba73294241490620', - decimals: 6, - }, - }, - [constants_1.Network.ZKEVM]: { - ETH: { - address: constants_1.ETHER_ADDRESS, - decimals: 18, - }, - WETH: { - address: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9', - decimals: 18, - }, - MATIC: { - address: '0xa2036f0538221a77a3937f1379699f44945018d0', - decimals: 18, - }, - WBTC: { - address: '0xea034fb02eb1808c2cc3adbc15f447b93cbe08e1', - decimals: 8, - }, - USDC: { - address: '0xa8ce8aee21bc2a48a5ef670afcc9274c7bbbc035', - decimals: 6, - }, - }, - [constants_1.Network.BASE]: { - wstETH: { - address: `0xc1cba3fcea344f92d9239c08c0568f6f2f0ee452`, - decimals: 18, - }, - PRIME: { - address: '0xfA980cEd6895AC314E7dE34Ef1bFAE90a5AdD21b', - decimals: 18, - }, - WETH: { - address: '0x4200000000000000000000000000000000000006', - decimals: 18, - }, - MAV: { - address: '0x64b88c73A5DfA78D1713fE1b4c69a22d7E0faAa7', - decimals: 18, - }, - crvUSD: { - address: '0x417ac0e078398c154edfadd9ef675d30be60af93', - decimals: 18, - }, - USDC: { - address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', - symbol: 'USDC', - decimals: 6, - }, - USDM: { - address: '0x59d9356e565ab3a36dd77763fc0d87feaf85508c', - decimals: 18, - }, - wUSDM: { - address: '0x57f5e098cad7a3d1eed53991d4d66c45c9af7812', - decimals: 18, - }, - USDbC: { - address: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', - decimals: 6, - }, - DOG: { - address: '0xAfb89a09D82FBDE58f18Ac6437B3fC81724e4dF6', - decimals: 18, - }, - cbETH: { - address: '0x2ae3f1ec7f1f5012cfeab0185bfc7aa3cf0dec22', - decimals: 18, - }, - tBTC: { - address: '0x236aa50979d5f3de3bd1eeb40e81137f22ab794b', - decimals: 18, - }, - DAI: { - address: '0x50c5725949a6f0c72e6c4a641f24049a917db0cb', - decimals: 18, - }, - ALB: { - address: '0x1dd2d631c92b1acdfcdd51a0f7145a50130050c4', - decimals: 18, - }, - BAL: { - address: '0x4158734d47fc9692176b5085e0f52ee0da5d47f1', - decimals: 18, - }, - GOLD: { - address: '0xbeFD5C25A59ef2C1316c5A4944931171F30Cd3E4', - decimals: 18, - }, - SDEX: { - address: '0xFd4330b0312fdEEC6d4225075b82E00493FF2e3f', - decimals: 18, - }, - EURA: { - address: '0xA61BeB4A3d02decb01039e378237032B351125B4', - decimals: 18, - symbol: 'EURA', - }, - USDA: { - address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', - decimals: 18, - symbol: 'USDA', - }, - stUSD: { - address: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - decimals: 18, - }, - ETH: { address: constants_1.ETHER_ADDRESS, decimals: 18 }, - AERO: { - address: '0x940181a94A35A4569E4529A3CDfB74e38FD98631', - decimals: 18, - }, - stataUSDC: { - address: '0x4ea71a20e655794051d1ee8b6e4a3269b13ccacc', - decimals: 6, - }, - aaveUSDC: { - address: '0x4e65fe4dba92790696d040ac24aa414708f5c0ab', - decimals: 6, - }, - }, -}; -exports.Holders = { - [constants_1.Network.MAINNET]: { - USDS: '0xB1796E8f1eEcF23027c1E3C00fE303629A189d10', - sUSDS: '0xd564B3aE673CAa49D054Bf185bD72a6853763eE7', - SKY: '0x0ddda327A6614130CCb20bc0097313A282176A01', - MKR: '0xe9aAA7A9DDc0877626C1779AbC29993aD89A6c1f', - // Idle tokens - AA_wstETH: '0xd7C1b48877A7dFA7D51cf1144c89C0A3F134F935', - 'AA_idle_cpPOR-USDC': '0x085c8eaccA6911fE60aE3f8FbAe5F3012E3A05Ec', - 'BB_idle_cpFAS-USDT': '0xFDAD59EF0686C3Da702b7D651a3bD35a539c8Bc4', - AA_steakUSDC: '0x28C1eCF5B0f16E1D85B9D2677EfB79d68167cAf2', - BB_steakUSDC: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300', - AA_Re7WETH: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb', - BB_Re7WETH: '0x442Aea0Fd2AFbd3391DAE768F7046f132F0a6300', - BB_dUSDCV3: '0xFb3bD022D5DAcF95eE28a6B07825D4Ff9C5b3814', - AA_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4', - BB_sUSDe: '0xaFeb95DEF3B2A3D532D74DaBd51E62048d6c07A4', - AA_iETHv2: '0xA118aD79E2152b9a3c7Df8B8791887762b0f1D49', - BB_iETHv2: '0x15079cBAa74C1df2a602fAc88Bd5b98B08FfE6A4', - ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132', - USDC: '0x7713974908be4bed47172370115e8b1219f4a5f0', - USDE: '0x8707f238936c12c309bfc2B9959C35828AcFc512', - AMPL: '0x223592a191ECfC7FDC38a9256c3BD96E771539A9', - WBTC: '0x6daB3bCbFb336b29d06B9C793AEF7eaA57888922', - tBTCv2: '0x84eA3907b9206427F45c7b2614925a2B86D12611', - sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195', - TUSD: '0x88369cB14F9893aEA737F61ad31Bc6d018af7985', - aEthUSDC: '0x42EFD1E0DB4ADa762cc5092ECBD052dE7c6e72E2', - MAV: '0x92582aa69BB6117903a01eDdfe6EFfDDe564A69f', - BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a', - STETH: '0x6663613FbD927cE78abBF7F5Ca7e2c3FE0d96d18', - SUSHI: '0x8a108e4761386c94b8d2f98A5fFe13E472cFE76a', - wstETH: '0x3c22ec75ea5D745c78fc84762F7F1E6D82a2c5BF', - WETH: '0x6B44ba0a126a2A1a8aa6cD1AdeeD002e141Bcd44', - USDT: '0xAf64555DDD61FcF7D094824dd9B4eBea165aFc5b', - XAUT: '0xc4e161e8d8a4bc4ac762ab33a28bbac5474203d7', - R: '0xBfe4c9D3235475C138a61f62e9e72FaD94A3303b', - sDAI: '0x4C612E3B15b96Ff9A6faED838F8d07d479a8dD4c', - CVX: '0x0aCA67Fa70B142A3b9bF2eD89A81B40ff85dACdC', - MIM: '0xa046a8660e66d178ee07ec97c585eeb6aa18c26c', - AnkETH: '0xF7260D4ADc48fEefd5a19a9Eb23f9747CeE15C92', - DAI: '0xd1668fb5f690c59ab4b0cabad0f8c1617895052b', - oldFRAX: '0x183d0dc5867c01bfb1dbbc41d6a9d3de6e044626', - newFRAX: '0x183d0dc5867c01bfb1dbbc41d6a9d3de6e044626', - FEI: '0x19c549357034d10db8d75ed812b45be1dd8a7218', - BAL: '0x0659FB78b5139eE5bC9238b2C85944a112A7b591', - OHM: '0x3D7FEAB5cfab1c7De8ab2b7D5B260E76fD88BC78', - AURA: '0xBB19053E031D9B2B364351B21a8ed3568b21399b', - WISE: '0x25c315e0758beeab30ee048a4e2080e7084b64b3', - DDIM: '0x229cbd1955fee93ab6e7876c1b17f6d0b859e953', - DODO: '0x3e19d726ed435afd3a42967551426b3a47c0f5b7', - ADAI: '0x826c3064d4f5b9507152f5cb440ca9326e1ec8fa', - AWETH: '0xa433105e7396070a5e1fdd7e2b2338f1bfa0de68', - BUSD: '0xf977814e90da44bfa03b6295a0616a897441acec', - INCH: '0x4ee7c0f5480eb1edd8902a5e8b991ed52992d5f5', - mUSD: '0x3aD1D5CFCF9169Da73C23D85d5f2Bf53bC9d39dF', - mBTC: '0x15A295e9BCFcF93a8721DCb9A19330fc59771271', - renBTC: '0xAaE0633E15200bc9C50d45cD762477D268E126BD', - tBTC: '0xC25099792E9349C7DD09759744ea681C7de2cb66', - HBTC: '0x52885fF60Cd7Ae081e0665968C457DdACF888C90', - GUSD: '0x550Def3DB74F583c7A1eDf2DFFE84a7398850D0c', - LINK: '0x8d4169cCf3aD88EaFBB09580e7441D3eD2b4B922', - ADAIv1: '0x3021026e4ff227571a5a563ad19ea657c7027e59', - CETH: '0x712d0f306956a6a4b4f9319ad9b9de48c5345996', - CDAI: '0xab4ce310054a11328685ece1043211b68ba5d082', - CUSDC: '0xC2F61a6eEEC48d686901D325CDE9233b81c793F3', - EURS: '0xC1056Adeb61a01964Ea265cA95EffB7016f9Ed78', - EURT: '0x6914FC70fAC4caB20a8922E900C4BA57fEECf8E1', - CRV: '0x7a16fF8270133F063aAb6C9977183D9e72835428', - jEUR: '0x937Df4e3d6dB229A10ff0098ab3A1bCC40C33ea4', - UST: '0xf16e9b0d03470827a95cdfd0cb8a8a3b46969b91', - SAITAMA: '0x763d5d93f27615aac852b70549f5877b92193864', - aETH: '0xc03c4476fbe25138bf724fa1b95551c6e6b8fd2c', - aWETH: '0x3ddfa8ec3052539b6c9549f12cea2c295cff5296', - aUSDT: '0x4aef720f7bbe98f916221bbc2fb5a15efe6d2cb8', - BBAUSD: '0x4361b7425cff39b1be9bf12cee2ef32f89656cda', - sETH: '0x274d9E726844AB52E351e8F1272e7fc3f58B7E5F', - sUSD: '0xcb68110C43C97b6051FEd5e2Bacc2814aDaD1688', - USDD: '0xf89d7b9c864f589bbf53a82105107622b35eaa40', - alETH: '0xBD28e1B15EcbE72706A445f77bd17FCd8Fe6f652', - SHIBA: '0x73af3bcf944a6559933396c1577b257e2054d935', - aEthWETH: '0x931433324E6B0b5B04E3460ef3fb3f78dda3c721', - dUSDC: '0x2FC2F705110A7F46Ce85F701d7217EF1018f01A3', - PSP: '0xE5E5440a1CE69C5cf67BFFA74d185e57c31b43E5', - EUROC: '0x64AE5802620398143FC7113037769175F74825Ea', - bC3M: '0x5f9F41497f9e11fd7D4c4B067413199682eE2CFF', - bERNX: '0x5F7A4c11bde4f218f0025Ef444c369d838ffa2aD', - bIB01: '0x5F7A4c11bde4f218f0025Ef444c369d838ffa2aD', - steakUSDC: '0xC977d218Fde6A39c7aCE71C8243545c276B48931', - EURA: '0xa116f421ff82a9704428259fd8cc63347127b777', - stEUR: '0xdC7Aa225964267c7E0EfB35f4931426209E90312', - USDA: '0x2686bC6A56D205010637CE1DF124b20Cb19E4054', - stUSD: '0x4e83c0a323b68E3Bc7CC8a4E35326Fd0544A291E', - crvUSD: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635', - GHO: '0x0F11640BF66e2D9352d9c41434A5C6E597c5e4c8', - wibBTC: '0xFbdCA68601f835b27790D98bbb8eC7f05FDEaA9B', - MATIC: '0x7073783eee7e9b3e6e4ddac4d7f49dc46044dd9a', - POL: '0x05A47D9f589a001C15E38D068dCc5DaE6D96a2eb', - SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058', - frxETH: '0x9df2322bdAEC46627100C999E6dDdD27837fec6e', - LUSD: '0xEd279fDD11cA84bEef15AF5D39BB4d4bEE23F0cA', - BNT: '0xf727e20e081aAE428E7c6bE07b156bB21ab587a7', - USDe: '0x74e6c48e667d698a4cf90665b6960a5bae39e603', - eETH: '0x0f1DfeF1a40557d279d0de6E49aB306891A638b8', - stataUSDT: '0x6803364AceD5181877abC11E865FB27cB654a426', - aaveUSDT: '0x32c98a981Fe7C333Bd4e8E7630E8e0CF5ce20987', - weETH: '0x267ed5f71EE47D3E45Bb1569Aa37889a2d10f91e', - rUSD: '0xEC2eda1C4F981E468ABF62424a10B69B738b498E', - arUSD: '0xeFc24206053a452e2299BF3b8f964512b041Db4C', - USD0: '0x6A5d5Af0E266a24648a9d7E8D388EAEc7AbD8433', - 'USD0++': '0x2227b6806339906707b43F36a1f07B52FF7Fa776', - USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', - wUSDM: '0x3B95bC951EE0f553ba487327278cAc44f29715E5', - }, - [constants_1.Network.POLYGON]: { - jGBP: '0x02aa0B826c7BA6386DdBE04C0a8715A1c0A16B24', - MATIC: '0xfCbB9e5BB354B6F9fd40362Cee043F510dd3028D', - DAI: '0x98F911D496Cf46bf9FF9CdD7039Cf579B26F01B9', - WETH: '0x62ac55b745f9b08f1a81dcbbe630277095cf4be1', - WMATIC: '0x0AFF6665bB45bF349489B20E225A6c5D78E2280F', - AMWMATIC: '0x975779102B2A82384f872EE759801DB5204CE331', - USDC: '0xf89d7b9c864f589bbf53a82105107622b35eaa40', - BAL: '0xF1CFf6380D9A15dB33Eed0309541E254fC7dE695', - AAVE: '0x256e063f7fb60a3004D13e1D09e7A9D200A5C5bA', - PSP: '0xa902c6a26bcaC4c62Eb8667E3Ef9368f78421dB5', - POPS: '0x2693b57ee51f4e2a26dfb339a911fa8731061f49', - MUST: '0x9f2a409848fb9b7bd058b24a23e8dbf1e166a109', - AMDAI: '0xFA0DCe8280FCDf369a4cbFc1830d3302789307a6', - mUSD: '0x5084f622cbDf1E22E473d66d97916524745B9b6e', - USDT: '0x2D55eccD5F50D325ee3CE192322911f87113bCd3', - WBTC: '0xdc9232e2df177d7a12fdff6ecbab114e2231198d', - AMWETH: '0x6f1c28c40b5fed4fb546f85959ae2f7c16365cad', - KNC: '0x41Af7fd16dFC29bdA8D8aAA4CeFfC0E8046992eC', - jEUR: '0x807B465fC3f72aF3AAfda74480CA7E4E55964cd3', - aUSDT: '0x027ffd3c119567e85998f4e6b9c3d83d5702660c', - aPolUSDT: '0x941da3d6759147736456cee36647213183079337', - aPolWMATIC: '0xfB3C01F90B4629DBD4Fd5310E995Ef3FE2e7AbeE', - RADIO: '0x60531b9c3645546d864604ee0fc5b7d6adc81cc2', - HANZO: '0x8a151b6ec99c7b90b342ab401d511b480309b220', - RVLT: '0x815f87ca3db2b9491115a7769aeacb140361c5a9', - stMATIC: '0x7C8963BddC17095aDbc9387Cc6cdcCaA798feA52', - axlUSDC: '0x9298F93ee0393a823C242D80F1a4aDf4c8a3Feef', - deUSDC: '0x94d5ead1f80cf0b4d3480ab59dff16d47c93e9fe', - amUSDT: '0x832b11846a27b3ba25d68ae80c39fab155d18c49', - amUSDC: '0x6e7f19cd23049c7118e14470e2bf85d2e26ee0ae', - MAI: '0x9a8cf02f3e56c664ce75e395d0e4f3dc3dafe138', - SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058', - CRV: '0x2151578e1fEc29361bB0481312Ea6b935014D636', - SUSHI: '0x1605CE87dD176b38a17d30e8926370ffD5268bf6', - EURA: '0x9A760aa1Fe631fD9aC0Aee0965736121c7c132cc', - stEUR: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', - USDA: '0x741383AbD73891b40822A069f14d6fc5b5685020', - stUSD: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', - stataUSDCn: '0xFAB1420c84fF5E058B8AD12604D24247e268f362', - aaveUSDCn: '0xEBA9C3C1B41A846431F970aCA5Eee10f55969B76', - crvUSD: '0x61aE20E0292a5E6CF2F017236755246BB9e0f57a', - USDCe: '0xA67EFB69A4f58F568aAB1b9d51110102985835b0', - USDCn: '0x4B6f17856215eab57c29ebfA18B0a0F74A3627bb', - USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', - wUSDM: '0x76272a79F7e529247b663fC8857BD69244b0d412', - TRYB: '0xD05007f1BD1304bFAEb370Ec5EbD18fD02a581e6', - }, - [constants_1.Network.FANTOM]: { - DAI: '0x370f4b2dcf75c94d8d4450b493661a9c6170d0b5', - FTM: '0x431e81E5dfB5A24541b5Ff8762bDEF3f32F96354', - WFTM: '0xB7D0fB518a5b7bf8dc7ea19A715E8FD8BD983e27', - USDC: '0xf53feaeb035361c046e5669745695e450ebb4028', - USDCe: '0x305fa2FB5AF034D490A9C9be8bcd9b01902480BF', - FUSDT: '0x9ade1c17d25246c405604344f89E8F23F8c1c632', - POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', - aFanUSDT: '0x8EBc96fF91A30059E447bFC7C0a7394f8A5793E6', - aFanWFTM: '0x935AD0fBea9572bB24138F23A69e314f0BDbdDbE', - MIM: '0xbcab7d083cf6a01e0dda9ed7f8a02b47d125e682', - FRAX: '0x4423ac71f53ca92e2f2be5917a9c2468e7412f4a', - nETH: '0x16b658270ac50c0063940ed287c401b3df7ccf70', - WETH: '0x7b7b957c284c2c227c980d6e2f804311947b84d0', - SPIRIT: '0x0d0707963952f2fba59dd06f2b425ace40b492fe', - wBOMB: '0x28aa4f9ffe21365473b64c161b566c3cdead0108', - TOR: '0x70de4b5ed310fd93da3c0bae824fb99cb4d44dd8', - BOO: '0xf778f4d7a14a8cb73d5261f9c61970ef4e7d7842', - ETH: '0xf48883940b4056801de30f12b934dcea90133ee6', - GUSDC: '0x894d774a293f8aa3d23d67815d4cadb5319c1094', - GDAI: '0x0e2ed73f9c1409e2b36fe6c46e60d4557b7c2ac0', - EQUAL: '0x8b187ea19c93091a4d6b426b71871648182b5fac', - FVM: '0x07BB65fAaC502d4996532F834A1B7ba5dC32Ff96', - lzUSDC: '0x06F1C4A56357bF3971C79063f2B58E58c547BC0B', - axlUSDC: '0xccf932cd565c21d2e516c8ff3a4f244eea27e09a', - SOLID: '0xddf169bf228e6d6e701180e2e6f290739663a784', - scrvUSDC_e: '0xb8c1dAb69724da9d3225F14bfD76Ae97bB92BFda', - scrvUSDC_p: '0x74796478d7755a77807fADd2389A18DF1baf9e7c', - }, - [constants_1.Network.BSC]: { - DAI: '0xf68a4b64162906eff0ff6ae34e2bb1cd42fef62d', - WBNB: '0x59d779bed4db1e734d3fda3172d45bc3063ecd69', - BUSD: '0x0D0707963952f2fBA59dD06f2b425ace40b492Fe', - POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', - BNB: '0xf68a4b64162906eff0ff6ae34e2bb1cd42fef62d', - USDT: '0xf89d7b9c864f589bbf53a82105107622b35eaa40', - ETH: '0xefdca55e4bce6c1d535cb2d0687b5567eef2ae83', - USDC: '0x554b52bf57b387fd09d6644368c5a8aacaaf5ae0', - RADIO: '0x75b3efed620e2d6750d88263cd4d7a27b0d7d3c5', - bBTC: '0x72a53cdbbcc1b9efa39c834a540550e23463aacb', - anyBTC: '0x4ffef8e8a75c20ab0ddf96c50d2457277d27923c', - nUSD: '0x28ec0b36f0819ecb5005cab836f4ed5a2eca4d13', - axlUSD: '0xc03fbeda9069b22a120ae6a09349a0b5eea5570a', - FRAX: '0xEB4576fE753DAB07635c0Bb6c8f0A355e1Db5d31', - frxETH: '0xf324adC872005197A6f7DAE214d3b63aa0C3625F', - USDFI: '0x2E00D722e091836B39Db3e4dcE6eE51c90c5B221', - SDEX: '0xB0470cF15B22a6A32c49a7C20E3821B944A76058', - BNBx: '0xFF4606bd3884554CDbDabd9B6e25E2faD4f6fc54', - EURA: '0x4A5362ef534FFB27510E4E4C9A215BB5436377C2', - USDA: '0x230c1f68aBE6033Cba3Fe0D2C0D7097e9923C3bC', - stUSD: '0x0022228a2cc5E7eF0274A7Baa600d44da5aB5776', - stataUSDT: '', - aaveUSDT: '0x5DE3c5BE52D7aDbdC3aEFe2eA061A2ECE0C7d766', - }, - [constants_1.Network.AVALANCHE]: { - LINKe: '0x9efa0A617C0552F1558c95993aA8b8A68b3e709C', - AVAX: '0xD6216fC19DB775Df9774a6E33526131dA7D19a2c', - avWAVAX: '0xc5ed2333f8a2C351fCA35E5EBAdb2A82F5d254C3', - WAVAX: '0x5CfCd7E6D055Ba4f7B998914336254aDE3F69f26', - sAVAX: '0xC73DF1e68FC203F6E4b6270240D6f82A850e8D38', - BETS: '0x8cc2284c90d05578633418f9cde104f402375a65', - HATCHY: '0x14ec295ec8def851ec6e2959df872dd24e422631', - USDCe: '0x3a2434c698f8d79af1f5a9e43013157ca8b11a66', - USDC: '0xcc2da711D621A4491b338CAC88B9C0954db3e75B', - USDTe: '0x84d34f4f83a87596cd3fb6887cff8f17bf5a7b83', - WETHe: '0x9bdB521a97E95177BF252C253E256A60C3e14447', - POPS: '0x5268c2331658cb0b2858cfa9db27d8f22f5434bc', - ETH: '0x9852e84b5AA485683d8AeE7B0332e42442763b75', - DAIE: '0xED2a7edd7413021d440b09D654f3b87712abAB66', - TUSD: '0x5Db946411F08f15300f23D9bde4A407B07D56C03', - PNG: '0x348b11CF986e8E1CdA10c4A7E375aA252b47fc55', - SHIBX: '0xfE5ADf65BE1a46b83EF3d352A8F9258A039f3050', - wBTC: '0xbB2BD754A45f400A01158A8b3C89DE085D58ABF1', - renBTC: '0xb8D1D22609D10078Db36915fc4610F8674b44319', - ADAI: '0xc5ed2333f8a2C351fCA35E5EBAdb2A82F5d254C3', - MIM: '0x64cb3f5aada07d831b8db6c6d9c715c53c251ef3', - TSD: '0x691A89db352B72dDb249bFe16503494eC0D920A4', - THO: '0xc40d16c47394a506d451475c8a7c46c1175c1da1', - aAvaUSDT: '0x50B1Ba98Cf117c9682048D56628B294ebbAA4ec2', - USDT: '0x0d0707963952f2fba59dd06f2b425ace40b492fe', - aAvaWAVAX: '0x1B18Df70863636AEe4BfBAb6F7C70ceBCA9bA404', - oldFRAX: '0x4e3376018add04ebe4c46bf6f924ddec8c67aa7b', - newFRAX: '0x4e3376018add04ebe4c46bf6f924ddec8c67aa7b', - nETH: '0xcf2ef00e75558512ae735679ea5df62ad2056786', - avWETH: '0x92d78e32b990d10aeca0875dc5585f1a6f958179', - YUSD: '0x86D0c0e4B8CC5409144f66E6E76b904bb9ce9cDb', - BTCb: '0x2446bEb3905CfFbd2c5eB18F1f9c2996B05257c4', - AMPL: '0xfcaA5ea7F8eb0631BcA72C345025C0A5a6D93f0E', - PHAR: '0x654296D56532f62B7d91d335791d3c364a9385b5', - stataUSDT: '', - aaveUSDT: '0xB2d3ad6e99D2A043EF77e3812461Ad2D4Ae3da8B', - }, - [constants_1.Network.ARBITRUM]: { - SEN: '0x76d39045d856caf9bfae12ba611ca4a94449a4f1', - RDPX: '0x115b818593c00da4f9d1d8f5ce7d7f88cce48bee', - ARB: '0xb65edba80a3d81903ecd499c8eb9cf0e19096bd0', - ETH: '0xfa0a32e5c33b6123122b6b68099001d9371d14e9', - DAI: '0x2d070ed1321871841245d8ee5b84bd2712644322', - WETH: '0x3368e17064c9ba5d6f1f93c4c678bea00cc78555', - BAL: '0x7b7b957c284c2c227c980d6e2f804311947b84d0', - USDCe: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', - USDC: '0xb38e8c17e38363af6ebdcb3dae12e0243582891d', - OHM: '0xebce5f29ff5ca9aa330ebdf7ec6b5f474bff271e', - USDT: '0xf977814e90da44bfa03b6295a0616a897441acec', - POPS: '0x4b78b52e7de4d8b7d367297cb8a87c1875a9d591', - FRAX: '0x59bf0545fca0e5ad48e13da269facd2e8c886ba4', - nUSD: '0x9dd329f5411466d9e0c488ff72519ca9fef0cb40', - nETH: '0xa067668661c84476afcdc6fa5d758c4c01c34352', - AAVE: '0x8D2876aD4D2A994C529F19D846CA541015dc3f05', - aArbAAVE: '0x439901eCaB06F75B14bC25fD60d53bB3A3b9e277', - EURS: '0x251aeE4A9eB1d8251485D1A9b3bE68975B39EC33', - aArbEURS: '0xD2BC982A2035dB0E1Be7c2C1a9f87E31794C653e', - MIM: '0xf46bb6dda9709c49efb918201d97f6474eac5aea', - VST: '0x59bf0545fca0e5ad48e13da269facd2e8c886ba4', - aArbUSDC: '0x048BF2F5908e95976CeAD0E47D805b3803E286e2', - ZYB: '0x3ec0eddcd1e25025077327886a78133589082fb2', - WBTC: '0xd9d611c6943585bc0e18e51034af8fa28778f7da', - RDNT: '0x62383739d68dd0f844103db8dfb05a7eded5bbe6', - SDEX: '0xb0470cf15b22a6a32c49a7c20e3821b944a76058', - LINK: '0x7f1fa204bb700853d36994da19f830b6ad18455c', - DMT: '0x40414f138eb2ef938e6c3629897ef99d4464d4e8', - PENDLE: '0x5bdf85216ec1e38d6458c870992a69e38e03f7ef', - wstETH: '0x3c22ec75ea5D745c78fc84762F7F1E6D82a2c5BF', - EURA: '0x6dd7b830896b56812aa667bdd14b71c8b3252f8e', - stEUR: '0xE588611e7A2392507879E3be80531654b85C16aA', - USDA: '0xa86ff337db9107b54862d30d1a598f8be847b05e', - stUSD: '0xBa511aAd739358b2F34285f9E2d5344017b7DcaD', - stataUSDT: '0xc5042f9d9a18e95547864438455c8f05b4987399', - aaveUSDT: '0xAfa788fab589fe61C23DF76905558f4734444D67', - crvUSD: '0x9755e99bdb99495d3d31d953785d993c6df8552e', - GHO: '0xda39E48523770197EF3CbB70C1bf1cCCF9B4b1E7', - USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', - wUSDM: '0x12c9cE6b155c8aaC74004732A621B64bC669bb79', - }, - [constants_1.Network.OPTIMISM]: { - ETH: '0xF6D4E5a7c5215F91f59a95065190CCa24bf64554', - DAI: '0x1337bedc9d22ecbe766df105c9623922a27963ec', - WETH: '0x86bb63148d17d445ed5398ef26aa05bf76dd5b59', - POPS: '0x3cbd9044aaabef08ce93a68448e093cff405ad76', - USDCe: '0xdecc0c09c3b5f6e92ef4184125d5648a66e35298', - USDC: '0x8aF3827a41c26C7F32C81E93bb66e837e0210D5c', - USDT: '0xf977814e90da44bfa03b6295a0616a897441acec', - OP: '0xEBb8EA128BbdFf9a1780A4902A9380022371d466', - aOptWETH: '0x7B7D80C40415F744864f051B806b466e2fbB8E68', - aOptUSDC: '0x8c0Fcf914E90fF5d7f2D02c1576BF4245FaD2B7F', - sBTC: '0xbbb33d2e7bd7ddc722e53da9ca8ee97df41cfabf', - sETH: '0xce3850927d0e631b6082f9d45a6391a3794c51eb', - sUSD: '0xa5f7a39e55d7878bc5bd754ee5d6bd7a7662355b', - wstETH: '0x63f6D9E7d3953106bCaf98832BD9C88A54AfCc9D', - rETH: '0x4c2e69e58b14de9afedfb94319519ce34e087283', - WBTC: '0xb9c8f0d3254007ee4b98970b94544e473cd610ec', - frxETH: '0x4d4edf8291d169f975b99914b6ab3326abb45938', - EURA: '0x9A760aa1Fe631fD9aC0Aee0965736121c7c132cc', - stEUR: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', - USDA: '0x7dFf12833a6f0e88f610E79E11E9506848cCF187', - stUSD: '0xC98b0729695A25152B8D5b6B95709070605A7F60', - crvUSD: '0x7a16fF8270133F063aAb6C9977183D9e72835428', - LUSD: '0xf0a9abb11958a071e168f2ee5bcbacf1abbde9cf', - GRAI: '0x92b051204816DC4fbA7AC1A68a2cf319A9a387CB', - stataUSDT: '0xd55263b84685Ced7e10a77607C7fFD763D495B6e', - aaveUSDT: '0x1Fd458C52fEb7Bb35097ebd9566DB6C269341FDD', - tBTC: '0xf7b4531e52211CC44379102F719cad29411dB053', - PSTAKE: '0xc45398444B83183b2018e0224B3D332b42D492Af', - USDM: '0x57F5E098CaD7A3D1Eed53991D4d66C45C9AF7812', - wUSDM: '0x1Ab0b1A5A239B524702EcE9cCe77E096d4daE75B', - }, - [constants_1.Network.ZKEVM]: { - ETH: '0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9', - WETH: '0xc44b0378e400a9958219ec8f294c23b9976e3c5d', - MATIC: '0x8f2a1450c040b3c19efe9676165d8f30d8280019', - WBTC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c', - USDC: '0x99b31498b0a1dae01fc3433e3cb60f095340935c', - }, - [constants_1.Network.BASE]: { - WETH: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28', - PRIME: '0xe3879b7359695f802d6FD56Bb76fD82C362Dafd6', - ETH: '0xd34ea7278e6bd48defe656bbe263aef11101469c', - MAV: '0xf977814e90da44bfa03b6295a0616a897441acec', - USDC: '0x21bD501F86A0B5cE0907651Df3368DA905B300A9', - USDbC: '0x4bb6b2efe7036020ba6f02a05602546c9f25bf28', - DAI: '0x20f03e26968b179025f65c1f4afadfd3959c8d03', - BAL: '0x854b004700885a61107b458f11ecc169a019b764', - GOLD: '0x1374c25b3710758c326ee0c70ec48b595d5ccf8c', - SDEX: '0xa5d378c05192e3f1f365d6298921879c4d51c5a3', - EURA: '0x5b5614b9fffab7c751799eb12d5cb9165c8c40ad', - stEUR: '0xA9DdD91249DFdd450E81E1c56Ab60E1A62651701', - USDA: '0x7FE4b2632f5AE6d930677D662AF26Bc0a06672b3', - stUSD: '0x8deeffb6047b8ee91b09334eb2a4ca120f43f596', - ALB: '0x365c6d588e8611125de3bea5b9280c304fa54113', - AERO: '0x807877258b55bfefabdd469da1c72731c5070839', - tBTC: '0x9f1920d0cbb63ed03376a1e09fd2851d601234c8', - DOG: '0xbe3ab8a87730684ef1e476064c2e43c3e982f8e8', - stataUSDC: '0x88Cac91ADDE2208039A227B373C2A692C0700547', - aaveUSDC: '0x5DE3c5BE52D7aDbdC3aEFe2eA061A2ECE0C7d766', - USDM: '0x426c4966fC76Bf782A663203c023578B744e4C5E', - crvUSD: '0xBbAbDB1385deA5285113581A7024d6DC04131101', - cbETH: '0x50e011dD1e2b4906F1534623cD134B30422bb11E', - wUSDM: '0xe30965Acd0Ee1CE2e0Cd0AcBFB3596bD6fC78A51', - }, -}; -exports.SmartTokens = Object.keys(exports.Tokens).reduce((acc, _network) => { - const network = parseInt(_network, 10); - acc[+network] = Object.keys(exports.Tokens[network]).reduce((_acc, tokenName) => { - const token = exports.Tokens[network][tokenName]; - if (token.addAllowance && token.addBalance) { - _acc[tokenName] = new smart_tokens_1.SmartToken(token); - } - return _acc; - }, {}); - return acc; -}, {}); -exports.NativeTokenSymbols = { - [constants_1.Network.MAINNET]: 'ETH', - [constants_1.Network.POLYGON]: 'MATIC', - [constants_1.Network.BSC]: 'BNB', - [constants_1.Network.AVALANCHE]: 'AVAX', - [constants_1.Network.FANTOM]: 'FTM', - [constants_1.Network.ARBITRUM]: 'ETH', - [constants_1.Network.OPTIMISM]: 'ETH', - [constants_1.Network.BASE]: 'ETH', -}; -exports.WrappedNativeTokenSymbols = { - [constants_1.Network.MAINNET]: 'WETH', - [constants_1.Network.POLYGON]: 'WMATIC', - [constants_1.Network.BSC]: 'WBNB', - [constants_1.Network.AVALANCHE]: 'WAVAX', - [constants_1.Network.FANTOM]: 'WFTM', - [constants_1.Network.ARBITRUM]: 'WETH', - [constants_1.Network.OPTIMISM]: 'WETH', - [constants_1.Network.BASE]: 'WETH', -}; -//# sourceMappingURL=constants-e2e.js.map \ No newline at end of file diff --git a/tests/constants-e2e.js.map b/tests/constants-e2e.js.map deleted file mode 100644 index 0f77ff873..000000000 --- a/tests/constants-e2e.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"constants-e2e.js","sourceRoot":"","sources":["constants-e2e.ts"],"names":[],"mappings":";;;AAAA,wDAU+B;AAE/B,gDAA0D;AAE7C,QAAA,cAAc,GAAG,4CAA4C,CAAC;AAC9D,QAAA,aAAa,GAAG,4CAA4C,CAAC;AAC7D,QAAA,aAAa,GAAG,4CAA4C,CAAC;AAE7D,QAAA,MAAM,GAEf;IACF,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;QACjB,KAAK,EAAE;YACL,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,IAAI,EAAE;YACJ,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,GAAG,EAAE;YACH,OAAO,EAAE,4CAA4C;YACrD,QAAQ,EAAE,EAAE;SACb;QACD,GAAG,EAAE;YACH,OAAO,EAA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M;IACrB,CAAC,mBAAO,CAAC,SAAS,CAAC,EAAE,OAAO;IAC5B,CAAC,mBAAO,CAAC,MAAM,CAAC,EAAE,MAAM;IACxB,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;IAC1B,CAAC,mBAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;IAC1B,CAAC,mBAAO,CAAC,IAAI,CAAC,EAAE,MAAM;CACvB,CAAC"} \ No newline at end of file diff --git a/tests/smart-tokens.d.ts b/tests/smart-tokens.d.ts deleted file mode 100644 index 1ba9d1d0f..000000000 --- a/tests/smart-tokens.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Address, Token } from '../src/types'; -export declare type StateOverride = { - value: Record; -}; -export declare type StateSimulateApiOverride = { - storage: { - value: Record; - }; -}; -export declare type StateOverrides = { - networkID: string; - stateOverrides: Record; -}; -export declare type AddBalanceFn = (address: Address, amount: string) => Record; -export declare type AddAllowanceFn = (address: Address, spender: Address, amount: string) => Record; -export declare const balanceOfFn: AddBalanceFn; -export declare const balancesFn: AddBalanceFn; -export declare const balanceAndBlacklistStatesFn: AddBalanceFn; -export declare const _balancesFn: AddBalanceFn; -export declare const allowanceFn: AddAllowanceFn; -export declare const _allowancesFn: AddAllowanceFn; -export declare const allowedFn: AddAllowanceFn; -export declare type SmartTokenParams = Token & { - addBalance?: AddBalanceFn; - addAllowance?: AddAllowanceFn; -}; -export declare class SmartToken { - private params; - private value; - constructor(params: SmartTokenParams); - get address(): string; - get token(): Token; - addBalance(address: Address, amount: string): SmartToken; - addAllowance(address: Address, spender: string, amount: string): SmartToken; - applyOverrides(overrides: StateOverrides): void; -} diff --git a/tests/smart-tokens.js b/tests/smart-tokens.js deleted file mode 100644 index ddd01ca43..000000000 --- a/tests/smart-tokens.js +++ /dev/null @@ -1,64 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SmartToken = exports.allowedFn = exports._allowancesFn = exports.allowanceFn = exports._balancesFn = exports.balanceAndBlacklistStatesFn = exports.balancesFn = exports.balanceOfFn = void 0; -const constructAddBalanceFn = (varName) => { - return (address, amount) => { - return { - [`${varName}[${address}]`]: amount, - }; - }; -}; -const constructAddBAllowanceFn = (varName) => { - return (address, spender, amount) => { - return { - [`${varName}[${address}][${spender}]`]: amount, - }; - }; -}; -exports.balanceOfFn = constructAddBalanceFn('balanceOf'); -exports.balancesFn = constructAddBalanceFn('balances'); -exports.balanceAndBlacklistStatesFn = constructAddBalanceFn('balanceAndBlacklistStates'); -exports._balancesFn = constructAddBalanceFn('_balances'); -exports.allowanceFn = constructAddBAllowanceFn('allowance'); -exports._allowancesFn = constructAddBAllowanceFn('_allowances'); -exports.allowedFn = constructAddBAllowanceFn('allowed'); -class SmartToken { - constructor(params) { - this.params = params; - this.value = {}; - if (!params.addBalance) { - throw new Error(`${params.address} ${params.symbol} needs to provide addBalance fn`); - } - if (!params.addAllowance) { - throw new Error(`${params.address} ${params.symbol} needs to provide addAllowance fn`); - } - } - get address() { - return this.params.address; - } - get token() { - return { - address: this.params.address, - decimals: this.params.decimals, - symbol: this.params.symbol, - type: this.params.type, - }; - } - addBalance(address, amount) { - const [key, value] = Object.entries(this.params.addBalance(address, amount))[0]; - this.value[key] = value; - return this; - } - addAllowance(address, spender, amount) { - const [key, value] = Object.entries(this.params.addAllowance(address, spender, amount))[0]; - this.value[key] = value; - return this; - } - applyOverrides(overrides) { - overrides.stateOverrides[this.params.address] = { - value: this.value, - }; - } -} -exports.SmartToken = SmartToken; -//# sourceMappingURL=smart-tokens.js.map \ No newline at end of file diff --git a/tests/smart-tokens.js.map b/tests/smart-tokens.js.map deleted file mode 100644 index 0673066e4..000000000 --- a/tests/smart-tokens.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"smart-tokens.js","sourceRoot":"","sources":["smart-tokens.ts"],"names":[],"mappings":";;;AA2BA,MAAM,qBAAqB,GAAG,CAAC,OAAe,EAAgB,EAAE;IAC9D,OAAO,CAAC,OAAgB,EAAE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3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94145f01b..9b8a30854 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.9.7-fluid-dex.2", + "version": "3.9.7-fluid-dex.3", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib", From ccb3d7c07bb36e32b84aed26aa40cb1440d60c52 Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 30 Oct 2024 13:21:25 +0300 Subject: [PATCH 60/64] fix for integration tests --- .../fluid-dex/fluid-dex-integration.test.ts | 49 ++++++++++--------- src/dex/fluid-dex/fluid-dex.ts | 4 +- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index 3eb0b7741..ebe4421d8 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -33,13 +33,14 @@ import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; function getReaderCalldata( exchangeAddress: string, readerIface: Interface, + poolAddress: string, amounts: bigint[], funcName: string, ) { return amounts.map(amount => ({ target: exchangeAddress, callData: readerIface.encodeFunctionData(funcName, [ - '0x0b1a513ee24972daef112bc777a5610d4325c9e7', + poolAddress, funcName == 'estimateSwapIn' ? true : false, amount, funcName == 'estimateSwapIn' ? 0 : 2n * amount, @@ -60,6 +61,7 @@ function decodeReaderResult( async function checkOnChainPricing( fluidDex: FluidDex, funcName: string, + poolAddress: string, blockNumber: number, prices: bigint[], amounts: bigint[], @@ -71,9 +73,11 @@ async function checkOnChainPricing( const readerCallData = getReaderCalldata( resolverAddress, readerIface, + poolAddress, amounts.slice(1), funcName, ); + const readerResult = ( await fluidDex.dexHelper.multiContract.methods .aggregate(readerCallData) @@ -83,6 +87,8 @@ async function checkOnChainPricing( const expectedPrices = [0n].concat( decodeReaderResult(readerResult, readerIface, funcName), ); + + expect(prices).toEqual(expectedPrices); } async function testPricingOnNetwork( @@ -138,6 +144,7 @@ async function testPricingOnNetwork( await checkOnChainPricing( fluidDex, funcNameToCheck, + poolPrices![0].poolAddresses![0], blockNumber, poolPrices![0].prices, amounts, @@ -153,8 +160,6 @@ describe('FluidDex', function () { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); - const tokens = Tokens[network]; - beforeAll(async () => { blockNumber = await dexHelper.provider.getBlockNumber(); fluidDex = new FluidDex(network, dexKey, dexHelper); @@ -169,16 +174,16 @@ describe('FluidDex', function () { const amountsForSell = [ 0n, - 1n * BI_POWS[8], - 2n * BI_POWS[8], - 3n * BI_POWS[8], - 4n * BI_POWS[8], - 5n * BI_POWS[8], - 6n * BI_POWS[8], - 7n * BI_POWS[8], - 8n * BI_POWS[8], - 9n * BI_POWS[8], - 10n * BI_POWS[8], + 1n * BI_POWS[18], + 2n * BI_POWS[18], + 3n * BI_POWS[18], + 4n * BI_POWS[18], + 5n * BI_POWS[18], + 6n * BI_POWS[18], + 7n * BI_POWS[18], + 8n * BI_POWS[18], + 9n * BI_POWS[18], + 10n * BI_POWS[18], ]; it('wstETH -> ETH, getPoolIdentifiers and getPricesVolume SELL', async function () { @@ -216,16 +221,16 @@ describe('FluidDex', function () { const amountsForSell = [ 0n, - 1n * BI_POWS[6], - 2n * BI_POWS[6], - 3n * BI_POWS[6], - 4n * BI_POWS[6], - 5n * BI_POWS[6], - 6n * BI_POWS[6], - 7n * BI_POWS[6], - 8n * BI_POWS[6], - 9n * BI_POWS[6], 10n * BI_POWS[6], + 20n * BI_POWS[6], + 30n * BI_POWS[6], + 40n * BI_POWS[6], + 50n * BI_POWS[6], + 60n * BI_POWS[6], + 70n * BI_POWS[6], + 80n * BI_POWS[6], + 90n * BI_POWS[6], + 100n * BI_POWS[6], ]; it('USDC -> USDT getPoolIdentifiers and getPricesVolume SELL', async function () { diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 9884d8b33..7958e8e48 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -139,6 +139,8 @@ export class FluidDex extends SimpleExchange implements IDex { side: SwapSide, blockNumber: number, ): Promise { + if (side === SwapSide.BUY) return []; + const pool = await this.getPoolByTokenPair( srcToken.address, destToken.address, @@ -183,7 +185,7 @@ export class FluidDex extends SimpleExchange implements IDex { if (srcToken.address.toLowerCase() === destToken.address.toLowerCase()) return null; - if (side === SwapSide.BUY) throw new Error(`Buy not supported`); + if (side === SwapSide.BUY) return null; // Get the pool to use. const pool = await this.getPoolByTokenPair( srcToken.address, From 9ee964be36e3d6b729b7e5f41f8c19f7fae457cc Mon Sep 17 00:00:00 2001 From: Alexander Burkut Date: Wed, 30 Oct 2024 14:14:13 +0300 Subject: [PATCH 61/64] fix integration tests --- src/dex/fluid-dex/fluid-dex-e2e.test.ts | 1 - .../fluid-dex/fluid-dex-integration.test.ts | 36 ++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex-e2e.test.ts b/src/dex/fluid-dex/fluid-dex-e2e.test.ts index c9d101329..f0c42d91f 100644 --- a/src/dex/fluid-dex/fluid-dex-e2e.test.ts +++ b/src/dex/fluid-dex/fluid-dex-e2e.test.ts @@ -12,7 +12,6 @@ import { } from '../../../tests/constants-e2e'; import { Network, ContractMethod, SwapSide } from '../../constants'; import { generateConfig } from '../../config'; -import { DummyDexHelper } from '../../dex-helper'; /* README diff --git a/src/dex/fluid-dex/fluid-dex-integration.test.ts b/src/dex/fluid-dex/fluid-dex-integration.test.ts index ebe4421d8..1002281db 100644 --- a/src/dex/fluid-dex/fluid-dex-integration.test.ts +++ b/src/dex/fluid-dex/fluid-dex-integration.test.ts @@ -14,6 +14,8 @@ import { } from '../../../tests/utils'; import { Tokens } from '../../../tests/constants-e2e'; import ResolverABI from '../../abi/fluid-dex/resolver.abi.json'; +import { Contract } from 'ethers'; +import { Pool } from './types'; /* README @@ -36,12 +38,18 @@ function getReaderCalldata( poolAddress: string, amounts: bigint[], funcName: string, + pools: { address: string; token0: string; token1: string }[], + srcToken: string, ) { + const pool = pools.find( + item => item.address.toLowerCase() === poolAddress.toLowerCase(), + ); + return amounts.map(amount => ({ target: exchangeAddress, callData: readerIface.encodeFunctionData(funcName, [ poolAddress, - funcName == 'estimateSwapIn' ? true : false, + pool!.token0.toLowerCase() === srcToken.toLowerCase() ? true : false, amount, funcName == 'estimateSwapIn' ? 0 : 2n * amount, ]), @@ -65,17 +73,36 @@ async function checkOnChainPricing( blockNumber: number, prices: bigint[], amounts: bigint[], + dexHelper: DummyDexHelper, + srcToken: string, ) { const resolverAddress = '0xE8a07a32489BD9d5a00f01A55749Cf5cB854Fd13'; const readerIface = new Interface(ResolverABI); + const resolverContract = new Contract( + resolverAddress, + ResolverABI, + dexHelper.provider, + ); + const rawResult = await resolverContract.callStatic.getAllPools({ + blockTag: blockNumber, + }); + + const pools: Pool[] = rawResult.map((result: any) => ({ + address: result[0], + token0: result[1], + token1: result[2], + })); + const readerCallData = getReaderCalldata( resolverAddress, readerIface, poolAddress, amounts.slice(1), funcName, + pools, + srcToken, ); const readerResult = ( @@ -101,6 +128,7 @@ async function testPricingOnNetwork( side: SwapSide, amounts: bigint[], funcNameToCheck: string, + dexHelper: DummyDexHelper, ) { const networkTokens = Tokens[network]; @@ -148,6 +176,8 @@ async function testPricingOnNetwork( blockNumber, poolPrices![0].prices, amounts, + dexHelper, + networkTokens[srcTokenSymbol].address, ); } @@ -197,6 +227,7 @@ describe('FluidDex', function () { SwapSide.SELL, amountsForSell, 'estimateSwapIn', + dexHelper, ); }); @@ -211,6 +242,7 @@ describe('FluidDex', function () { SwapSide.SELL, amountsForSell, 'estimateSwapIn', + dexHelper, ); }); }); @@ -244,6 +276,7 @@ describe('FluidDex', function () { SwapSide.SELL, amountsForSell, 'estimateSwapIn', + dexHelper, ); }); @@ -258,6 +291,7 @@ describe('FluidDex', function () { SwapSide.SELL, amountsForSell, 'estimateSwapIn', + dexHelper, ); }); }); From 28ad69761c6ee9113efc4f97b44b349fc824fbce Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Wed, 30 Oct 2024 16:50:04 +0200 Subject: [PATCH 62/64] fix: apply fee after `swapRoutingIn` on `FluidDex` --- src/dex/fluid-dex/fluid-dex.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index 7958e8e48..b0704e119 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -31,6 +31,7 @@ import { getDexKeysWithNetwork, getBigIntPow } from '../../utils'; import { extractReturnAmountPosition } from '../../executor/utils'; import { MultiResult } from '../../lib/multi-wrapper'; import { generalDecoder } from '../../lib/decoders'; +import { BigNumber } from 'ethers'; export class FluidDex extends SimpleExchange implements IDex { eventPools: { [id: string]: FluidDexEventPool } = {}; @@ -360,15 +361,14 @@ export class FluidDex extends SimpleExchange implements IDex { return 0n; } const amountInAdjusted = - (((amountIn * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT) * - BigInt(10 ** 12)) / - BigInt(10 ** inDecimals); + (amountIn * BigInt(10 ** 12)) / BigInt(10 ** inDecimals); const amountOut = this.swapInAdjusted( swap0To1, amountInAdjusted, // Convert back to number for internal calculations colReserves, debtReserves, + fee, ); const result = (amountOut * BigInt(10 ** outDecimals)) / BigInt(10 ** 12); return result; @@ -387,6 +387,7 @@ export class FluidDex extends SimpleExchange implements IDex { amountToSwap: bigint, colReserves: CollateralReserves, debtReserves: DebtReserves, + fee: bigint, ): bigint { const { token0RealReserves, @@ -468,22 +469,26 @@ export class FluidDex extends SimpleExchange implements IDex { if (a <= BigInt(0)) { // Entire trade routes through debt pool amountOutDebt = this.getAmountOut( - amountToSwap, + this.applyFee(amountToSwap, fee), debtIReserveIn, debtIReserveOut, ); } else if (a >= amountToSwap) { // Entire trade routes through collateral pool amountOutCollateral = this.getAmountOut( - amountToSwap, + this.applyFee(amountToSwap, fee), colIReserveIn, colIReserveOut, ); } else { // Trade routes through both pools - amountOutCollateral = this.getAmountOut(a, colIReserveIn, colIReserveOut); + amountOutCollateral = this.getAmountOut( + this.applyFee(a, fee), + colIReserveIn, + colIReserveOut, + ); amountOutDebt = this.getAmountOut( - amountToSwap - a, + this.applyFee(amountToSwap - a, fee), debtIReserveIn, debtIReserveOut, ); @@ -501,6 +506,10 @@ export class FluidDex extends SimpleExchange implements IDex { return totalAmountOut; } + applyFee(amount: bigint, fee: bigint): bigint { + return (amount * (this.FEE_100_PERCENT - fee)) / this.FEE_100_PERCENT; + } + /** * 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. From 631cd72f59a5cfa70abc08330f6688cf96fec1fb Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Wed, 30 Oct 2024 16:52:50 +0200 Subject: [PATCH 63/64] fix: perform more precise `sqrt` on bignumbers in `FluidDex` --- src/dex/fluid-dex/fluid-dex.ts | 17 +++++++---------- src/dex/fluid-dex/utils.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 src/dex/fluid-dex/utils.ts diff --git a/src/dex/fluid-dex/fluid-dex.ts b/src/dex/fluid-dex/fluid-dex.ts index b0704e119..be13c52fa 100644 --- a/src/dex/fluid-dex/fluid-dex.ts +++ b/src/dex/fluid-dex/fluid-dex.ts @@ -32,6 +32,7 @@ import { extractReturnAmountPosition } from '../../executor/utils'; import { MultiResult } from '../../lib/multi-wrapper'; import { generalDecoder } from '../../lib/decoders'; import { BigNumber } from 'ethers'; +import { sqrt } from './utils'; export class FluidDex extends SimpleExchange implements IDex { eventPools: { [id: string]: FluidDexEventPool } = {}; @@ -610,18 +611,14 @@ export class FluidDex extends SimpleExchange implements IDex { ): bigint { // Adding 1e18 precision - const xyRoot = BigInt(Math.floor(Math.sqrt(Number(x * y * BigInt(1e18))))); - const x2y2Root = BigInt( - Math.floor(Math.sqrt(Number(x2 * y2 * BigInt(1e18)))), - ); + const xyRoot = sqrt(BigNumber.from(x).mul(y).mul(BigInt(1e18))).toBigInt(); + const x2y2Root = sqrt( + BigNumber.from(x2).mul(y2).mul(BigInt(1e18)), + ).toBigInt(); // Calculating 'a' using the given formula - const a = - (Number(y2) * Number(xyRoot) + - Number(t) * Number(xyRoot) - - Number(y) * Number(x2y2Root)) / - (Number(xyRoot) + Number(x2y2Root)); - return BigInt(Math.floor(a)); + const a = (y2 * xyRoot + t * xyRoot - y * x2y2Root) / (xyRoot + x2y2Root); + return a; } /** diff --git a/src/dex/fluid-dex/utils.ts b/src/dex/fluid-dex/utils.ts new file mode 100644 index 000000000..ff9dd3620 --- /dev/null +++ b/src/dex/fluid-dex/utils.ts @@ -0,0 +1,15 @@ +import { BigNumber } from 'ethers'; + +const ONE = BigNumber.from(1); +const TWO = BigNumber.from(2); + +export function sqrt(value: BigNumber) { + let x = value; + let z = x.add(ONE).div(TWO); + let y = x; + while (z.sub(y).isNegative()) { + y = z; + z = x.div(z).add(z).div(TWO); + } + return y; +} From cb7a46f555e6650cbfe690d144986bab91e6d291 Mon Sep 17 00:00:00 2001 From: Danylo Kanievskyi Date: Wed, 30 Oct 2024 17:08:12 +0200 Subject: [PATCH 64/64] 3.10.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 285182360..3a394ec2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@paraswap/dex-lib", - "version": "3.10.0", + "version": "3.10.1", "main": "build/index.js", "types": "build/index.d.ts", "repository": "https://github.com/paraswap/paraswap-dex-lib",