@paraswap/dex-lib 3.8.31 → 3.8.32-aave-gsm

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/build/abi/inception/inception-ratio-feed.json +239 -3
  2. package/build/dex/aave-gsm/aave-gsm-pool.d.ts +3 -0
  3. package/build/dex/aave-gsm/aave-gsm-pool.js +30 -0
  4. package/build/dex/aave-gsm/aave-gsm-pool.js.map +1 -1
  5. package/build/dex/aave-gsm/aave-gsm.d.ts +2 -0
  6. package/build/dex/aave-gsm/aave-gsm.js +29 -9
  7. package/build/dex/aave-gsm/aave-gsm.js.map +1 -1
  8. package/build/dex/aave-gsm/types.d.ts +1 -0
  9. package/build/dex/inception/config.d.ts +1 -2
  10. package/build/dex/inception/config.js +1 -4
  11. package/build/dex/inception/config.js.map +1 -1
  12. package/build/dex/inception/inception-event-pool.d.ts +4 -13
  13. package/build/dex/inception/inception-event-pool.js +9 -15
  14. package/build/dex/inception/inception-event-pool.js.map +1 -1
  15. package/build/dex/inception/inception.d.ts +6 -7
  16. package/build/dex/inception/inception.js +36 -17
  17. package/build/dex/inception/inception.js.map +1 -1
  18. package/build/dex/inception/tokens.d.ts +1 -1
  19. package/build/dex/index.js +2 -0
  20. package/build/dex/index.js.map +1 -1
  21. package/build/dex/stkgho/stkgho-pool.js +1 -1
  22. package/build/dex/stkgho/stkgho-pool.js.map +1 -1
  23. package/build/dex/stkgho/stkgho.js +5 -1
  24. package/build/dex/stkgho/stkgho.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/abi/stkGHO.json +1131 -0
  27. package/src/dex/aave-gsm/aave-gsm-e2e.test.ts +2 -1
  28. package/src/dex/aave-gsm/aave-gsm-events.test.ts +3 -0
  29. package/src/dex/aave-gsm/aave-gsm-pool.ts +47 -0
  30. package/src/dex/aave-gsm/aave-gsm.ts +36 -10
  31. package/src/dex/aave-gsm/types.ts +1 -0
  32. package/src/dex/index.ts +2 -0
  33. package/src/dex/stkgho/config.ts +14 -0
  34. package/src/dex/stkgho/stkgho-e2e.test.ts +77 -0
  35. package/src/dex/stkgho/stkgho-events.test.ts +79 -0
  36. package/src/dex/stkgho/stkgho-integration.test.ts +226 -0
  37. package/src/dex/stkgho/stkgho-pool.ts +111 -0
  38. package/src/dex/stkgho/stkgho.ts +221 -0
  39. package/src/dex/stkgho/types.ts +14 -0
  40. package/tests/constants-e2e.ts +4 -0
@@ -76,7 +76,8 @@ describe('AaveGsm E2E', () => {
76
76
  const tokenBSymbol: string = 'USDT';
77
77
 
78
78
  const tokenAAmount: string = '1000000000000000000';
79
- const tokenBAmount: string = '1000000';
79
+ const tokenBAmount: string = '47166262';
80
+ // const tokenBAmount: string = '47166263';
80
81
 
81
82
  testForNetwork(
82
83
  network,
@@ -38,6 +38,9 @@ describe('AaveGsm EventPool Mainnet', function () {
38
38
  const eventsToTest: Record<Address, EventMappings> = {
39
39
  [AaveGsmConfig[dexKey][network].GSM_USDT]: {
40
40
  FeeStrategyUpdated: [], // Hasn't been emitted yet
41
+ BuyAsset: [20634073],
42
+ SellAsset: [20641217, 20641520, 20641913],
43
+ ExposureCapUpdated: [], // Hasn't been emitted yet
41
44
  },
42
45
  };
43
46
 
@@ -47,6 +47,10 @@ export class AaveGsmEventPool extends StatefulEventSubscriber<PoolState> {
47
47
 
48
48
  this.handlers['SwapFreeze'] = this.handleSwapFreeze.bind(this);
49
49
  this.handlers['Seized'] = this.handleSeized.bind(this);
50
+ this.handlers['ExposureCapUpdated'] =
51
+ this.handleExposureCapUpdated.bind(this);
52
+ this.handlers['BuyAsset'] = this.handleBuyAsset.bind(this);
53
+ this.handlers['SellAsset'] = this.handleSellAsset.bind(this);
50
54
  }
51
55
 
52
56
  getIdentifier(): string {
@@ -106,6 +110,11 @@ export class AaveGsmEventPool extends StatefulEventSubscriber<PoolState> {
106
110
  callData: this.aaveGsmIface.encodeFunctionData('getIsSeized', []),
107
111
  decodeFunction: booleanDecode,
108
112
  },
113
+ {
114
+ target: this.gsm,
115
+ callData: this.aaveGsmIface.encodeFunctionData('getExposureCap', []),
116
+ decodeFunction: uint256ToBigInt,
117
+ },
109
118
  ];
110
119
 
111
120
  const results = await this.dexHelper.multiWrapper.tryAggregate<
@@ -118,6 +127,7 @@ export class AaveGsmEventPool extends StatefulEventSubscriber<PoolState> {
118
127
  underlyingLiquidity: results[2].returnData as bigint,
119
128
  isFrozen: results[3].returnData as boolean,
120
129
  isSeized: results[4].returnData as boolean,
130
+ exposureCap: results[5].returnData as bigint,
121
131
  };
122
132
  }
123
133
 
@@ -173,6 +183,43 @@ export class AaveGsmEventPool extends StatefulEventSubscriber<PoolState> {
173
183
  return {
174
184
  ...state,
175
185
  isSeized: true,
186
+ exposureCap: BigInt(0),
187
+ underlyingLiquidity: BigInt(0),
188
+ };
189
+ }
190
+
191
+ async handleExposureCapUpdated(
192
+ event: any,
193
+ state: DeepReadonly<PoolState>,
194
+ log: Readonly<Log>,
195
+ ): Promise<DeepReadonly<PoolState> | null> {
196
+ return {
197
+ ...state,
198
+ exposureCap: BigInt(event.args.newExposureCap),
199
+ };
200
+ }
201
+
202
+ async handleBuyAsset(
203
+ event: any,
204
+ state: DeepReadonly<PoolState>,
205
+ log: Readonly<Log>,
206
+ ): Promise<DeepReadonly<PoolState> | null> {
207
+ return {
208
+ ...state,
209
+ underlyingLiquidity:
210
+ state.underlyingLiquidity - BigInt(event.args.underlyingAmount),
211
+ };
212
+ }
213
+
214
+ async handleSellAsset(
215
+ event: any,
216
+ state: DeepReadonly<PoolState>,
217
+ log: Readonly<Log>,
218
+ ): Promise<DeepReadonly<PoolState> | null> {
219
+ return {
220
+ ...state,
221
+ underlyingLiquidity:
222
+ state.underlyingLiquidity + BigInt(event.args.underlyingAmount),
176
223
  };
177
224
  }
178
225
  }
@@ -1,4 +1,3 @@
1
- import { AsyncOrSync } from 'ts-essentials';
2
1
  import {
3
2
  Token,
4
3
  Address,
@@ -147,25 +146,43 @@ export class AaveGsm extends SimpleExchange implements IDex<AaveGsmData> {
147
146
  return onChainState;
148
147
  }
149
148
 
149
+ canBuyAsset(assetAmount: bigint, state: PoolState) {
150
+ return assetAmount > 0n && state.underlyingLiquidity >= assetAmount;
151
+ }
152
+
153
+ canSellAsset(assetAmount: bigint, state: PoolState) {
154
+ return (
155
+ assetAmount > 0n &&
156
+ state.underlyingLiquidity + assetAmount <= state.exposureCap
157
+ );
158
+ }
159
+
150
160
  getGhoAmountForBuyAsset(assetAmount: bigint, state: PoolState) {
151
- if (assetAmount === 0n) {
161
+ if (!this.canBuyAsset(assetAmount, state)) {
152
162
  return 0n;
153
163
  }
154
164
 
155
165
  const grossAmount = assetAmount * 1_000_000_000_000n; // 18 - 6 = 12 (decimals)
156
166
  const fee = MMath.mulDiv(grossAmount, state.buyFee, 10_000n, true);
157
167
 
158
- return grossAmount + fee;
168
+ const result = grossAmount + fee;
169
+
170
+ return result;
159
171
  }
160
172
 
161
173
  getAssetAmountForBuyAsset(ghoAmount: bigint, state: PoolState) {
162
174
  const grossAmount = (ghoAmount * 10_000n) / (10_000n + state.buyFee);
163
175
 
164
- return grossAmount / 1_000_000_000_000n; // 18 - 6 = 12 (decimals)
176
+ const result = grossAmount / 1_000_000_000_000n; // 18 - 6 = 12 (decimals)
177
+
178
+ if (this.canBuyAsset(result, state)) {
179
+ return result;
180
+ }
181
+ return 0n;
165
182
  }
166
183
 
167
184
  getGhoAmountForSellAsset(assetAmount: bigint, state: PoolState) {
168
- if (assetAmount === 0n) {
185
+ if (!this.canSellAsset(assetAmount, state)) {
169
186
  return 0n;
170
187
  }
171
188
 
@@ -183,7 +200,12 @@ export class AaveGsm extends SimpleExchange implements IDex<AaveGsmData> {
183
200
  true,
184
201
  );
185
202
 
186
- return MMath.mulDiv(grossAmount, 1n, 1_000_000_000_000n, true); // 18 - 6 = 12 (decimals)
203
+ const result = MMath.mulDiv(grossAmount, 1n, 1_000_000_000_000n, true); // 18 - 6 = 12 (decimals)
204
+
205
+ if (this.canSellAsset(result, state)) {
206
+ return result;
207
+ }
208
+ return 0n;
187
209
  }
188
210
 
189
211
  async getPricesVolume(
@@ -224,16 +246,20 @@ export class AaveGsm extends SimpleExchange implements IDex<AaveGsmData> {
224
246
  }
225
247
 
226
248
  if (srcTokenAddress === this.config.GHO && side === SwapSide.BUY) {
227
- endpoint = this.getGhoAmountForBuyAsset;
249
+ // amount = destAmount = assetAmount
250
+ endpoint = this.getGhoAmountForBuyAsset.bind(this);
228
251
  gas = 80_000;
229
252
  } else if (srcTokenAddress === this.config.GHO && side === SwapSide.SELL) {
230
- endpoint = this.getAssetAmountForBuyAsset;
253
+ // amount = srcAmount = ghoAmount
254
+ endpoint = this.getAssetAmountForBuyAsset.bind(this);
231
255
  gas = 80_000;
232
256
  } else if (destTokenAddress === this.config.GHO && side === SwapSide.SELL) {
233
- endpoint = this.getGhoAmountForSellAsset;
257
+ // amount = srcAmount = assetAmount
258
+ endpoint = this.getGhoAmountForSellAsset.bind(this);
234
259
  gas = 70_000;
235
260
  } else {
236
- endpoint = this.getAssetAmountForSellAsset;
261
+ // amount = destAmount = ghoAmount
262
+ endpoint = this.getAssetAmountForSellAsset.bind(this);
237
263
  gas = 70_000;
238
264
  }
239
265
 
@@ -6,6 +6,7 @@ export type PoolState = {
6
6
  underlyingLiquidity: bigint;
7
7
  isFrozen: boolean;
8
8
  isSeized: boolean;
9
+ exposureCap: bigint;
9
10
  };
10
11
 
11
12
  export type AaveGsmData = {
package/src/dex/index.ts CHANGED
@@ -88,6 +88,7 @@ import { ConcentratorArusd } from './concentrator-arusd/concentrator-arusd';
88
88
  import { FxProtocolRusd } from './fx-protocol-rusd/fx-protocol-rusd';
89
89
  import { AaveGsm } from './aave-gsm/aave-gsm';
90
90
  import { LitePsm } from './lite-psm/lite-psm';
91
+ import { StkGHO } from './stkgho/stkgho';
91
92
 
92
93
  const LegacyDexes = [
93
94
  CurveV2,
@@ -171,6 +172,7 @@ const Dexes = [
171
172
  FxProtocolRusd,
172
173
  AaveGsm,
173
174
  LitePsm,
175
+ StkGHO,
174
176
  ];
175
177
 
176
178
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -0,0 +1,14 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ import { Network } from '../../constants';
4
+
5
+ import { MiscEthereum } from '@bgd-labs/aave-address-book';
6
+
7
+ export const StkGHOConfig: DexConfigMap<DexParams> = {
8
+ StkGHO: {
9
+ [Network.MAINNET]: {
10
+ stkGHO: '0x1a88Df1cFe15Af22B3c4c783D4e6F7F9e0C1885d',
11
+ GHO: MiscEthereum.GHO_TOKEN,
12
+ },
13
+ },
14
+ };
@@ -0,0 +1,77 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { testE2E } from '../../../tests/utils-e2e';
6
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
7
+ import { Network, ContractMethod, SwapSide } from '../../constants';
8
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
9
+ import { generateConfig } from '../../config';
10
+
11
+ function testForNetwork(
12
+ network: Network,
13
+ dexKey: string,
14
+ tokenASymbol: string,
15
+ tokenBSymbol: string,
16
+ tokenAAmount: string,
17
+ tokenBAmount: string,
18
+ ) {
19
+ const provider = new StaticJsonRpcProvider(
20
+ generateConfig(network).privateHttpProvider,
21
+ network,
22
+ );
23
+ const tokens = Tokens[network];
24
+ const holders = Holders[network];
25
+
26
+ const sideToContractMethods = new Map([
27
+ [SwapSide.SELL, [ContractMethod.swapExactAmountIn]],
28
+ [SwapSide.BUY, [ContractMethod.swapExactAmountOut]],
29
+ ]);
30
+
31
+ describe(`${network}`, () => {
32
+ sideToContractMethods.forEach((contractMethods, side) =>
33
+ describe(`${side}`, () => {
34
+ contractMethods.forEach((contractMethod: ContractMethod) => {
35
+ describe(`${contractMethod}`, () => {
36
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
37
+ await testE2E(
38
+ tokens[tokenASymbol],
39
+ tokens[tokenBSymbol],
40
+ holders[tokenASymbol],
41
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
42
+ side,
43
+ dexKey,
44
+ contractMethod,
45
+ network,
46
+ provider,
47
+ );
48
+ });
49
+ });
50
+ });
51
+ }),
52
+ );
53
+ });
54
+ }
55
+
56
+ describe('StkGHO E2E', () => {
57
+ const dexKey = 'StkGHO';
58
+
59
+ describe('Mainnet', () => {
60
+ const network = Network.MAINNET;
61
+
62
+ const tokenASymbol: string = 'GHO';
63
+ const tokenBSymbol: string = 'stkGHO';
64
+
65
+ const tokenAAmount: string = '1000000000000000000';
66
+ const tokenBAmount: string = '1000000000000000000';
67
+
68
+ testForNetwork(
69
+ network,
70
+ dexKey,
71
+ tokenASymbol,
72
+ tokenBSymbol,
73
+ tokenAAmount,
74
+ tokenBAmount,
75
+ );
76
+ });
77
+ });
@@ -0,0 +1,79 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { StkGHOEventPool } from './stkgho-pool';
6
+ import { Network } from '../../constants';
7
+ import { Address } from '../../types';
8
+ import { DummyDexHelper } from '../../dex-helper/index';
9
+ import { testEventSubscriber } from '../../../tests/utils-events';
10
+ import { PoolState } from './types';
11
+ import { StkGHOConfig } from './config';
12
+
13
+ jest.setTimeout(50 * 1000);
14
+
15
+ async function fetchPoolState(
16
+ stkGHOPool: StkGHOEventPool,
17
+ blockNumber: number,
18
+ poolAddress: string,
19
+ ): Promise<PoolState> {
20
+ const eventState = stkGHOPool.getState(blockNumber);
21
+ if (eventState) return eventState;
22
+ const onChainState = await stkGHOPool.generateState(blockNumber);
23
+ stkGHOPool.setState(onChainState, blockNumber);
24
+ return onChainState;
25
+ }
26
+
27
+ // eventName -> blockNumbers
28
+ type EventMappings = Record<string, number[]>;
29
+
30
+ describe('StkGHO EventPool Mainnet', function () {
31
+ const dexKey = 'StkGHO';
32
+ const network = Network.MAINNET;
33
+ const dexHelper = new DummyDexHelper(network);
34
+ const logger = dexHelper.getLogger(dexKey);
35
+ let stkGHOPool: StkGHOEventPool;
36
+
37
+ // poolAddress -> EventMappings
38
+ const eventsToTest: Record<Address, EventMappings> = {
39
+ [StkGHOConfig[dexKey][network].stkGHO]: {
40
+ ExchangeRateChanged: [], // haven't been emitted yet
41
+ },
42
+ };
43
+
44
+ beforeEach(async () => {
45
+ stkGHOPool = new StkGHOEventPool(
46
+ dexKey,
47
+ dexKey,
48
+ network,
49
+ dexHelper,
50
+ logger,
51
+ );
52
+ });
53
+
54
+ Object.entries(eventsToTest).forEach(
55
+ ([poolAddress, events]: [string, EventMappings]) => {
56
+ describe(`Events for ${poolAddress}`, () => {
57
+ Object.entries(events).forEach(
58
+ ([eventName, blockNumbers]: [string, number[]]) => {
59
+ describe(`${eventName}`, () => {
60
+ blockNumbers.forEach((blockNumber: number) => {
61
+ it(`State after ${blockNumber}`, async function () {
62
+ await testEventSubscriber(
63
+ stkGHOPool,
64
+ stkGHOPool.addressesSubscribed,
65
+ (_blockNumber: number) =>
66
+ fetchPoolState(stkGHOPool, _blockNumber, poolAddress),
67
+ blockNumber,
68
+ `${dexKey}_${poolAddress}`,
69
+ dexHelper.provider,
70
+ );
71
+ });
72
+ });
73
+ });
74
+ },
75
+ );
76
+ });
77
+ },
78
+ );
79
+ });
@@ -0,0 +1,226 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { Interface, Result } from '@ethersproject/abi';
6
+ import { DummyDexHelper } from '../../dex-helper/index';
7
+ import { Network, SwapSide } from '../../constants';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { StkGHO } from './stkgho';
10
+ import {
11
+ checkPoolPrices,
12
+ checkPoolsLiquidity,
13
+ checkConstantPoolPrices,
14
+ } from '../../../tests/utils';
15
+ import { Tokens } from '../../../tests/constants-e2e';
16
+ import StkGHO_ABI from '../../abi/stkGHO.json';
17
+
18
+ function getReaderCalldata(
19
+ exchangeAddress: string,
20
+ readerIface: Interface,
21
+ amounts: bigint[],
22
+ funcName: string,
23
+ ) {
24
+ return amounts.map(amount => ({
25
+ target: exchangeAddress,
26
+ callData: readerIface.encodeFunctionData(funcName, [amount]),
27
+ }));
28
+ }
29
+
30
+ function decodeReaderResult(
31
+ results: Result,
32
+ readerIface: Interface,
33
+ funcName: string,
34
+ ) {
35
+ return results.map(result => {
36
+ const parsed = readerIface.decodeFunctionResult(funcName, result);
37
+ return BigInt(parsed[0]._hex);
38
+ });
39
+ }
40
+
41
+ async function checkOnChainPricing(
42
+ stkGHO: StkGHO,
43
+ funcName: string,
44
+ blockNumber: number,
45
+ prices: bigint[],
46
+ amounts: bigint[],
47
+ ) {
48
+ const exchangeAddress = '0x1a88Df1cFe15Af22B3c4c783D4e6F7F9e0C1885d';
49
+ const readerIface = new Interface(StkGHO_ABI);
50
+
51
+ const readerCallData = getReaderCalldata(
52
+ exchangeAddress,
53
+ readerIface,
54
+ amounts.slice(1),
55
+ funcName,
56
+ );
57
+ const readerResult = (
58
+ await stkGHO.dexHelper.multiContract.methods
59
+ .aggregate(readerCallData)
60
+ .call({}, blockNumber)
61
+ ).returnData;
62
+
63
+ const expectedPrices = [0n].concat(
64
+ decodeReaderResult(readerResult, readerIface, funcName),
65
+ );
66
+
67
+ expect(prices).toEqual(expectedPrices);
68
+ }
69
+
70
+ async function testPricingOnNetwork(
71
+ stkGHO: StkGHO,
72
+ network: Network,
73
+ dexKey: string,
74
+ blockNumber: number,
75
+ srcTokenSymbol: string,
76
+ destTokenSymbol: string,
77
+ side: SwapSide,
78
+ amounts: bigint[],
79
+ funcNameToCheck: string,
80
+ ) {
81
+ const networkTokens = Tokens[network];
82
+
83
+ const pools = await stkGHO.getPoolIdentifiers(
84
+ networkTokens[srcTokenSymbol],
85
+ networkTokens[destTokenSymbol],
86
+ side,
87
+ blockNumber,
88
+ );
89
+ console.log(
90
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Identifiers: `,
91
+ pools,
92
+ );
93
+
94
+ expect(pools.length).toBeGreaterThan(0);
95
+
96
+ const poolPrices = await stkGHO.getPricesVolume(
97
+ networkTokens[srcTokenSymbol],
98
+ networkTokens[destTokenSymbol],
99
+ amounts,
100
+ side,
101
+ blockNumber,
102
+ pools,
103
+ );
104
+ console.log(
105
+ `${srcTokenSymbol} <> ${destTokenSymbol} Pool Prices: `,
106
+ poolPrices,
107
+ );
108
+
109
+ expect(poolPrices).not.toBeNull();
110
+ if (stkGHO.hasConstantPriceLargeAmounts) {
111
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
112
+ } else {
113
+ checkPoolPrices(poolPrices!, amounts, side, dexKey);
114
+ }
115
+
116
+ await checkOnChainPricing(
117
+ stkGHO,
118
+ funcNameToCheck,
119
+ blockNumber,
120
+ poolPrices![0].prices,
121
+ amounts,
122
+ );
123
+ }
124
+
125
+ describe('StkGHO', function () {
126
+ const dexKey = 'StkGHO';
127
+ let blockNumber: number;
128
+ let stkGHO: StkGHO;
129
+
130
+ describe('Mainnet', () => {
131
+ const network = Network.MAINNET;
132
+ const dexHelper = new DummyDexHelper(network);
133
+
134
+ const tokens = Tokens[network];
135
+
136
+ // Don't forget to update relevant tokens in constant-e2e.ts
137
+ const srcTokenSymbol = 'GHO';
138
+ const destTokenSymbol = 'stkGHO';
139
+
140
+ const amountsForSell = [
141
+ 0n,
142
+ 1n * BI_POWS[tokens[srcTokenSymbol].decimals],
143
+ 2n * BI_POWS[tokens[srcTokenSymbol].decimals],
144
+ 3n * BI_POWS[tokens[srcTokenSymbol].decimals],
145
+ 4n * BI_POWS[tokens[srcTokenSymbol].decimals],
146
+ 5n * BI_POWS[tokens[srcTokenSymbol].decimals],
147
+ 6n * BI_POWS[tokens[srcTokenSymbol].decimals],
148
+ 7n * BI_POWS[tokens[srcTokenSymbol].decimals],
149
+ 8n * BI_POWS[tokens[srcTokenSymbol].decimals],
150
+ 9n * BI_POWS[tokens[srcTokenSymbol].decimals],
151
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
152
+ ];
153
+
154
+ const amountsForBuy = [
155
+ 0n,
156
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
157
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
158
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
159
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
160
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
161
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
162
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
163
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
164
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
165
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
166
+ ];
167
+
168
+ beforeAll(async () => {
169
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
170
+ stkGHO = new StkGHO(network, dexKey, dexHelper);
171
+ if (stkGHO.initializePricing) {
172
+ await stkGHO.initializePricing(blockNumber);
173
+ }
174
+ });
175
+
176
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
177
+ await testPricingOnNetwork(
178
+ stkGHO,
179
+ network,
180
+ dexKey,
181
+ blockNumber,
182
+ srcTokenSymbol,
183
+ destTokenSymbol,
184
+ SwapSide.SELL,
185
+ amountsForSell,
186
+ 'previewStake',
187
+ );
188
+ });
189
+
190
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
191
+ await testPricingOnNetwork(
192
+ stkGHO,
193
+ network,
194
+ dexKey,
195
+ blockNumber,
196
+ srcTokenSymbol,
197
+ destTokenSymbol,
198
+ SwapSide.BUY,
199
+ amountsForBuy,
200
+ 'previewStake',
201
+ );
202
+ });
203
+
204
+ it('getTopPoolsForToken', async function () {
205
+ // We have to check without calling initializePricing, because
206
+ // pool-tracker is not calling that function
207
+ const newStkGHO = new StkGHO(network, dexKey, dexHelper);
208
+ if (newStkGHO.updatePoolState) {
209
+ await newStkGHO.updatePoolState();
210
+ }
211
+ const poolLiquidity = await newStkGHO.getTopPoolsForToken(
212
+ tokens[srcTokenSymbol].address,
213
+ 10,
214
+ );
215
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
216
+
217
+ if (!newStkGHO.hasConstantPriceLargeAmounts) {
218
+ checkPoolsLiquidity(
219
+ poolLiquidity,
220
+ Tokens[network][srcTokenSymbol].address,
221
+ dexKey,
222
+ );
223
+ }
224
+ });
225
+ });
226
+ });