diff --git a/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts b/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts index e75f37b02..b855fc257 100644 --- a/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts +++ b/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts @@ -71,29 +71,28 @@ function testForNetwork( describe('AaveV3Stata E2E', () => { const dexKey = 'AaveV3StataV2'; - // polygon is not yet live - describe.skip('Polygon', () => { - const network = Network.POLYGON; + describe('Mainnet', () => { + const network = Network.MAINNET; const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [ [ { - name: 'USDCn', + name: 'USDT', amount: '100000', }, { - name: 'stataUSDCn', + name: 'waEthUSDT', amount: '100000', }, ], [ { - name: 'aaveUSDCn', + name: 'aaveUSDT', amount: '100000', skipBuy: true, }, { - name: 'stataUSDCn', + name: 'waEthUSDT', amount: '100000', }, ], @@ -112,28 +111,29 @@ describe('AaveV3Stata E2E', () => { }); }); - describe('Mainnet', () => { - const network = Network.MAINNET; + // polygon is not yet live + describe.skip('Polygon', () => { + const network = Network.POLYGON; const pairs: { name: string; amount: string; skipBuy?: boolean }[][] = [ [ { - name: 'USDT', + name: 'USDCn', amount: '100000', }, { - name: 'waEthUSDT', + name: 'stataUSDCn', amount: '100000', }, ], [ { - name: 'aaveUSDT', + name: 'aaveUSDCn', amount: '100000', skipBuy: true, }, { - name: 'waEthUSDT', + name: 'stataUSDCn', amount: '100000', }, ], diff --git a/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-integration.test.ts b/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-integration.test.ts index c0c8f8d27..6dc153323 100644 --- a/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-integration.test.ts +++ b/src/dex/aave-v3-stata-v2/aave-v3-stata-v2-integration.test.ts @@ -39,13 +39,12 @@ function decodeReaderResult( async function checkOnChainPricing( aaveV3Statav2: AaveV3StataV2, + exchangeAddress: string, funcName: string, blockNumber: number, prices: bigint[], amounts: bigint[], ) { - const exchangeAddress = '0x2dca80061632f3f87c9ca28364d1d0c30cd79a19'; // stataUSDCn - const readerIface = AaveV3StataV2.stata; const readerCallData = getReaderCalldata( @@ -76,6 +75,7 @@ async function testPricingOnNetwork( destTokenSymbol: string, side: SwapSide, amounts: bigint[], + exchangeAddress: string, funcNameToCheck: string, ) { const networkTokens = Tokens[network]; @@ -116,6 +116,7 @@ async function testPricingOnNetwork( // Check if onchain pricing equals to calculated ones await checkOnChainPricing( aaveV3Statav2, + exchangeAddress, funcNameToCheck, blockNumber, poolPrices![0].prices, @@ -123,11 +124,167 @@ async function testPricingOnNetwork( ); } -describe('AaveV3Stata', function () { - const dexKey = 'AaveV3Stata'; +describe('AaveV3StataV2', function () { + const dexKey = 'AaveV3StataV2'; let blockNumber: number; let aaveV3Statav2: AaveV3StataV2; + describe('Mainnet', () => { + const network = Network.MAINNET; + const dexHelper = new DummyDexHelper(network); + + const tokens = Tokens[network]; + + const srcTokenSymbol = 'USDT'; + const destTokenSymbol = 'waEthUSDT'; + + 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(); + aaveV3Statav2 = new AaveV3StataV2(network, dexKey, dexHelper); + if (aaveV3Statav2.initializePricing) { + await aaveV3Statav2.initializePricing(blockNumber); + } + }); + + it('getPoolIdentifiers and getPricesVolume SELL USDT -> waEthUSDT', async function () { + await testPricingOnNetwork( + aaveV3Statav2, + network, + dexKey, + blockNumber, + srcTokenSymbol, + destTokenSymbol, + SwapSide.SELL, + amountsForSell, + '0x7Bc3485026Ac48b6cf9BaF0A377477Fff5703Af8', + 'previewDeposit', + ); + }); + + it('getPoolIdentifiers and getPricesVolume SELL waEthUSDT -> USDT ', async function () { + await testPricingOnNetwork( + aaveV3Statav2, + network, + dexKey, + blockNumber, + destTokenSymbol, + srcTokenSymbol, + SwapSide.SELL, + amountsForSell, + '0x7Bc3485026Ac48b6cf9BaF0A377477Fff5703Af8', + 'previewRedeem', + ); + }); + + it('getPoolIdentifiers and getPricesVolume BUY USDT -> waEthUSDT', async function () { + await testPricingOnNetwork( + aaveV3Statav2, + network, + dexKey, + blockNumber, + srcTokenSymbol, + destTokenSymbol, + SwapSide.BUY, + amountsForBuy, + '0x7Bc3485026Ac48b6cf9BaF0A377477Fff5703Af8', + 'previewMint', + ); + }); + + it('getPoolIdentifiers and getPricesVolume BUY waEthUSDT -> USDT', async function () { + await testPricingOnNetwork( + aaveV3Statav2, + network, + dexKey, + blockNumber, + destTokenSymbol, + srcTokenSymbol, + SwapSide.BUY, + amountsForBuy, + '0x7Bc3485026Ac48b6cf9BaF0A377477Fff5703Af8', + 'previewWithdraw', + ); + }); + + it(`getTopPoolsForToken - ${srcTokenSymbol}`, async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + const newAaveV3Stata = new AaveV3StataV2(network, dexKey, dexHelper); + if (newAaveV3Stata.updatePoolState) { + await newAaveV3Stata.updatePoolState(); + } + const poolLiquidity = await newAaveV3Stata.getTopPoolsForToken( + tokens[srcTokenSymbol].address, + 10, + ); + console.log( + `${srcTokenSymbol} Top Pools:`, + JSON.stringify(poolLiquidity, null, 2), + ); + + if (!newAaveV3Stata.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][srcTokenSymbol].address, + dexKey, + ); + } + }); + + it(`getTopPoolsForToken - ${destTokenSymbol}`, async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + const newAaveV3Stata = new AaveV3StataV2(network, dexKey, dexHelper); + if (newAaveV3Stata.updatePoolState) { + await newAaveV3Stata.updatePoolState(); + } + const poolLiquidity = await newAaveV3Stata.getTopPoolsForToken( + tokens[destTokenSymbol].address, + 10, + ); + console.log( + `${destTokenSymbol} Top Pools:`, + JSON.stringify(poolLiquidity, null, 2), + ); + + if (!newAaveV3Stata.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][destTokenSymbol].address, + dexKey, + ); + } + }); + }); + // polygon is not yet live describe.skip('Polygon', () => { const network = Network.POLYGON; @@ -184,6 +341,7 @@ describe('AaveV3Stata', function () { destTokenSymbol, SwapSide.SELL, amountsForSell, + '0x2dca80061632f3f87c9ca28364d1d0c30cd79a19', 'previewDeposit', ); }); @@ -198,6 +356,7 @@ describe('AaveV3Stata', function () { srcTokenSymbol, SwapSide.SELL, amountsForSell, + '0x2dca80061632f3f87c9ca28364d1d0c30cd79a19', 'previewRedeem', ); }); @@ -212,6 +371,7 @@ describe('AaveV3Stata', function () { destTokenSymbol, SwapSide.BUY, amountsForBuy, + '0x2dca80061632f3f87c9ca28364d1d0c30cd79a19', 'previewMint', ); }); @@ -226,6 +386,7 @@ describe('AaveV3Stata', function () { srcTokenSymbol, SwapSide.BUY, amountsForBuy, + '0x2dca80061632f3f87c9ca28364d1d0c30cd79a19', 'previewWithdraw', ); }); diff --git a/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts b/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts index bde522f80..312914e01 100644 --- a/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts +++ b/src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts @@ -23,7 +23,7 @@ import { TokenType, } from './types'; import { SimpleExchange } from '../simple-exchange'; -import { AaveV3StataConfig, Adapters } from './config'; +import { AaveV3StataConfig } from './config'; import { Interface } from '@ethersproject/abi'; import { fetchTokenList } from './utils'; import { @@ -70,7 +70,6 @@ export class AaveV3StataV2 readonly dexKey: string, readonly dexHelper: IDexHelper, protected config = AaveV3StataConfig[dexKey][network], - protected adapters = Adapters[network], ) { super(dexHelper, dexKey); this.logger = dexHelper.getLogger(dexKey); diff --git a/src/dex/aave-v3-stata-v2/config.ts b/src/dex/aave-v3-stata-v2/config.ts index 729200583..d4b52b3a8 100644 --- a/src/dex/aave-v3-stata-v2/config.ts +++ b/src/dex/aave-v3-stata-v2/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'; import { AaveV3Ethereum, AaveV3EthereumLido, @@ -22,9 +22,3 @@ export const AaveV3StataConfig: DexConfigMap = { }, }, }; - -export const Adapters: Record = { - // TODO: add adapters for each chain for V5 support - [Network.MAINNET]: { [SwapSide.SELL]: [{ name: '', index: 0 }] }, - [Network.GNOSIS]: { [SwapSide.SELL]: [{ name: '', index: 0 }] }, -}; diff --git a/src/dex/aave-v3-stata-v2/types.ts b/src/dex/aave-v3-stata-v2/types.ts index dda89bfb8..d62de7f82 100644 --- a/src/dex/aave-v3-stata-v2/types.ts +++ b/src/dex/aave-v3-stata-v2/types.ts @@ -1,11 +1,6 @@ import { Address } from '../../types'; -export type PoolState = { - // TODO: poolState is the state of event - // subscriber. This should be the minimum - // set of parameters required to compute - // pool prices. Complete me! -}; +export type PoolState = {}; export enum TokenType { UNDERLYING, @@ -15,10 +10,6 @@ export enum TokenType { } export type AaveV3StataV2Data = { - // TODO: AaveV3StataData 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! exchange: Address; srcType: TokenType; destType: TokenType;