@paraswap/dex-lib 3.8.28 → 3.8.29-stkgho

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 (171) hide show
  1. package/build/abi/Aave_GSM.json +751 -0
  2. package/build/abi/aave-gsm/Aave_GSM.json +751 -0
  3. package/build/abi/aave-gsm/IFeeStrategy.json +78 -0
  4. package/build/abi/inception/inception-ineth-pool.json +1062 -0
  5. package/build/abi/inception/inception-ineth.json +609 -0
  6. package/build/abi/inception/inception-ratio-feed.json +93 -0
  7. package/build/abi/inception/inception-vault.json +991 -0
  8. package/build/abi/stkGHO.json +1131 -0
  9. package/build/abi/usual-bond/usd0pp.abi.json +867 -0
  10. package/build/config.js +3 -3
  11. package/build/dex/aave-gsm/aave-gsm-pool.d.ts +26 -0
  12. package/build/dex/aave-gsm/aave-gsm-pool.js +91 -0
  13. package/build/dex/aave-gsm/aave-gsm-pool.js.map +1 -0
  14. package/build/dex/aave-gsm/aave-gsm.d.ts +43 -0
  15. package/build/dex/aave-gsm/aave-gsm.js +305 -0
  16. package/build/dex/aave-gsm/aave-gsm.js.map +1 -0
  17. package/build/dex/aave-gsm/config.d.ts +3 -0
  18. package/build/dex/aave-gsm/config.js +17 -0
  19. package/build/dex/aave-gsm/config.js.map +1 -0
  20. package/build/dex/aave-gsm/types.d.ts +16 -0
  21. package/build/dex/aave-gsm/types.js +3 -0
  22. package/build/dex/aave-gsm/types.js.map +1 -0
  23. package/build/dex/aave-v1/aave-v1.js +0 -1
  24. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  25. package/build/dex/dexalot/dexalot.js +4 -4
  26. package/build/dex/dexalot/dexalot.js.map +1 -1
  27. package/build/dex/generic-rfq/generic-rfq.js +10 -1
  28. package/build/dex/generic-rfq/generic-rfq.js.map +1 -1
  29. package/build/dex/hashflow/hashflow.js +3 -3
  30. package/build/dex/hashflow/hashflow.js.map +1 -1
  31. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  32. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  33. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  34. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  35. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  36. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  37. package/build/dex/idle-dao/scripts.d.ts +9 -0
  38. package/build/dex/idle-dao/scripts.js +552 -0
  39. package/build/dex/idle-dao/scripts.js.map +1 -0
  40. package/build/dex/inception/config.d.ts +5 -0
  41. package/build/dex/inception/config.js +112 -0
  42. package/build/dex/inception/config.js.map +1 -0
  43. package/build/dex/inception/inception-event-pool.d.ts +25 -0
  44. package/build/dex/inception/inception-event-pool.js +57 -0
  45. package/build/dex/inception/inception-event-pool.js.map +1 -0
  46. package/build/dex/inception/inception-native.d.ts +43 -0
  47. package/build/dex/inception/inception-native.js +131 -0
  48. package/build/dex/inception/inception-native.js.map +1 -0
  49. package/build/dex/inception/inception-pool.d.ts +18 -0
  50. package/build/dex/inception/inception-pool.js +32 -0
  51. package/build/dex/inception/inception-pool.js.map +1 -0
  52. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  53. package/build/dex/inception/inception-price-feed.js +51 -0
  54. package/build/dex/inception/inception-price-feed.js.map +1 -0
  55. package/build/dex/inception/inception.d.ts +44 -0
  56. package/build/dex/inception/inception.js +177 -0
  57. package/build/dex/inception/inception.js.map +1 -0
  58. package/build/dex/inception/tokens.d.ts +9 -0
  59. package/build/dex/inception/tokens.js +28 -0
  60. package/build/dex/inception/tokens.js.map +1 -0
  61. package/build/dex/inception/types.d.ts +22 -0
  62. package/build/dex/inception/types.js +3 -0
  63. package/build/dex/inception/types.js.map +1 -0
  64. package/build/dex/inception/utils.d.ts +7 -0
  65. package/build/dex/inception/utils.js +58 -0
  66. package/build/dex/inception/utils.js.map +1 -0
  67. package/build/dex/index.js +2 -0
  68. package/build/dex/index.js.map +1 -1
  69. package/build/dex/platypus/platypus.js +3 -17
  70. package/build/dex/platypus/platypus.js.map +1 -1
  71. package/build/dex/stkgho/config.d.ts +3 -0
  72. package/build/dex/stkgho/config.js +14 -0
  73. package/build/dex/stkgho/config.js.map +1 -0
  74. package/build/dex/stkgho/stkgho-pool.d.ts +41 -0
  75. package/build/dex/stkgho/stkgho-pool.js +81 -0
  76. package/build/dex/stkgho/stkgho-pool.js.map +1 -0
  77. package/build/dex/stkgho/stkgho.d.ts +41 -0
  78. package/build/dex/stkgho/stkgho.js +159 -0
  79. package/build/dex/stkgho/stkgho.js.map +1 -0
  80. package/build/dex/stkgho/types.d.ts +11 -0
  81. package/build/dex/stkgho/types.js +3 -0
  82. package/build/dex/stkgho/types.js.map +1 -0
  83. package/build/dex/swaap-v1/swaap-v1.js +0 -4
  84. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  85. package/build/dex/swaap-v2/swaap-v2.js +5 -5
  86. package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
  87. package/build/dex/usual-bond/config.d.ts +3 -0
  88. package/build/dex/usual-bond/config.js +13 -0
  89. package/build/dex/usual-bond/config.js.map +1 -0
  90. package/build/dex/usual-bond/types.d.ts +7 -0
  91. package/build/dex/usual-bond/types.js +3 -0
  92. package/build/dex/usual-bond/types.js.map +1 -0
  93. package/build/dex/usual-bond/usual-bond.d.ts +35 -0
  94. package/build/dex/usual-bond/usual-bond.js +162 -0
  95. package/build/dex/usual-bond/usual-bond.js.map +1 -0
  96. package/build/implementations/local-paraswap-sdk.js +1 -0
  97. package/build/implementations/local-paraswap-sdk.js.map +1 -1
  98. package/build/types.d.ts +1 -0
  99. package/package.json +1 -1
  100. package/src/abi/stkGHO.json +1131 -0
  101. package/src/config.ts +3 -3
  102. package/src/dex/dexalot/dexalot.ts +4 -4
  103. package/src/dex/generic-rfq/generic-rfq.ts +22 -1
  104. package/src/dex/hashflow/hashflow.ts +3 -3
  105. package/src/dex/index.ts +2 -0
  106. package/src/dex/stkgho/config.ts +14 -0
  107. package/src/dex/stkgho/stkgho-e2e.test.ts +77 -0
  108. package/src/dex/stkgho/stkgho-events.test.ts +79 -0
  109. package/src/dex/stkgho/stkgho-integration.test.ts +226 -0
  110. package/src/dex/stkgho/stkgho-pool.ts +111 -0
  111. package/src/dex/stkgho/stkgho.ts +217 -0
  112. package/src/dex/stkgho/types.ts +14 -0
  113. package/src/dex/swaap-v2/swaap-v2.ts +5 -5
  114. package/src/implementations/local-paraswap-sdk.ts +1 -0
  115. package/src/types.ts +1 -0
  116. package/tests/constants-e2e.ts +4 -0
  117. package/.vscode/launch.json +0 -53
  118. package/.vscode/settings.json +0 -2
  119. package/.vscode/tasks.json +0 -15
  120. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  121. package/build/abi/wombat/pool.json +0 -1289
  122. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  123. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  124. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  125. package/build/dex/bProtocol.d.ts +0 -18
  126. package/build/dex/bProtocol.js +0 -39
  127. package/build/dex/bProtocol.js.map +0 -1
  128. package/build/dex/bancor.d.ts +0 -26
  129. package/build/dex/bancor.js +0 -58
  130. package/build/dex/bancor.js.map +0 -1
  131. package/build/dex/compound.d.ts +0 -18
  132. package/build/dex/compound.js +0 -46
  133. package/build/dex/compound.js.map +0 -1
  134. package/build/dex/curve-v2.d.ts +0 -58
  135. package/build/dex/curve-v2.js +0 -180
  136. package/build/dex/curve-v2.js.map +0 -1
  137. package/build/dex/dodo-v1.d.ts +0 -33
  138. package/build/dex/dodo-v1.js +0 -63
  139. package/build/dex/dodo-v1.js.map +0 -1
  140. package/build/dex/lido.d.ts +0 -19
  141. package/build/dex/lido.js +0 -42
  142. package/build/dex/lido.js.map +0 -1
  143. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  144. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  145. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  146. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  147. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  148. package/build/dex/onebit.d.ts +0 -25
  149. package/build/dex/onebit.js +0 -42
  150. package/build/dex/onebit.js.map +0 -1
  151. package/build/dex/smoothy.d.ts +0 -26
  152. package/build/dex/smoothy.js +0 -48
  153. package/build/dex/smoothy.js.map +0 -1
  154. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  155. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  156. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  157. package/build/dex/stable-pool.d.ts +0 -28
  158. package/build/dex/stable-pool.js +0 -55
  159. package/build/dex/stable-pool.js.map +0 -1
  160. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  161. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  162. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
  163. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  164. package/build/dex/trader-joe-v2.1.js +0 -79
  165. package/build/dex/trader-joe-v2.1.js.map +0 -1
  166. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  167. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  168. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  169. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  170. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  171. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
package/src/config.ts CHANGED
@@ -400,9 +400,9 @@ const baseConfigs: { [network: number]: BaseConfig } = {
400
400
  hashFlowDisabledMMs: [],
401
401
  augustusV6Address: '0x6a000f20005980200259b80c5102003040001068',
402
402
  executorsAddresses: {
403
- Executor01: '0x5f0000d4780a00d2dce0a00004000800cb0e5041',
404
- Executor02: '0xd08d0006f00040b400180f9500b00c5026ac0900',
405
- Executor03: '0x5006860a0906b0d8c9c050200947000030081006',
403
+ Executor01: '0xa600910B670804230E00A100000D28000AE005C0',
404
+ Executor02: '0x3800091020a00290f20606b000000000E38c33Ef',
405
+ Executor03: '0x20004f017a0bC0050bc004d9C500a7A089800000',
406
406
  },
407
407
  adapterAddresses: {
408
408
  BaseAdapter01: '0xe53d24CD81cC81bbf271AD7B02D0d67f851D727c',
@@ -598,7 +598,7 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
598
598
  takerAsset: ethers.utils.getAddress(takerToken.address),
599
599
  makerAmount: isBuy ? optimalSwapExchange.destAmount : undefined,
600
600
  takerAmount: isSell ? optimalSwapExchange.srcAmount : undefined,
601
- userAddress: options.txOrigin,
601
+ userAddress: options.userAddress,
602
602
  chainid: this.network,
603
603
  executor: options.executionContractAddress,
604
604
  partner: options.partner,
@@ -725,11 +725,11 @@ export class Dexalot extends SimpleExchange implements IDex<DexalotData> {
725
725
  const errorData = e.response.data as RFQResponseError;
726
726
  if (errorData.ReasonCode === 'FQ-009') {
727
727
  this.logger.warn(
728
- `${this.dexKey}-${this.network}: Encountered rate limited user=${options.txOrigin}. Adding to local rate limit cache`,
728
+ `${this.dexKey}-${this.network}: Encountered rate limited user=${options.userAddress}. Adding to local rate limit cache`,
729
729
  );
730
- await this.setRateLimited(options.txOrigin, errorData.RetryAfter);
730
+ await this.setRateLimited(options.userAddress, errorData.RetryAfter);
731
731
  } else {
732
- await this.setBlacklist(options.txOrigin);
732
+ await this.setBlacklist(options.userAddress);
733
733
  this.logger.error(
734
734
  `${this.dexKey}-${this.network}: Failed to fetch RFQ for ${swapIdentifier}: ${errorData.Reason}`,
735
735
  );
@@ -324,6 +324,27 @@ export class GenericRFQ extends ParaSwapLimitOrders {
324
324
  side: SwapSide,
325
325
  options: PreprocessTransactionOptions,
326
326
  ): Promise<[OptimalSwapExchange<ParaSwapLimitOrdersData>, ExchangeTxInfo]> {
327
+ if (await this.isBlacklisted(options.txOrigin)) {
328
+ this.logger.warn(
329
+ `${this.dexKey}-${this.network}: blacklisted TX Origin address '${options.txOrigin}' trying to build a transaction. Bailing...`,
330
+ );
331
+ throw new Error(
332
+ `${this.dexKey}-${this.network}: user=${options.txOrigin} is blacklisted`,
333
+ );
334
+ }
335
+
336
+ if (
337
+ options.userAddress !== options.txOrigin &&
338
+ (await this.isBlacklisted(options.userAddress))
339
+ ) {
340
+ this.logger.warn(
341
+ `${this.dexKey}-${this.network}: blacklisted user address '${options.userAddress}' trying to build a transaction. Bailing...`,
342
+ );
343
+ throw new Error(
344
+ `${this.dexKey}-${this.network}: user=${options.userAddress} is blacklisted`,
345
+ );
346
+ }
347
+
327
348
  const isSell = side === SwapSide.SELL;
328
349
 
329
350
  const order = await this.rateFetcher.getFirmRate(
@@ -334,7 +355,7 @@ export class GenericRFQ extends ParaSwapLimitOrders {
334
355
  : overOrder(optimalSwapExchange.destAmount, 1),
335
356
  side,
336
357
  options.executionContractAddress,
337
- options.txOrigin,
358
+ options.userAddress,
338
359
  options.partner,
339
360
  options.special,
340
361
  );
@@ -597,7 +597,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
597
597
  : { quoteTokenAmount: optimalSwapExchange.destAmount }),
598
598
  // receiver address
599
599
  wallet: options.recipient.toLowerCase(),
600
- effectiveTrader: options.txOrigin.toLowerCase(),
600
+ effectiveTrader: options.userAddress.toLowerCase(),
601
601
  marketMakers: [mm],
602
602
  });
603
603
 
@@ -731,9 +731,9 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
731
731
  e.message?.toLowerCase().includes('user is restricted')
732
732
  ) {
733
733
  this.logger.warn(
734
- `${this.dexKey}-${this.network}: Encountered restricted user=${options.txOrigin}. Adding to local blacklist cache`,
734
+ `${this.dexKey}-${this.network}: Encountered restricted user=${options.userAddress}. Adding to local blacklist cache`,
735
735
  );
736
- await this.setBlacklist(options.txOrigin);
736
+ await this.setBlacklist(options.userAddress);
737
737
  } else {
738
738
  if (e instanceof TooStrictSlippageCheckError) {
739
739
  this.logger.warn(
package/src/dex/index.ts CHANGED
@@ -87,6 +87,7 @@ import { OSwap } from './oswap/oswap';
87
87
  import { ConcentratorArusd } from './concentrator-arusd/concentrator-arusd';
88
88
  import { FxProtocolRusd } from './fx-protocol-rusd/fx-protocol-rusd';
89
89
  import { LitePsm } from './lite-psm/lite-psm';
90
+ import { StkGHO } from './stkgho/stkgho';
90
91
 
91
92
  const LegacyDexes = [
92
93
  CurveV2,
@@ -169,6 +170,7 @@ const Dexes = [
169
170
  ConcentratorArusd,
170
171
  FxProtocolRusd,
171
172
  LitePsm,
173
+ StkGHO,
172
174
  ];
173
175
 
174
176
  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: [20630408, 20623242],
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
+ });
@@ -0,0 +1,111 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { Log, Logger } from '../../types';
4
+ import { catchParseLogError } from '../../utils';
5
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
+ import { IDexHelper } from '../../dex-helper/idex-helper';
7
+ import { PoolState } from './types';
8
+ import StkGHO_ABI from '../../abi/stkGHO.json';
9
+ import { StkGHOConfig } from './config';
10
+ import { uint256ToBigInt } from '../../lib/decoders';
11
+
12
+ export class StkGHOEventPool extends StatefulEventSubscriber<PoolState> {
13
+ handlers: {
14
+ [event: string]: (
15
+ event: any,
16
+ state: DeepReadonly<PoolState>,
17
+ log: Readonly<Log>,
18
+ ) => DeepReadonly<PoolState> | null;
19
+ } = {};
20
+
21
+ logDecoder: (log: Log) => any;
22
+
23
+ addressesSubscribed: string[];
24
+
25
+ constructor(
26
+ readonly poolName: string,
27
+ readonly parentName: string,
28
+ protected network: number,
29
+ protected dexHelper: IDexHelper,
30
+ logger: Logger,
31
+ protected stkGHOIface = new Interface(StkGHO_ABI),
32
+ ) {
33
+ super(parentName, poolName, dexHelper, logger);
34
+
35
+ this.logDecoder = (log: Log) => this.stkGHOIface.parseLog(log);
36
+ this.addressesSubscribed = [StkGHOConfig[parentName][network].stkGHO];
37
+
38
+ this.handlers['ExchangeRateChanged'] =
39
+ this.handleExchangeRateChanged.bind(this);
40
+ }
41
+
42
+ getIdentifier(): string {
43
+ return `${this.parentName}`;
44
+ }
45
+
46
+ /**
47
+ * The function is called every time any of the subscribed
48
+ * addresses release log. The function accepts the current
49
+ * state, updates the state according to the log, and returns
50
+ * the updated state.
51
+ * @param state - Current state of event subscriber
52
+ * @param log - Log released by one of the subscribed addresses
53
+ * @returns Updates state of the event subscriber after the log
54
+ */
55
+ protected processLog(
56
+ state: DeepReadonly<PoolState>,
57
+ log: Readonly<Log>,
58
+ ): DeepReadonly<PoolState> | null {
59
+ try {
60
+ const event = this.logDecoder(log);
61
+ if (event.name in this.handlers) {
62
+ return this.handlers[event.name](event, state, log);
63
+ }
64
+ } catch (e) {
65
+ catchParseLogError(e, this.logger);
66
+ }
67
+
68
+ return null;
69
+ }
70
+
71
+ /**
72
+ * The function generates state using on-chain calls. This
73
+ * function is called to regenerate state if the event based
74
+ * system fails to fetch events and the local state is no
75
+ * more correct.
76
+ * @param blockNumber - Blocknumber for which the state should
77
+ * should be generated
78
+ * @returns state of the event subscriber at blocknumber
79
+ */
80
+ async generateState(blockNumber: number): Promise<DeepReadonly<PoolState>> {
81
+ const callData = [
82
+ {
83
+ target: this.addressesSubscribed[0],
84
+ callData: this.stkGHOIface.encodeFunctionData('getExchangeRate', []),
85
+ decodeFunction: uint256ToBigInt,
86
+ },
87
+ ];
88
+
89
+ const res = await this.dexHelper.multiWrapper.tryAggregate<bigint>(
90
+ true,
91
+ callData,
92
+ blockNumber,
93
+ );
94
+
95
+ const result = {
96
+ exchangeRate: res[0].returnData,
97
+ };
98
+
99
+ return result;
100
+ }
101
+
102
+ handleExchangeRateChanged(
103
+ event: any,
104
+ state: DeepReadonly<PoolState>,
105
+ log: Readonly<Log>,
106
+ ): DeepReadonly<PoolState> | null {
107
+ return {
108
+ exchangeRate: uint256ToBigInt(event.args.exchangeRate),
109
+ };
110
+ }
111
+ }