@paraswap/dex-lib 2.42.28 → 2.42.29-wombat.2

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 (162) hide show
  1. package/build/abi/{algebra/AlgebraPool.abi.json → solidly-v3/SolidlyV3Pool.abi.json} +293 -282
  2. package/build/abi/solidly-v3/SolidlyV3StateMulticall.abi.json +375 -0
  3. package/build/abi/trader-joe-v2_1/FactoryABI.json +0 -0
  4. package/build/abi/trader-joe-v2_1/PairABI.json +1493 -0
  5. package/build/abi/trader-joe-v2_1/RouterABI.json +1489 -0
  6. package/build/abi/wombat/pool-v2.json +1289 -0
  7. package/build/abi/wombat/pool-v3.json +2013 -0
  8. package/build/config.js +2 -2
  9. package/build/dex/index.js +4 -1
  10. package/build/dex/index.js.map +1 -1
  11. package/build/dex/solidly-v3/config.d.ts +9 -0
  12. package/build/dex/solidly-v3/config.js +58 -0
  13. package/build/dex/solidly-v3/config.js.map +1 -0
  14. package/build/dex/solidly-v3/constants.d.ts +27 -0
  15. package/build/dex/solidly-v3/constants.js +34 -0
  16. package/build/dex/solidly-v3/constants.js.map +1 -0
  17. package/build/dex/solidly-v3/contract-math/BitMath.d.ts +4 -0
  18. package/build/dex/solidly-v3/contract-math/BitMath.js +93 -0
  19. package/build/dex/solidly-v3/contract-math/BitMath.js.map +1 -0
  20. package/build/dex/solidly-v3/contract-math/FixedPoint128.d.ts +3 -0
  21. package/build/dex/solidly-v3/contract-math/FixedPoint128.js +8 -0
  22. package/build/dex/solidly-v3/contract-math/FixedPoint128.js.map +1 -0
  23. package/build/dex/solidly-v3/contract-math/FixedPoint96.d.ts +4 -0
  24. package/build/dex/solidly-v3/contract-math/FixedPoint96.js +9 -0
  25. package/build/dex/solidly-v3/contract-math/FixedPoint96.js.map +1 -0
  26. package/build/dex/solidly-v3/contract-math/FullMath.d.ts +4 -0
  27. package/build/dex/solidly-v3/contract-math/FullMath.js +19 -0
  28. package/build/dex/solidly-v3/contract-math/FullMath.js.map +1 -0
  29. package/build/dex/solidly-v3/contract-math/LiquidityMath.d.ts +3 -0
  30. package/build/dex/solidly-v3/contract-math/LiquidityMath.js +22 -0
  31. package/build/dex/solidly-v3/contract-math/LiquidityMath.js.map +1 -0
  32. package/build/dex/solidly-v3/contract-math/SqrtPriceMath.d.ts +10 -0
  33. package/build/dex/solidly-v3/contract-math/SqrtPriceMath.js +91 -0
  34. package/build/dex/solidly-v3/contract-math/SqrtPriceMath.js.map +1 -0
  35. package/build/dex/solidly-v3/contract-math/SwapMath.d.ts +8 -0
  36. package/build/dex/solidly-v3/contract-math/SwapMath.js +70 -0
  37. package/build/dex/solidly-v3/contract-math/SwapMath.js.map +1 -0
  38. package/build/dex/solidly-v3/contract-math/Tick.d.ts +7 -0
  39. package/build/dex/solidly-v3/contract-math/Tick.js +36 -0
  40. package/build/dex/solidly-v3/contract-math/Tick.js.map +1 -0
  41. package/build/dex/solidly-v3/contract-math/TickBitMap.d.ts +7 -0
  42. package/build/dex/solidly-v3/contract-math/TickBitMap.js +84 -0
  43. package/build/dex/solidly-v3/contract-math/TickBitMap.js.map +1 -0
  44. package/build/dex/solidly-v3/contract-math/TickMath.d.ts +8 -0
  45. package/build/dex/solidly-v3/contract-math/TickMath.js +162 -0
  46. package/build/dex/solidly-v3/contract-math/TickMath.js.map +1 -0
  47. package/build/dex/solidly-v3/contract-math/UnsafeMath.d.ts +3 -0
  48. package/build/dex/solidly-v3/contract-math/UnsafeMath.js +10 -0
  49. package/build/dex/solidly-v3/contract-math/UnsafeMath.js.map +1 -0
  50. package/build/dex/solidly-v3/contract-math/uniswap-v3-math.d.ts +31 -0
  51. package/build/dex/solidly-v3/contract-math/uniswap-v3-math.js +363 -0
  52. package/build/dex/solidly-v3/contract-math/uniswap-v3-math.js.map +1 -0
  53. package/build/dex/solidly-v3/contract-math/utils.d.ts +7 -0
  54. package/build/dex/solidly-v3/contract-math/utils.js +39 -0
  55. package/build/dex/solidly-v3/contract-math/utils.js.map +1 -0
  56. package/build/dex/solidly-v3/solidly-v3-factory.d.ts +26 -0
  57. package/build/dex/solidly-v3/solidly-v3-factory.js +44 -0
  58. package/build/dex/solidly-v3/solidly-v3-factory.js.map +1 -0
  59. package/build/dex/{algebra/algebra-pool.d.ts → solidly-v3/solidly-v3-pool.d.ts} +14 -16
  60. package/build/dex/{algebra/algebra-pool.js → solidly-v3/solidly-v3-pool.js} +127 -165
  61. package/build/dex/solidly-v3/solidly-v3-pool.js.map +1 -0
  62. package/build/dex/solidly-v3/solidly-v3.d.ts +67 -0
  63. package/build/dex/solidly-v3/solidly-v3.js +590 -0
  64. package/build/dex/solidly-v3/solidly-v3.js.map +1 -0
  65. package/build/dex/solidly-v3/types.d.ts +132 -0
  66. package/build/dex/solidly-v3/types.js +9 -0
  67. package/build/dex/solidly-v3/types.js.map +1 -0
  68. package/build/dex/solidly-v3/utils.d.ts +6 -0
  69. package/build/dex/solidly-v3/utils.js +53 -0
  70. package/build/dex/solidly-v3/utils.js.map +1 -0
  71. package/build/dex/trader-joe-v2-1-2/config.d.ts +4 -0
  72. package/build/dex/trader-joe-v2-1-2/config.js +43 -0
  73. package/build/dex/trader-joe-v2-1-2/config.js.map +1 -0
  74. package/build/dex/trader-joe-v2-1-2/constants.d.ts +17 -0
  75. package/build/dex/trader-joe-v2-1-2/constants.js +19 -0
  76. package/build/dex/trader-joe-v2-1-2/constants.js.map +1 -0
  77. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.d.ts +60 -0
  78. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js +199 -0
  79. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js.map +1 -0
  80. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.d.ts +49 -0
  81. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js +269 -0
  82. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js.map +1 -0
  83. package/build/dex/trader-joe-v2-1-2/types.d.ts +81 -0
  84. package/build/dex/trader-joe-v2-1-2/types.js +9 -0
  85. package/build/dex/trader-joe-v2-1-2/types.js.map +1 -0
  86. package/build/dex/trader-joe-v2_1/config.d.ts +4 -0
  87. package/build/dex/trader-joe-v2_1/config.js +43 -0
  88. package/build/dex/trader-joe-v2_1/config.js.map +1 -0
  89. package/build/dex/trader-joe-v2_1/constants.d.ts +16 -0
  90. package/build/dex/trader-joe-v2_1/constants.js +18 -0
  91. package/build/dex/trader-joe-v2_1/constants.js.map +1 -0
  92. package/build/dex/trader-joe-v2_1/trader-joe-v2.1.d.ts +0 -0
  93. package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js +384 -0
  94. package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js.map +1 -0
  95. package/build/dex/trader-joe-v2_1/types.d.ts +39 -0
  96. package/build/dex/trader-joe-v2_1/types.js +3 -0
  97. package/build/dex/trader-joe-v2_1/types.js.map +1 -0
  98. package/build/dex/wombat/types.d.ts +2 -0
  99. package/build/dex/wombat/utils.d.ts +1 -0
  100. package/build/dex/wombat/utils.js +14 -1
  101. package/build/dex/wombat/utils.js.map +1 -1
  102. package/build/dex/wombat/wombat-bmw.d.ts +2 -2
  103. package/build/dex/wombat/wombat-bmw.js +8 -25
  104. package/build/dex/wombat/wombat-bmw.js.map +1 -1
  105. package/build/dex/wombat/wombat-pool-poller.d.ts +22 -0
  106. package/build/dex/wombat/wombat-pool-poller.js +164 -0
  107. package/build/dex/wombat/wombat-pool-poller.js.map +1 -0
  108. package/build/dex/wombat/wombat-pool.d.ts +51 -17
  109. package/build/dex/wombat/wombat-pool.js +393 -112
  110. package/build/dex/wombat/wombat-pool.js.map +1 -1
  111. package/build/dex/wombat/wombat.d.ts +1 -1
  112. package/build/dex/wombat/wombat.js +12 -18
  113. package/build/dex/wombat/wombat.js.map +1 -1
  114. package/package.json +1 -1
  115. package/src/abi/solidly-v3/SolidlyV3Pool.abi.json +738 -0
  116. package/src/abi/solidly-v3/SolidlyV3StateMulticall.abi.json +375 -0
  117. package/src/abi/wombat/pool-v3.json +2013 -0
  118. package/src/config.ts +2 -2
  119. package/src/dex/index.ts +4 -1
  120. package/src/dex/solidly-v3/config.ts +64 -0
  121. package/src/dex/solidly-v3/constants.ts +42 -0
  122. package/src/dex/solidly-v3/contract-math/BitMath.ts +90 -0
  123. package/src/dex/solidly-v3/contract-math/FixedPoint128.ts +3 -0
  124. package/src/dex/solidly-v3/contract-math/FixedPoint96.ts +4 -0
  125. package/src/dex/solidly-v3/contract-math/FullMath.ts +30 -0
  126. package/src/dex/solidly-v3/contract-math/LiquidityMath.ts +17 -0
  127. package/src/dex/solidly-v3/contract-math/SqrtPriceMath.ts +226 -0
  128. package/src/dex/solidly-v3/contract-math/SwapMath.ts +139 -0
  129. package/src/dex/solidly-v3/contract-math/Tick.ts +66 -0
  130. package/src/dex/solidly-v3/contract-math/TickBitMap.ts +123 -0
  131. package/src/dex/solidly-v3/contract-math/TickMath.ts +211 -0
  132. package/src/dex/solidly-v3/contract-math/UnsafeMath.ts +5 -0
  133. package/src/dex/solidly-v3/contract-math/uniswap-v3-math.ts +570 -0
  134. package/src/dex/solidly-v3/contract-math/utils.ts +50 -0
  135. package/src/dex/solidly-v3/solidly-v3-e2e.test.ts +124 -0
  136. package/src/dex/solidly-v3/solidly-v3-events.test.ts +144 -0
  137. package/src/dex/solidly-v3/solidly-v3-factory.ts +73 -0
  138. package/src/dex/solidly-v3/solidly-v3-integration.test.ts +358 -0
  139. package/src/dex/solidly-v3/solidly-v3-pool.ts +494 -0
  140. package/src/dex/solidly-v3/solidly-v3.ts +988 -0
  141. package/src/dex/solidly-v3/types.ts +158 -0
  142. package/src/dex/solidly-v3/utils.ts +71 -0
  143. package/src/dex/uniswap-v3/uniswap-v3-events.test.ts +3 -0
  144. package/src/dex/wombat/types.ts +5 -0
  145. package/src/dex/wombat/utils.ts +20 -0
  146. package/src/dex/wombat/wombat-bmw.ts +8 -31
  147. package/src/dex/wombat/wombat-e2e.test.ts +13 -1
  148. package/src/dex/wombat/wombat-events.test.ts +147 -0
  149. package/src/dex/wombat/wombat-integration.test.ts +101 -111
  150. package/src/dex/wombat/wombat-pool.ts +620 -171
  151. package/src/dex/wombat/wombat.ts +13 -23
  152. package/tests/constants-e2e.ts +11 -1
  153. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  154. package/build/dex/algebra/algebra-pool.js.map +0 -1
  155. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  156. package/build/dex/quickswap/camelot-v3.js +0 -19
  157. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  158. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  159. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  160. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  161. package/build/dex/uniswap-v2/rebase-tokens.json +0 -7
  162. /package/src/abi/wombat/{pool.json → pool-v2.json} +0 -0
@@ -0,0 +1,158 @@
1
+ import { BigNumber, BytesLike } from 'ethers';
2
+ import { NumberAsString } from '../../types';
3
+ import { Address } from '../../types';
4
+ import { AbiItem } from 'web3-utils';
5
+ import { MultiResult } from '../../lib/multi-wrapper';
6
+
7
+ export type FactoryState = Record<string, never>;
8
+
9
+ export type TickInfo = {
10
+ liquidityGross: bigint;
11
+ liquidityNet: bigint;
12
+ initialized: boolean;
13
+ };
14
+
15
+ export type Slot0 = {
16
+ sqrtPriceX96: bigint;
17
+ tick: bigint;
18
+ fee: bigint;
19
+ };
20
+
21
+ export type PoolState = {
22
+ pool: string;
23
+ blockTimestamp: bigint;
24
+ tickSpacing: bigint;
25
+ slot0: Slot0;
26
+ liquidity: bigint;
27
+ maxLiquidityPerTick: bigint;
28
+ tickBitmap: Record<NumberAsString, bigint>;
29
+ ticks: Record<NumberAsString, TickInfo>;
30
+ isValid: boolean;
31
+ startTickBitmap: bigint;
32
+ lowestKnownTick: bigint;
33
+ highestKnownTick: bigint;
34
+ balance0: bigint;
35
+ balance1: bigint;
36
+ };
37
+
38
+ export type SolidlyV3Data = {
39
+ zeroForOne: boolean;
40
+ poolAddress: string;
41
+ isApproved?: boolean;
42
+ };
43
+
44
+ export type DecodeStateMultiCallFunc = (
45
+ result: MultiResult<BytesLike> | BytesLike,
46
+ ) => DecodedStateMultiCallResultWithRelativeBitmaps;
47
+
48
+ export type DexParams = {
49
+ quoter: Address;
50
+ factory: Address;
51
+ stateMulticall: Address;
52
+ supportedTickSpacings: bigint[];
53
+ chunksCount: number;
54
+ initRetryFrequency: number;
55
+ deployer?: Address;
56
+ subgraphURL: string;
57
+ initHash: string;
58
+ stateMultiCallAbi?: AbiItem[];
59
+ decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
60
+ };
61
+
62
+ export type UniswapV3SimpleSwapSellParam = {
63
+ path: string;
64
+ recipient: Address;
65
+ deadline: string;
66
+ amountIn: NumberAsString;
67
+ amountOutMinimum: NumberAsString;
68
+ };
69
+
70
+ export type UniswapV3SimpleSwapBuyParam = {
71
+ path: string;
72
+ recipient: Address;
73
+ deadline: string;
74
+ amountOut: NumberAsString;
75
+ amountInMaximum: NumberAsString;
76
+ };
77
+
78
+ export type UniswapV3SimpleSwapParams =
79
+ | UniswapV3SimpleSwapSellParam
80
+ | UniswapV3SimpleSwapBuyParam;
81
+
82
+ export type SolidlyV3SimpleSwapParams = {
83
+ recipient: string;
84
+ zeroForOne: boolean;
85
+ amountSpecified: NumberAsString;
86
+ sqrtPriceLimitX96: NumberAsString;
87
+ };
88
+
89
+ export type UniswapV3Param = [
90
+ fromToken: Address,
91
+ toToken: Address,
92
+ exchange: Address,
93
+ fromAmount: NumberAsString,
94
+ toAmount: NumberAsString,
95
+ expectedAmount: NumberAsString,
96
+ feePercent: NumberAsString,
97
+ deadline: NumberAsString,
98
+ partner: Address,
99
+ isApproved: boolean,
100
+ beneficiary: Address,
101
+ path: string,
102
+ permit: string,
103
+ uuid: string,
104
+ ];
105
+
106
+ export enum UniswapV3Functions {
107
+ exactInput = 'exactInput',
108
+ exactOutput = 'exactOutput',
109
+ }
110
+
111
+ export type TickInfoMappings = {
112
+ index: number;
113
+ value: TickInfo;
114
+ };
115
+
116
+ export type TickBitMapMappings = {
117
+ index: number;
118
+ value: bigint;
119
+ };
120
+
121
+ export type OutputResult = {
122
+ outputs: bigint[];
123
+ tickCounts: number[];
124
+ };
125
+
126
+ // Just rewrote every type with BigNumber basically
127
+
128
+ export type TickBitMapMappingsWithBigNumber = {
129
+ index: number;
130
+ value: BigNumber;
131
+ };
132
+
133
+ export type TickInfoWithBigNumber = {
134
+ initialized: boolean;
135
+ liquidityGross: BigNumber;
136
+ liquidityNet: BigNumber;
137
+ };
138
+
139
+ export type TickInfoMappingsWithBigNumber = {
140
+ index: number;
141
+ value: TickInfoWithBigNumber;
142
+ };
143
+
144
+ export type DecodedStateMultiCallResultWithRelativeBitmaps = {
145
+ pool: Address;
146
+ blockTimestamp: BigNumber;
147
+ slot0: {
148
+ sqrtPriceX96: BigNumber;
149
+ tick: number;
150
+ fee: number;
151
+ unlocked: boolean;
152
+ };
153
+ liquidity: BigNumber;
154
+ tickSpacing: number;
155
+ maxLiquidityPerTick: BigNumber;
156
+ tickBitmap: TickBitMapMappingsWithBigNumber[];
157
+ ticks: TickInfoMappingsWithBigNumber[];
158
+ };
@@ -0,0 +1,71 @@
1
+ import { BytesLike, ethers } from 'ethers';
2
+ import { assert } from 'ts-essentials';
3
+ import { extractSuccessAndValue } from '../../lib/decoders';
4
+ import { MultiResult } from '../../lib/multi-wrapper';
5
+ import { DexConfigMap } from '../../types';
6
+ import {
7
+ DexParams,
8
+ DecodedStateMultiCallResultWithRelativeBitmaps,
9
+ } from './types';
10
+
11
+ export function getUniswapV3DexKey(UniswapV3Config: DexConfigMap<DexParams>) {
12
+ const UniswapV3Keys = Object.keys(UniswapV3Config);
13
+ if (UniswapV3Keys.length !== 1) {
14
+ throw new Error(
15
+ `UniswapV3 key in UniswapV3Config is not unique. Update relevant places (optimizer) or fix config issue. Received: ${JSON.stringify(
16
+ UniswapV3Config,
17
+ (_0, value) => (typeof value === 'bigint' ? value.toString() : value),
18
+ )}`,
19
+ );
20
+ }
21
+
22
+ return UniswapV3Keys[0].toLowerCase();
23
+ }
24
+
25
+ export function decodeStateMultiCallResultWithRelativeBitmaps(
26
+ result: MultiResult<BytesLike> | BytesLike,
27
+ ): DecodedStateMultiCallResultWithRelativeBitmaps {
28
+ const [isSuccess, toDecode] = extractSuccessAndValue(result);
29
+
30
+ assert(
31
+ isSuccess && toDecode !== '0x',
32
+ `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
33
+ );
34
+
35
+ const decoded = ethers.utils.defaultAbiCoder.decode(
36
+ [
37
+ // I don't want to pass here any interface, so I just use it in ethers format
38
+ `
39
+ tuple(
40
+ address pool,
41
+ uint256 blockTimestamp,
42
+ tuple(
43
+ uint160 sqrtPriceX96,
44
+ int24 tick,
45
+ uint24 fee,
46
+ bool unlocked,
47
+ ) slot0,
48
+ uint128 liquidity,
49
+ int24 tickSpacing,
50
+ uint128 maxLiquidityPerTick,
51
+ tuple(
52
+ int16 index,
53
+ uint256 value,
54
+ )[] tickBitmap,
55
+ tuple(
56
+ int24 index,
57
+ tuple(
58
+ uint128 liquidityGross,
59
+ int128 liquidityNet,
60
+ bool initialized,
61
+ ) value,
62
+ )[] ticks
63
+ )
64
+ `,
65
+ ],
66
+ toDecode,
67
+ )[0];
68
+ // This conversion is not precise, because when we decode, we have more values
69
+ // But I typed only the ones that are used later
70
+ return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
71
+ }
@@ -13,6 +13,7 @@ import { Interface } from '@ethersproject/abi';
13
13
  import ERC20ABI from '../../abi/erc20.json';
14
14
  import StateMulticallABI from '../../abi/uniswap-v3/UniswapV3StateMulticall.abi.json';
15
15
  import { AbiItem } from 'web3-utils';
16
+ import { decodeStateMultiCallResultWithRelativeBitmaps } from './utils';
16
17
 
17
18
  jest.setTimeout(300 * 1000);
18
19
  const dexKey = 'UniswapV3';
@@ -100,6 +101,7 @@ describe('UniswapV3 Event', function () {
100
101
  StateMulticallABI as AbiItem[],
101
102
  config.stateMulticall,
102
103
  ),
104
+ decodeStateMultiCallResultWithRelativeBitmaps,
103
105
  new Interface(ERC20ABI),
104
106
  config.factory,
105
107
  poolFeeCode,
@@ -155,6 +157,7 @@ describe('UniswapV3 Event', function () {
155
157
  StateMulticallABI as AbiItem[],
156
158
  config.stateMulticall,
157
159
  ),
160
+ decodeStateMultiCallResultWithRelativeBitmaps,
158
161
  new Interface(ERC20ABI),
159
162
  _config.factory,
160
163
  _feeCode,
@@ -1,3 +1,4 @@
1
+ import { DeepReadonly } from 'ts-essentials';
1
2
  import { Address } from '../../types';
2
3
 
3
4
  // State-related types
@@ -16,6 +17,10 @@ export type PoolState = {
16
17
  asset: { [underlyingAddress: string]: AssetState };
17
18
  };
18
19
 
20
+ export type StateGenerator = (
21
+ blockNumber: number,
22
+ ) => Promise<DeepReadonly<PoolState>>;
23
+
19
24
  export type AssetState = {
20
25
  address: Address;
21
26
  paused: boolean;
@@ -60,3 +60,23 @@ export const uint120ToBigInt = (
60
60
  ): bigint => {
61
61
  return generalDecoder(result, ['uint120'], 0n, value => value[0].toBigInt());
62
62
  };
63
+
64
+ export function convertUint256ToInt256(uint256Value: bigint): bigint {
65
+ const isNegative =
66
+ (uint256Value &
67
+ BigInt(
68
+ '0x8000000000000000000000000000000000000000000000000000000000000000',
69
+ )) !==
70
+ BigInt(0);
71
+
72
+ if (isNegative) {
73
+ return (
74
+ uint256Value -
75
+ BigInt(
76
+ '0x10000000000000000000000000000000000000000000000000000000000000000',
77
+ )
78
+ );
79
+ } else {
80
+ return uint256Value;
81
+ }
82
+ }
@@ -10,7 +10,7 @@ import { IDexHelper } from '../../dex-helper';
10
10
  import { BmwState } from './types';
11
11
  import BmwABI from '../../abi/wombat/bmw.json';
12
12
  import AssetABI from '../../abi/wombat/asset.json';
13
- import PoolABI from '../../abi/wombat/pool.json';
13
+ import PoolABI from '../../abi/wombat/pool-v2.json';
14
14
 
15
15
  export class WombatBmw extends StatefulEventSubscriber<BmwState> {
16
16
  static readonly bmwInterface = new Interface(BmwABI);
@@ -36,13 +36,12 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
36
36
  protected bmwAddress: Address,
37
37
  protected onAssetAdded: (
38
38
  pool: Address,
39
- asset2TokenMap: Map<Address, Address>,
40
39
  blockNumber: number,
41
40
  ) => Promise<void>,
42
41
  ) {
43
42
  super(
44
- `${dexKey} ${name}`,
45
- `${dexKey}-${network} ${name}`,
43
+ `${dexKey}-${name}`,
44
+ `${dexKey}-${network}-${name}`,
46
45
  dexHelper,
47
46
  logger,
48
47
  );
@@ -118,11 +117,6 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
118
117
 
119
118
  inputs = [];
120
119
  for (const lpToken of lpTokens) {
121
- inputs.push({
122
- target: lpToken,
123
- callData:
124
- WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
125
- });
126
120
  inputs.push({
127
121
  target: lpToken,
128
122
  callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
@@ -135,26 +129,20 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
135
129
  .call({}, blockNumber)
136
130
  ).returnData;
137
131
 
138
- const pool2AssetInfo = new Map<Address, Map<Address, Address>>();
132
+ const poolAddressSet = new Set<Address>();
139
133
  let i = 0;
140
134
  for (const lpToken of lpTokens) {
141
- const underlyingToken = WombatBmw.assetInterface
142
- .decodeFunctionResult('underlyingToken', returnData[i++])[0]
143
- .toLowerCase();
144
135
  const pool = WombatBmw.assetInterface
145
136
  .decodeFunctionResult('pool', returnData[i++])[0]
146
137
  .toLowerCase();
147
138
 
148
- if (!pool2AssetInfo.has(pool)) {
149
- pool2AssetInfo.set(pool, new Map<Address, Address>());
150
- }
151
- pool2AssetInfo.get(pool)!.set(lpToken, underlyingToken);
139
+ poolAddressSet.add(pool);
152
140
  }
153
141
 
154
142
  const promises: Promise<void>[] = [];
155
- pool2AssetInfo.forEach((asset2TokenMap, pool) => {
143
+ poolAddressSet.forEach(pool => {
156
144
  bmwState.pools.push(pool);
157
- promises.push(this.onAssetAdded(pool, asset2TokenMap, blockNumber));
145
+ promises.push(this.onAssetAdded(pool, blockNumber));
158
146
  });
159
147
  await Promise.all(promises);
160
148
 
@@ -173,10 +161,6 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
173
161
  target: lpToken,
174
162
  callData: WombatBmw.assetInterface.encodeFunctionData('pool'),
175
163
  });
176
- multiCallInputs.push({
177
- target: lpToken,
178
- callData: WombatBmw.assetInterface.encodeFunctionData('underlyingToken'),
179
- });
180
164
 
181
165
  const returnData = (
182
166
  await this.dexHelper.multiContract.methods
@@ -187,15 +171,8 @@ export class WombatBmw extends StatefulEventSubscriber<BmwState> {
187
171
  const pool = WombatBmw.assetInterface
188
172
  .decodeFunctionResult('pool', returnData[0])[0]
189
173
  .toLowerCase();
190
- const underlyingToken = WombatBmw.assetInterface
191
- .decodeFunctionResult('underlyingToken', returnData[1])[0]
192
- .toLowerCase();
193
174
 
194
- await this.onAssetAdded(
195
- pool,
196
- new Map<Address, Address>().set(lpToken, underlyingToken),
197
- log.blockNumber,
198
- );
175
+ await this.onAssetAdded(pool, log.blockNumber);
199
176
  if (!state.pools.includes(pool)) {
200
177
  return {
201
178
  pools: [...state.pools, pool],
@@ -172,7 +172,7 @@ describe('Wombat E2E', () => {
172
172
  buyAmount: '1000000000000000000',
173
173
  },
174
174
  {
175
- name: 'wstETH',
175
+ name: 'frxETH',
176
176
  sellAmount: '1000000000000000000',
177
177
  buyAmount: '1000000000000000000',
178
178
  },
@@ -252,6 +252,18 @@ describe('Wombat E2E', () => {
252
252
  buyAmount: '100000000',
253
253
  },
254
254
  ],
255
+ [
256
+ {
257
+ name: 'ETH',
258
+ sellAmount: '100000000000000000',
259
+ buyAmount: '100000000000000000',
260
+ },
261
+ {
262
+ name: 'frxETH',
263
+ sellAmount: '100000000000000000',
264
+ buyAmount: '100000000000000000',
265
+ },
266
+ ],
255
267
  ];
256
268
 
257
269
  testForNetwork(network, dexKey, pairs);
@@ -0,0 +1,147 @@
1
+ import dotenv from 'dotenv';
2
+
3
+ dotenv.config();
4
+
5
+ import { DeepReadonly } from 'ts-essentials';
6
+ import { WombatPool } from './wombat-pool';
7
+ import { Network } from '../../constants';
8
+ import { Address } from '../../types';
9
+ import { DummyDexHelper } from '../../dex-helper';
10
+ import { BmwState, PoolState } from './types';
11
+ import { WombatConfig } from './config';
12
+ import { Wombat } from './wombat';
13
+ import { WombatBmw } from './wombat-bmw';
14
+ import { testEventSubscriber } from '../../../tests/utils-events';
15
+
16
+ jest.setTimeout(100 * 1000);
17
+
18
+ async function fetchPoolState(
19
+ wombatPool: WombatPool,
20
+ blockNumber: number,
21
+ ): Promise<DeepReadonly<PoolState>> {
22
+ return await wombatPool.generateState(blockNumber);
23
+ }
24
+
25
+ async function fetchBmwState(
26
+ wombatBmw: WombatBmw,
27
+ blockNumber: number,
28
+ ): Promise<DeepReadonly<BmwState>> {
29
+ return await wombatBmw.generateState(blockNumber);
30
+ }
31
+
32
+ // eventName -> blockNumbers
33
+ type EventMappings = Record<string, number[]>;
34
+
35
+ describe('Wombat EventPool BSC', function () {
36
+ const dexKey = 'Wombat';
37
+ const network = Network.BSC;
38
+ const dexHelper = new DummyDexHelper(network);
39
+ const logger = dexHelper.getLogger(dexKey);
40
+ const v2Pool = '0x9498563e47D7CFdFa22B818bb8112781036c201C'; // stable guild pool
41
+ const v3Pool = '0x1ee15673e07105Bcf360139fa8CafeBDd7754BeF'; // cross chain pool
42
+ const eventsToTest: Record<Address, EventMappings> = {
43
+ [v2Pool]: {
44
+ // topic0: 0xf5dd9317b9e63ac316ce44acc85f670b54b339cfa3e9076e1dd55065b922314b
45
+ ['Deposit']: [34556359, 34556365, 34558365],
46
+ // topic0: 0xfb80d861da582b723be2d19507ce3e03851820c464abea89156ec77e089b1ad9
47
+ ['Withdraw']: [34208250, 34262795, 34549292],
48
+ // topic0: 0x54787c404bb33c88e86f4baf88183a3b0141d0a848e6a9f7a13b66ae3a9b73d1
49
+ ['Swap']: [34588909, 34590323, 34593343, 34600568, 34602207],
50
+ ['SetAmpFactor']: [],
51
+ ['SetHaircutRate']: [],
52
+ // topic0: 0x0bb5715f0f217c2fe9a0c877ea87d474380c641102f3440ee2a4c8b9d9790918
53
+ ['AssetAdded']: [28050075],
54
+ // topic0: 0x0fa1e4606af435f32f05b3804033d2933e691fab32ee74d2db6fa82d2741f1ea
55
+ ['AssetRemoved']: [34463362],
56
+ // topic0: 0x4941e18a2bcbb0f9fa0081238f26793a8ad8c202b913ae8bf5f7e523f68ff137
57
+ ['FillPool']: [],
58
+ ['Paused']: [34342956],
59
+ // topic0: 0x5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa
60
+ ['Unpaused']: [34463362],
61
+ // topic0: 0xdcb65c0553aaa433aadd180404ff195259c48f78aa50f877ebcb4bb215129a4e
62
+ ['PausedAsset']: [34463362],
63
+ ['UnpausedAsset']: [],
64
+ },
65
+ [v3Pool]: {
66
+ // topic0: 0xf5dd9317b9e63ac316ce44acc85f670b54b339cfa3e9076e1dd55065b922314b
67
+ ['Deposit']: [34558302, 34564573, 34597601],
68
+ // // topic0: 0xfb80d861da582b723be2d19507ce3e03851820c464abea89156ec77e089b1ad9
69
+ ['Withdraw']: [34567962, 34569797, 34596990],
70
+ // // topic0: 0x7fa01e8d24e5a6ec56e00b4ff8ee7ed97e7650a7846ec494bbaa5d65f1be9ea4
71
+ ['SwapV2']: [34609776, 34610336, 34610364, 34611146, 34611872],
72
+ // topic0: 0x0fa1e4606af435f32f05b3804033d2933e691fab32ee74d2db6fa82d2741f1ea
73
+ ['AssetRemoved']: [34463362],
74
+ },
75
+ };
76
+
77
+ for (const [poolAddress, events] of Object.entries(eventsToTest)) {
78
+ describe(`Events for ${poolAddress}`, () => {
79
+ for (const [eventName, blockNumbers] of Object.entries(events)) {
80
+ describe(`${eventName}`, () => {
81
+ for (const blockNumber of blockNumbers) {
82
+ it(`State after ${blockNumber}`, async function () {
83
+ const wombatPool = new WombatPool(
84
+ dexKey,
85
+ poolAddress,
86
+ network,
87
+ dexHelper,
88
+ logger,
89
+ poolAddress.toLowerCase(),
90
+ );
91
+ await wombatPool.initialize(blockNumber - 1);
92
+
93
+ await testEventSubscriber(
94
+ wombatPool,
95
+ wombatPool.addressesSubscribed,
96
+ (_blockNumber: number) =>
97
+ fetchPoolState(wombatPool, _blockNumber),
98
+ blockNumber,
99
+ `${dexKey}_${poolAddress}`,
100
+ dexHelper.provider,
101
+ );
102
+ });
103
+ }
104
+ });
105
+ }
106
+ });
107
+ }
108
+ });
109
+ describe('Wombat BMW ARB', function () {
110
+ const dexKey = 'Wombat';
111
+ const network = Network.ARBITRUM;
112
+ const dexHelper = new DummyDexHelper(network);
113
+ const bmwAddress = WombatConfig.Wombat[network].bmwAddress;
114
+ const eventsToTest: Record<Address, EventMappings> = {
115
+ [bmwAddress]: {
116
+ // topic0: 0xec85b1d1f037ff3a8722aaf5d4d8e7d93c7ff10c056430c18d76a9ec23aa397e
117
+ ['Add']: [158157042, 162173973],
118
+ },
119
+ };
120
+
121
+ const wombat = new Wombat(network, dexKey, dexHelper);
122
+
123
+ for (const [poolAddress, events] of Object.entries(eventsToTest)) {
124
+ describe(`Events for ${poolAddress}`, () => {
125
+ for (const [eventName, blockNumbers] of Object.entries(events)) {
126
+ describe(`${eventName}`, () => {
127
+ for (const blockNumber of blockNumbers) {
128
+ it(`State after ${blockNumber}`, async function () {
129
+ if (wombat.initializePricing) {
130
+ await wombat.initializePricing(blockNumber);
131
+ }
132
+ await testEventSubscriber(
133
+ wombat.bmw,
134
+ wombat.bmw.addressesSubscribed,
135
+ (_blockNumber: number) =>
136
+ fetchBmwState(wombat.bmw, _blockNumber),
137
+ blockNumber,
138
+ `${dexKey}_${bmwAddress}`,
139
+ dexHelper.provider,
140
+ );
141
+ });
142
+ }
143
+ });
144
+ }
145
+ });
146
+ }
147
+ });