@paraswap/dex-lib 2.30.1 → 2.30.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 (149) hide show
  1. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  2. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  3. package/build/abi/woo-fi/WooFeeManager.abi.json +318 -0
  4. package/build/abi/woo-fi/WooPP.abi.json +548 -0
  5. package/build/abi/woo-fi/Wooracle.abi.json +260 -0
  6. package/build/dex/aave-v3/tokens/arbitrum.json +50 -0
  7. package/build/dex/aave-v3/tokens/avalanche.json +74 -0
  8. package/build/dex/aave-v3/tokens/fantom.json +62 -0
  9. package/build/dex/aave-v3/tokens/optimism.json +50 -0
  10. package/build/dex/aave-v3/tokens/polygon.json +116 -0
  11. package/build/dex/balancer-v2/LinearMath.d.ts +19 -0
  12. package/build/dex/balancer-v2/LinearMath.js +179 -0
  13. package/build/dex/balancer-v2/LinearMath.js.map +1 -0
  14. package/build/dex/balancer-v2/LinearPool.d.ts +47 -0
  15. package/build/dex/balancer-v2/LinearPool.js +324 -0
  16. package/build/dex/balancer-v2/LinearPool.js.map +1 -0
  17. package/build/dex/balancer-v2/PhantomStablePool.d.ts +47 -0
  18. package/build/dex/balancer-v2/PhantomStablePool.js +294 -0
  19. package/build/dex/balancer-v2/PhantomStablePool.js.map +1 -0
  20. package/build/dex/balancer-v2/StableMath.d.ts +9 -0
  21. package/build/dex/balancer-v2/StableMath.js +272 -0
  22. package/build/dex/balancer-v2/StableMath.js.map +1 -0
  23. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +75 -0
  24. package/build/dex/balancer-v2/balancer-v2-pool.js +417 -0
  25. package/build/dex/balancer-v2/balancer-v2-pool.js.map +1 -0
  26. package/build/dex/curve-v1-factory/config.js +17 -9
  27. package/build/dex/curve-v1-factory/config.js.map +1 -1
  28. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +1 -1
  29. package/build/dex/curve-v1-factory/curve-v1-factory.js +192 -177
  30. package/build/dex/curve-v1-factory/curve-v1-factory.js.map +1 -1
  31. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js +4 -1
  32. package/build/dex/curve-v1-factory/curve-v1-pool-manager.js.map +1 -1
  33. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js +1 -0
  34. package/build/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.js.map +1 -1
  35. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js +1 -0
  36. package/build/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.js.map +1 -1
  37. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js +1 -0
  38. package/build/dex/curve-v1-factory/price-handlers/functions/_rates.js.map +1 -1
  39. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js +1 -0
  40. package/build/dex/curve-v1-factory/price-handlers/functions/_xp.js.map +1 -1
  41. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js +1 -0
  42. package/build/dex/curve-v1-factory/price-handlers/functions/_xp_mem.js.map +1 -1
  43. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js +73 -1
  44. package/build/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.js.map +1 -1
  45. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js +1 -0
  46. package/build/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.js.map +1 -1
  47. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js +10 -0
  48. package/build/dex/curve-v1-factory/price-handlers/functions/constants.js.map +1 -1
  49. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js +1 -0
  50. package/build/dex/curve-v1-factory/price-handlers/functions/get_D.js.map +1 -1
  51. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js +1 -0
  52. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_mem.js.map +1 -1
  53. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js +1 -0
  54. package/build/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.js.map +1 -1
  55. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js +1 -0
  56. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy.js.map +1 -1
  57. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js +1 -0
  58. package/build/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.js.map +1 -1
  59. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js +1 -0
  60. package/build/dex/curve-v1-factory/price-handlers/functions/get_y.js.map +1 -1
  61. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js +1 -0
  62. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
  63. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +1 -1
  64. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +2 -2
  65. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  66. package/build/dex/curve-v1-factory/types.d.ts +4 -1
  67. package/build/dex/curve-v1-factory/types.js +1 -0
  68. package/build/dex/curve-v1-factory/types.js.map +1 -1
  69. package/build/dex/quickswap-v3.d.ts +21 -0
  70. package/build/dex/quickswap-v3.js +40 -0
  71. package/build/dex/quickswap-v3.js.map +1 -0
  72. package/build/dex/solidly/forks-override/ramses.js +20 -8
  73. package/build/dex/solidly/forks-override/ramses.js.map +1 -1
  74. package/build/dex/solidly/solidly.js +1 -1
  75. package/build/dex/test-dex/config.d.ts +4 -0
  76. package/build/dex/test-dex/config.js +15 -0
  77. package/build/dex/test-dex/config.js.map +1 -0
  78. package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
  79. package/build/dex/test-dex/test-dex-pool.js +63 -0
  80. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  81. package/build/dex/test-dex/test-dex.d.ts +37 -0
  82. package/build/dex/test-dex/test-dex.js +126 -0
  83. package/build/dex/test-dex/test-dex.js.map +1 -0
  84. package/build/dex/test-dex/types.d.ts +6 -0
  85. package/build/dex/test-dex/types.js +3 -0
  86. package/build/dex/test-dex/types.js.map +1 -0
  87. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
  88. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
  89. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
  90. package/build/dex/uniswap-v3/types.js.map +1 -1
  91. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  92. package/build/dex/uniswap-v3/uniswap-v3.js +1 -1
  93. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  94. package/build/dex/woo-fi/config.d.ts +4 -0
  95. package/build/dex/woo-fi/config.js +141 -0
  96. package/build/dex/woo-fi/config.js.map +1 -0
  97. package/build/dex/woo-fi/constants.d.ts +5 -0
  98. package/build/dex/woo-fi/constants.js +20 -0
  99. package/build/dex/woo-fi/constants.js.map +1 -0
  100. package/build/dex/woo-fi/types.d.ts +48 -0
  101. package/build/dex/woo-fi/types.js +3 -0
  102. package/build/dex/woo-fi/types.js.map +1 -0
  103. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +14 -0
  104. package/build/dex/woo-fi/woo-fi-decimal-math.js +42 -0
  105. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +1 -0
  106. package/build/dex/woo-fi/woo-fi-math.d.ts +31 -0
  107. package/build/dex/woo-fi/woo-fi-math.js +300 -0
  108. package/build/dex/woo-fi/woo-fi-math.js.map +1 -0
  109. package/build/dex/woo-fi/woo-fi.d.ts +65 -0
  110. package/build/dex/woo-fi/woo-fi.js +480 -0
  111. package/build/dex/woo-fi/woo-fi.js.map +1 -0
  112. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  113. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  114. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  115. package/package.json +1 -1
  116. package/src/dex/curve-v1-factory/config.ts +17 -9
  117. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +19 -0
  118. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +108 -45
  119. package/src/dex/curve-v1-factory/curve-v1-factory.ts +415 -367
  120. package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +4 -1
  121. package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +1 -0
  122. package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +1 -0
  123. package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +1 -0
  124. package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +1 -0
  125. package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +1 -0
  126. package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +91 -1
  127. package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +1 -0
  128. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +11 -0
  129. package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +2 -0
  130. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +1 -0
  131. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +1 -0
  132. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +1 -0
  133. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +1 -0
  134. package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +1 -0
  135. package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +1 -0
  136. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +2 -1
  137. package/src/dex/curve-v1-factory/types.ts +3 -1
  138. package/src/dex/solidly/forks-override/ramses.ts +105 -76
  139. package/src/dex/solidly/solidly.ts +1 -1
  140. package/src/dex/uniswap-v3/types.ts +4 -2
  141. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +50 -46
  142. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +2 -15
  143. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +5 -2
  144. package/src/dex/uniswap-v3/uniswap-v3.ts +1 -1
  145. package/tests/constants-e2e.ts +10 -0
  146. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  147. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  148. package/build/dex/algebra/algebra-pool.js +0 -336
  149. package/build/dex/algebra/algebra-pool.js.map +0 -1
@@ -42,7 +42,10 @@ export class CurveV1FactoryPoolManager {
42
42
  // It should bo considered for optimizing
43
43
  private coinAddressesToPoolIdentifiers: Record<string, string[]> = {};
44
44
 
45
- private allCurveLiquidityApiSlugs: Set<string> = new Set(['/factory']);
45
+ private allCurveLiquidityApiSlugs: Set<string> = new Set([
46
+ '/factory',
47
+ '/factory-crvusd',
48
+ ]);
46
49
 
47
50
  private statePollingManager = StatePollingManager;
48
51
  private taskScheduler: TaskScheduler;
@@ -284,6 +284,7 @@ const implementations: Record<ImplementationNames, _calc_withdraw_one_coin> = {
284
284
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customArbitrum2CoinBtc,
285
285
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customArbitrum2CoinBtc,
286
286
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
287
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customArbitrum2CoinBtc,
287
288
  };
288
289
 
289
290
  export default implementations;
@@ -93,6 +93,7 @@ const implementations: Record<ImplementationNames, _dynamic_fee> = {
93
93
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
94
94
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
95
95
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
96
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
96
97
  };
97
98
 
98
99
  export default implementations;
@@ -108,6 +108,7 @@ const implementations: Record<ImplementationNames, _rates> = {
108
108
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
109
109
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
110
110
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
111
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
111
112
  };
112
113
 
113
114
  export default implementations;
@@ -106,6 +106,7 @@ const implementations: Record<ImplementationNames, _xp> = {
106
106
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
107
107
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
108
108
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
109
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
109
110
  };
110
111
 
111
112
  export default implementations;
@@ -95,6 +95,7 @@ const implementations: Record<ImplementationNames, _xp_mem> = {
95
95
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
96
96
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
97
97
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2Basic,
98
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: factoryPlain2Basic,
98
99
  };
99
100
 
100
101
  export default implementations;
@@ -64,6 +64,95 @@ const customAvalanche3CoinLending: calc_token_amount = (
64
64
  return (diff * state.totalSupply) / D0;
65
65
  };
66
66
 
67
+ const factoryPlain2Basic: calc_token_amount = (
68
+ self: IPoolContext,
69
+ state: PoolState,
70
+ amounts: bigint[],
71
+ is_deposit: boolean,
72
+ ) => {
73
+ const { N_COINS } = self.constants;
74
+ const amp = state.A;
75
+ const balances = [...state.balances];
76
+ const D0 = self.get_D(self, balances, amp);
77
+ for (const i of _.range(N_COINS)) {
78
+ if (is_deposit) balances[i] += amounts[i];
79
+ else balances[i] -= amounts[i];
80
+ }
81
+ const D1 = self.get_D(self, balances, amp);
82
+
83
+ if (state.totalSupply === undefined) {
84
+ throw new Error(
85
+ `${self.IMPLEMENTATION_NAME} customPlain3CoinThree: totalSupply is not provided`,
86
+ );
87
+ }
88
+
89
+ const token_amount = state.totalSupply;
90
+ let diff = 0n;
91
+ if (is_deposit) {
92
+ diff = D1 - D0;
93
+ } else {
94
+ diff = D0 - D1;
95
+ }
96
+ return (diff * token_amount) / D0;
97
+ };
98
+
99
+ const customPlain2CoinCrv: calc_token_amount = (
100
+ self: IPoolContext,
101
+ state: PoolState,
102
+ amounts: bigint[],
103
+ is_deposit: boolean,
104
+ ) => {
105
+ const { N_COINS, BI_N_COINS, FEE_DENOMINATOR } = self.constants;
106
+ const amp = state.A;
107
+ const balances = [...state.balances];
108
+ const D0 = self.get_D_mem(self, state, balances, amp);
109
+ for (const i of _.range(N_COINS)) {
110
+ if (is_deposit) balances[i] += amounts[i];
111
+ else balances[i] -= amounts[i];
112
+ }
113
+ const D1 = self.get_D_mem(self, state, balances, amp);
114
+
115
+ if (state.totalSupply === undefined) {
116
+ throw new Error(
117
+ `${self.IMPLEMENTATION_NAME} customPlain3CoinThree: totalSupply is not provided`,
118
+ );
119
+ }
120
+
121
+ const total_supply = state.totalSupply;
122
+ let D2 = D1;
123
+
124
+ if (total_supply > 0n) {
125
+ const base_fee = (state.fee * BI_N_COINS) / (4n * (BI_N_COINS - 1n));
126
+ for (const i of _.range(N_COINS)) {
127
+ const ideal_balance = (D1 * state.balances[i]) / D0;
128
+ let difference = 0n;
129
+ const new_balance = balances[i];
130
+ if (ideal_balance > new_balance) {
131
+ difference = ideal_balance - new_balance;
132
+ } else {
133
+ difference = new_balance - ideal_balance;
134
+ }
135
+ balances[i] -= (base_fee * difference) / FEE_DENOMINATOR;
136
+ }
137
+ const xp = self._xp_mem(
138
+ self,
139
+ [...state.constants.rate_multipliers],
140
+ balances,
141
+ );
142
+ D2 = self.get_D_mem(self, state, xp, amp);
143
+ } else {
144
+ return D1;
145
+ }
146
+
147
+ let diff = 0n;
148
+ if (is_deposit) {
149
+ diff = D2 - D0;
150
+ } else {
151
+ diff = D0 - D2;
152
+ }
153
+ return (diff * total_supply) / D0;
154
+ };
155
+
67
156
  const notImplemented: calc_token_amount = (
68
157
  self: IPoolContext,
69
158
  state: PoolState,
@@ -114,7 +203,7 @@ const implementations: Record<ImplementationNames, calc_token_amount> = {
114
203
  [ImplementationNames.FACTORY_META_USD_BALANCES_FRAX_USDC]: notImplemented,
115
204
 
116
205
  [ImplementationNames.FACTORY_PLAIN_2_BALANCES]: notImplemented,
117
- [ImplementationNames.FACTORY_PLAIN_2_BASIC]: notImplemented,
206
+ [ImplementationNames.FACTORY_PLAIN_2_BASIC]: factoryPlain2Basic,
118
207
  [ImplementationNames.FACTORY_PLAIN_2_ETH]: notImplemented,
119
208
  [ImplementationNames.FACTORY_PLAIN_2_OPTIMIZED]: notImplemented,
120
209
 
@@ -133,6 +222,7 @@ const implementations: Record<ImplementationNames, calc_token_amount> = {
133
222
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain3CoinThree,
134
223
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain3CoinThree,
135
224
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain3CoinThree,
225
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain2CoinCrv,
136
226
  };
137
227
 
138
228
  export default implementations;
@@ -82,6 +82,7 @@ export const implementations: Record<
82
82
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain3CoinThree,
83
83
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain3CoinThree,
84
84
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain3CoinThree,
85
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain3CoinThree,
85
86
  };
86
87
 
87
88
  export default implementations;
@@ -573,6 +573,17 @@ const implementationConstants: Record<
573
573
  isFeeOnTransferSupported: true,
574
574
  isLending: false,
575
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
+ },
582
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: {
583
+ isWrapNative: false,
584
+ isFeeOnTransferSupported: false,
585
+ isLending: false,
586
+
576
587
  N_COINS: 2,
577
588
  BI_N_COINS: 2n,
578
589
  PRECISION: BI_POWS[18],
@@ -321,6 +321,8 @@ const implementations: Record<ImplementationNames, get_D> = {
321
321
  makeFuncCacheable(factoryPlain2Basic),
322
322
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]:
323
323
  makeFuncCacheable(factoryPlain2Basic),
324
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]:
325
+ makeFuncCacheable(factoryPlain2Basic),
324
326
  };
325
327
 
326
328
  export default implementations;
@@ -140,6 +140,7 @@ export const implementations: Record<ImplementationNames, get_D_mem> = {
140
140
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
141
141
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
142
142
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
143
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: factoryPlain2Basic,
143
144
  };
144
145
 
145
146
  export default implementations;
@@ -112,6 +112,7 @@ const implementations: Record<ImplementationNames, get_D_precisions> = {
112
112
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
113
113
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
114
114
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
115
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
115
116
  };
116
117
 
117
118
  export default implementations;
@@ -266,6 +266,7 @@ const implementations: Record<ImplementationNames, get_dy> = {
266
266
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: factoryPlain2Basic,
267
267
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
268
268
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
269
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: factoryPlain2Basic,
269
270
  };
270
271
 
271
272
  export default implementations;
@@ -285,6 +285,7 @@ const implementations: Record<ImplementationNames, get_dy_underlying> = {
285
285
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: notExist,
286
286
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
287
287
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
288
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
288
289
  };
289
290
 
290
291
  export default implementations;
@@ -189,6 +189,7 @@ const implementations: Record<ImplementationNames, get_y> = {
189
189
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain2CoinFrax,
190
190
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
191
191
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
192
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain2CoinFrax,
192
193
  };
193
194
 
194
195
  export default implementations;
@@ -175,6 +175,7 @@ const implementations: Record<ImplementationNames, get_y_D> = {
175
175
  [ImplementationNames.FACTORY_PLAIN_2_BASIC_EMA]: customPlain2CoinFrax,
176
176
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
177
177
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
178
+ [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain2CoinFrax,
178
179
  };
179
180
 
180
181
  export default implementations;
@@ -44,6 +44,7 @@ export class FactoryStateHandler extends PoolPollingBase {
44
44
  readonly poolConstants: PoolConstants,
45
45
  readonly poolContextConstants: PoolContextConstants,
46
46
  readonly isSrcFeeOnTransferSupported: boolean,
47
+ liquidityApiSlug: string,
47
48
  baseStatePoolPolling?: PoolPollingBase,
48
49
  customGasCost?: number,
49
50
  readonly isStoredRatesSupported: boolean = false,
@@ -65,7 +66,7 @@ export class FactoryStateHandler extends PoolPollingBase {
65
66
  poolIdentifier,
66
67
  poolConstants,
67
68
  address,
68
- '/factory',
69
+ liquidityApiSlug,
69
70
  false,
70
71
  baseStatePoolPolling,
71
72
  isSrcFeeOnTransferSupported,
@@ -104,6 +104,7 @@ export enum FactoryImplementationNames {
104
104
  FACTORY_PLAIN_2_ETH_EMA = 'factory_plain_2_eth_ema',
105
105
  FACTORY_PLAIN_2_ETH_EMA2 = 'factory_plain_2_eth_ema2',
106
106
  FACTORY_PLAIN_2_OPTIMIZED = 'factory_plain_2_optimized',
107
+ FACTORY_PLAIN_2_CRV_EMA = 'factory_plain_2_crv_ema',
107
108
 
108
109
  FACTORY_PLAIN_3_BALANCES = 'factory_plain_3_balances',
109
110
  FACTORY_PLAIN_3_BASIC = 'factory_plain_3_basic',
@@ -154,6 +155,7 @@ export type FactoryPoolImplementations = {
154
155
  basePoolAddress?: Address;
155
156
  customGasCost?: number;
156
157
  isStoreRateSupported?: boolean;
158
+ liquidityApiSlug?: string;
157
159
  };
158
160
 
159
161
  export type CustomPoolConfig = {
@@ -174,7 +176,7 @@ export type CustomPoolConfig = {
174
176
  };
175
177
 
176
178
  export type DexParams = {
177
- factoryAddress: string | null;
179
+ factoryAddresses: string[] | null;
178
180
  stateUpdatePeriodMs: number;
179
181
  factoryPoolImplementations: Record<Address, FactoryPoolImplementations>;
180
182
  customPools: Record<string, CustomPoolConfig>;
@@ -9,12 +9,11 @@ import { IDexHelper } from '../../../dex-helper';
9
9
  import { SolidlyPair } from '../types';
10
10
  import { Interface } from '@ethersproject/abi';
11
11
 
12
-
13
12
  const RamsesFactoryABI = [
14
13
  {
15
- inputs: [{internalType: 'address', name: '', type: 'address'}],
14
+ inputs: [{ internalType: 'address', name: '', type: 'address' }],
16
15
  name: 'pairFee',
17
- outputs: [{internalType: 'uint256', 'name': '', type: 'uint256'}],
16
+ outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
18
17
  stateMutability: 'view',
19
18
  type: 'function',
20
19
  },
@@ -34,10 +33,9 @@ export type RamsesSubgraphPool = {
34
33
  export type RamsesSubgraphToken = {
35
34
  id: string;
36
35
  decimals: string;
37
- }
36
+ };
38
37
 
39
38
  export class Ramses extends Solidly {
40
-
41
39
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
42
40
  getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Ramses']));
43
41
 
@@ -57,7 +55,9 @@ export class Ramses extends Solidly {
57
55
  protected getFeesMultiCallData(pair: SolidlyPair) {
58
56
  const callEntry = {
59
57
  target: this.factoryAddress,
60
- callData: ramsesFactoryIface.encodeFunctionData('pairFee', [pair.exchange]),
58
+ callData: ramsesFactoryIface.encodeFunctionData('pairFee', [
59
+ pair.exchange,
60
+ ]),
61
61
  };
62
62
  const callDecoder = (values: any[]) =>
63
63
  parseInt(
@@ -109,8 +109,11 @@ export class Ramses extends Solidly {
109
109
  if (!(data && data.pools0 && data.pools1))
110
110
  throw new Error("Couldn't fetch the pools from the subgraph");
111
111
 
112
- const tokenIds = _.uniq([].concat(data.pools0, data.pools1).map(
113
- (pool: RamsesSubgraphPool) => [ pool.token0, pool.token1]).flat(),
112
+ const tokenIds = _.uniq(
113
+ []
114
+ .concat(data.pools0, data.pools1)
115
+ .map((pool: RamsesSubgraphPool) => [pool.token0, pool.token1])
116
+ .flat(),
114
117
  );
115
118
 
116
119
  const tokensQuery = `
@@ -121,7 +124,6 @@ export class Ramses extends Solidly {
121
124
  }
122
125
  }`;
123
126
 
124
-
125
127
  const { data: tokensData } = await this.dexHelper.httpRequest.post(
126
128
  this.subgraphURL,
127
129
  {
@@ -131,35 +133,45 @@ export class Ramses extends Solidly {
131
133
  SUBGRAPH_TIMEOUT,
132
134
  );
133
135
 
134
- const pools0 = await this.prepareSubgraphPools(tokensData.tokens, data.pools0, (pool,{
135
- address1, decimals1, liquidityUSDToken0, liquidityUSDToken1,
136
- }) => ({
137
- exchange: this.dexKey,
138
- stable: pool.isStable,
139
- address: pool.id.toLowerCase(),
140
- connectorTokens: [
141
- {
142
- address: address1,
143
- decimals: decimals1,
144
- },
145
- ],
146
- liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
147
- }));
148
-
149
- const pools1 = await this.prepareSubgraphPools(tokensData.tokens, data.pools1, (pool,{
150
- address0, decimals0, liquidityUSDToken0, liquidityUSDToken1,
151
- }) => ({
152
- exchange: this.dexKey,
153
- stable: pool.isStable,
154
- address: pool.id.toLowerCase(),
155
- connectorTokens: [
156
- {
157
- address: address0,
158
- decimals: decimals0,
159
- },
160
- ],
161
- liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
162
- }));
136
+ const pools0 = await this.prepareSubgraphPools(
137
+ tokensData.tokens,
138
+ data.pools0,
139
+ (
140
+ pool,
141
+ { address1, decimals1, liquidityUSDToken0, liquidityUSDToken1 },
142
+ ) => ({
143
+ exchange: this.dexKey,
144
+ stable: pool.isStable,
145
+ address: pool.id.toLowerCase(),
146
+ connectorTokens: [
147
+ {
148
+ address: address1,
149
+ decimals: decimals1,
150
+ },
151
+ ],
152
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
153
+ }),
154
+ );
155
+
156
+ const pools1 = await this.prepareSubgraphPools(
157
+ tokensData.tokens,
158
+ data.pools1,
159
+ (
160
+ pool,
161
+ { address0, decimals0, liquidityUSDToken0, liquidityUSDToken1 },
162
+ ) => ({
163
+ exchange: this.dexKey,
164
+ stable: pool.isStable,
165
+ address: pool.id.toLowerCase(),
166
+ connectorTokens: [
167
+ {
168
+ address: address0,
169
+ decimals: decimals0,
170
+ },
171
+ ],
172
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
173
+ }),
174
+ );
163
175
 
164
176
  return _.slice(
165
177
  _.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
@@ -172,7 +184,8 @@ export class Ramses extends Solidly {
172
184
  tokens: RamsesSubgraphToken[],
173
185
  pools: RamsesSubgraphPool[],
174
186
  iterator: (
175
- pool: RamsesSubgraphPool, {
187
+ pool: RamsesSubgraphPool,
188
+ {
176
189
  address0,
177
190
  address1,
178
191
  decimals0,
@@ -182,43 +195,59 @@ export class Ramses extends Solidly {
182
195
  liquidityUSDToken0,
183
196
  liquidityUSDToken1,
184
197
  }: {
185
- address0: string,
186
- address1: string,
187
- decimals0: number,
188
- decimals1: number,
189
- reserve0: bigint,
190
- reserve1: bigint,
191
- liquidityUSDToken0: number,
192
- liquidityUSDToken1: number,
193
- }) => PoolLiquidity
198
+ address0: string;
199
+ address1: string;
200
+ decimals0: number;
201
+ decimals1: number;
202
+ reserve0: bigint;
203
+ reserve1: bigint;
204
+ liquidityUSDToken0: number;
205
+ liquidityUSDToken1: number;
206
+ },
207
+ ) => PoolLiquidity,
194
208
  ): Promise<PoolLiquidity[]> {
195
- return Promise.all(pools.map(async (
196
- pool: RamsesSubgraphPool,
197
- ) => {
198
- const address0 = pool.token0.toLowerCase();
199
- const address1 = pool.token1.toLowerCase();
200
-
201
- const decimals0 = parseInt(tokens.find((t) => t.id === address0)!.decimals);
202
- const decimals1 = parseInt(tokens.find((t) => t.id === address1)!.decimals);
203
-
204
- const reserve0 = BigInt(new BigNumber(pool.reserve0).toFixed());
205
- const reserve1 = BigInt(new BigNumber(pool.reserve1).toFixed());
206
-
207
- const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice({
208
- address: address0,
209
- decimals: decimals0,
210
- }, reserve0);
211
-
212
- const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice({
213
- address: address1,
214
- decimals: decimals1,
215
- }, reserve1);
216
-
217
- return iterator(
218
- pool, {
219
- address0, address1, decimals0, decimals1, reserve0, reserve1, liquidityUSDToken0, liquidityUSDToken1,
220
- },
221
- );
222
- }));
209
+ return Promise.all(
210
+ pools.map(async (pool: RamsesSubgraphPool) => {
211
+ const address0 = pool.token0.toLowerCase();
212
+ const address1 = pool.token1.toLowerCase();
213
+
214
+ const decimals0 = parseInt(
215
+ tokens.find(t => t.id === address0)!.decimals,
216
+ );
217
+ const decimals1 = parseInt(
218
+ tokens.find(t => t.id === address1)!.decimals,
219
+ );
220
+
221
+ const reserve0 = BigInt(new BigNumber(pool.reserve0).toFixed());
222
+ const reserve1 = BigInt(new BigNumber(pool.reserve1).toFixed());
223
+
224
+ const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice(
225
+ {
226
+ address: address0,
227
+ decimals: decimals0,
228
+ },
229
+ reserve0,
230
+ );
231
+
232
+ const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice(
233
+ {
234
+ address: address1,
235
+ decimals: decimals1,
236
+ },
237
+ reserve1,
238
+ );
239
+
240
+ return iterator(pool, {
241
+ address0,
242
+ address1,
243
+ decimals0,
244
+ decimals1,
245
+ reserve0,
246
+ reserve1,
247
+ liquidityUSDToken0,
248
+ liquidityUSDToken1,
249
+ });
250
+ }),
251
+ );
223
252
  }
224
253
  }
@@ -72,7 +72,7 @@ export class Solidly extends UniswapV2 {
72
72
  'Thena',
73
73
  'SoliSnek',
74
74
  'Chronos',
75
- 'Ramses'
75
+ 'Ramses',
76
76
  ]),
77
77
  );
78
78
 
@@ -62,7 +62,9 @@ export type UniswapV3Data = {
62
62
  isApproved?: boolean;
63
63
  };
64
64
 
65
- export type DecodeStateMultiCallFunc = (result: MultiResult<BytesLike> | BytesLike) => DecodedStateMultiCallResultWithRelativeBitmaps;
65
+ export type DecodeStateMultiCallFunc = (
66
+ result: MultiResult<BytesLike> | BytesLike,
67
+ ) => DecodedStateMultiCallResultWithRelativeBitmaps;
66
68
 
67
69
  export type DexParams = {
68
70
  router: Address;
@@ -77,7 +79,7 @@ export type DexParams = {
77
79
  subgraphURL: string;
78
80
  initHash: string;
79
81
  stateMultiCallAbi?: AbiItem[];
80
- decodeStateMultiCallResultWithRelativeBitmaps? : DecodeStateMultiCallFunc,
82
+ decodeStateMultiCallResultWithRelativeBitmaps?: DecodeStateMultiCallFunc;
81
83
  };
82
84
 
83
85
  export type UniswapV3SimpleSwapSellParam = {