@paraswap/dex-lib 2.20.3 → 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 (111) hide show
  1. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  2. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  3. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  4. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  5. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  6. package/build/dex/curve-v1-factory/config.js +91 -9
  7. package/build/dex/curve-v1-factory/config.js.map +1 -1
  8. package/build/dex/curve-v1-factory/curve-v1-factory.js +9 -3
  9. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  10. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +2 -0
  11. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
  12. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +27 -3
  13. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
  14. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +6 -0
  15. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
  16. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +6 -0
  17. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
  18. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +6 -0
  19. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
  20. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +6 -0
  21. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
  22. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +6 -0
  23. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
  24. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +6 -0
  25. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
  26. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +66 -0
  27. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  28. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +6 -0
  29. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
  30. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +20 -0
  31. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
  32. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +6 -0
  33. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
  34. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +26 -3
  35. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
  36. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +6 -0
  37. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
  38. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +6 -0
  39. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
  40. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +6 -0
  41. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
  42. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.d.ts +1 -4
  43. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js +2 -5
  44. package/build/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.js.map +1 -1
  45. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +3 -1
  46. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +22 -3
  47. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  48. package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.d.ts +1 -1
  49. package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js +28 -3
  50. package/build/dex/curve-v1-factory/state-polling-pools/polling-manager.js.map +1 -1
  51. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.d.ts +2 -1
  52. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js +2 -1
  53. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  54. package/build/dex/curve-v1-factory/types.d.ts +16 -0
  55. package/build/dex/curve-v1-factory/types.js +6 -0
  56. package/build/dex/curve-v1-factory/types.js.map +1 -1
  57. package/build/dex/index.js +2 -0
  58. package/build/dex/index.js.map +1 -1
  59. package/build/dex/quickswap/camelot-v3.d.ts +6 -0
  60. package/build/dex/quickswap/camelot-v3.js +19 -0
  61. package/build/dex/quickswap/camelot-v3.js.map +1 -0
  62. package/build/dex/quickswap/config.js +8 -0
  63. package/build/dex/quickswap/config.js.map +1 -1
  64. package/build/dex/swaap-v2/rate-fetcher.js.map +1 -1
  65. package/build/dex/test-dex/config.d.ts +4 -0
  66. package/build/dex/test-dex/config.js +15 -0
  67. package/build/dex/test-dex/config.js.map +1 -0
  68. package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
  69. package/build/dex/test-dex/test-dex-pool.js +63 -0
  70. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  71. package/build/dex/test-dex/test-dex.d.ts +37 -0
  72. package/build/dex/test-dex/test-dex.js +126 -0
  73. package/build/dex/test-dex/test-dex.js.map +1 -0
  74. package/build/dex/test-dex/types.d.ts +6 -0
  75. package/build/dex/test-dex/types.js +3 -0
  76. package/build/dex/test-dex/types.js.map +1 -0
  77. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  78. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  79. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  80. package/package.json +1 -1
  81. package/src/dex/curve-v1-factory/config.ts +91 -9
  82. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +36 -0
  83. package/src/dex/curve-v1-factory/curve-v1-factory.ts +12 -1
  84. package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +6 -0
  85. package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +53 -6
  86. package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +7 -0
  87. package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +7 -0
  88. package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +7 -0
  89. package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +7 -0
  90. package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +7 -0
  91. package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +7 -0
  92. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +78 -0
  93. package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +13 -0
  94. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +40 -3
  95. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +7 -0
  96. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +53 -4
  97. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +7 -0
  98. package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +7 -0
  99. package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +7 -0
  100. package/src/dex/curve-v1-factory/state-polling-pools/custom-pool-polling.ts +5 -3
  101. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +42 -1
  102. package/src/dex/curve-v1-factory/state-polling-pools/polling-manager.ts +43 -9
  103. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +1 -0
  104. package/src/dex/curve-v1-factory/types.ts +14 -0
  105. package/src/dex/index.ts +2 -0
  106. package/src/dex/quickswap/camelot-v3.ts +15 -0
  107. package/src/dex/quickswap/config.ts +9 -0
  108. package/src/dex/quickswap/quickswap-e2e.test.ts +109 -0
  109. package/src/dex/swaap-v2/rate-fetcher.ts +10 -10
  110. package/src/dex/swaap-v2/swaap-v2-e2e.test.ts +1 -4
  111. package/tests/constants-e2e.ts +6 -10
@@ -111,6 +111,42 @@ describe('CurveV1Factory E2E', () => {
111
111
  tokenBAmount,
112
112
  );
113
113
  });
114
+ describe('Mainnet ng pool', () => {
115
+ const network = Network.MAINNET;
116
+
117
+ const tokenASymbol: string = 'ETH';
118
+ const tokenBSymbol: string = 'STETH';
119
+
120
+ const tokenAAmount: string = '1000000000000000000';
121
+ const tokenBAmount: string = '1000000000000000000';
122
+
123
+ testForNetwork(
124
+ network,
125
+ dexKey,
126
+ tokenASymbol,
127
+ tokenBSymbol,
128
+ tokenAAmount,
129
+ tokenBAmount,
130
+ );
131
+ });
132
+ describe('Mainnet SBTC2 pool', () => {
133
+ const network = Network.MAINNET;
134
+
135
+ const tokenASymbol: string = 'WBTC';
136
+ const tokenBSymbol: string = 'sBTC';
137
+
138
+ const tokenAAmount: string = '100000000';
139
+ const tokenBAmount: string = '1000000000000000000';
140
+
141
+ testForNetwork(
142
+ network,
143
+ dexKey,
144
+ tokenASymbol,
145
+ tokenBSymbol,
146
+ tokenAAmount,
147
+ tokenBAmount,
148
+ );
149
+ });
114
150
  describe('Polygon', () => {
115
151
  const network = Network.POLYGON;
116
152
 
@@ -160,6 +160,14 @@ export class CurveV1Factory
160
160
  return acc;
161
161
  }, {});
162
162
 
163
+ Object.values(this.config.customPools).reduce((acc, curr) => {
164
+ if (curr.useForPricing) {
165
+ acc[curr.address] = new PriceHandler(this.logger, curr.name);
166
+ }
167
+
168
+ return acc;
169
+ }, allPriceHandlers);
170
+
163
171
  this.poolManager = new CurveV1FactoryPoolManager(
164
172
  this.dexKey,
165
173
  dexHelper.getLogger(`${this.dexKey}-state-manager`),
@@ -256,7 +264,7 @@ export class CurveV1Factory
256
264
  CustomImplementationNames,
257
265
  ).includes(customPool.name)
258
266
  ) {
259
- // We don't want custom pools to be used for pricing
267
+ // We don't want custom pools to be used for pricing, unless explicitly specified
260
268
  newPool = new CustomBasePoolForFactory(
261
269
  this.logger,
262
270
  this.dexKey,
@@ -274,6 +282,7 @@ export class CurveV1Factory
274
282
  isLending,
275
283
  customPool.balancesInputType,
276
284
  useLending,
285
+ customPool.useForPricing,
277
286
  );
278
287
  } else {
279
288
  // Use for pricing pools from factory
@@ -580,6 +589,8 @@ export class CurveV1Factory
580
589
  factoryImplementationConstants,
581
590
  factoryImplementationConstants.isFeeOnTransferSupported,
582
591
  basePoolStateFetcher,
592
+ factoryImplementationFromConfig.customGasCost,
593
+ factoryImplementationFromConfig.isStoreRateSupported,
583
594
  );
584
595
 
585
596
  this.poolManager.initializeNewPool(poolIdentifier, newPool);
@@ -16,6 +16,7 @@ import { PoolPollingBase } from './state-polling-pools/pool-polling-base';
16
16
  import { StatePollingManager } from './state-polling-pools/polling-manager';
17
17
  import { CACHE_PREFIX, NULL_ADDRESS } from '../../constants';
18
18
  import { LiquidityInCache } from './types';
19
+ import { assert } from 'ts-essentials';
19
20
 
20
21
  /*
21
22
  * The idea of FactoryPoolManager is to try to abstract both pool types: fully event based
@@ -123,6 +124,11 @@ export class CurveV1FactoryPoolManager {
123
124
  }
124
125
 
125
126
  getPriceHandler(implementationAddress: string): PriceHandler {
127
+ assert(
128
+ this.allPriceHandlers[implementationAddress],
129
+ `No price handler for ${implementationAddress}`,
130
+ );
131
+
126
132
  return this.allPriceHandlers[implementationAddress];
127
133
  }
128
134
 
@@ -52,22 +52,21 @@ const customPlain3CoinThree: _calc_withdraw_one_coin = (
52
52
  return [dy, dy_0 - dy, undefined];
53
53
  };
54
54
 
55
- const customArbitrum2CoinBtc: _calc_withdraw_one_coin = (
55
+ const _genericCustomArbitrum2CoinBtc = (
56
56
  self: IPoolContext,
57
57
  state: PoolState,
58
58
  _token_amount: bigint,
59
59
  i: number,
60
- ) => {
60
+ rates: bigint[],
61
+ ): [bigint, bigint, undefined] => {
61
62
  const { N_COINS, BI_N_COINS, FEE_DENOMINATOR, PRECISION } = self.constants;
63
+
62
64
  if (state.totalSupply === undefined) {
63
65
  throw new Error(
64
- `${self.IMPLEMENTATION_NAME} customArbitrum2CoinBtc: totalSupply is not provided`,
66
+ `${self.IMPLEMENTATION_NAME} _genericCustomArbitrum2CoinBtc: totalSupply is not provided`,
65
67
  );
66
68
  }
67
-
68
69
  const amp = state.A;
69
- const rates = [...state.constants.rate_multipliers];
70
-
71
70
  const xp = self._xp_mem(self, rates, state.balances);
72
71
  const D0 = self.get_D(self, xp, amp);
73
72
 
@@ -96,6 +95,46 @@ const customArbitrum2CoinBtc: _calc_withdraw_one_coin = (
96
95
  return [dy, dy_0 - dy, undefined];
97
96
  };
98
97
 
98
+ const customArbitrum2CoinBtc: _calc_withdraw_one_coin = (
99
+ self: IPoolContext,
100
+ state: PoolState,
101
+ _token_amount: bigint,
102
+ i: number,
103
+ ) => {
104
+ const rates = [...state.constants.rate_multipliers];
105
+ return _genericCustomArbitrum2CoinBtc(self, state, _token_amount, i, rates);
106
+ };
107
+
108
+ const factoryPlain2EthEma2: _calc_withdraw_one_coin = (
109
+ self: IPoolContext,
110
+ state: PoolState,
111
+ _token_amount: bigint,
112
+ i: number,
113
+ ) => {
114
+ if (state.storedRates === undefined) {
115
+ throw new Error(
116
+ `${self.IMPLEMENTATION_NAME} factoryPlain2EthEma2: storedRates is not provided`,
117
+ );
118
+ }
119
+ const rates = [...state.storedRates];
120
+ return _genericCustomArbitrum2CoinBtc(self, state, _token_amount, i, rates);
121
+ };
122
+
123
+ const factoryMetaBtcSbtc2: _calc_withdraw_one_coin = (
124
+ self: IPoolContext,
125
+ state: PoolState,
126
+ _token_amount: bigint,
127
+ i: number,
128
+ ) => {
129
+ if (state.virtualPrice === undefined) {
130
+ throw new Error(
131
+ `${self.IMPLEMENTATION_NAME} factoryMetaBtcSbtc2: virtualPrice is not provided`,
132
+ );
133
+ }
134
+ const rates = [state.constants.rate_multipliers[0], state.virtualPrice];
135
+ return _genericCustomArbitrum2CoinBtc(self, state, _token_amount, i, rates);
136
+ };
137
+
99
138
  const customAvalanche3CoinLending: _calc_withdraw_one_coin = (
100
139
  self: IPoolContext,
101
140
  state: PoolState,
@@ -187,6 +226,7 @@ const notImplemented: _calc_withdraw_one_coin = (
187
226
  const implementations: Record<ImplementationNames, _calc_withdraw_one_coin> = {
188
227
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain3CoinThree,
189
228
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
229
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customFantom2CoinBtc,
190
230
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
191
231
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
192
232
 
@@ -237,6 +277,13 @@ const implementations: Record<ImplementationNames, _calc_withdraw_one_coin> = {
237
277
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
238
278
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
239
279
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
280
+
281
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryMetaBtcSbtc2,
282
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryMetaBtcSbtc2,
283
+ // Keep in mind: these 2 are not 100% correct, because I don't calculate last "last_p" entry, because it doesn't affect pricing
284
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customArbitrum2CoinBtc,
285
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customArbitrum2CoinBtc,
286
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
240
287
  };
241
288
 
242
289
  export default implementations;
@@ -36,6 +36,7 @@ const notExist: _dynamic_fee = (
36
36
  const implementations: Record<ImplementationNames, _dynamic_fee> = {
37
37
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: notExist,
38
38
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: notExist,
39
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: notExist,
39
40
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: notExist,
40
41
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: notExist,
41
42
 
@@ -86,6 +87,12 @@ const implementations: Record<ImplementationNames, _dynamic_fee> = {
86
87
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
87
88
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
88
89
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
90
+
91
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: notExist,
92
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: notExist,
93
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
94
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
95
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
89
96
  };
90
97
 
91
98
  export default implementations;
@@ -55,6 +55,7 @@ const notExist: _rates = (self: IPoolContext, state: PoolState) => {
55
55
  const implementations: Record<ImplementationNames, _rates> = {
56
56
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: notExist,
57
57
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinSbtc,
58
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: notExist,
58
59
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinSbtc,
59
60
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: notExist,
60
61
 
@@ -101,6 +102,12 @@ const implementations: Record<ImplementationNames, _rates> = {
101
102
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
102
103
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
103
104
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
105
+
106
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: notExist,
107
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: notExist,
108
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
109
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
110
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
104
111
  };
105
112
 
106
113
  export default implementations;
@@ -53,6 +53,7 @@ const notExist: _xp = (self: IPoolContext, state: PoolState) => {
53
53
  const implementations: Record<ImplementationNames, _xp> = {
54
54
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain2CoinFrax,
55
55
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinSbtc,
56
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain2CoinFrax,
56
57
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinSbtc,
57
58
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
58
59
 
@@ -99,6 +100,12 @@ const implementations: Record<ImplementationNames, _xp> = {
99
100
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notExist,
100
101
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notExist,
101
102
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notExist,
103
+
104
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: notExist,
105
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: notExist,
106
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
107
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
108
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
102
109
  };
103
110
 
104
111
  export default implementations;
@@ -42,6 +42,7 @@ const notExist: _xp_mem = (
42
42
  const implementations: Record<ImplementationNames, _xp_mem> = {
43
43
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain3CoinThree,
44
44
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: factoryPlain2Basic,
45
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain3CoinThree,
45
46
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: factoryPlain2Basic,
46
47
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
47
48
 
@@ -88,6 +89,12 @@ const implementations: Record<ImplementationNames, _xp_mem> = {
88
89
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: factoryPlain2Basic,
89
90
  [ImplementationNames.FACTORY_PLAIN_4_BALANCES]: factoryPlain2Basic,
90
91
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: factoryPlain2Basic,
92
+
93
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: factoryPlain2Basic,
94
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: factoryPlain2Basic,
95
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
96
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
97
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2Basic,
91
98
  };
92
99
 
93
100
  export default implementations;
@@ -76,6 +76,7 @@ const notImplemented: calc_token_amount = (
76
76
  const implementations: Record<ImplementationNames, calc_token_amount> = {
77
77
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain3CoinThree,
78
78
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
79
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain3CoinThree,
79
80
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
80
81
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
81
82
 
@@ -126,6 +127,12 @@ const implementations: Record<ImplementationNames, calc_token_amount> = {
126
127
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
127
128
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
128
129
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
130
+
131
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: customPlain3CoinThree,
132
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: customPlain3CoinThree,
133
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain3CoinThree,
134
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain3CoinThree,
135
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain3CoinThree,
129
136
  };
130
137
 
131
138
  export default implementations;
@@ -29,6 +29,7 @@ export const implementations: Record<
29
29
  > = {
30
30
  [ImplementationNames.CUSTOM_PLAIN_2COIN_FRAX]: customPlain3CoinThree,
31
31
  [ImplementationNames.CUSTOM_PLAIN_2COIN_RENBTC]: customPlain3CoinThree,
32
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: customPlain3CoinThree,
32
33
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: customPlain3CoinThree,
33
34
  [ImplementationNames.CUSTOM_PLAIN_3COIN_THREE]: customPlain3CoinThree,
34
35
 
@@ -75,6 +76,12 @@ export const implementations: Record<
75
76
  [ImplementationNames.FACTORY_PLAIN_4_BASIC]: notImplemented,
76
77
  [ImplementationNames.FACTORY_PLAIN_4_ETH]: notImplemented,
77
78
  [ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED]: notImplemented,
79
+
80
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: customPlain3CoinThree,
81
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: customPlain3CoinThree,
82
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain3CoinThree,
83
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain3CoinThree,
84
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain3CoinThree,
78
85
  };
79
86
 
80
87
  export default implementations;
@@ -1,5 +1,6 @@
1
1
  import {} from 'ts-essentials';
2
2
  import { BI_POWS } from '../../../../bigint-constants';
3
+ import { PRECISION } from '../../../kyberdmm/fee-formula';
3
4
  import { ImplementationNames, PoolContextConstants } from '../../types';
4
5
 
5
6
  const implementationConstants: Record<
@@ -35,6 +36,21 @@ const implementationConstants: Record<
35
36
  LENDING_PRECISION: BI_POWS[18],
36
37
  USE_LENDING: [true, false],
37
38
  },
39
+ [ImplementationNames.CUSTOM_PLAIN_2COIN_WBTC]: {
40
+ isWrapNative: false,
41
+ isFeeOnTransferSupported: false,
42
+ isLending: false,
43
+
44
+ N_COINS: 2,
45
+ BI_N_COINS: 2n,
46
+
47
+ FEE_DENOMINATOR: BI_POWS[10],
48
+ PRECISION: BI_POWS[18],
49
+
50
+ PRECISION_MUL: [10000000000n, 1n],
51
+ RATES: [10000000000000000000000000000n, 1000000000000000000n],
52
+ A_PRECISION: 100n,
53
+ },
38
54
  [ImplementationNames.CUSTOM_PLAIN_3COIN_SBTC]: {
39
55
  isWrapNative: false,
40
56
  isFeeOnTransferSupported: false,
@@ -501,6 +517,68 @@ const implementationConstants: Record<
501
517
 
502
518
  A_PRECISION: 100n,
503
519
  },
520
+
521
+ [ImplementationNames.FACTORY_META_BTC_SBTC2]: {
522
+ isWrapNative: false,
523
+ isFeeOnTransferSupported: false,
524
+ isLending: false,
525
+
526
+ N_COINS: 2,
527
+ BI_N_COINS: 2n,
528
+ MAX_COIN: 2 - 1,
529
+
530
+ BASE_N_COINS: 2,
531
+ PRECISION: BI_POWS[18],
532
+ FEE_DENOMINATOR: BI_POWS[10],
533
+ A_PRECISION: 100n,
534
+ },
535
+ [ImplementationNames.FACTORY_META_BTC_BALANCES_SBTC2]: {
536
+ isWrapNative: false,
537
+ isFeeOnTransferSupported: true,
538
+ isLending: false,
539
+
540
+ N_COINS: 2,
541
+ BI_N_COINS: 2n,
542
+ MAX_COIN: 2 - 1,
543
+
544
+ BASE_N_COINS: 2,
545
+ PRECISION: BI_POWS[18],
546
+ FEE_DENOMINATOR: BI_POWS[10],
547
+ A_PRECISION: 100n,
548
+ },
549
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: {
550
+ isWrapNative: false,
551
+ isFeeOnTransferSupported: false,
552
+ isLending: false,
553
+
554
+ N_COINS: 2,
555
+ BI_N_COINS: 2n,
556
+ PRECISION: BI_POWS[18],
557
+ FEE_DENOMINATOR: BI_POWS[10],
558
+ A_PRECISION: 100n,
559
+ },
560
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: {
561
+ isWrapNative: false,
562
+ isFeeOnTransferSupported: false,
563
+ isLending: false,
564
+
565
+ N_COINS: 2,
566
+ BI_N_COINS: 2n,
567
+ PRECISION: BI_POWS[18],
568
+ FEE_DENOMINATOR: BI_POWS[10],
569
+ A_PRECISION: 100n,
570
+ },
571
+ [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: {
572
+ isWrapNative: false,
573
+ isFeeOnTransferSupported: true,
574
+ isLending: false,
575
+
576
+ N_COINS: 2,
577
+ BI_N_COINS: 2n,
578
+ PRECISION: BI_POWS[18],
579
+ FEE_DENOMINATOR: BI_POWS[10],
580
+ A_PRECISION: 100n,
581
+ },
504
582
  };
505
583
 
506
584
  export default implementationConstants;
@@ -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;