Skip to content

Commit

Permalink
chore: add more tests on EUR
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS committed Apr 18, 2024
1 parent 529a7d7 commit a27ce09
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 125 deletions.
2 changes: 1 addition & 1 deletion scripts/fetch-event-blocknumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ const provider = new StaticJsonRpcProvider(
network,
);

getBlockNumbersForEvents(address, ABI, eventNames, 0, 200000000, provider);
getBlockNumbersForEvents(address, ABI, eventNames, 0, 20000000, provider);
74 changes: 73 additions & 1 deletion src/dex/angle-staked-stable/angle-staked-stable-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function testForNetwork(
describe(`${network}`, () => {
sideToContractMethods.forEach((contractMethods, side) =>
describe(`${side}`, () => {
// biome-ignore lint/complexity/noForEach: <explanation>
contractMethods.forEach((contractMethod: ContractMethod) => {
describe(`${contractMethod}`, () => {
it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
Expand All @@ -50,6 +51,10 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
1,
);
});
it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
Expand All @@ -63,6 +68,10 @@ function testForNetwork(
contractMethod,
network,
provider,
undefined,
undefined,
undefined,
1,
);
});
});
Expand All @@ -78,7 +87,70 @@ describe('AngleStakedStable E2E', () => {
describe('Mainnet', () => {
const network = Network.MAINNET;

const tokenASymbol: string = 'agEUR';
const tokenASymbol: string = 'EURA';
const tokenBSymbol: string = 'stEUR';

const tokenAAmount: string = '1000000000000000000';
const tokenBAmount: string = '1000000000000000000';
const nativeTokenAmount = '1000000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
});

describe('Arbitrum', () => {
const network = Network.ARBITRUM;

const tokenASymbol: string = 'EURA';
const tokenBSymbol: string = 'stEUR';

const tokenAAmount: string = '1000000000000000000';
const tokenBAmount: string = '1000000000000000000';
const nativeTokenAmount = '1000000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
});

describe('Polygon', () => {
const network = Network.POLYGON;

const tokenASymbol: string = 'EURA';
const tokenBSymbol: string = 'stEUR';

const tokenAAmount: string = '1000000000000000000';
const tokenBAmount: string = '1000000000000000000';
const nativeTokenAmount = '1000000000000000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
);
});

describe('Optimism', () => {
const network = Network.OPTIMISM;

const tokenASymbol: string = 'EURA';
const tokenBSymbol: string = 'stEUR';

const tokenAAmount: string = '1000000000000000000';
Expand Down
26 changes: 20 additions & 6 deletions src/dex/angle-staked-stable/angle-staked-stable-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function fetchPoolState(
// eventName -> blockNumbers
type EventMappings = Record<string, number[]>;

describe('AngleStakedStable EventPool Mainnet', function () {
describe('AngleStakedStable EventPool Mainnet', () => {
const dexKey = 'AngleStakedStable';
const network = Network.MAINNET;
const dexHelper = new DummyDexHelper(network);
Expand All @@ -66,11 +66,22 @@ describe('AngleStakedStable EventPool Mainnet', function () {
// poolAddress -> EventMappings
const eventsToTest: Record<Address, EventMappings> = {
'0x004626a008b1acdc4c74ab51644093b155e59a23': {
Accrued: [],
Deposit: [18134921, 18135441],
Withdraw: [18135030],
Accrued: [
19368181, 19387091, 19387136, 19390671, 19395050, 19395068, 19404404,
19404492, 19407830, 19410813, 19482839, 19575712, 19622932, 19622960,
19632489, 19650535, 19668024, 19668335, 19669259, 19672358, 19675559,
19679409,
],
Deposit: [
19387091, 19387136, 19395050, 19404404, 19410813, 19622932, 19622960,
19632489, 19668335, 19669259, 19672358, 19675559,
],
Withdraw: [
19368181, 19390671, 19395068, 19404492, 19407830, 19482839, 19575712,
19650535, 19679409,
],
ToggledPause: [],
RateUpdated: [18176668],
RateUpdated: [19668024],
},
};

Expand All @@ -84,14 +95,17 @@ describe('AngleStakedStable EventPool Mainnet', function () {
);
});

// biome-ignore lint/complexity/noForEach: <explanation>
Object.entries(eventsToTest).forEach(
([poolAddress, events]: [string, EventMappings]) => {
describe(`Events for ${poolAddress}`, () => {
// biome-ignore lint/complexity/noForEach: <explanation>
Object.entries(events).forEach(
([eventName, blockNumbers]: [string, number[]]) => {
describe(`${eventName}`, () => {
// biome-ignore lint/complexity/noForEach: <explanation>
blockNumbers.forEach((blockNumber: number) => {
it(`State after ${blockNumber}`, async function () {
it(`State after ${blockNumber}`, async () => {
await testEventSubscriber(
angleStakedStablePool,
angleStakedStablePool.addressesSubscribed,
Expand Down
136 changes: 95 additions & 41 deletions src/dex/angle-staked-stable/angle-staked-stable-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async function testPricingOnNetwork(
);
}

describe('AngleStakedStable', function () {
describe('AngleStakedStable', () => {
const dexKey = 'AngleStakedStable';
let blockNumber: number;
let angleStakedStable: AngleStakedStable;
Expand All @@ -159,42 +159,42 @@ describe('AngleStakedStable', function () {
const tokens = Tokens[network];

// Don't forget to update relevant tokens in constant-e2e.ts
const srcTokenSymbol = 'agEUR';
const destTokenSymbol = 'stEUR';
const funcNameSell = 'previewDeposit';
const funcNameBuy = 'previewMint';
const srcTokenSymbolEnter = 'EURA';
const destTokenSymbolEnter = 'stEUR';
const funcNameSellEnter = 'previewDeposit';
const funcNameBuyEnter = 'previewMint';

// const srcTokenSymbol = 'stEUR';
// const destTokenSymbol = 'agEUR';
// const funcNameSell = 'previewRedeem';
// const funcNameBuy = 'previewWithdraw';
const srcTokenSymbolExit = 'stEUR';
const destTokenSymbolExit = 'EURA';
const funcNameSellExit = 'previewRedeem';
const funcNameBuyExit = 'previewWithdraw';

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[srcTokenSymbolEnter].decimals],
2n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
3n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
4n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
5n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
6n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
7n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
8n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
9n * BI_POWS[tokens[srcTokenSymbolEnter].decimals],
10n * BI_POWS[tokens[srcTokenSymbolEnter].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],
1n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
2n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
3n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
4n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
5n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
6n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
7n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
8n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
9n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
10n * BI_POWS[tokens[destTokenSymbolEnter].decimals],
];

beforeAll(async () => {
Expand All @@ -205,35 +205,89 @@ describe('AngleStakedStable', function () {
}
});

it('getPoolIdentifiers and getPricesVolume SELL', async function () {
it('getPoolIdentifiers and getPricesVolume SELL - EURA', async () => {
await testPricingOnNetwork(
angleStakedStable,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
srcTokenSymbolEnter,
destTokenSymbolEnter,
SwapSide.SELL,
amountsForSell,
funcNameSell,
funcNameSellEnter,
);
});

it('getPoolIdentifiers and getPricesVolume BUY', async function () {
it('getPoolIdentifiers and getPricesVolume BUY - stEUR', async () => {
await testPricingOnNetwork(
angleStakedStable,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
srcTokenSymbolEnter,
destTokenSymbolEnter,
SwapSide.BUY,
amountsForBuy,
funcNameBuy,
funcNameBuyEnter,
);
});

it('getTopPoolsForToken', async function () {
it('getPoolIdentifiers and getPricesVolume SELL - stEUR', async () => {
await testPricingOnNetwork(
angleStakedStable,
network,
dexKey,
blockNumber,
srcTokenSymbolExit,
destTokenSymbolExit,
SwapSide.SELL,
amountsForSell,
funcNameSellExit,
);
});

it('getPoolIdentifiers and getPricesVolume BUY - EURA', async () => {
await testPricingOnNetwork(
angleStakedStable,
network,
dexKey,
blockNumber,
srcTokenSymbolExit,
destTokenSymbolExit,
SwapSide.BUY,
amountsForBuy,
funcNameBuyExit,
);
});

it('getTopPoolsForToken -EURA', async () => {
// We have to check without calling initializePricing, because
// pool-tracker is not calling that function
const newAngleStakedStable = new AngleStakedStable(
network,
dexKey,
dexHelper,
);
if (newAngleStakedStable.updatePoolState) {
await newAngleStakedStable.updatePoolState();
}
const poolLiquidity = await newAngleStakedStable.getTopPoolsForToken(
tokens[srcTokenSymbolEnter].address,
10,
);
console.log(`${srcTokenSymbolEnter} Top Pools:`, poolLiquidity);

if (!newAngleStakedStable.hasConstantPriceLargeAmounts) {
checkPoolsLiquidity(
poolLiquidity,
Tokens[network][srcTokenSymbolEnter].address,
dexKey,
);
}
});

it('getTopPoolsForToken - stEUR', async () => {
// We have to check without calling initializePricing, because
// pool-tracker is not calling that function
const newAngleStakedStable = new AngleStakedStable(
Expand All @@ -245,15 +299,15 @@ describe('AngleStakedStable', function () {
await newAngleStakedStable.updatePoolState();
}
const poolLiquidity = await newAngleStakedStable.getTopPoolsForToken(
tokens[srcTokenSymbol].address,
tokens[srcTokenSymbolExit].address,
10,
);
console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
console.log(`${srcTokenSymbolExit} Top Pools:`, poolLiquidity);

if (!newAngleStakedStable.hasConstantPriceLargeAmounts) {
checkPoolsLiquidity(
poolLiquidity,
Tokens[network][srcTokenSymbol].address,
Tokens[network][srcTokenSymbolExit].address,
dexKey,
);
}
Expand Down
Loading

0 comments on commit a27ce09

Please sign in to comment.