@paraswap/dex-lib 2.21.0 → 2.21.1

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 (107) hide show
  1. package/build/dex/curve-v1-factory/config.js +91 -9
  2. package/build/dex/curve-v1-factory/config.js.map +1 -1
  3. package/build/dex/curve-v1-factory/curve-v1-factory.js +9 -3
  4. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  5. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +2 -0
  6. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
  7. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +27 -3
  8. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
  9. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +6 -0
  10. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
  11. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +6 -0
  12. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
  13. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +6 -0
  14. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
  15. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +6 -0
  16. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
  17. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +6 -0
  18. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
  19. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +6 -0
  20. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
  21. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +66 -0
  22. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  23. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +6 -0
  24. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
  25. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +20 -0
  26. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
  27. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +6 -0
  28. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
  29. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +26 -3
  30. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
  31. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +6 -0
  32. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
  33. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +6 -0
  34. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
  35. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +6 -0
  36. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
  37. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +1 -4
  38. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +2 -5
  39. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
  40. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +3 -1
  41. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +22 -3
  42. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  43. package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.d.ts +1 -1
  44. package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js +28 -3
  45. package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js.map +1 -1
  46. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +2 -1
  47. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +2 -1
  48. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  49. package/build/dex/curve-v1-factory/types.d.ts +16 -0
  50. package/build/dex/curve-v1-factory/types.js +6 -0
  51. package/build/dex/curve-v1-factory/types.js.map +1 -1
  52. package/build/dex/swaap-v2/rate-fetcher.js.map +1 -1
  53. package/build/dex/test-dex/config.d.ts +4 -0
  54. package/build/dex/test-dex/config.js +15 -0
  55. package/build/dex/test-dex/config.js.map +1 -0
  56. package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
  57. package/build/dex/test-dex/test-dex-pool.js +63 -0
  58. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  59. package/build/dex/test-dex/test-dex.d.ts +37 -0
  60. package/build/dex/test-dex/test-dex.js +126 -0
  61. package/build/dex/test-dex/test-dex.js.map +1 -0
  62. package/build/dex/test-dex/types.d.ts +6 -0
  63. package/build/dex/{pancakeswap-v3 → test-dex}/types.js.map +1 -1
  64. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  65. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  66. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  67. package/package.json +1 -1
  68. package/src/dex/curve-v1-factory/config.ts +91 -9
  69. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +36 -0
  70. package/src/dex/curve-v1-factory/curve-v1-factory.ts +12 -1
  71. package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +6 -0
  72. package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +53 -6
  73. package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +7 -0
  74. package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +7 -0
  75. package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +7 -0
  76. package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +7 -0
  77. package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +7 -0
  78. package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +7 -0
  79. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +78 -0
  80. package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +13 -0
  81. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +40 -3
  82. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +7 -0
  83. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +53 -4
  84. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +7 -0
  85. package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +7 -0
  86. package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +7 -0
  87. package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +5 -3
  88. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +42 -1
  89. package/src/dex/curve-v1-factory/state-polling-pools/polling-manager.ts +43 -9
  90. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +1 -0
  91. package/src/dex/curve-v1-factory/types.ts +14 -0
  92. package/src/dex/quickswap/quickswap-e2e.test.ts +1 -1
  93. package/src/dex/swaap-v2/rate-fetcher.ts +10 -10
  94. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +1 -4
  95. package/tests/constants-e2e.ts +6 -10
  96. package/.idea/aws.xml +0 -17
  97. package/.idea/codeStyles/Project.xml +0 -19
  98. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  99. package/.idea/misc.xml +0 -6
  100. package/.idea/modules.xml +0 -8
  101. package/.idea/paraswap-dex-lib.iml +0 -9
  102. package/.idea/vcs.xml +0 -6
  103. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  104. package/build/dex/solidly/forks-override/chronos.d.ts +0 -20
  105. package/build/dex/solidly/forks-override/chronos.js +0 -44
  106. package/build/dex/solidly/forks-override/chronos.js.map +0 -1
  107. /package/build/dex/{pancakeswap-v3 → test-dex}/types.js +0 -0
@@ -225,6 +225,8 @@ const implementations: Record<ImplementationNames, get_D> = {
225
225
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: makeFuncCacheable(
226
226
  customPlain3CoinThree,
227
227
  ),
228
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]:
229
+ makeFuncCacheable(customPlain2CoinFrax),
228
230
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: makeFuncCacheable(
229
231
  customPlain3CoinThree,
230
232
  ),
@@ -308,6 +310,17 @@ const implementations: Record<ImplementationNames, get_D> = {
308
310
  makeFuncCacheable(customPlain2CoinFrax),
309
311
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]:
310
312
  makeFuncCacheable(customPlain2CoinFrax),
313
+
314
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]:
315
+ makeFuncCacheable(customPlain2CoinFrax),
316
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]:
317
+ makeFuncCacheable(customPlain2CoinFrax),
318
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]:
319
+ makeFuncCacheable(factoryPlain2Basic),
320
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]:
321
+ makeFuncCacheable(factoryPlain2Basic),
322
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]:
323
+ makeFuncCacheable(factoryPlain2Basic),
311
324
  };
312
325
 
313
326
  export default implementations;
@@ -3,7 +3,7 @@ import { ImplementationNames, PoolState } from '../../types';
3
3
  import { get_D_mem, IPoolContext } from '../types';
4
4
  import { requireConstant, throwNotExist, throwNotImplemented } from './utils';
5
5
 
6
- const factoryPlain2Basic = (
6
+ const factoryPlain2Basic: get_D_mem = (
7
7
  self: IPoolContext,
8
8
  state: PoolState,
9
9
  _balances: bigint[],
@@ -13,7 +13,7 @@ const factoryPlain2Basic = (
13
13
  return self.get_D(self, self._xp_mem(self, rates, _balances), amp);
14
14
  };
15
15
 
16
- const customPlain3CoinThree = (
16
+ const customPlain3CoinThree: get_D_mem = (
17
17
  self: IPoolContext,
18
18
  state: PoolState,
19
19
  _balances: bigint[],
@@ -23,7 +23,7 @@ const customPlain3CoinThree = (
23
23
  return self.get_D(self, self._xp_mem(self, [...RATES], _balances), amp);
24
24
  };
25
25
 
26
- const customPlain3CoinSbtc = (
26
+ const customPlain3CoinSbtc: get_D_mem = (
27
27
  self: IPoolContext,
28
28
  state: PoolState,
29
29
  _balances: bigint[],
@@ -36,6 +36,36 @@ const customPlain3CoinSbtc = (
36
36
  );
37
37
  };
38
38
 
39
+ const factoryMetaBtcSbtc2: get_D_mem = (
40
+ self: IPoolContext,
41
+ state: PoolState,
42
+ _balances: bigint[],
43
+ amp: bigint,
44
+ ): bigint => {
45
+ if (state.virtualPrice === undefined) {
46
+ throw new Error(
47
+ `${self.IMPLEMENTATION_NAME} factoryMetaBtcSbtc2: virtualPrice is not provided`,
48
+ );
49
+ }
50
+ const rates = [state.constants.rate_multipliers[0], state.virtualPrice];
51
+ return self.get_D(self, self._xp_mem(self, rates, _balances), amp);
52
+ };
53
+
54
+ const factoryPlain2EthEma2: get_D_mem = (
55
+ self: IPoolContext,
56
+ state: PoolState,
57
+ _balances: bigint[],
58
+ amp: bigint,
59
+ ) => {
60
+ if (state.storedRates === undefined) {
61
+ throw new Error(
62
+ `${self.IMPLEMENTATION_NAME} factoryPlain2EthEma2: storedRates is not provided`,
63
+ );
64
+ }
65
+ const rates = [...state.storedRates];
66
+ return self.get_D(self, self._xp_mem(self, rates, _balances), amp);
67
+ };
68
+
39
69
  const notImplemented: get_D_mem = (
40
70
  self: IPoolContext,
41
71
  state: PoolState,
@@ -57,6 +87,7 @@ const notExist: get_D_mem = (
57
87
  export const implementations: Record<ImplementationNames, get_D_mem> = {
58
88
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain3CoinThree,
59
89
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinSbtc,
90
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain3CoinThree,
60
91
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinSbtc,
61
92
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
62
93
 
@@ -103,6 +134,12 @@ export const implementations: Record<ImplementationNames, get_D_mem> = {
103
134
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
104
135
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
105
136
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
137
+
138
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaBtcSbtc2,
139
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaBtcSbtc2,
140
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
141
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
142
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
106
143
  };
107
144
 
108
145
  export default implementations;
@@ -51,6 +51,7 @@ const makeFuncCacheable = (func: get_D_precisions): get_D_precisions => {
51
51
  const implementations: Record<ImplementationNames, get_D_precisions> = {
52
52
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: notExist,
53
53
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: notExist,
54
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: notExist,
54
55
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: notExist,
55
56
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: notExist,
56
57
 
@@ -105,6 +106,12 @@ const implementations: Record<ImplementationNames, get_D_precisions> = {
105
106
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
106
107
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
107
108
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
109
+
110
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: notExist,
111
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: notExist,
112
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
113
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
114
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
108
115
  };
109
116
 
110
117
  export default implementations;
@@ -3,16 +3,15 @@ import { ImplementationNames, PoolState } from '../../types';
3
3
  import { get_dy, IPoolContext } from '../types';
4
4
  import { requireConstant, requireValue } from './utils';
5
5
 
6
- const factoryPlain2Basic: get_dy = (
6
+ const _genericFactoryPlain2Basic = (
7
7
  self: IPoolContext,
8
8
  state: PoolState,
9
9
  i: number,
10
10
  j: number,
11
11
  dx: bigint,
12
- ): bigint => {
12
+ rates: bigint[],
13
+ ) => {
13
14
  const { PRECISION, FEE_DENOMINATOR } = self.constants;
14
- const { rate_multipliers } = state.constants;
15
- const rates = [...rate_multipliers];
16
15
  const xp = self._xp_mem(self, rates, state.balances);
17
16
 
18
17
  const x = xp[i] + (dx * rates[i]) / PRECISION;
@@ -22,6 +21,49 @@ const factoryPlain2Basic: get_dy = (
22
21
  return ((dy - _fee) * PRECISION) / rates[j];
23
22
  };
24
23
 
24
+ const factoryPlain2Basic: get_dy = (
25
+ self: IPoolContext,
26
+ state: PoolState,
27
+ i: number,
28
+ j: number,
29
+ dx: bigint,
30
+ ): bigint => {
31
+ const { rate_multipliers } = state.constants;
32
+ const rates = [...rate_multipliers];
33
+ return _genericFactoryPlain2Basic(self, state, i, j, dx, rates);
34
+ };
35
+
36
+ const factoryPlain2EthEma2: get_dy = (
37
+ self: IPoolContext,
38
+ state: PoolState,
39
+ i: number,
40
+ j: number,
41
+ dx: bigint,
42
+ ): bigint => {
43
+ if (state.storedRates === undefined) {
44
+ throw new Error(
45
+ `${self.IMPLEMENTATION_NAME} factoryPlain2EthEma2: storedRates is not provided`,
46
+ );
47
+ }
48
+ const rates = [...state.storedRates];
49
+ return _genericFactoryPlain2Basic(self, state, i, j, dx, rates);
50
+ };
51
+ const factoryMetaBtcSbtc2: get_dy = (
52
+ self: IPoolContext,
53
+ state: PoolState,
54
+ i: number,
55
+ j: number,
56
+ dx: bigint,
57
+ ): bigint => {
58
+ if (state.virtualPrice === undefined) {
59
+ throw new Error(
60
+ `${self.IMPLEMENTATION_NAME} factoryMetaBtcSbtc2: virtualPrice is not provided`,
61
+ );
62
+ }
63
+ const rates = [state.constants.rate_multipliers[0], state.virtualPrice];
64
+ return _genericFactoryPlain2Basic(self, state, i, j, dx, rates);
65
+ };
66
+
25
67
  const factoryPlain2Optimized: get_dy = (
26
68
  self: IPoolContext,
27
69
  state: PoolState,
@@ -167,6 +209,7 @@ const customAvalanche3CoinLending: get_dy = (
167
209
  const implementations: Record<ImplementationNames, get_dy> = {
168
210
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
169
211
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinBtc,
212
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
170
213
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinBtc,
171
214
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
172
215
 
@@ -217,6 +260,12 @@ const implementations: Record<ImplementationNames, get_dy> = {
217
260
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: factoryPlain2Basic,
218
261
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: factoryPlain2Basic,
219
262
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: factoryPlain2Optimized,
263
+
264
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaBtcSbtc2,
265
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaBtcSbtc2,
266
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
267
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
268
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
220
269
  };
221
270
 
222
271
  export default implementations;
@@ -231,6 +231,7 @@ const notExist: get_dy_underlying = (
231
231
  const implementations: Record<ImplementationNames, get_dy_underlying> = {
232
232
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: notExist,
233
233
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: notExist,
234
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: notExist,
234
235
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: notExist,
235
236
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: notExist,
236
237
 
@@ -278,6 +279,12 @@ const implementations: Record<ImplementationNames, get_dy_underlying> = {
278
279
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
279
280
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
280
281
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
282
+
283
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaUsdFraxUsdc,
284
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaUsdFraxUsdc,
285
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
286
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
287
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
281
288
  };
282
289
 
283
290
  export default implementations;
@@ -135,6 +135,7 @@ const customPlain2CoinFrax = (
135
135
  const implementations: Record<ImplementationNames, get_y> = {
136
136
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
137
137
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
138
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
138
139
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
139
140
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
140
141
 
@@ -182,6 +183,12 @@ const implementations: Record<ImplementationNames, get_y> = {
182
183
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: customPlain2CoinFrax,
183
184
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: customPlain2CoinFrax,
184
185
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: customPlain2CoinFrax,
186
+
187
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: customPlain2CoinFrax,
188
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: customPlain2CoinFrax,
189
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain2CoinFrax,
190
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
191
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
185
192
  };
186
193
 
187
194
  export default implementations;
@@ -122,6 +122,7 @@ const notImplemented: get_y_D = (
122
122
  const implementations: Record<ImplementationNames, get_y_D> = {
123
123
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
124
124
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
125
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
125
126
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
126
127
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
127
128
 
@@ -168,6 +169,12 @@ const implementations: Record<ImplementationNames, get_y_D> = {
168
169
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
169
170
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
170
171
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
172
+
173
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: customPlain2CoinFrax,
174
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: customPlain2CoinFrax,
175
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain2CoinFrax,
176
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
177
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
171
178
  };
172
179
 
173
180
  export default implementations;
@@ -100,9 +100,9 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
100
100
  readonly dexKey: string,
101
101
  network: number,
102
102
  cacheStateKey: string,
103
- readonly implementationName: ImplementationNames,
104
- readonly implementationAddress: Address,
105
- readonly address: Address,
103
+ implementationName: ImplementationNames,
104
+ implementationAddress: Address,
105
+ address: Address,
106
106
  stateUpdatePeriodMs: number,
107
107
  readonly poolIdentifier: string,
108
108
  readonly poolConstants: PoolConstants,
@@ -114,6 +114,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
114
114
  readonly useLending?: boolean[],
115
115
  readonly isUsedForPricing: boolean = false,
116
116
  readonly contractABIs = ContractABIs,
117
+ customGasCost?: number,
117
118
  ) {
118
119
  // Current custom pools are always plain
119
120
  super(
@@ -131,6 +132,7 @@ export class CustomBasePoolForFactory extends PoolPollingBase {
131
132
  isLendingPool,
132
133
  undefined,
133
134
  CustomBasePoolForFactory.IS_SRC_FEE_ON_TRANSFER_SUPPORTED,
135
+ customGasCost,
134
136
  );
135
137
  }
136
138
 
@@ -14,10 +14,21 @@ import { BytesLike } from 'ethers/lib/utils';
14
14
  import { Address } from '@paraswap/core';
15
15
  import { BigNumber } from 'ethers';
16
16
  import { _require } from '../../../utils';
17
+ import { AbiItem } from 'web3-utils';
17
18
 
18
19
  const DEFAULT_2_ZERO_ARRAY = [0n, 0n];
19
20
  const DEFAULT_4_ZERO_ARRAY = [0n, 0n, 0n, 0n];
20
21
 
22
+ type AdditionalContractFunctions = 'stored_rates';
23
+
24
+ const getStoredRatesABI = (n: number) => ({
25
+ name: 'stored_rates',
26
+ stateMutability: 'view',
27
+ type: 'function',
28
+ inputs: [],
29
+ outputs: [{ name: '', type: `uint256[${n}]` }],
30
+ });
31
+
21
32
  export class FactoryStateHandler extends PoolPollingBase {
22
33
  constructor(
23
34
  readonly logger: Logger,
@@ -34,9 +45,14 @@ export class FactoryStateHandler extends PoolPollingBase {
34
45
  readonly poolContextConstants: PoolContextConstants,
35
46
  readonly isSrcFeeOnTransferSupported: boolean,
36
47
  baseStatePoolPolling?: PoolPollingBase,
48
+ customGasCost?: number,
49
+ readonly isStoredRatesSupported: boolean = false,
37
50
  private factoryIface: Interface = new Interface(
38
51
  FactoryCurveV1ABI as JsonFragment[],
39
52
  ),
53
+ private additionalFuncsIface: Interface = new Interface([
54
+ getStoredRatesABI(poolContextConstants.N_COINS),
55
+ ]),
40
56
  ) {
41
57
  super(
42
58
  logger,
@@ -53,6 +69,7 @@ export class FactoryStateHandler extends PoolPollingBase {
53
69
  false,
54
70
  baseStatePoolPolling,
55
71
  isSrcFeeOnTransferSupported,
72
+ customGasCost,
56
73
  );
57
74
 
58
75
  if (this.isMetaPool && this.baseStatePoolPolling === undefined) {
@@ -93,6 +110,24 @@ export class FactoryStateHandler extends PoolPollingBase {
93
110
  ),
94
111
  },
95
112
  ];
113
+
114
+ if (this.isStoredRatesSupported) {
115
+ calls.push({
116
+ target: this.address,
117
+ callData: this.additionalFuncsIface.encodeFunctionData(
118
+ 'stored_rates',
119
+ [],
120
+ ),
121
+ decodeFunction: (result: MultiResult<BytesLike> | BytesLike) =>
122
+ generalDecoder(
123
+ result,
124
+ [`uint256[${this.poolContextConstants.N_COINS}]`],
125
+ new Array(this.poolContextConstants.N_COINS).fill(0n),
126
+ parsed => parsed[0].map((p: BigNumber) => p.toBigInt()),
127
+ ),
128
+ });
129
+ }
130
+
96
131
  return calls;
97
132
  }
98
133
 
@@ -101,7 +136,12 @@ export class FactoryStateHandler extends PoolPollingBase {
101
136
  blockNumber: number,
102
137
  updatedAtMs: number,
103
138
  ): PoolState {
104
- const [A, fees, balances] = multiOutputs as [bigint, bigint[], bigint[]];
139
+ const [A, fees, balances, storedRates] = multiOutputs as [
140
+ bigint,
141
+ bigint[],
142
+ bigint[],
143
+ bigint[] | undefined,
144
+ ];
105
145
 
106
146
  let basePoolState: PoolState | undefined;
107
147
  if (this.isMetaPool) {
@@ -126,6 +166,7 @@ export class FactoryStateHandler extends PoolPollingBase {
126
166
  basePoolState,
127
167
  updatedAtMs,
128
168
  blockNumber,
169
+ storedRates,
129
170
  };
130
171
  }
131
172
  }
@@ -3,7 +3,7 @@ import { Network } from '../../../constants';
3
3
  import { IDexHelper } from '../../../dex-helper';
4
4
  import { Utils, _require } from '../../../utils';
5
5
  import { PoolState } from '../types';
6
- import { PoolPollingBase } from './pool-polling-base';
6
+ import { MulticallReturnedTypes, PoolPollingBase } from './pool-polling-base';
7
7
 
8
8
  /*
9
9
  * Since we are updating all pools state at once, I need some generalized iterator without state,
@@ -15,7 +15,7 @@ export class StatePollingManager {
15
15
  dexHelper: IDexHelper,
16
16
  pools: PoolPollingBase[],
17
17
  blockNumber?: number,
18
- ): Promise<PoolState[]> {
18
+ ): Promise<(PoolState | null)[]> {
19
19
  if (pools.length === 0) {
20
20
  return [];
21
21
  }
@@ -42,7 +42,8 @@ export class StatePollingManager {
42
42
  _blockNumber = 0;
43
43
  }
44
44
 
45
- const result = await dexHelper.multiWrapper.aggregate(
45
+ const results = await dexHelper.multiWrapper.tryAggregate(
46
+ false,
46
47
  callDatas,
47
48
  blockNumber,
48
49
  1000,
@@ -52,8 +53,36 @@ export class StatePollingManager {
52
53
  let lastStart = 0;
53
54
 
54
55
  for (const [i, p] of pools.entries()) {
56
+ const resultsForPool = results.slice(
57
+ lastStart,
58
+ lastStart + poolResultDividers[i],
59
+ );
60
+
61
+ let someCallsFailed = false;
62
+ let failedCalls: number[] = [];
63
+ const multiOutputs = resultsForPool.map((result, i) => {
64
+ if (result.success === false) {
65
+ someCallsFailed = true;
66
+ failedCalls.push(i);
67
+ return null;
68
+ }
69
+ return result.returnData;
70
+ // I consider this conversion safe without further checks, because if call failed, we won't proceed to state parsing
71
+ }) as MulticallReturnedTypes[];
72
+
73
+ if (someCallsFailed) {
74
+ const multiCallRequests = p.getStateMultiCalldata();
75
+ failedCalls.forEach(i => {
76
+ p.logger.error(
77
+ `Call number ${i} for pool=${p.address} to ${multiCallRequests[i].target} with ${multiCallRequests[i].callData} failed`,
78
+ );
79
+ });
80
+ newStates[i] = null;
81
+ continue;
82
+ }
83
+
55
84
  const newState = p.parseMultiResultsToStateValues(
56
- result.slice(lastStart, lastStart + poolResultDividers[i]),
85
+ multiOutputs,
57
86
  _blockNumber,
58
87
  updatedAt,
59
88
  );
@@ -86,13 +115,18 @@ export class StatePollingManager {
86
115
  );
87
116
  await Promise.all(
88
117
  pools.map(async (p, i) => {
89
- await dexHelper.cache.hset(
90
- p.cacheStateKey,
91
- p.poolIdentifier,
92
- Utils.Serialize(newStates[i]),
93
- );
118
+ if (newStates[i] !== null) {
119
+ await dexHelper.cache.hset(
120
+ p.cacheStateKey,
121
+ p.poolIdentifier,
122
+ Utils.Serialize(newStates[i]),
123
+ );
124
+ } else {
125
+ await dexHelper.cache.hdel(p.cacheStateKey, [p.poolIdentifier]);
126
+ }
94
127
  }),
95
128
  );
129
+
96
130
  logger.info(
97
131
  `${dexKey}: all (${pools.length}) pools state was successfully updated on network ${dexHelper.config.data.network}`,
98
132
  );
@@ -48,6 +48,7 @@ export abstract class PoolPollingBase {
48
48
  readonly isLendingPool: boolean,
49
49
  readonly baseStatePoolPolling: PoolPollingBase | undefined,
50
50
  readonly isSrcFeeOnTransferSupported: boolean,
51
+ readonly customGasCost: number | undefined,
51
52
  ) {
52
53
  this.fullName = `${dexKey}-${network}-${this.CLASS_NAME}-${this.implementationName}-${this.address}`;
53
54
  this.isMetaPool = baseStatePoolPolling !== undefined;
@@ -57,6 +57,7 @@ export type PoolState = {
57
57
  exchangeRateCurrent?: (bigint | undefined)[]; // from cToken -> exchangeRateCurrent()
58
58
  offpeg_fee_multiplier?: bigint; // from pool
59
59
  basePoolState?: PoolState;
60
+ storedRates?: bigint[]; // from pool, but only for oracle ones
60
61
  };
61
62
 
62
63
  export type PoolStateWithUpdateInfo<T> = {
@@ -84,6 +85,9 @@ export enum FactoryImplementationNames {
84
85
  FACTORY_META_BTC = 'factory_meta_btc',
85
86
  FACTORY_META_BTC_BALANCES = 'factory_meta_btc_balances',
86
87
 
88
+ FACTORY_META_BTC_SBTC2 = 'factory_meta_btc_sbtc2',
89
+ FACTORY_META_BTC_BALANCES_SBTC2 = 'factory_meta_btc_balances_sbtc2',
90
+
87
91
  FACTORY_META_BTC_REN = 'factory_meta_btc_ren',
88
92
  FACTORY_META_BTC_BALANCES_REN = 'factory_meta_btc_balances_ren',
89
93
 
@@ -95,7 +99,10 @@ export enum FactoryImplementationNames {
95
99
 
96
100
  FACTORY_PLAIN_2_BALANCES = 'factory_plain_2_balances',
97
101
  FACTORY_PLAIN_2_BASIC = 'factory_plain_2_basic',
102
+ FACTORY_PLAIN_2_BASIC_EMA = 'factory_plain_2_basic_ema',
98
103
  FACTORY_PLAIN_2_ETH = 'factory_plain_2_eth',
104
+ FACTORY_PLAIN_2_ETH_EMA = 'factory_plain_2_eth_ema',
105
+ FACTORY_PLAIN_2_ETH_EMA2 = 'factory_plain_2_eth_ema2',
99
106
  FACTORY_PLAIN_2_OPTIMIZED = 'factory_plain_2_optimized',
100
107
 
101
108
  FACTORY_PLAIN_3_BALANCES = 'factory_plain_3_balances',
@@ -114,6 +121,7 @@ export enum CustomImplementationNames {
114
121
  CUSTOM_PLAIN_2COIN_RENBTC = 'custom_plain_2coin_renbtc',
115
122
  CUSTOM_PLAIN_3COIN_SBTC = 'custom_plain_3coin_sbtc',
116
123
  CUSTOM_PLAIN_3COIN_THREE = 'custom_plain_3coin_three',
124
+ CUSTOM_PLAIN_2COIN_WBTC = 'custom_plain_2coin_wbtc',
117
125
 
118
126
  CUSTOM_ARBITRUM_2COIN_USD = 'custom_arbitrum_2coin_usd',
119
127
  CUSTOM_ARBITRUM_2COIN_BTC = 'custom_arbitrum_2coin_btc',
@@ -144,6 +152,8 @@ export type FactoryPoolImplementations = {
144
152
  name: FactoryImplementationNames;
145
153
  address: Address;
146
154
  basePoolAddress?: Address;
155
+ customGasCost?: number;
156
+ isStoreRateSupported?: boolean;
147
157
  };
148
158
 
149
159
  export type CustomPoolConfig = {
@@ -157,6 +167,10 @@ export type CustomPoolConfig = {
157
167
  // You must specify what typ must be encoded/decoded for coins request
158
168
  coinsInputType: string;
159
169
  balancesInputType: string;
170
+ // Because we have legacy event based implementation and new one, we don't want to use all
171
+ // pools for pricing. Only the ones that are explicitly specified. After legacy is fully moved to this implementation
172
+ // we can remove this flag
173
+ useForPricing: boolean;
160
174
  };
161
175
 
162
176
  export type DexParams = {
@@ -366,7 +366,7 @@ describe('QuickSwap', () => {
366
366
  ContractMethod.megaSwap,
367
367
  ],
368
368
  ],
369
- [ SwapSide.BUY, [ ContractMethod.simpleBuy, ContractMethod.buy ] ],
369
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
370
370
  ]);
371
371
 
372
372
  const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
@@ -8,11 +8,14 @@ import {
8
8
  SwaapV2QuoteResponse,
9
9
  SwaapV2PriceLevels,
10
10
  SwaapV2QuoteRequest,
11
- SwaapV2OrderType, SwaapV2TokensResponse, TokensMap,
11
+ SwaapV2OrderType,
12
+ SwaapV2TokensResponse,
13
+ TokensMap,
12
14
  } from './types';
13
15
  import {
14
16
  priceLevelsResponseValidator,
15
- getQuoteResponseValidator, getTokensResponseValidator,
17
+ getQuoteResponseValidator,
18
+ getTokensResponseValidator,
16
19
  } from './validators';
17
20
  import { normalizeTokenAddress } from './utils';
18
21
  import { SWAAP_RFQ_QUOTE_TIMEOUT_MS } from './constants';
@@ -71,7 +74,7 @@ export class RateFetcher {
71
74
  },
72
75
  config.tokensConfig.tokensIntervalMs,
73
76
  logger,
74
- )
77
+ );
75
78
  }
76
79
 
77
80
  start() {
@@ -89,13 +92,10 @@ export class RateFetcher {
89
92
  return;
90
93
  }
91
94
 
92
- const tokensMap = Object.keys(resp.tokens).reduce(
93
- (acc, key: string) => {
94
- acc[key.toLowerCase()] = resp.tokens[key];
95
- return acc;
96
- },
97
- {} as TokensMap,
98
- );
95
+ const tokensMap = Object.keys(resp.tokens).reduce((acc, key: string) => {
96
+ acc[key.toLowerCase()] = resp.tokens[key];
97
+ return acc;
98
+ }, {} as TokensMap);
99
99
 
100
100
  this.dexHelper.cache.setex(
101
101
  this.dexKey,
@@ -2,10 +2,7 @@ import dotenv from 'dotenv';
2
2
  dotenv.config();
3
3
 
4
4
  import { testE2E } from '../../../tests/utils-e2e';
5
- import {
6
- Tokens,
7
- Holders,
8
- } from '../../../tests/constants-e2e';
5
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
9
6
  import { Network, ContractMethod, SwapSide } from '../../constants';
10
7
  import { StaticJsonRpcProvider } from '@ethersproject/providers';
11
8
  import { generateConfig } from '../../config';
@@ -43,6 +43,10 @@ export const Tokens: {
43
43
  addBalance: balancesFn,
44
44
  addAllowance: allowedFn,
45
45
  },
46
+ sBTC: {
47
+ address: '0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6',
48
+ decimals: 18,
49
+ },
46
50
  BADGER: {
47
51
  address: '0x3472A5A71965499acd81997a54BBA8D852C6E53d',
48
52
  decimals: 18,
@@ -271,10 +275,6 @@ export const Tokens: {
271
275
  address: '0x853d955aCEf822Db058eb8505911ED77F175b99e',
272
276
  decimals: 18,
273
277
  },
274
- sBTC: {
275
- address: '0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6',
276
- decimals: 18,
277
- },
278
278
  sETH: {
279
279
  address: '0x5e74C9036fb86BD7eCdcb084a0673EFc32eA31cb',
280
280
  decimals: 18,
@@ -796,10 +796,6 @@ export const Tokens: {
796
796
  address: '0x4200000000000000000000000000000000000042',
797
797
  decimals: 18,
798
798
  },
799
- sBTC: {
800
- address: '0x298B9B95708152ff6968aafd889c6586e9169f1D',
801
- decimals: 18,
802
- },
803
799
  sETH: {
804
800
  address: '0xE405de8F52ba7559f9df3C368500B6E6ae6Cee49',
805
801
  decimals: 18,
@@ -833,7 +829,8 @@ export const Holders: {
833
829
  [Network.MAINNET]: {
834
830
  ETH: '0x176F3DAb24a159341c0509bB36B833E7fdd0a132',
835
831
  USDC: '0x79E2Ba942B0e8fDB6ff3d406e930289d10B49ADe',
836
- WBTC: '0x1Cb17a66DC606a52785f69F08F4256526aBd4943',
832
+ WBTC: '0x1cb17a66dc606a52785f69f08f4256526abd4943',
833
+ sBTC: '0xA2e3475D13776C6E42ff37B47286827d959B2195',
837
834
  BADGER: '0x34e2741a3f8483dbe5231f61c005110ff4b9f50a',
838
835
  STETH: '0x9bdb521a97e95177bf252c253e256a60c3e14447',
839
836
  wstETH: '0x6cE0F913F035ec6195bC3cE885aec4C66E485BC4',
@@ -878,7 +875,6 @@ export const Holders: {
878
875
  aWETH: '0x3ddfa8ec3052539b6c9549f12cea2c295cff5296',
879
876
  aUSDT: '0x4aef720f7bbe98f916221bbc2fb5a15efe6d2cb8',
880
877
  BBAUSD: '0x4361b7425cff39b1be9bf12cee2ef32f89656cda',
881
- sBTC: '0xc8c2b727d864cc75199f5118f0943d2087fb543b',
882
878
  sETH: '0x5fe009d78afabc1b04abd2d4361f8e95cd402648',
883
879
  sUSD: '0xcfb87039a1eda5428e2c8386d31ccf121835ecdb',
884
880
  USDD: '0xf89d7b9c864f589bbf53a82105107622b35eaa40',