@paraswap/dex-lib 2.50.5 → 2.50.6-sdai

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 (263) hide show
  1. package/build/abi/maker-psm/pot.json +322 -0
  2. package/build/abi/{angle/stagToken.json → sdai/SavingsDai.abi.json} +177 -263
  3. package/build/config.js +2 -1
  4. package/build/config.js.map +1 -1
  5. package/build/dex/curve-v1-factory/config.js +11 -128
  6. package/build/dex/curve-v1-factory/config.js.map +1 -1
  7. package/build/dex/curve-v1-factory/curve-v1-factory.d.ts +0 -1
  8. package/build/dex/curve-v1-factory/curve-v1-factory.js +17 -29
  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 +0 -1
  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 +0 -1
  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 +1 -4
  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 +0 -1
  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 +0 -1
  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 +0 -1
  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 +0 -1
  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 +0 -1
  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 +0 -10
  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 +0 -40
  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 +0 -1
  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 +0 -1
  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 +0 -24
  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 +0 -1
  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 +0 -53
  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 +0 -1
  41. package/build/dex/curve-v1-factory/price-handlers/functions/get_y_D.js.map +1 -1
  42. package/build/dex/curve-v1-factory/price-handlers/functions/utils.d.ts +0 -1
  43. package/build/dex/curve-v1-factory/price-handlers/functions/utils.js +1 -5
  44. package/build/dex/curve-v1-factory/price-handlers/functions/utils.js.map +1 -1
  45. package/build/dex/curve-v1-factory/price-handlers/types.d.ts +2 -2
  46. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.d.ts +2 -3
  47. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js +6 -38
  48. package/build/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.js.map +1 -1
  49. package/build/dex/curve-v1-factory/state-polling-pools/pool-polling-base.js.map +1 -1
  50. package/build/dex/curve-v1-factory/types.d.ts +2 -11
  51. package/build/dex/curve-v1-factory/types.js +0 -3
  52. package/build/dex/curve-v1-factory/types.js.map +1 -1
  53. package/build/dex/hashflow/constants.d.ts +0 -27
  54. package/build/dex/hashflow/constants.js +1 -29
  55. package/build/dex/hashflow/constants.js.map +1 -1
  56. package/build/dex/hashflow/hashflow.d.ts +2 -3
  57. package/build/dex/hashflow/hashflow.js +12 -69
  58. package/build/dex/hashflow/hashflow.js.map +1 -1
  59. package/build/dex/hashflow/types.d.ts +0 -11
  60. package/build/dex/hashflow/types.js +0 -9
  61. package/build/dex/hashflow/types.js.map +1 -1
  62. package/build/dex/idex.d.ts +1 -1
  63. package/build/dex/index.d.ts +2 -2
  64. package/build/dex/index.js +2 -0
  65. package/build/dex/index.js.map +1 -1
  66. package/build/dex/pancakeswap-v3/config.js +0 -15
  67. package/build/dex/pancakeswap-v3/config.js.map +1 -1
  68. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +1 -1
  69. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  70. package/build/dex/sdai/config.d.ts +11 -0
  71. package/build/dex/sdai/config.js +24 -0
  72. package/build/dex/sdai/config.js.map +1 -0
  73. package/build/dex/sdai/constants.d.ts +2 -0
  74. package/build/dex/sdai/constants.js +6 -0
  75. package/build/dex/sdai/constants.js.map +1 -0
  76. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  77. package/build/dex/sdai/scripts/validate-state.js +102 -0
  78. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  79. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  80. package/build/dex/sdai/sdai-pool.js +85 -0
  81. package/build/dex/sdai/sdai-pool.js.map +1 -0
  82. package/build/dex/sdai/sdai.d.ts +51 -0
  83. package/build/dex/sdai/sdai.js +172 -0
  84. package/build/dex/sdai/sdai.js.map +1 -0
  85. package/build/dex/sdai/types.d.ts +21 -0
  86. package/build/dex/sdai/types.js +11 -0
  87. package/build/dex/sdai/types.js.map +1 -0
  88. package/build/dex/sdai/utils.d.ts +4 -0
  89. package/build/dex/sdai/utils.js +39 -0
  90. package/build/dex/sdai/utils.js.map +1 -0
  91. package/build/dex/woo-fi-v2/config.js +4 -4
  92. package/package.json +1 -1
  93. package/src/abi/maker-psm/pot.json +322 -0
  94. package/src/abi/sdai/SavingsDai.abi.json +877 -0
  95. package/src/abi/uniswap-v3/AlienBaseV3Router.abi.json +52 -0
  96. package/src/config.ts +2 -1
  97. package/src/dex/curve-v1-factory/config.ts +11 -128
  98. package/src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts +1 -123
  99. package/src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts +0 -392
  100. package/src/dex/curve-v1-factory/curve-v1-factory.ts +39 -61
  101. package/src/dex/curve-v1-factory/curve-v1-pool-manager.ts +0 -1
  102. package/src/dex/curve-v1-factory/price-handlers/functions/_calc_withdraw_one_coin.ts +0 -2
  103. package/src/dex/curve-v1-factory/price-handlers/functions/_dynamic_fee.ts +2 -6
  104. package/src/dex/curve-v1-factory/price-handlers/functions/_rates.ts +0 -2
  105. package/src/dex/curve-v1-factory/price-handlers/functions/_xp.ts +0 -2
  106. package/src/dex/curve-v1-factory/price-handlers/functions/_xp_mem.ts +0 -2
  107. package/src/dex/curve-v1-factory/price-handlers/functions/calc_token_amount.ts +0 -2
  108. package/src/dex/curve-v1-factory/price-handlers/functions/calc_withdraw_one_coin.ts +0 -2
  109. package/src/dex/curve-v1-factory/price-handlers/functions/constants.ts +0 -11
  110. package/src/dex/curve-v1-factory/price-handlers/functions/get_D.ts +1 -59
  111. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_mem.ts +0 -2
  112. package/src/dex/curve-v1-factory/price-handlers/functions/get_D_precisions.ts +0 -2
  113. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy.ts +0 -51
  114. package/src/dex/curve-v1-factory/price-handlers/functions/get_dy_underlying.ts +0 -2
  115. package/src/dex/curve-v1-factory/price-handlers/functions/get_y.ts +1 -68
  116. package/src/dex/curve-v1-factory/price-handlers/functions/get_y_D.ts +0 -2
  117. package/src/dex/curve-v1-factory/price-handlers/functions/utils.ts +0 -4
  118. package/src/dex/curve-v1-factory/price-handlers/types.ts +1 -8
  119. package/src/dex/curve-v1-factory/state-polling-pools/factory-pool-polling.ts +18 -71
  120. package/src/dex/curve-v1-factory/state-polling-pools/pool-polling-base.ts +0 -1
  121. package/src/dex/curve-v1-factory/types.ts +1 -12
  122. package/src/dex/hashflow/constants.ts +0 -32
  123. package/src/dex/hashflow/hashflow.ts +19 -121
  124. package/src/dex/hashflow/types.ts +2 -20
  125. package/src/dex/idex.ts +1 -1
  126. package/src/dex/index.ts +4 -2
  127. package/src/dex/pancakeswap-v3/config.ts +0 -16
  128. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +1 -3
  129. package/src/dex/sdai/config.ts +28 -0
  130. package/src/dex/sdai/constants.ts +2 -0
  131. package/src/dex/sdai/scripts/validate-state.ts +144 -0
  132. package/src/dex/sdai/sdai-e2e.test.ts +96 -0
  133. package/src/dex/sdai/sdai-events.test.ts +105 -0
  134. package/src/dex/sdai/sdai-integration.test.ts +148 -0
  135. package/src/dex/sdai/sdai-pool.ts +113 -0
  136. package/src/dex/sdai/sdai.ts +233 -0
  137. package/src/dex/sdai/types.ts +23 -0
  138. package/src/dex/sdai/utils.ts +48 -0
  139. package/src/dex/woo-fi-v2/config.ts +4 -4
  140. package/tests/constants-e2e.ts +3 -38
  141. package/tests/utils-e2e.ts +0 -1
  142. package/build/abi/Redstone.json +0 -739
  143. package/build/abi/angle-transmuter/MorphoOracle.json +0 -193
  144. package/build/abi/angle-transmuter/MorphoVault.json +0 -2506
  145. package/build/abi/angle-transmuter/Pyth.json +0 -1534
  146. package/build/abi/angle-transmuter/Transmuter.json +0 -1711
  147. package/build/abi/pharaoh/PharaohPool.abi.json +0 -1582
  148. package/build/abi/smardex/smardex-factory.json +0 -185
  149. package/build/abi/smardex/smardex-pool.json +0 -578
  150. package/build/abi/smardex/smardex-router.json +0 -648
  151. package/build/abi/trader-joe-v2_1/FactoryABI.json +0 -1208
  152. package/build/abi/trader-joe-v2_1/PairABI.json +0 -1493
  153. package/build/abi/trader-joe-v2_1/RouterABI.json +0 -1489
  154. package/build/abi/trader-joe-v2_1/StateMulticall.json +0 -193
  155. package/build/abi/wombat/pool.json +0 -1289
  156. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  157. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  158. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  159. package/build/dex/angle-staked-stable/angle-staked-stable-pool.d.ts +0 -55
  160. package/build/dex/angle-staked-stable/angle-staked-stable-pool.js +0 -183
  161. package/build/dex/angle-staked-stable/angle-staked-stable-pool.js.map +0 -1
  162. package/build/dex/angle-staked-stable/angle-staked-stable.d.ts +0 -50
  163. package/build/dex/angle-staked-stable/angle-staked-stable.js +0 -228
  164. package/build/dex/angle-staked-stable/angle-staked-stable.js.map +0 -1
  165. package/build/dex/angle-staked-stable/config.d.ts +0 -4
  166. package/build/dex/angle-staked-stable/config.js +0 -139
  167. package/build/dex/angle-staked-stable/config.js.map +0 -1
  168. package/build/dex/angle-staked-stable/types.d.ts +0 -15
  169. package/build/dex/angle-staked-stable/types.js +0 -3
  170. package/build/dex/angle-staked-stable/types.js.map +0 -1
  171. package/build/dex/angle-transmuter/angle-transmuter-pool.d.ts +0 -61
  172. package/build/dex/angle-transmuter/angle-transmuter-pool.js +0 -415
  173. package/build/dex/angle-transmuter/angle-transmuter-pool.js.map +0 -1
  174. package/build/dex/angle-transmuter/angle-transmuter.d.ts +0 -59
  175. package/build/dex/angle-transmuter/angle-transmuter.js +0 -262
  176. package/build/dex/angle-transmuter/angle-transmuter.js.map +0 -1
  177. package/build/dex/angle-transmuter/backedOracle.d.ts +0 -19
  178. package/build/dex/angle-transmuter/backedOracle.js +0 -56
  179. package/build/dex/angle-transmuter/backedOracle.js.map +0 -1
  180. package/build/dex/angle-transmuter/config.d.ts +0 -4
  181. package/build/dex/angle-transmuter/config.js +0 -30
  182. package/build/dex/angle-transmuter/config.js.map +0 -1
  183. package/build/dex/angle-transmuter/constants.d.ts +0 -77
  184. package/build/dex/angle-transmuter/constants.js +0 -94
  185. package/build/dex/angle-transmuter/constants.js.map +0 -1
  186. package/build/dex/angle-transmuter/morphoOracle.d.ts +0 -42
  187. package/build/dex/angle-transmuter/morphoOracle.js +0 -179
  188. package/build/dex/angle-transmuter/morphoOracle.js.map +0 -1
  189. package/build/dex/angle-transmuter/morphoVault.d.ts +0 -19
  190. package/build/dex/angle-transmuter/morphoVault.js +0 -78
  191. package/build/dex/angle-transmuter/morphoVault.js.map +0 -1
  192. package/build/dex/angle-transmuter/pyth.d.ts +0 -19
  193. package/build/dex/angle-transmuter/pyth.js +0 -70
  194. package/build/dex/angle-transmuter/pyth.js.map +0 -1
  195. package/build/dex/angle-transmuter/redstone.d.ts +0 -20
  196. package/build/dex/angle-transmuter/redstone.js +0 -73
  197. package/build/dex/angle-transmuter/redstone.js.map +0 -1
  198. package/build/dex/angle-transmuter/transmuter.d.ts +0 -52
  199. package/build/dex/angle-transmuter/transmuter.js +0 -374
  200. package/build/dex/angle-transmuter/transmuter.js.map +0 -1
  201. package/build/dex/angle-transmuter/types.d.ts +0 -188
  202. package/build/dex/angle-transmuter/types.js +0 -33
  203. package/build/dex/angle-transmuter/types.js.map +0 -1
  204. package/build/dex/angle-transmuter/utils.d.ts +0 -9
  205. package/build/dex/angle-transmuter/utils.js +0 -252
  206. package/build/dex/angle-transmuter/utils.js.map +0 -1
  207. package/build/dex/smardex/subgraph-queries.d.ts +0 -1
  208. package/build/dex/smardex/subgraph-queries.js +0 -17
  209. package/build/dex/smardex/subgraph-queries.js.map +0 -1
  210. package/build/dex/smardex/usd-reserves.d.ts +0 -23
  211. package/build/dex/smardex/usd-reserves.js +0 -86
  212. package/build/dex/smardex/usd-reserves.js.map +0 -1
  213. package/build/dex/trader-joe-v2-1-2/config.d.ts +0 -4
  214. package/build/dex/trader-joe-v2-1-2/config.js +0 -47
  215. package/build/dex/trader-joe-v2-1-2/config.js.map +0 -1
  216. package/build/dex/trader-joe-v2-1-2/constants.d.ts +0 -20
  217. package/build/dex/trader-joe-v2-1-2/constants.js +0 -22
  218. package/build/dex/trader-joe-v2-1-2/constants.js.map +0 -1
  219. package/build/dex/trader-joe-v2-1-2/math/index.d.ts +0 -37
  220. package/build/dex/trader-joe-v2-1-2/math/index.js +0 -291
  221. package/build/dex/trader-joe-v2-1-2/math/index.js.map +0 -1
  222. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.d.ts +0 -60
  223. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js +0 -248
  224. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2-pool.js.map +0 -1
  225. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.d.ts +0 -53
  226. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js +0 -307
  227. package/build/dex/trader-joe-v2-1-2/trader-joe-v2-1-2.js.map +0 -1
  228. package/build/dex/trader-joe-v2-1-2/types.d.ts +0 -82
  229. package/build/dex/trader-joe-v2-1-2/types.js +0 -9
  230. package/build/dex/trader-joe-v2-1-2/types.js.map +0 -1
  231. package/build/dex/trader-joe-v2_1/config.d.ts +0 -4
  232. package/build/dex/trader-joe-v2_1/config.js +0 -47
  233. package/build/dex/trader-joe-v2_1/config.js.map +0 -1
  234. package/build/dex/trader-joe-v2_1/constants.d.ts +0 -20
  235. package/build/dex/trader-joe-v2_1/constants.js +0 -22
  236. package/build/dex/trader-joe-v2_1/constants.js.map +0 -1
  237. package/build/dex/trader-joe-v2_1/math/index.d.ts +0 -37
  238. package/build/dex/trader-joe-v2_1/math/index.js +0 -291
  239. package/build/dex/trader-joe-v2_1/math/index.js.map +0 -1
  240. package/build/dex/trader-joe-v2_1/trader-joe-v2.1.d.ts +0 -0
  241. package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js +0 -384
  242. package/build/dex/trader-joe-v2_1/trader-joe-v2.1.js.map +0 -1
  243. package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.d.ts +0 -60
  244. package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js +0 -247
  245. package/build/dex/trader-joe-v2_1/trader-joe-v2_1-pool.js.map +0 -1
  246. package/build/dex/trader-joe-v2_1/trader-joe-v2_1.d.ts +0 -53
  247. package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js +0 -307
  248. package/build/dex/trader-joe-v2_1/trader-joe-v2_1.js.map +0 -1
  249. package/build/dex/trader-joe-v2_1/types.d.ts +0 -82
  250. package/build/dex/trader-joe-v2_1/types.js +0 -9
  251. package/build/dex/trader-joe-v2_1/types.js.map +0 -1
  252. package/build/dex/wombat/wombat-pool-poller.d.ts +0 -22
  253. package/build/dex/wombat/wombat-pool-poller.js +0 -164
  254. package/build/dex/wombat/wombat-pool-poller.js.map +0 -1
  255. package/build/dex-helper/Cache.d.ts +0 -31
  256. package/build/dex-helper/Cache.js +0 -106
  257. package/build/dex-helper/Cache.js.map +0 -1
  258. package/build/dex-helper/RedisBatcher.d.ts +0 -20
  259. package/build/dex-helper/RedisBatcher.js +0 -75
  260. package/build/dex-helper/RedisBatcher.js.map +0 -1
  261. package/build/dex-helper/RedisWrapper.d.ts +0 -37
  262. package/build/dex-helper/RedisWrapper.js +0 -165
  263. package/build/dex-helper/RedisWrapper.js.map +0 -1
@@ -2,12 +2,7 @@ import _ from 'lodash';
2
2
  import { CONVERGENCE_ERROR_PREFIX } from '../../constants';
3
3
  import { ImplementationNames } from '../../types';
4
4
  import { get_D, IPoolContext } from '../types';
5
- import {
6
- getCachedValueOrCallFunc,
7
- pow_mod256,
8
- requireConstant,
9
- requireValue,
10
- } from './utils';
5
+ import { getCachedValueOrCallFunc, requireConstant } from './utils';
11
6
 
12
7
  /*
13
8
  * This function get_D may be optimized further. We are doing many redundant
@@ -57,57 +52,6 @@ const customPlain3CoinThree: get_D = (
57
52
  return D;
58
53
  };
59
54
 
60
- const stableNg: get_D = (
61
- self: IPoolContext,
62
- xp: bigint[],
63
- amp: bigint,
64
- N_COINS?: number,
65
- ): bigint => {
66
- const A_PRECISION = requireConstant(self, 'A_PRECISION', 'stableNg');
67
- const BI_N_COINS = BigInt(N_COINS!);
68
-
69
- let S = 0n;
70
- let Dprev = 0n;
71
-
72
- for (const _x of xp) {
73
- S += _x;
74
- }
75
- if (S === 0n) {
76
- return 0n;
77
- }
78
-
79
- let D = S;
80
- const Ann = amp * BI_N_COINS;
81
- for (const _i of _.range(255)) {
82
- let D_P = D;
83
- for (const _x of xp) {
84
- D_P = (D_P * D) / _x;
85
- }
86
-
87
- D_P /= pow_mod256(BI_N_COINS, BI_N_COINS);
88
- Dprev = D;
89
- D =
90
- (((Ann * S) / A_PRECISION + D_P * BI_N_COINS) * D) /
91
- (((Ann - A_PRECISION) * D) / A_PRECISION + (BI_N_COINS + 1n) * D_P);
92
- // Equality with the precision of 1
93
- if (D > Dprev) {
94
- if (D - Dprev <= 1n) {
95
- return D;
96
- }
97
- } else {
98
- if (Dprev - D <= 1n) {
99
- return D;
100
- }
101
- }
102
- }
103
-
104
- // convergence typically occurs in 4 rounds or less, this should be unreachable!
105
- // if it does happen the pool is borked and LPs can withdraw via `remove_liquidity`
106
- throw new Error(
107
- `${CONVERGENCE_ERROR_PREFIX}_${self.IMPLEMENTATION_NAME}: function stableNg didn't converge`,
108
- );
109
- };
110
-
111
55
  const customPlain2CoinFrax: get_D = (
112
56
  self: IPoolContext,
113
57
  xp: bigint[],
@@ -379,8 +323,6 @@ const implementations: Record<ImplementationNames, get_D> = {
379
323
  makeFuncCacheable(factoryPlain2Basic),
380
324
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]:
381
325
  makeFuncCacheable(factoryPlain2Basic),
382
-
383
- [ImplementationNames.FACTORY_STABLE_NG]: stableNg,
384
326
  };
385
327
 
386
328
  export default implementations;
@@ -141,8 +141,6 @@ export const implementations: Record<ImplementationNames, get_D_mem> = {
141
141
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
142
142
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
143
143
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: factoryPlain2Basic,
144
-
145
- [ImplementationNames.FACTORY_STABLE_NG]: notImplemented,
146
144
  };
147
145
 
148
146
  export default implementations;
@@ -113,8 +113,6 @@ const implementations: Record<ImplementationNames, get_D_precisions> = {
113
113
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
114
114
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
115
115
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
116
-
117
- [ImplementationNames.FACTORY_STABLE_NG]: notExist,
118
116
  };
119
117
 
120
118
  export default implementations;
@@ -2,7 +2,6 @@ import _ from 'lodash';
2
2
  import { ImplementationNames, PoolState } from '../../types';
3
3
  import { get_dy, IPoolContext } from '../types';
4
4
  import { requireConstant, requireValue } from './utils';
5
- import get_y from './get_y';
6
5
 
7
6
  const _genericFactoryPlain2Basic = (
8
7
  self: IPoolContext,
@@ -163,54 +162,6 @@ const customPlain3CoinBtc: get_dy = (
163
162
  return dy - _fee;
164
163
  };
165
164
 
166
- const stableNg: get_dy = (
167
- self: IPoolContext,
168
- state: PoolState,
169
- i: number,
170
- j: number,
171
- dx: bigint,
172
- ) => {
173
- const rates = requireValue(self, state, 'storedRates', 'stableNg');
174
- const N_COINS = requireValue(self, state, 'n_coins', 'stableNg');
175
- const A = requireValue(self, state, 'A', 'stableNg');
176
- const stateFee = requireValue(self, state, 'fee', 'stableNg');
177
- const offpeg_fee_multiplier = requireValue(
178
- self,
179
- state,
180
- 'offpeg_fee_multiplier',
181
- 'stableNg',
182
- );
183
-
184
- const { FEE_DENOMINATOR, PRECISION } = self.constants;
185
- const xp: bigint[] = [];
186
- const { balances } = state;
187
-
188
- for (const idx of _.range(N_COINS)) {
189
- xp.push((rates[idx] * balances[idx]) / PRECISION);
190
- }
191
-
192
- const amp = A;
193
- const D = self.get_D(self, xp, amp, N_COINS);
194
-
195
- const x = xp[i] + (dx * rates[i]) / PRECISION;
196
- const y = self.get_y(self, state, i, j, x, xp, amp, D);
197
- const dy = xp[j] - y - 1n;
198
-
199
- const base_fee = stateFee;
200
- const fee_multiplier = offpeg_fee_multiplier;
201
- const dynamic_fee = self._dynamic_fee(
202
- self,
203
- (xp[i] + x) / 2n,
204
- (xp[j] + y) / 2n,
205
- base_fee,
206
- fee_multiplier,
207
- );
208
-
209
- const fee = (dynamic_fee * dy) / FEE_DENOMINATOR;
210
-
211
- return ((dy - fee) * PRECISION) / rates[j];
212
- };
213
-
214
165
  const customAvalanche3CoinLending: get_dy = (
215
166
  self: IPoolContext,
216
167
  state: PoolState,
@@ -316,8 +267,6 @@ const implementations: Record<ImplementationNames, get_dy> = {
316
267
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: factoryPlain2Basic,
317
268
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: factoryPlain2EthEma2,
318
269
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: factoryPlain2Basic,
319
-
320
- [ImplementationNames.FACTORY_STABLE_NG]: stableNg,
321
270
  };
322
271
 
323
272
  export default implementations;
@@ -286,8 +286,6 @@ const implementations: Record<ImplementationNames, get_dy_underlying> = {
286
286
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: notExist,
287
287
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: notExist,
288
288
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: notExist,
289
-
290
- [ImplementationNames.FACTORY_STABLE_NG]: notExist,
291
289
  };
292
290
 
293
291
  export default implementations;
@@ -2,74 +2,9 @@ import _ from 'lodash';
2
2
  import { ImplementationNames, PoolState } from '../../types';
3
3
  import { _require } from '../../../../utils';
4
4
  import { get_y, IPoolContext } from '../types';
5
- import { requireConstant, requireValue } from './utils';
5
+ import { requireConstant } from './utils';
6
6
  import { CONVERGENCE_ERROR_PREFIX } from '../../constants';
7
7
 
8
- const stableNg = (
9
- self: IPoolContext,
10
- state: PoolState,
11
- i: number,
12
- j: number,
13
- x: bigint,
14
- xp: bigint[],
15
- _amp?: bigint,
16
- _D?: bigint,
17
- ): bigint => {
18
- const A_PRECISION = requireConstant(self, 'A_PRECISION', 'stableNg');
19
- const N_COINS = requireValue(self, state, 'n_coins', 'stableNg');
20
- // x in the input is converted to the same price/precision
21
-
22
- _require(i !== j, 'same coin', { i, j }, 'i !== j');
23
- _require(j >= 0, 'j below zero', { i, j }, 'j >= 0');
24
- _require(j < N_COINS, 'j above N_COINS', { i, j, N_COINS }, 'j < N_COINS');
25
-
26
- // should be unreachable, but good for safety
27
- _require(i >= 0, 'i below zero', { i, j }, 'i >= 0');
28
- _require(i < N_COINS, 'i above N_COINS', { i, j, N_COINS }, 'i < N_COINS');
29
-
30
- const BI_N_COINS = BigInt(N_COINS);
31
-
32
- const amp = _amp!;
33
- const D = _D!;
34
- let c = D;
35
- let S_ = 0n;
36
- const Ann = amp * BI_N_COINS;
37
-
38
- let _x = 0n;
39
- for (const _i of _.range(N_COINS)) {
40
- if (_i === i) {
41
- _x = x;
42
- } else if (_i !== j) {
43
- _x = xp[_i];
44
- } else {
45
- continue;
46
- }
47
- S_ += _x;
48
- c = (c * D) / (_x * BI_N_COINS);
49
- }
50
- c = (c * D * A_PRECISION) / (Ann * BI_N_COINS);
51
- const b = S_ + (D * A_PRECISION) / Ann; // - D
52
- let y_prev = 0n;
53
- let y = D;
54
-
55
- for (const _i of _.range(255)) {
56
- y_prev = y;
57
- y = (y * y + c) / (2n * y + b - D);
58
- //
59
- // Equality with the precision of 1
60
- if (y > y_prev) {
61
- if (y - y_prev <= 1) {
62
- break;
63
- }
64
- } else {
65
- if (y_prev - y <= 1) {
66
- break;
67
- }
68
- }
69
- }
70
- return y;
71
- };
72
-
73
8
  const customPlain3CoinThree = (
74
9
  self: IPoolContext,
75
10
  state: PoolState,
@@ -255,8 +190,6 @@ const implementations: Record<ImplementationNames, get_y> = {
255
190
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
256
191
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
257
192
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain2CoinFrax,
258
-
259
- [ImplementationNames.FACTORY_STABLE_NG]: stableNg,
260
193
  };
261
194
 
262
195
  export default implementations;
@@ -176,8 +176,6 @@ const implementations: Record<ImplementationNames, get_y_D> = {
176
176
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA]: customPlain2CoinFrax,
177
177
  [ImplementationNames.FACTORY_PLAIN_2_ETH_EMA2]: customPlain2CoinFrax,
178
178
  [ImplementationNames.FACTORY_PLAIN_2_CRV_EMA]: customPlain2CoinFrax,
179
-
180
- [ImplementationNames.FACTORY_STABLE_NG]: customPlain2CoinFrax,
181
179
  };
182
180
 
183
181
  export default implementations;
@@ -70,7 +70,3 @@ export const getCachedValueOrCallFunc = <T>(
70
70
  curveV1FactoryNodeCache.set(key, calculated);
71
71
  return calculated;
72
72
  };
73
-
74
- export function pow_mod256(a: bigint, b: bigint): bigint {
75
- return a ** b % 2n ** 256n;
76
- }
@@ -52,12 +52,7 @@ export type get_D_precisions = (
52
52
  amp: bigint,
53
53
  ) => bigint;
54
54
 
55
- export type get_D = (
56
- self: IPoolContext,
57
- xp: bigint[],
58
- amp: bigint,
59
- N_COINS?: number,
60
- ) => bigint;
55
+ export type get_D = (self: IPoolContext, xp: bigint[], amp: bigint) => bigint;
61
56
 
62
57
  export type get_dy_underlying = (
63
58
  self: IPoolContext,
@@ -90,8 +85,6 @@ export type get_y = (
90
85
  j: number,
91
86
  x: bigint,
92
87
  xp_: bigint[],
93
- _amp?: bigint,
94
- _D?: bigint,
95
88
  ) => bigint;
96
89
 
97
90
  /*
@@ -2,7 +2,6 @@ import { Interface, JsonFragment } from '@ethersproject/abi';
2
2
  import { Logger } from 'log4js';
3
3
  import { MultiCallParams, MultiResult } from '../../../lib/multi-wrapper';
4
4
  import {
5
- DexParams,
6
5
  FactoryImplementationNames,
7
6
  PoolConstants,
8
7
  PoolContextConstants,
@@ -10,20 +9,19 @@ import {
10
9
  } from '../types';
11
10
  import { PoolPollingBase, MulticallReturnedTypes } from './pool-polling-base';
12
11
  import FactoryCurveV1ABI from '../../../abi/curve-v1-factory/FactoryCurveV1.json';
13
- import {
14
- generalDecoder,
15
- uint256DecodeToNumber,
16
- uint256ToBigInt,
17
- } from '../../../lib/decoders';
12
+ import { generalDecoder, uint256ToBigInt } from '../../../lib/decoders';
18
13
  import { BytesLike } from 'ethers/lib/utils';
19
14
  import { Address } from '@paraswap/core';
20
15
  import { BigNumber } from 'ethers';
21
- import { DexConfigMap } from '../../../types';
16
+ import { _require } from '../../../utils';
17
+ import { AbiItem } from 'web3-utils';
22
18
 
23
19
  const DEFAULT_2_ZERO_ARRAY = [0n, 0n];
24
20
  const DEFAULT_4_ZERO_ARRAY = [0n, 0n, 0n, 0n];
25
21
 
26
- const getStoredRatesABI = (n: string) => ({
22
+ type AdditionalContractFunctions = 'stored_rates';
23
+
24
+ const getStoredRatesABI = (n: number) => ({
27
25
  name: 'stored_rates',
28
26
  stateMutability: 'view',
29
27
  type: 'function',
@@ -40,7 +38,7 @@ export class FactoryStateHandler extends PoolPollingBase {
40
38
  readonly implementationName: FactoryImplementationNames,
41
39
  implementationAddress: Address,
42
40
  readonly address: Address,
43
- readonly config: DexParams,
41
+ stateUpdatePeriodMs: number,
44
42
  readonly factoryAddress: Address,
45
43
  readonly poolIdentifier: string,
46
44
  readonly poolConstants: PoolConstants,
@@ -54,7 +52,7 @@ export class FactoryStateHandler extends PoolPollingBase {
54
52
  FactoryCurveV1ABI as JsonFragment[],
55
53
  ),
56
54
  private additionalFuncsIface: Interface = new Interface([
57
- getStoredRatesABI(poolContextConstants?.N_COINS?.toString() || ''),
55
+ getStoredRatesABI(poolContextConstants.N_COINS),
58
56
  ]),
59
57
  ) {
60
58
  super(
@@ -64,7 +62,7 @@ export class FactoryStateHandler extends PoolPollingBase {
64
62
  cacheStateKey,
65
63
  implementationName,
66
64
  implementationAddress,
67
- config.stateUpdatePeriodMs,
65
+ stateUpdatePeriodMs,
68
66
  poolIdentifier,
69
67
  poolConstants,
70
68
  address,
@@ -83,11 +81,6 @@ export class FactoryStateHandler extends PoolPollingBase {
83
81
  }
84
82
 
85
83
  getStateMultiCalldata(): MultiCallParams<MulticallReturnedTypes>[] {
86
- const factoryConfig = this.config.factories?.find(
87
- ({ address }) =>
88
- address.toLowerCase() === this.factoryAddress.toLowerCase(),
89
- );
90
-
91
84
  const calls = [
92
85
  {
93
86
  target: this.factoryAddress,
@@ -113,11 +106,8 @@ export class FactoryStateHandler extends PoolPollingBase {
113
106
  this.address,
114
107
  ]),
115
108
  decodeFunction: (result: MultiResult<BytesLike> | BytesLike) =>
116
- generalDecoder(
117
- result,
118
- [`uint256[${factoryConfig?.isStableNg ? '' : '4'}]`],
119
- DEFAULT_4_ZERO_ARRAY,
120
- parsed => parsed[0].map((p: BigNumber) => p.toBigInt()),
109
+ generalDecoder(result, ['uint256[4]'], DEFAULT_4_ZERO_ARRAY, parsed =>
110
+ parsed[0].map((p: BigNumber) => p.toBigInt()),
121
111
  ),
122
112
  },
123
113
  ];
@@ -132,51 +122,13 @@ export class FactoryStateHandler extends PoolPollingBase {
132
122
  decodeFunction: (result: MultiResult<BytesLike> | BytesLike) =>
133
123
  generalDecoder(
134
124
  result,
135
- [
136
- `uint256[${
137
- factoryConfig?.isStableNg
138
- ? ''
139
- : this.poolContextConstants.N_COINS
140
- }]`,
141
- ],
125
+ [`uint256[${this.poolContextConstants.N_COINS}]`],
142
126
  new Array(this.poolContextConstants.N_COINS).fill(0n),
143
127
  parsed => parsed[0].map((p: BigNumber) => p.toBigInt()),
144
128
  ),
145
129
  });
146
130
  }
147
131
 
148
- if (factoryConfig?.isStableNg) {
149
- calls.push({
150
- target: this.address,
151
- callData: this.abiCoder.encodeFunctionCall(
152
- {
153
- stateMutability: 'view',
154
- type: 'function',
155
- name: 'offpeg_fee_multiplier',
156
- inputs: [],
157
- outputs: [{ name: '', type: 'uint256' }],
158
- },
159
- [],
160
- ),
161
- decodeFunction: uint256ToBigInt,
162
- });
163
-
164
- calls.push({
165
- target: this.address,
166
- callData: this.abiCoder.encodeFunctionCall(
167
- {
168
- stateMutability: 'view',
169
- type: 'function',
170
- name: 'N_COINS',
171
- inputs: [],
172
- outputs: [{ name: '', type: 'uint256' }],
173
- },
174
- [],
175
- ),
176
- decodeFunction: uint256DecodeToNumber,
177
- });
178
- }
179
-
180
132
  return calls;
181
133
  }
182
134
 
@@ -185,15 +137,12 @@ export class FactoryStateHandler extends PoolPollingBase {
185
137
  blockNumber: number,
186
138
  updatedAtMs: number,
187
139
  ): PoolState {
188
- const [A, fees, balances, storedRates, offpeg_fee_multiplier, n_coins] =
189
- multiOutputs as [
190
- bigint,
191
- bigint[],
192
- bigint[],
193
- bigint[] | undefined,
194
- bigint | undefined,
195
- number | undefined,
196
- ];
140
+ const [A, fees, balances, storedRates] = multiOutputs as [
141
+ bigint,
142
+ bigint[],
143
+ bigint[],
144
+ bigint[] | undefined,
145
+ ];
197
146
 
198
147
  let basePoolState: PoolState | undefined;
199
148
  if (this.isMetaPool) {
@@ -215,11 +164,9 @@ export class FactoryStateHandler extends PoolPollingBase {
215
164
  fee: fees[0], // Array has [fee, adminFee], but we want only fee
216
165
  balances: balances,
217
166
  constants: this.poolConstants,
218
- n_coins,
219
167
  basePoolState,
220
168
  updatedAtMs,
221
169
  blockNumber,
222
- offpeg_fee_multiplier,
223
170
  storedRates,
224
171
  };
225
172
  }
@@ -53,7 +53,6 @@ export abstract class PoolPollingBase {
53
53
  this.fullName = `${dexKey}-${network}-${this.CLASS_NAME}-${this.implementationName}-${this.address}`;
54
54
  this.isMetaPool = baseStatePoolPolling !== undefined;
55
55
  this.coinsToIndices = this._reduceToIndexMapping(poolConstants.COINS);
56
-
57
56
  this.underlyingCoinsToIndices = baseStatePoolPolling
58
57
  ? this._reduceToIndexMapping([
59
58
  poolConstants.COINS[0],
@@ -58,7 +58,6 @@ export type PoolState = {
58
58
  offpeg_fee_multiplier?: bigint; // from pool
59
59
  basePoolState?: PoolState;
60
60
  storedRates?: bigint[]; // from pool, but only for oracle ones
61
- n_coins?: number;
62
61
  };
63
62
 
64
63
  export type PoolStateWithUpdateInfo<T> = {
@@ -116,10 +115,6 @@ export enum FactoryImplementationNames {
116
115
  FACTORY_PLAIN_4_BASIC = 'factory_plain_4_basic',
117
116
  FACTORY_PLAIN_4_ETH = 'factory_plain_4_eth',
118
117
  FACTORY_PLAIN_4_OPTIMIZED = 'factory_plain_4_optimized',
119
-
120
- FACTORY_STABLE_NG = 'factory_stable_ng',
121
- // FACTORY_STABLE_6_NG = 'factory_stable_6_ng',
122
- // FACTORY_STABLE_8_NG = 'factory_stable_8_ng',
123
118
  }
124
119
 
125
120
  export enum CustomImplementationNames {
@@ -180,14 +175,8 @@ export type CustomPoolConfig = {
180
175
  useForPricing: boolean;
181
176
  };
182
177
 
183
- type DexParamFactory = {
184
- address: string;
185
- maxPlainCoins?: number;
186
- isStableNg?: boolean;
187
- };
188
-
189
178
  export type DexParams = {
190
- factories: DexParamFactory[] | null;
179
+ factoryAddresses: string[] | null;
191
180
  stateUpdatePeriodMs: number;
192
181
  factoryPoolImplementations: Record<Address, FactoryPoolImplementations>;
193
182
  customPools: Record<string, CustomPoolConfig>;
@@ -20,35 +20,3 @@ export const HASHFLOW_GAS_COST = 100_000;
20
20
 
21
21
  export const HASHFLOW_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION =
22
22
  new BigNumber('0.001');
23
-
24
- export const RESTRICT_79_TTL_MS = 60 * 30 * 1000; // 30 mins
25
- export const RESTRICT_SLIPPAGE_TTL_MS = 60 * 30 * 1000; // 30 mins
26
- export const RESTRICT_84_TTL_MS = 60 * 10 * 1000; // 10 mins
27
- export const RESTRICT_76_TTL_MS = 60 * 30 * 1000; // 30 mins
28
- export const RESTRICT_82_TTL_MS = 60 * 30 * 1000; // 30 mins
29
- export const RESTRICT_42_TTL_MS = 60 * 60 * 1000; // 60 mins
30
- export const RESTRICT_85_TTL_MS = 60 * 20 * 1000; // 20 mins
31
- export const RESTRICT_74_TTL_MS = 60 * 20 * 1000; // 20 mins
32
- export const RESTRICT_UNKNOWN_TTL_MS = 60 * 60 * 1000; // 60 mins
33
- export const RESTRICT_MISSING_QUOTE_DATA_TTL_MS = 60 * 10 * 1000; // 10 mins
34
- export const RESTRICT_MISSING_SIGNATURE_TTL_MS = 60 * 10 * 1000; // 10 mins
35
-
36
- export const UNKNOWN_ERROR_CODE = 'UNKNOWN';
37
-
38
- export const ERROR_CODE_TO_RESTRICT_TTL = {
39
- '79': RESTRICT_79_TTL_MS, // {"code":79,"message":"Below minimum amount"}
40
- SLIPPAGE: RESTRICT_SLIPPAGE_TTL_MS, // Error: Hashflow-56: too much slippage on quote SELL quoteTokenAmount 800317519410129900 / destAmount 848781022570196154 < 0.995
41
- '84': RESTRICT_84_TTL_MS, // {"code":84,"message":"Rate Limit"}
42
- '76': RESTRICT_76_TTL_MS, // {"code":76,"message":"Exceeds supported amounts"}
43
- '82': RESTRICT_82_TTL_MS, // {"code":82,"message":"No maker supports this request"}
44
- '42': RESTRICT_42_TTL_MS, // {"code":42,"message":"Unknown error"}
45
- '85': RESTRICT_85_TTL_MS, // {"code":85,"message":"Markets too volatile"}
46
- '74': RESTRICT_74_TTL_MS, // {"code":74,"message":"No maker could quote"}
47
- MISSING_QUOTE_DATA: RESTRICT_MISSING_QUOTE_DATA_TTL_MS, // missing quote data
48
- MISSING_SIGNATURE_DATA: RESTRICT_MISSING_SIGNATURE_TTL_MS, // missing signature
49
- [UNKNOWN_ERROR_CODE]: RESTRICT_UNKNOWN_TTL_MS, // unknown error
50
- };
51
-
52
- // not actually consecutive, meaning is if the error appeared > CONSECUTIVE_ERROR_THRESHOLD times within CONSECUTIVE_ERROR_TIMESPAN_MS ms -> restrict mm for ERROR_CODE_TO_RESTRICT_TTL[errorCode] ms
53
- export const CONSECUTIVE_ERROR_TIMESPAN_MS = 60 * 60 * 1000; // 1 hour
54
- export const CONSECUTIVE_ERROR_THRESHOLD = 3;