Skip to content

Commit

Permalink
update pool state logs and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy-wombat committed Nov 3, 2023
1 parent 0e81d78 commit 22e5316
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 57 deletions.
100 changes: 52 additions & 48 deletions src/dex/wombat/wombat-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
);
}
});
});
});
24 changes: 15 additions & 9 deletions src/dex/wombat/wombat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
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(
Expand Down Expand Up @@ -230,7 +232,9 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
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;
}

Expand All @@ -241,7 +245,8 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
state.asset[srcTokenAddress] &&
state.asset[destTokenAddress] &&
(liquidityThresholdInUSD === 0 ||
this.poolLiquidityUSD![poolAddress] > liquidityThresholdInUSD)
(this.poolLiquidityUSD![poolAddress] &&
this.poolLiquidityUSD![poolAddress] > liquidityThresholdInUSD))
) {
pools.push(poolAddress);
}
Expand Down Expand Up @@ -332,14 +337,16 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
const usdPromises = [];
const poolStates: { [poolAddress: string]: DeepReadonly<PoolState> } = {};
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;
Expand Down Expand Up @@ -379,15 +386,14 @@ export class Wombat extends SimpleExchange implements IDex<WombatData> {
limit: number,
): Promise<PoolLiquidity[]> {
if (!this.poolLiquidityUSD) await this.updatePoolState();
const blockNumber = await this.dexHelper.provider.getBlockNumber();
tokenAddress = tokenAddress.toLowerCase();
const pools: string[] = [];
const poolStates: { [poolAddress: string]: DeepReadonly<PoolState> } = {};
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;
}
Expand Down

0 comments on commit 22e5316

Please sign in to comment.