Skip to content

Commit

Permalink
add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aburkut committed Dec 19, 2024
1 parent dcaa14d commit 6954fe5
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 37 deletions.
26 changes: 13 additions & 13 deletions src/dex/aave-v3-stata-v2/aave-v3-stata-v2-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
Expand All @@ -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',
},
],
Expand Down
169 changes: 165 additions & 4 deletions src/dex/aave-v3-stata-v2/aave-v3-stata-v2-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -76,6 +75,7 @@ async function testPricingOnNetwork(
destTokenSymbol: string,
side: SwapSide,
amounts: bigint[],
exchangeAddress: string,
funcNameToCheck: string,
) {
const networkTokens = Tokens[network];
Expand Down Expand Up @@ -116,18 +116,175 @@ async function testPricingOnNetwork(
// Check if onchain pricing equals to calculated ones
await checkOnChainPricing(
aaveV3Statav2,
exchangeAddress,
funcNameToCheck,
blockNumber,
poolPrices![0].prices,
amounts,
);
}

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;
Expand Down Expand Up @@ -184,6 +341,7 @@ describe('AaveV3Stata', function () {
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
'0x2dca80061632f3f87c9ca28364d1d0c30cd79a19',
'previewDeposit',
);
});
Expand All @@ -198,6 +356,7 @@ describe('AaveV3Stata', function () {
srcTokenSymbol,
SwapSide.SELL,
amountsForSell,
'0x2dca80061632f3f87c9ca28364d1d0c30cd79a19',
'previewRedeem',
);
});
Expand All @@ -212,6 +371,7 @@ describe('AaveV3Stata', function () {
destTokenSymbol,
SwapSide.BUY,
amountsForBuy,
'0x2dca80061632f3f87c9ca28364d1d0c30cd79a19',
'previewMint',
);
});
Expand All @@ -226,6 +386,7 @@ describe('AaveV3Stata', function () {
srcTokenSymbol,
SwapSide.BUY,
amountsForBuy,
'0x2dca80061632f3f87c9ca28364d1d0c30cd79a19',
'previewWithdraw',
);
});
Expand Down
3 changes: 1 addition & 2 deletions src/dex/aave-v3-stata-v2/aave-v3-stata-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions src/dex/aave-v3-stata-v2/config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,9 +22,3 @@ export const AaveV3StataConfig: DexConfigMap<DexParams> = {
},
},
};

export const Adapters: Record<number, AdapterMappings> = {
// TODO: add adapters for each chain for V5 support
[Network.MAINNET]: { [SwapSide.SELL]: [{ name: '', index: 0 }] },
[Network.GNOSIS]: { [SwapSide.SELL]: [{ name: '', index: 0 }] },
};
11 changes: 1 addition & 10 deletions src/dex/aave-v3-stata-v2/types.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 6954fe5

Please sign in to comment.