From 22e531656103d255f519f16acfcb9cecd0f948c4 Mon Sep 17 00:00:00 2001 From: Koala <142200506+koala0814@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:38:28 +0800 Subject: [PATCH] update pool state logs and integration tests --- src/dex/wombat/wombat-integration.test.ts | 100 +++++++++++----------- src/dex/wombat/wombat.ts | 24 ++++-- 2 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/dex/wombat/wombat-integration.test.ts b/src/dex/wombat/wombat-integration.test.ts index 16b3e7459..e7dfb3727 100644 --- a/src/dex/wombat/wombat-integration.test.ts +++ b/src/dex/wombat/wombat-integration.test.ts @@ -189,12 +189,33 @@ describe('Wombat', function () { beforeAll(async () => { blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); wombat = new Wombat(network, dexKey, dexHelper); - if (wombat.initializePricing) { - await wombat.initializePricing(blockNumber); + }); + + it('getTopPoolsForToken', async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + if (wombat.updatePoolState) { + await wombat.updatePoolState(); + } + const poolLiquidity = await wombat.getTopPoolsForToken( + tokens[srcTokenSymbol].address, + 10, + ); + console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); + + if (!wombat.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][srcTokenSymbol].address, + dexKey, + ); } }); it('getPoolIdentifiers and getPricesVolume SELL', async function () { + if (wombat.initializePricing) { + await wombat.initializePricing(blockNumber); + } await testPricingOnNetwork( wombat, network, @@ -209,6 +230,9 @@ describe('Wombat', function () { }); it('getPoolIdentifiers and getPricesVolume BUY', async function () { + if (wombat.initializePricing) { + await wombat.initializePricing(blockNumber); + } await testPricingOnNetwork( wombat, network, @@ -221,28 +245,6 @@ describe('Wombat', function () { 'quotePotentialSwap', ); }); - - it('getTopPoolsForToken', async function () { - // We have to check without calling initializePricing, because - // pool-tracker is not calling that function - const newWombat = new Wombat(network, dexKey, dexHelper); - if (newWombat.updatePoolState) { - await newWombat.updatePoolState(); - } - const poolLiquidity = await newWombat.getTopPoolsForToken( - tokens[srcTokenSymbol].address, - 10, - ); - console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); - - if (!newWombat.hasConstantPriceLargeAmounts) { - checkPoolsLiquidity( - poolLiquidity, - Tokens[network][srcTokenSymbol].address, - dexKey, - ); - } - }); }); describe('Arbitrum', () => { @@ -285,12 +287,33 @@ describe('Wombat', function () { beforeAll(async () => { blockNumber = await dexHelper.web3Provider.eth.getBlockNumber(); wombat = new Wombat(network, dexKey, dexHelper); - if (wombat.initializePricing) { - await wombat.initializePricing(blockNumber); + }); + + it('getTopPoolsForToken', async function () { + // We have to check without calling initializePricing, because + // pool-tracker is not calling that function + if (wombat.updatePoolState) { + await wombat.updatePoolState(); + } + const poolLiquidity = await wombat.getTopPoolsForToken( + tokens[srcTokenSymbol].address, + 10, + ); + console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); + + if (!wombat.hasConstantPriceLargeAmounts) { + checkPoolsLiquidity( + poolLiquidity, + Tokens[network][srcTokenSymbol].address, + dexKey, + ); } }); it('getPoolIdentifiers and getPricesVolume SELL', async function () { + if (wombat.initializePricing) { + await wombat.initializePricing(blockNumber); + } await testPricingOnNetwork( wombat, network, @@ -305,6 +328,9 @@ describe('Wombat', function () { }); it('getPoolIdentifiers and getPricesVolume BUY', async function () { + if (wombat.initializePricing) { + await wombat.initializePricing(blockNumber); + } await testPricingOnNetwork( wombat, network, @@ -317,27 +343,5 @@ describe('Wombat', function () { 'quotePotentialSwap', ); }); - - it('getTopPoolsForToken', async function () { - // We have to check without calling initializePricing, because - // pool-tracker is not calling that function - const newWombat = new Wombat(network, dexKey, dexHelper); - if (newWombat.updatePoolState) { - await newWombat.updatePoolState(); - } - const poolLiquidity = await newWombat.getTopPoolsForToken( - tokens[srcTokenSymbol].address, - 10, - ); - console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity); - - if (!newWombat.hasConstantPriceLargeAmounts) { - checkPoolsLiquidity( - poolLiquidity, - Tokens[network][srcTokenSymbol].address, - dexKey, - ); - } - }); }); }); diff --git a/src/dex/wombat/wombat.ts b/src/dex/wombat/wombat.ts index 3d8ab613e..a9f487be8 100644 --- a/src/dex/wombat/wombat.ts +++ b/src/dex/wombat/wombat.ts @@ -174,7 +174,9 @@ export class Wombat extends SimpleExchange implements IDex { for (const poolAddress of pools) { let state = await this.pools![poolAddress].getState(blockNumber); if (!state) { - this.logger.error(`State is null in getPricesVolume`); + this.logger.warn( + `State of pool ${poolAddress} is null in getPricesVolume, skipping...`, + ); continue; } const [unit, ...prices] = this.computePrices( @@ -230,7 +232,9 @@ export class Wombat extends SimpleExchange implements IDex { for (const [poolAddress, pool] of Object.entries(this.pools)) { let stateOj = await pool.getState(blockNumber); if (!stateOj) { - this.logger.error(`State is null in findPools`); + this.logger.warn( + `State of pool ${poolAddress} is null in findPools, skipping...`, + ); continue; } @@ -241,7 +245,8 @@ export class Wombat extends SimpleExchange implements IDex { state.asset[srcTokenAddress] && state.asset[destTokenAddress] && (liquidityThresholdInUSD === 0 || - this.poolLiquidityUSD![poolAddress] > liquidityThresholdInUSD) + (this.poolLiquidityUSD![poolAddress] && + this.poolLiquidityUSD![poolAddress] > liquidityThresholdInUSD)) ) { pools.push(poolAddress); } @@ -332,14 +337,16 @@ export class Wombat extends SimpleExchange implements IDex { const usdPromises = []; const poolStates: { [poolAddress: string]: DeepReadonly } = {}; const poolStateObjs = await Promise.all( - Object.values(this.pools).map(pool => pool.getState(blockNumber)), + Object.values(this.pools).map(pool => pool.getState()), ); for (const [poolAddress, pool] of Object.entries(this.pools)) { const index = Object.keys(this.pools).indexOf(poolAddress); let state = poolStateObjs[index]; if (!state) { - this.logger.error(`State of ${poolAddress} is null in updatePoolState`); + this.logger.warn( + `State of ${poolAddress} is null in updatePoolState, skipping...`, + ); continue; } poolStates[poolAddress] = state.value; @@ -379,15 +386,14 @@ export class Wombat extends SimpleExchange implements IDex { limit: number, ): Promise { if (!this.poolLiquidityUSD) await this.updatePoolState(); - const blockNumber = await this.dexHelper.provider.getBlockNumber(); tokenAddress = tokenAddress.toLowerCase(); const pools: string[] = []; const poolStates: { [poolAddress: string]: DeepReadonly } = {}; for (const [poolAddress, eventPool] of Object.entries(this.pools)) { - let state = await eventPool.getState(blockNumber); + let state = await eventPool.getState(); if (!state) { - this.logger.error( - `State of ${poolAddress} is null in getTopPoolsForToken`, + this.logger.warn( + `State of ${poolAddress} is null in getTopPoolsForToken, skipping...`, ); continue; }