@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
@@ -33,14 +33,11 @@ import {
33
33
  SimpleExchangeParam,
34
34
  Token,
35
35
  } from '../../types';
36
- import { getDexKeysWithNetwork, Utils } from '../../utils';
36
+ import { getDexKeysWithNetwork } from '../../utils';
37
37
  import { TooStrictSlippageCheckError } from '../generic-rfq/types';
38
38
  import { SimpleExchange } from '../simple-exchange';
39
39
  import { Adapters, HashflowConfig } from './config';
40
40
  import {
41
- CONSECUTIVE_ERROR_THRESHOLD,
42
- CONSECUTIVE_ERROR_TIMESPAN_MS,
43
- ERROR_CODE_TO_RESTRICT_TTL,
44
41
  HASHFLOW_API_CLIENT_NAME,
45
42
  HASHFLOW_API_MARKET_MAKERS_POLLING_INTERVAL_MS,
46
43
  HASHFLOW_API_PRICES_POLLING_INTERVAL_MS,
@@ -51,12 +48,9 @@ import {
51
48
  HASHFLOW_MIN_SLIPPAGE_FACTOR_THRESHOLD_FOR_RESTRICTION,
52
49
  HASHFLOW_MM_RESTRICT_TTL_S,
53
50
  HASHFLOW_PRICES_CACHES_TTL_S,
54
- UNKNOWN_ERROR_CODE,
55
51
  } from './constants';
56
52
  import { RateFetcher } from './rate-fetcher';
57
53
  import {
58
- CacheErrorCodesData,
59
- ErrorCode,
60
54
  HashflowData,
61
55
  PriceLevel,
62
56
  RfqError,
@@ -75,7 +69,6 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
75
69
  private hashFlowAuthToken: string;
76
70
  private disabledMMs: Set<string>;
77
71
  private runtimeMMsRestrictHashMapKey: string;
78
- private runtimeMMsRestrictHashMapErrorCodesKey: string;
79
72
 
80
73
  private pricesCacheKey: string;
81
74
  private marketMakersCacheKey: string;
@@ -115,8 +108,6 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
115
108
  this.disabledMMs = new Set(dexHelper.config.data.hashFlowDisabledMMs);
116
109
  this.runtimeMMsRestrictHashMapKey =
117
110
  `${CACHE_PREFIX}_${this.dexKey}_${this.network}_restricted_mms`.toLowerCase();
118
- this.runtimeMMsRestrictHashMapErrorCodesKey =
119
- `${CACHE_PREFIX}_${this.dexKey}_${this.network}_restricted_mms_error_codes`.toLowerCase();
120
111
 
121
112
  this.rateFetcher = new RateFetcher(
122
113
  this.dexHelper,
@@ -604,7 +595,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
604
595
  normalizedDestToken.address,
605
596
  )}: ${JSON.stringify(rfq)}`;
606
597
  this.logger.warn(message);
607
- throw new RfqError(message, `${rfq?.error?.code}` as ErrorCode);
598
+ throw new RfqError(message);
608
599
  } else if (!rfq.quotes[0].quoteData) {
609
600
  const message = `${this.dexKey}-${
610
601
  this.network
@@ -613,7 +604,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
613
604
  normalizedDestToken.address,
614
605
  )}. Missing quote data`;
615
606
  this.logger.warn(message);
616
- throw new RfqError(message, 'MISSING_QUOTE_DATA');
607
+ throw new RfqError(message);
617
608
  } else if (!rfq.quotes[0].signature) {
618
609
  const message = `${this.dexKey}-${
619
610
  this.network
@@ -622,7 +613,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
622
613
  normalizedDestToken.address,
623
614
  )}. Missing signature`;
624
615
  this.logger.warn(message);
625
- throw new RfqError(message, 'MISSING_SIGNATURE_DATA');
616
+ throw new RfqError(message);
626
617
  }
627
618
 
628
619
  assert(
@@ -738,13 +729,7 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
738
729
  this.logger.warn(
739
730
  `${this.dexKey}-${this.network} MM unknown preprocess transaction error: ${e}`,
740
731
  );
741
- const code =
742
- e instanceof RfqError || e instanceof SlippageCheckError
743
- ? e?.code || UNKNOWN_ERROR_CODE
744
- : UNKNOWN_ERROR_CODE;
745
- await this.restrictMM(mm, code).catch(err =>
746
- this.logger.warn(`Failed to restrict MM ${mm}: ${err}`),
747
- );
732
+ await this.restrictMM(mm);
748
733
  }
749
734
  }
750
735
 
@@ -752,111 +737,24 @@ export class Hashflow extends SimpleExchange implements IDex<HashflowData> {
752
737
  }
753
738
  }
754
739
 
755
- async restrictMM(mm: string, errorCode: ErrorCode): Promise<void> {
756
- const errorCodesRaw = await this.dexHelper.cache.hget(
757
- this.runtimeMMsRestrictHashMapErrorCodesKey,
758
- mm,
740
+ async restrictMM(mm: string): Promise<void> {
741
+ this.logger.warn(
742
+ `${this.dexKey}-${this.network}: ${mm} was restricted for ${HASHFLOW_MM_RESTRICT_TTL_S} sec. due to fails`,
759
743
  );
760
744
 
761
- const errorCodes: CacheErrorCodesData = Utils.Parse(errorCodesRaw) || {};
762
-
763
- const error = errorCodes?.[errorCode];
745
+ // We use timestamp for creation date to later discern if it already expired or not
746
+ await this.dexHelper.cache.hset(
747
+ this.runtimeMMsRestrictHashMapKey,
748
+ mm,
749
+ Date.now().toString(),
750
+ );
764
751
 
765
- if (
766
- !error ||
767
- error.addedDatetimeMS + CONSECUTIVE_ERROR_TIMESPAN_MS < Date.now()
768
- ) {
769
- this.logger.warn(
770
- `${this.dexKey}-${this.network}: First encounter of error code=${errorCode} for ${mm} OR error ocurred outside of threshold, setting up counter`,
771
- );
772
- const data: CacheErrorCodesData = {
773
- ...errorCodes,
774
- [errorCode]: {
775
- count: 1,
776
- addedDatetimeMS: Date.now(),
777
- },
778
- };
779
- await this.dexHelper.cache.hset(
780
- this.runtimeMMsRestrictHashMapErrorCodesKey,
781
- mm,
782
- Utils.Serialize(data),
752
+ // Expiry cache because it has levels for blacklisted MM
753
+ this.dexHelper.cache.del(this.dexKey, this.network, 'levels').catch(e => {
754
+ this.logger.error(
755
+ `${this.dexKey}-${this.network}: Failed to delete levels cache: ${e.message}`,
783
756
  );
784
- return;
785
- } else {
786
- const restrictTTLMs =
787
- ERROR_CODE_TO_RESTRICT_TTL[errorCode] ||
788
- ERROR_CODE_TO_RESTRICT_TTL[UNKNOWN_ERROR_CODE];
789
-
790
- if (error.count + 1 > CONSECUTIVE_ERROR_THRESHOLD) {
791
- this.logger.warn(
792
- `${this.dexKey}-${this.network}: ${mm} was restricted for ${
793
- restrictTTLMs / 1000
794
- } sec. due to ${errorCode} happening ${
795
- error.count + 1
796
- } times within last ${Math.floor(
797
- CONSECUTIVE_ERROR_TIMESPAN_MS / 1000 / 60,
798
- )} minutes`,
799
- );
800
-
801
- // date added is checked against HASHFLOW_MM_RESTRICT_TTL_S, as a hack we set a date so that it's checked against specific ttls based on error type to not change parsing logic for mms
802
- //
803
- // Example1: ttl for a particular error is 20 minutes (< default 60 minutes)
804
- // Meaning we need to set `addedDatetimeMS` for restrict hash as Date.now() - 40 minutes (diff between default restrict ttl=1h and particular error restrict ttl = 20 minutes). So the `addedDatetimeMS` is in the past, and after 20 minutes mm will not be considered as restricted
805
- //
806
- // Example 2: ttl for a particular error is 80 minutes (> default 60 minutes)
807
- // Meaning we need to set `addedDatetimeMS` for restrict hash as Date.now() + 20 minutes (in the future), then after an hour (default) it'll still be 20 minutes left for restriction to be cleared
808
-
809
- const defaultRestrictTTLMS = Math.floor(
810
- HASHFLOW_MM_RESTRICT_TTL_S * 1000,
811
- );
812
- const dateModifierMS =
813
- defaultRestrictTTLMS > restrictTTLMs
814
- ? -(defaultRestrictTTLMS - restrictTTLMs)
815
- : restrictTTLMs - defaultRestrictTTLMS;
816
-
817
- const date = (Date.now() + dateModifierMS).toString();
818
-
819
- // We use timestamp for creation date to later discern if it already expired or not
820
- await this.dexHelper.cache.hset(
821
- this.runtimeMMsRestrictHashMapKey,
822
- mm,
823
- date,
824
- );
825
-
826
- // resetting error count
827
- const data: CacheErrorCodesData = {
828
- ...errorCodes,
829
- [errorCode]: {
830
- count: 1,
831
- addedDatetimeMS: Date.now(),
832
- },
833
- };
834
- await this.dexHelper.cache.hset(
835
- this.runtimeMMsRestrictHashMapErrorCodesKey,
836
- mm,
837
- Utils.Serialize(data),
838
- );
839
-
840
- return;
841
- } else {
842
- const newCount = +error.count + 1;
843
- this.logger.warn(
844
- `${this.dexKey}-${this.network}: ${mm} Error with code: ${errorCode} happened ${newCount} times (below or equal to the limit: ${CONSECUTIVE_ERROR_THRESHOLD}), updating counter`,
845
- );
846
- const data: CacheErrorCodesData = {
847
- ...errorCodes,
848
- [errorCode]: {
849
- count: newCount,
850
- addedDatetimeMS: error.addedDatetimeMS, // initial date stays
851
- },
852
- };
853
- await this.dexHelper.cache.hset(
854
- this.runtimeMMsRestrictHashMapErrorCodesKey,
855
- mm,
856
- Utils.Serialize(data),
857
- );
858
- }
859
- }
757
+ });
860
758
  }
861
759
 
862
760
  getCalldataGasCost(poolPrices: PoolPrices<HashflowData>): number | number[] {
@@ -1,6 +1,5 @@
1
1
  import { Chain, QuoteData } from '@hashflow/taker-js/dist/types/common';
2
2
  import { RequestHeaders } from '../../dex-helper';
3
- import { ERROR_CODE_TO_RESTRICT_TTL, UNKNOWN_ERROR_CODE } from './constants';
4
3
 
5
4
  export type HashflowData = {
6
5
  mm: string;
@@ -17,22 +16,14 @@ export interface PriceLevel {
17
16
  p: string;
18
17
  }
19
18
 
20
- export class RfqError extends Error {
21
- code: ErrorCode;
22
- constructor(message: string, code: ErrorCode = UNKNOWN_ERROR_CODE) {
23
- super(message);
24
- this.code = code;
25
- }
26
- }
19
+ export class RfqError extends Error {}
27
20
 
28
21
  export enum RFQType {
29
22
  RFQT = 0,
30
23
  RFQM = 1,
31
24
  }
32
25
 
33
- export class SlippageCheckError extends Error {
34
- code: ErrorCode = 'SLIPPAGE';
35
- }
26
+ export class SlippageCheckError extends Error {}
36
27
 
37
28
  export type HashflowRatesLevel = {
38
29
  pair: Record<string, string>;
@@ -72,12 +63,3 @@ export type HashflowRateFetcherConfig = {
72
63
  marketMakersCacheTTLSecs: number;
73
64
  };
74
65
  };
75
-
76
- export type ErrorCode = keyof typeof ERROR_CODE_TO_RESTRICT_TTL;
77
-
78
- export type CacheErrorCodesData = {
79
- [code in ErrorCode]: {
80
- addedDatetimeMS: number;
81
- count: number;
82
- } | null;
83
- };
package/src/dex/idex.ts CHANGED
@@ -194,7 +194,7 @@ export interface IDex<
194
194
  IDexPooltracker {}
195
195
 
196
196
  // Defines the static objects of the IDex class
197
- export interface DexConstructor<
197
+ export interface DexContructor<
198
198
  ExchangeData,
199
199
  DirectParam = null,
200
200
  OptimizedExchangeData = ExchangeData,
package/src/dex/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import { UnoptimizedRate } from '../types';
3
3
  import { CurveV2 } from './curve-v2';
4
- import { IDexTxBuilder, DexConstructor, IDex, IRouteOptimizer } from './idex';
4
+ import { IDexTxBuilder, DexContructor, IDex, IRouteOptimizer } from './idex';
5
5
  import { Jarvis } from './jarvis';
6
6
  import { JarvisV6 } from './jarvis-v6/jarvis-v6';
7
7
  import { StablePool } from './stable-pool';
@@ -87,6 +87,7 @@ import { Wombat } from './wombat/wombat';
87
87
  import { Swell } from './swell/swell';
88
88
  import { PharaohV1 } from './solidly/forks-override/pharaohV1';
89
89
  import { EtherFi } from './etherfi';
90
+ import { SDai } from './sdai/sdai';
90
91
 
91
92
  const LegacyDexes = [
92
93
  CurveV2,
@@ -170,6 +171,7 @@ const Dexes = [
170
171
  Wombat,
171
172
  Swell,
172
173
  PharaohV1,
174
+ SDai,
173
175
  ];
174
176
 
175
177
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -183,7 +185,7 @@ interface IGetDirectFunctionName {
183
185
 
184
186
  export class DexAdapterService {
185
187
  dexToKeyMap: {
186
- [key: string]: LegacyDexConstructor | DexConstructor<any, any, any>;
188
+ [key: string]: LegacyDexConstructor | DexContructor<any, any, any>;
187
189
  } = {};
188
190
  directFunctionsNames: string[];
189
191
  dexInstances: {
@@ -69,22 +69,6 @@ export const PancakeswapV3Config: DexConfigMap<DexParams> = {
69
69
  'https://api.studio.thegraph.com/query/45376/exchange-v3-base/version/latest',
70
70
  },
71
71
  },
72
- DackieSwapV3: {
73
- [Network.BASE]: {
74
- factory: '0x3D237AC6D2f425D2E890Cc99198818cc1FA48870',
75
- quoter: '0x4fDBD73aD4B1DDde594BF05497C15f76308eFfb9',
76
- deployer: '0x4f205D69834f9B101b9289F7AFFAc9B77B3fF9b7',
77
- router: '0x4030ebafeb76e5fc848891076dfe315993800ba5',
78
- supportedFees: [10000n, 2500n, 500n, 100n],
79
- stateMulticall: '0xeBF40A40CA3D4310Bf53048F48e860656e1D7C81',
80
- uniswapMulticall: '0x091e99cb1C49331a94dD62755D168E941AbD0693',
81
- chunksCount: 10,
82
- initRetryFrequency: 10,
83
- initHash: `0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2`,
84
- subgraphURL:
85
- 'https://api.studio.thegraph.com/query/50473/exchange-clmm/version/latest',
86
- },
87
- },
88
72
  };
89
73
 
90
74
  export const Adapters: Record<number, AdapterMappings> = {
@@ -87,9 +87,7 @@ export class PancakeswapV3
87
87
  intervalTask?: NodeJS.Timeout;
88
88
 
89
89
  public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
90
- getDexKeysWithNetwork(
91
- _.pick(PancakeswapV3Config, ['PancakeswapV3', 'DackieSwapV3']),
92
- );
90
+ getDexKeysWithNetwork(_.pick(PancakeswapV3Config, ['PancakeswapV3']));
93
91
 
94
92
  logger: Logger;
95
93
 
@@ -0,0 +1,28 @@
1
+ import { SDaiParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ import { Network } from '../../constants';
4
+ import { SwapSide } from '@paraswap/core';
5
+
6
+ export const SDaiConfig: DexConfigMap<SDaiParams> = {
7
+ SDai: {
8
+ [Network.MAINNET]: {
9
+ sdaiAddress: '0x83F20F44975D03b1b09e64809B757c47f942BEeA',
10
+ daiAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
11
+ potAddress: '0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7',
12
+ },
13
+ },
14
+ };
15
+
16
+ export const Adapters: {
17
+ [chainId: number]: {
18
+ [side: string]: { name: string; index: number }[];
19
+ };
20
+ } = {
21
+ [Network.MAINNET]: {
22
+ // TODO: uncomment this when SDAI integration got deployed
23
+ // [SwapSide.SELL]: [{ name: 'Adapter06', index: 2 }],
24
+ // [SwapSide.BUY]: [{ name: 'BuyAdapter02', index: 5 }],
25
+ [SwapSide.SELL]: [{ name: 'Adapter06', index: 1 }],
26
+ [SwapSide.BUY]: [{ name: 'BuyAdapter02', index: 4 }],
27
+ },
28
+ };
@@ -0,0 +1,2 @@
1
+ export const SDAI_DEPOSIT_GAS_COST = 165_000;
2
+ export const SDAI_REDEEM_GAS_COST = 90_000;
@@ -0,0 +1,144 @@
1
+ /* eslint-disable no-console */
2
+ import dotenv from 'dotenv';
3
+ dotenv.config();
4
+
5
+ import { Network } from '../../../constants';
6
+ import { DummyDexHelper } from '../../../dex-helper';
7
+ import { SDaiPoolState } from '../types';
8
+ import { BlockHeader } from 'web3-eth';
9
+ import { ethers } from 'ethers';
10
+ import { SDai } from '../sdai';
11
+ import { SDaiConfig } from '../config';
12
+ import { getOnChainState } from '../utils';
13
+ import { Interface } from '@ethersproject/abi';
14
+ import PotAbi from '../../../abi/maker-psm/pot.json';
15
+
16
+ const network = Network.MAINNET;
17
+ const dexKey = 'SDai';
18
+
19
+ const { potAddress } = SDaiConfig[dexKey][network];
20
+ const blockHeaders: Record<number, BlockHeader> = {};
21
+
22
+ const dexHelper = new DummyDexHelper(network);
23
+ const logger = dexHelper.getLogger(dexKey);
24
+
25
+ function preprocessField(value: any): string {
26
+ if (
27
+ typeof value === 'bigint' ||
28
+ typeof value === 'number' ||
29
+ ethers.BigNumber.isBigNumber(value)
30
+ ) {
31
+ return value.toString();
32
+ }
33
+ return value;
34
+ }
35
+
36
+ function compareAndLogDifferences<T extends object, Y extends object>(
37
+ obj1: T,
38
+ obj2: Y,
39
+ keyNames: Array<keyof T & keyof Y>,
40
+ checkEachKey = false,
41
+ ) {
42
+ let isValid = true;
43
+ let keys = keyNames;
44
+
45
+ if (checkEachKey) {
46
+ // find common keys
47
+ const keys1 = Object.keys(obj1);
48
+ const keys2 = new Set(Object.keys(obj2));
49
+ keys = keys1.filter(key => keys2.has(key)) as Array<keyof T & keyof Y>;
50
+ }
51
+
52
+ for (let fieldName of keys) {
53
+ const value1 = preprocessField(obj1[fieldName]);
54
+ const value2 = preprocessField(obj2[fieldName]);
55
+
56
+ if (value1 !== value2) {
57
+ console.log(
58
+ `${fieldName.toString()} mismatch: actual: ${value1} vs pool: ${value2}`,
59
+ );
60
+ isValid = false;
61
+ }
62
+ }
63
+
64
+ return isValid;
65
+ }
66
+
67
+ async function isPoolStateEqualToReal(
68
+ state: SDaiPoolState,
69
+ blockNumber: number,
70
+ ) {
71
+ const expected = await getOnChainState(
72
+ dexHelper.multiContract,
73
+ potAddress,
74
+ new Interface(PotAbi),
75
+ blockNumber,
76
+ );
77
+
78
+ const isValidState = compareAndLogDifferences(state, expected, [
79
+ 'rho',
80
+ 'dsr',
81
+ 'dsr',
82
+ ]);
83
+
84
+ return isValidState;
85
+ }
86
+
87
+ async function checkPoolStateForBlockRange(
88
+ startBlockNumber: number,
89
+ endBlockNumber: number,
90
+ ): Promise<boolean> {
91
+ const network = Network.MAINNET;
92
+ const dexKey = 'SDai';
93
+ const dexHelper = new DummyDexHelper(network);
94
+
95
+ const sdai = new SDai(network, dexKey, dexHelper);
96
+ const pool = await sdai.eventPool;
97
+
98
+ const logsToDispatch = await dexHelper.provider.getLogs({
99
+ fromBlock: startBlockNumber,
100
+ toBlock: endBlockNumber,
101
+ address: potAddress,
102
+ });
103
+
104
+ console.log(logsToDispatch.length);
105
+
106
+ // group logs by block number
107
+ const logsByBlockNumber: Record<number, any[]> = {};
108
+ for (let log of logsToDispatch) {
109
+ if (!logsByBlockNumber[log.blockNumber]) {
110
+ logsByBlockNumber[log.blockNumber] = [];
111
+ }
112
+ logsByBlockNumber[log.blockNumber].push(log);
113
+ }
114
+
115
+ const sortedBlocks = Object.keys(logsByBlockNumber)
116
+ .map(Number)
117
+ .sort((a, b) => Number(a) - Number(b));
118
+
119
+ for (let blockNumber of sortedBlocks) {
120
+ if (!blockHeaders[blockNumber]) {
121
+ blockHeaders[blockNumber] = await dexHelper.web3Provider.eth.getBlock(
122
+ blockNumber,
123
+ );
124
+ }
125
+
126
+ await pool?.update(logsByBlockNumber[blockNumber], {
127
+ [blockNumber]: blockHeaders[blockNumber],
128
+ });
129
+ }
130
+
131
+ const state = pool?.getState(startBlockNumber) as SDaiPoolState;
132
+ return isPoolStateEqualToReal(state, endBlockNumber);
133
+ }
134
+
135
+ async function main() {
136
+ // use findBreakingBlock to find the block where the state is broken
137
+ // console.log(await findBreakingBlock(startBlockNumber, endBlockNumber));
138
+ // previously broken block 150502863
139
+ console.log(await checkPoolStateForBlockRange(19199247 - 10000, 19199247));
140
+ }
141
+
142
+ main()
143
+ .then(() => console.log('Done'))
144
+ .catch(e => console.error(e));
@@ -0,0 +1,96 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { testE2E } from '../../../tests/utils-e2e';
5
+ import { Tokens, Holders } from '../../../tests/constants-e2e';
6
+ import { Network, ContractMethod, SwapSide } from '../../constants';
7
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
8
+ import { generateConfig } from '../../config';
9
+
10
+ function testForNetwork(
11
+ network: Network,
12
+ dexKey: string,
13
+ tokenASymbol: string,
14
+ tokenBSymbol: string,
15
+ tokenAAmount: string,
16
+ tokenBAmount: string,
17
+ ) {
18
+ const provider = new StaticJsonRpcProvider(
19
+ generateConfig(network).privateHttpProvider,
20
+ network,
21
+ );
22
+ const tokens = Tokens[network];
23
+ const holders = Holders[network];
24
+
25
+ const sideToContractMethods = new Map([
26
+ [
27
+ SwapSide.SELL,
28
+ [
29
+ ContractMethod.simpleSwap,
30
+ ContractMethod.multiSwap,
31
+ ContractMethod.megaSwap,
32
+ ],
33
+ ],
34
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
35
+ ]);
36
+
37
+ describe(`${network}`, () => {
38
+ sideToContractMethods.forEach((contractMethods, side) =>
39
+ describe(`${side}`, () => {
40
+ contractMethods.forEach((contractMethod: ContractMethod) => {
41
+ describe(`${contractMethod}`, () => {
42
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
43
+ await testE2E(
44
+ tokens[tokenASymbol],
45
+ tokens[tokenBSymbol],
46
+ holders[tokenASymbol],
47
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
48
+ side,
49
+ dexKey,
50
+ contractMethod,
51
+ network,
52
+ provider,
53
+ );
54
+ });
55
+ it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
56
+ await testE2E(
57
+ tokens[tokenBSymbol],
58
+ tokens[tokenASymbol],
59
+ holders[tokenBSymbol],
60
+ side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
61
+ side,
62
+ dexKey,
63
+ contractMethod,
64
+ network,
65
+ provider,
66
+ );
67
+ });
68
+ });
69
+ });
70
+ }),
71
+ );
72
+ });
73
+ }
74
+
75
+ describe('sDAI E2E', () => {
76
+ const dexKey = 'sdai';
77
+
78
+ describe('Mainnet', () => {
79
+ const network = Network.MAINNET;
80
+
81
+ const tokenASymbol: string = 'DAI';
82
+ const tokenBSymbol: string = 'sDAI';
83
+
84
+ const tokenAAmount: string = '1000000000000000000';
85
+ const tokenBAmount: string = '1000000000000000000';
86
+
87
+ testForNetwork(
88
+ network,
89
+ dexKey,
90
+ tokenASymbol,
91
+ tokenBSymbol,
92
+ tokenAAmount,
93
+ tokenBAmount,
94
+ );
95
+ });
96
+ });