@paraswap/dex-lib 3.8.2 → 3.8.3

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 (346) hide show
  1. package/.vscode/launch.json +13 -0
  2. package/.vscode/settings.json +3 -0
  3. package/build/abi/AaveV1_lending_pool.json +27 -0
  4. package/build/abi/Uncompressor.json +250 -0
  5. package/build/abi/integral/factory.json +333 -0
  6. package/build/abi/integral/oracle.json +501 -0
  7. package/build/abi/integral/pool.json +1041 -0
  8. package/build/abi/integral/relayer.json +1536 -0
  9. package/build/abi/oswap/oswap.abi.json +452 -0
  10. package/build/abi/platypus/asset.json +490 -0
  11. package/build/abi/platypus/avax-pool.json +820 -0
  12. package/build/abi/platypus/oracle.json +119 -0
  13. package/build/abi/platypus/pool.json +677 -0
  14. package/build/abi/smardex/all/smardex-router.json +648 -0
  15. package/build/abi/smardex/layer-1/smardex-factory.json +242 -0
  16. package/build/abi/smardex/layer-1/smardex-pool.json +506 -0
  17. package/build/abi/smardex/layer-2/smardex-factory.json +185 -0
  18. package/build/abi/smardex/layer-2/smardex-pool.json +578 -0
  19. package/build/abi/swaap-v1/pool.json +1346 -0
  20. package/build/dex/aave-v1/aave-v1.d.ts +33 -0
  21. package/build/dex/aave-v1/aave-v1.js +158 -0
  22. package/build/dex/aave-v1/aave-v1.js.map +1 -0
  23. package/build/dex/aave-v1/config.d.ts +11 -0
  24. package/build/dex/aave-v1/config.js +20 -0
  25. package/build/dex/aave-v1/config.js.map +1 -0
  26. package/build/dex/aave-v1/tokens-mainnet.json +134 -0
  27. package/build/dex/aave-v1/tokens.d.ts +3 -0
  28. package/build/dex/aave-v1/tokens.js +50 -0
  29. package/build/dex/aave-v1/tokens.js.map +1 -0
  30. package/build/dex/aave-v1/types.d.ts +12 -0
  31. package/build/dex/aave-v1/types.js +3 -0
  32. package/build/dex/aave-v1/types.js.map +1 -0
  33. package/build/dex/aave-v3/aave-v3.js +2 -1
  34. package/build/dex/aave-v3/aave-v3.js.map +1 -1
  35. package/build/dex/aave-v3-stata/aave-v3-stata.js +1 -0
  36. package/build/dex/aave-v3-stata/aave-v3-stata.js.map +1 -1
  37. package/build/dex/angle-staked-stable/angle-staked-stable.js +4 -1
  38. package/build/dex/angle-staked-stable/angle-staked-stable.js.map +1 -1
  39. package/build/dex/bProtocol.d.ts +18 -0
  40. package/build/dex/bProtocol.js +39 -0
  41. package/build/dex/bProtocol.js.map +1 -0
  42. package/build/dex/bancor.d.ts +26 -0
  43. package/build/dex/bancor.js +58 -0
  44. package/build/dex/bancor.js.map +1 -0
  45. package/build/dex/compound/compound.js +2 -1
  46. package/build/dex/compound/compound.js.map +1 -1
  47. package/build/dex/compound.d.ts +18 -0
  48. package/build/dex/compound.js +46 -0
  49. package/build/dex/compound.js.map +1 -0
  50. package/build/dex/curve-v2.d.ts +58 -0
  51. package/build/dex/curve-v2.js +180 -0
  52. package/build/dex/curve-v2.js.map +1 -0
  53. package/build/dex/dodo-v1.d.ts +33 -0
  54. package/build/dex/dodo-v1.js +63 -0
  55. package/build/dex/dodo-v1.js.map +1 -0
  56. package/build/dex/etherfi/etherfi.d.ts +26 -0
  57. package/build/dex/etherfi/etherfi.js +96 -0
  58. package/build/dex/etherfi/etherfi.js.map +1 -0
  59. package/build/dex/etherfi.js +4 -1
  60. package/build/dex/etherfi.js.map +1 -1
  61. package/build/dex/idle-dao/idle-dao.js +1 -0
  62. package/build/dex/idle-dao/idle-dao.js.map +1 -1
  63. package/build/dex/integral/config.d.ts +4 -0
  64. package/build/dex/integral/config.js +20 -0
  65. package/build/dex/integral/config.js.map +1 -0
  66. package/build/dex/integral/context.d.ts +33 -0
  67. package/build/dex/integral/context.js +98 -0
  68. package/build/dex/integral/context.js.map +1 -0
  69. package/build/dex/integral/helpers.d.ts +17 -0
  70. package/build/dex/integral/helpers.js +157 -0
  71. package/build/dex/integral/helpers.js.map +1 -0
  72. package/build/dex/integral/integral-factory.d.ts +21 -0
  73. package/build/dex/integral/integral-factory.js +92 -0
  74. package/build/dex/integral/integral-factory.js.map +1 -0
  75. package/build/dex/integral/integral-pool.d.ts +46 -0
  76. package/build/dex/integral/integral-pool.js +143 -0
  77. package/build/dex/integral/integral-pool.js.map +1 -0
  78. package/build/dex/integral/integral-pricing.d.ts +18 -0
  79. package/build/dex/integral/integral-pricing.js +114 -0
  80. package/build/dex/integral/integral-pricing.js.map +1 -0
  81. package/build/dex/integral/integral-relayer.d.ts +39 -0
  82. package/build/dex/integral/integral-relayer.js +189 -0
  83. package/build/dex/integral/integral-relayer.js.map +1 -0
  84. package/build/dex/integral/integral-token.d.ts +22 -0
  85. package/build/dex/integral/integral-token.js +55 -0
  86. package/build/dex/integral/integral-token.js.map +1 -0
  87. package/build/dex/integral/integral.d.ts +41 -0
  88. package/build/dex/integral/integral.js +382 -0
  89. package/build/dex/integral/integral.js.map +1 -0
  90. package/build/dex/integral/types.d.ts +84 -0
  91. package/build/dex/integral/types.js +9 -0
  92. package/build/dex/integral/types.js.map +1 -0
  93. package/build/dex/integral/utils.d.ts +6 -0
  94. package/build/dex/integral/utils.js +23 -0
  95. package/build/dex/integral/utils.js.map +1 -0
  96. package/build/dex/lido.d.ts +19 -0
  97. package/build/dex/lido.js +42 -0
  98. package/build/dex/lido.js.map +1 -0
  99. package/build/dex/mStable.js +1 -1
  100. package/build/dex/mStable.js.map +1 -1
  101. package/build/dex/onebit.d.ts +25 -0
  102. package/build/dex/onebit.js +42 -0
  103. package/build/dex/onebit.js.map +1 -0
  104. package/build/dex/oswap/config.d.ts +5 -0
  105. package/build/dex/oswap/config.js +31 -0
  106. package/build/dex/oswap/config.js.map +1 -0
  107. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  108. package/build/dex/oswap/oswap-pool.js +150 -0
  109. package/build/dex/oswap/oswap-pool.js.map +1 -0
  110. package/build/dex/oswap/oswap.d.ts +46 -0
  111. package/build/dex/oswap/oswap.js +266 -0
  112. package/build/dex/oswap/oswap.js.map +1 -0
  113. package/build/dex/oswap/types.d.ts +20 -0
  114. package/build/dex/oswap/types.js +3 -0
  115. package/build/dex/oswap/types.js.map +1 -0
  116. package/build/dex/platypus/asset.d.ts +14 -0
  117. package/build/dex/platypus/asset.js +97 -0
  118. package/build/dex/platypus/asset.js.map +1 -0
  119. package/build/dex/platypus/config.d.ts +11 -0
  120. package/build/dex/platypus/config.js +69 -0
  121. package/build/dex/platypus/config.js.map +1 -0
  122. package/build/dex/platypus/platypus.d.ts +62 -0
  123. package/build/dex/platypus/platypus.js +442 -0
  124. package/build/dex/platypus/platypus.js.map +1 -0
  125. package/build/dex/platypus/pool-avax.d.ts +8 -0
  126. package/build/dex/platypus/pool-avax.js +54 -0
  127. package/build/dex/platypus/pool-avax.js.map +1 -0
  128. package/build/dex/platypus/pool-base.d.ts +19 -0
  129. package/build/dex/platypus/pool-base.js +86 -0
  130. package/build/dex/platypus/pool-base.js.map +1 -0
  131. package/build/dex/platypus/pool-pure.d.ts +8 -0
  132. package/build/dex/platypus/pool-pure.js +37 -0
  133. package/build/dex/platypus/pool-pure.js.map +1 -0
  134. package/build/dex/platypus/pool-subscriber.d.ts +14 -0
  135. package/build/dex/platypus/pool-subscriber.js +167 -0
  136. package/build/dex/platypus/pool-subscriber.js.map +1 -0
  137. package/build/dex/platypus/pool.d.ts +8 -0
  138. package/build/dex/platypus/pool.js +58 -0
  139. package/build/dex/platypus/pool.js.map +1 -0
  140. package/build/dex/platypus/types.d.ts +92 -0
  141. package/build/dex/platypus/types.js +10 -0
  142. package/build/dex/platypus/types.js.map +1 -0
  143. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  144. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  145. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  146. package/build/dex/sdai/config.d.ts +11 -0
  147. package/build/dex/sdai/config.js +21 -0
  148. package/build/dex/sdai/config.js.map +1 -0
  149. package/build/dex/sdai/constants.d.ts +2 -0
  150. package/build/dex/sdai/constants.js +6 -0
  151. package/build/dex/sdai/constants.js.map +1 -0
  152. package/build/dex/sdai/scripts/validate-state.d.ts +1 -0
  153. package/build/dex/sdai/scripts/validate-state.js +102 -0
  154. package/build/dex/sdai/scripts/validate-state.js.map +1 -0
  155. package/build/dex/sdai/sdai-pool.d.ts +16 -0
  156. package/build/dex/sdai/sdai-pool.js +85 -0
  157. package/build/dex/sdai/sdai-pool.js.map +1 -0
  158. package/build/dex/sdai/sdai.d.ts +51 -0
  159. package/build/dex/sdai/sdai.js +172 -0
  160. package/build/dex/sdai/sdai.js.map +1 -0
  161. package/build/dex/sdai/types.d.ts +21 -0
  162. package/build/dex/sdai/types.js +11 -0
  163. package/build/dex/sdai/types.js.map +1 -0
  164. package/build/dex/sdai/utils.d.ts +4 -0
  165. package/build/dex/sdai/utils.js +39 -0
  166. package/build/dex/sdai/utils.js.map +1 -0
  167. package/build/dex/simple-exchange.d.ts +1 -1
  168. package/build/dex/simple-exchange.js +4 -2
  169. package/build/dex/simple-exchange.js.map +1 -1
  170. package/build/dex/smardex/config.d.ts +4 -0
  171. package/build/dex/smardex/config.js +64 -0
  172. package/build/dex/smardex/config.js.map +1 -0
  173. package/build/dex/smardex/constants.d.ts +18 -0
  174. package/build/dex/smardex/constants.js +33 -0
  175. package/build/dex/smardex/constants.js.map +1 -0
  176. package/build/dex/smardex/sdk/constants.d.ts +6 -0
  177. package/build/dex/smardex/sdk/constants.js +13 -0
  178. package/build/dex/smardex/sdk/constants.js.map +1 -0
  179. package/build/dex/smardex/sdk/core.d.ts +113 -0
  180. package/build/dex/smardex/sdk/core.js +499 -0
  181. package/build/dex/smardex/sdk/core.js.map +1 -0
  182. package/build/dex/smardex/sdk/errors.d.ts +15 -0
  183. package/build/dex/smardex/sdk/errors.js +22 -0
  184. package/build/dex/smardex/sdk/errors.js.map +1 -0
  185. package/build/dex/smardex/sdk/types.d.ts +62 -0
  186. package/build/dex/smardex/sdk/types.js +3 -0
  187. package/build/dex/smardex/sdk/types.js.map +1 -0
  188. package/build/dex/smardex/sdk/utils.d.ts +44 -0
  189. package/build/dex/smardex/sdk/utils.js +133 -0
  190. package/build/dex/smardex/sdk/utils.js.map +1 -0
  191. package/build/dex/smardex/smardex-event-pool.d.ts +28 -0
  192. package/build/dex/smardex/smardex-event-pool.js +119 -0
  193. package/build/dex/smardex/smardex-event-pool.js.map +1 -0
  194. package/build/dex/smardex/smardex.d.ts +65 -0
  195. package/build/dex/smardex/smardex.js +519 -0
  196. package/build/dex/smardex/smardex.js.map +1 -0
  197. package/build/dex/smardex/types.d.ts +55 -0
  198. package/build/dex/smardex/types.js +3 -0
  199. package/build/dex/smardex/types.js.map +1 -0
  200. package/build/dex/smoothy.d.ts +26 -0
  201. package/build/dex/smoothy.js +48 -0
  202. package/build/dex/smoothy.js.map +1 -0
  203. package/build/dex/solidly/forks-override/cone.d.ts +22 -0
  204. package/build/dex/solidly/forks-override/cone.js +53 -0
  205. package/build/dex/solidly/forks-override/cone.js.map +1 -0
  206. package/build/dex/solidly/forks-override/solisnek.d.ts +8 -0
  207. package/build/dex/solidly/forks-override/solisnek.js +15 -0
  208. package/build/dex/solidly/forks-override/solisnek.js.map +1 -0
  209. package/build/dex/spark/spark.js +2 -1
  210. package/build/dex/spark/spark.js.map +1 -1
  211. package/build/dex/stable-pool.d.ts +28 -0
  212. package/build/dex/stable-pool.js +62 -0
  213. package/build/dex/stable-pool.js.map +1 -0
  214. package/build/dex/swaap-v1/config.d.ts +17 -0
  215. package/build/dex/swaap-v1/config.js +56 -0
  216. package/build/dex/swaap-v1/config.js.map +1 -0
  217. package/build/dex/swaap-v1/constants.d.ts +6 -0
  218. package/build/dex/swaap-v1/constants.js +17 -0
  219. package/build/dex/swaap-v1/constants.js.map +1 -0
  220. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +25 -0
  221. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +62 -0
  222. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +1 -0
  223. package/build/dex/swaap-v1/libraries/Const.d.ts +18 -0
  224. package/build/dex/swaap-v1/libraries/Const.js +26 -0
  225. package/build/dex/swaap-v1/libraries/Const.js.map +1 -0
  226. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +77 -0
  227. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +316 -0
  228. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +1 -0
  229. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +75 -0
  230. package/build/dex/swaap-v1/libraries/LogExpMath.js +418 -0
  231. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +1 -0
  232. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +185 -0
  233. package/build/dex/swaap-v1/libraries/MathMMM.js +453 -0
  234. package/build/dex/swaap-v1/libraries/MathMMM.js.map +1 -0
  235. package/build/dex/swaap-v1/libraries/Num.d.ts +31 -0
  236. package/build/dex/swaap-v1/libraries/Num.js +167 -0
  237. package/build/dex/swaap-v1/libraries/Num.js.map +1 -0
  238. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +23 -0
  239. package/build/dex/swaap-v1/libraries/PoolQuotations.js +131 -0
  240. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +1 -0
  241. package/build/dex/swaap-v1/libraries/Struct.d.ts +56 -0
  242. package/build/dex/swaap-v1/libraries/Struct.js +3 -0
  243. package/build/dex/swaap-v1/libraries/Struct.js.map +1 -0
  244. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +45 -0
  245. package/build/dex/swaap-v1/swaap-v1-pool.js +656 -0
  246. package/build/dex/swaap-v1/swaap-v1-pool.js.map +1 -0
  247. package/build/dex/swaap-v1/swaap-v1.d.ts +61 -0
  248. package/build/dex/swaap-v1/swaap-v1.js +369 -0
  249. package/build/dex/swaap-v1/swaap-v1.js.map +1 -0
  250. package/build/dex/swaap-v1/types.d.ts +106 -0
  251. package/build/dex/swaap-v1/types.js +9 -0
  252. package/build/dex/swaap-v1/types.js.map +1 -0
  253. package/build/dex/trader-joe-v2.1.d.ts +43 -0
  254. package/build/dex/trader-joe-v2.1.js +79 -0
  255. package/build/dex/trader-joe-v2.1.js.map +1 -0
  256. package/build/executor/Executor01BytecodeBuilder.js +3 -1
  257. package/build/executor/Executor01BytecodeBuilder.js.map +1 -1
  258. package/build/executor/Executor02BytecodeBuilder.js +3 -1
  259. package/build/executor/Executor02BytecodeBuilder.js.map +1 -1
  260. package/build/executor/Executor03BytecodeBuilder.js +2 -0
  261. package/build/executor/Executor03BytecodeBuilder.js.map +1 -1
  262. package/build/executor/ExecutorBytecodeBuilder.js +2 -0
  263. package/build/executor/ExecutorBytecodeBuilder.js.map +1 -1
  264. package/build/executor/compressor/Compressor.d.ts +23 -0
  265. package/build/executor/compressor/Compressor.js +144 -0
  266. package/build/executor/compressor/Compressor.js.map +1 -0
  267. package/build/executor/compressor/compress.d.ts +17 -0
  268. package/build/executor/compressor/compress.js +187 -0
  269. package/build/executor/compressor/compress.js.map +1 -0
  270. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +6 -0
  271. package/build/executor/compressor/compress_functions/addressSubstitution.js +29 -0
  272. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +1 -0
  273. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +10 -0
  274. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +40 -0
  275. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +1 -0
  276. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +11 -0
  277. package/build/executor/compressor/compress_functions/byteSubstitution.js +64 -0
  278. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +1 -0
  279. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +7 -0
  280. package/build/executor/compressor/compress_functions/ffSubstitution.js +54 -0
  281. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +1 -0
  282. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +8 -0
  283. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +67 -0
  284. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +1 -0
  285. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +8 -0
  286. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +61 -0
  287. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +1 -0
  288. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +6 -0
  289. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +37 -0
  290. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +1 -0
  291. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +9 -0
  292. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +33 -0
  293. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +1 -0
  294. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  295. package/build/executor/compressor/fetchSaved.js +17 -0
  296. package/build/executor/compressor/fetchSaved.js.map +1 -0
  297. package/build/executor/compressor/utils/computeCostL2.d.ts +2 -0
  298. package/build/executor/compressor/utils/computeCostL2.js +14 -0
  299. package/build/executor/compressor/utils/computeCostL2.js.map +1 -0
  300. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +2 -0
  301. package/build/executor/compressor/utils/findLongestDuplicatedString.js +30 -0
  302. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +1 -0
  303. package/build/executor/compressor/utils/getAllIndexes.d.ts +2 -0
  304. package/build/executor/compressor/utils/getAllIndexes.js +12 -0
  305. package/build/executor/compressor/utils/getAllIndexes.js.map +1 -0
  306. package/build/executor/compressor/utils/getByteForAddress.d.ts +2 -0
  307. package/build/executor/compressor/utils/getByteForAddress.js +14 -0
  308. package/build/executor/compressor/utils/getByteForAddress.js.map +1 -0
  309. package/build/executor/compressor/utils/intTo2Bytes.d.ts +2 -0
  310. package/build/executor/compressor/utils/intTo2Bytes.js +14 -0
  311. package/build/executor/compressor/utils/intTo2Bytes.js.map +1 -0
  312. package/build/executor/compressor/utils/intTo3Bytes.d.ts +2 -0
  313. package/build/executor/compressor/utils/intTo3Bytes.js +18 -0
  314. package/build/executor/compressor/utils/intTo3Bytes.js.map +1 -0
  315. package/build/executor/compressor/utils/intToByte.d.ts +2 -0
  316. package/build/executor/compressor/utils/intToByte.js +10 -0
  317. package/build/executor/compressor/utils/intToByte.js.map +1 -0
  318. package/build/types.d.ts +1 -0
  319. package/package.json +1 -1
  320. package/src/dex/aave-v3/aave-v3-e2e.test.ts +4 -9
  321. package/src/dex/aave-v3/aave-v3.ts +5 -0
  322. package/src/dex/aave-v3-stata/aave-v3-stata.ts +1 -0
  323. package/src/dex/angle-staked-stable/angle-staked-stable.ts +8 -0
  324. package/src/dex/compound/compound.ts +5 -0
  325. package/src/dex/etherfi.ts +5 -0
  326. package/src/dex/idle-dao/idle-dao.ts +1 -0
  327. package/src/dex/simple-exchange.ts +5 -5
  328. package/src/dex/spark/spark-e2e.test.ts +9 -1
  329. package/src/dex/spark/spark.ts +5 -0
  330. package/src/executor/Executor01BytecodeBuilder.ts +3 -1
  331. package/src/executor/Executor02BytecodeBuilder.ts +3 -1
  332. package/src/executor/Executor03BytecodeBuilder.ts +2 -0
  333. package/src/executor/ExecutorBytecodeBuilder.ts +2 -0
  334. package/src/executor/executor01-bytecode-builder-e2e.test.ts +25 -0
  335. package/src/executor/executor02-bytecode-builder-e2e.test.ts +29 -0
  336. package/src/types.ts +1 -0
  337. package/tests/constants-e2e.ts +13 -13
  338. package/tests/utils-e2e.ts +1 -1
  339. package/.idea/aws.xml +0 -17
  340. package/.idea/codeStyles/Project.xml +0 -19
  341. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  342. package/.idea/misc.xml +0 -6
  343. package/.idea/modules.xml +0 -8
  344. package/.idea/paraswap-dex-lib.iml +0 -9
  345. package/.idea/prettier.xml +0 -7
  346. package/.idea/vcs.xml +0 -6
@@ -0,0 +1,8 @@
1
+ import { Address, Token } from '../../types';
2
+ import { IDexHelper } from '../../dex-helper/idex-helper';
3
+ import { PlatypusPurePoolState, PlatypusPurePoolConfigInfo } from './types';
4
+ import { PlatypusPoolBase } from './pool-base';
5
+ export declare class PlatypusPurePool extends PlatypusPoolBase<PlatypusPurePoolState> {
6
+ constructor(dexKey: string, network: number, name: string, poolAddress: Address, poolCfg: PlatypusPurePoolConfigInfo, dexHelper: IDexHelper);
7
+ computePrices(srcToken: Token, destToken: Token, amounts: bigint[], state: PlatypusPurePoolState): bigint[];
8
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatypusPurePool = void 0;
4
+ const lens_1 = require("../../lens");
5
+ const asset_1 = require("./asset");
6
+ const pool_subscriber_1 = require("./pool-subscriber");
7
+ const utils_1 = require("../../utils");
8
+ const pool_base_1 = require("./pool-base");
9
+ class PlatypusPurePool extends pool_base_1.PlatypusPoolBase {
10
+ constructor(dexKey, network, name, poolAddress, poolCfg, dexHelper) {
11
+ super(dexKey, network, name, dexHelper, [
12
+ new pool_subscriber_1.PlatypusPoolSubscriber(poolAddress, (0, lens_1.lens)().params, dexHelper.getLogger(`${dexKey}-${network} Params ${name}`)),
13
+ ...Object.entries(poolCfg.tokens).map(([tokenAddress, c]) => new asset_1.PlatypusAssetSubscriber(c.assetAddress, (0, lens_1.lens)().asset[tokenAddress], dexHelper.getLogger(`${dexKey}-${network} ${c.tokenSymbol} asset ${name}`))),
14
+ ], {
15
+ params: {
16
+ paused: false,
17
+ slippageParamK: 0n,
18
+ slippageParamN: 0n,
19
+ c1: 0n,
20
+ xThreshold: 0n,
21
+ haircutRate: 0n,
22
+ retentionRatio: 0n,
23
+ maxPriceDeviation: 0n,
24
+ },
25
+ asset: {},
26
+ });
27
+ }
28
+ computePrices(srcToken, destToken, amounts, state) {
29
+ return amounts.map(fromAmount => {
30
+ const idealToAmount = (fromAmount * (0, utils_1.getBigIntPow)(destToken.decimals)) /
31
+ (0, utils_1.getBigIntPow)(srcToken.decimals);
32
+ return (0, pool_base_1.calcPrice)(srcToken, destToken, fromAmount, idealToAmount, state);
33
+ });
34
+ }
35
+ }
36
+ exports.PlatypusPurePool = PlatypusPurePool;
37
+ //# sourceMappingURL=pool-pure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool-pure.js","sourceRoot":"","sources":["../../../src/dex/platypus/pool-pure.ts"],"names":[],"mappings":";;;AAEA,qCAAkC;AAClC,mCAAkD;AAClD,uDAA2D;AAG3D,uCAA2C;AAC3C,2CAA0D;AAE1D,MAAa,gBAAiB,SAAQ,4BAAuC;IAC3E,YACE,MAAc,EACd,OAAe,EACf,IAAY,EACZ,WAAoB,EACpB,OAAmC,EACnC,SAAqB;QAErB,KAAK,CACH,MAAM,EACN,OAAO,EACP,IAAI,EACJ,SAAS,EACT;YACE,IAAI,wCAAsB,CACxB,WAAW,EACX,IAAA,WAAI,GAAuC,CAAC,MAAM,EAClD,SAAS,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,OAAO,WAAW,IAAI,EAAE,CAAC,CAC3D;YACD,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CACnC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE,CACpB,IAAI,+BAAuB,CACzB,CAAC,CAAC,YAAY,EACd,IAAA,WAAI,GAAuC,CAAC,KAAK,CAAC,YAAY,CAAC,EAC/D,SAAS,CAAC,SAAS,CACjB,GAAG,MAAM,IAAI,OAAO,IAAI,CAAC,CAAC,WAAW,UAAU,IAAI,EAAE,CACtD,CACF,CACJ;SACF,EACD;YACE,MAAM,EAAE;gBACN,MAAM,EAAE,KAAK;gBACb,cAAc,EAAE,EAAE;gBAClB,cAAc,EAAE,EAAE;gBAClB,EAAE,EAAE,EAAE;gBACN,UAAU,EAAE,EAAE;gBACd,WAAW,EAAE,EAAE;gBACf,cAAc,EAAE,EAAE;gBAClB,iBAAiB,EAAE,EAAE;aACtB;YACD,KAAK,EAAE,EAAE;SACV,CACF,CAAC;IACJ,CAAC;IAEM,aAAa,CAClB,QAAe,EACf,SAAgB,EAChB,OAAiB,EACjB,KAA4B;QAE5B,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YAC9B,MAAM,aAAa,GACjB,CAAC,UAAU,GAAG,IAAA,oBAAY,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC/C,IAAA,oBAAY,EAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,IAAA,qBAAS,EAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5DD,4CA4DC"}
@@ -0,0 +1,14 @@
1
+ import { DeepReadonly } from 'ts-essentials';
2
+ import { PartialEventSubscriber } from '../../composed-event-subscriber';
3
+ import { Address, BlockHeader, Log, Logger, MultiCallInput, MultiCallOutput } from '../../types';
4
+ import { Lens } from '../../lens';
5
+ import { Interface } from '@ethersproject/abi';
6
+ import { PlatypusPoolParams } from './types';
7
+ export declare class PlatypusPoolSubscriber<State> extends PartialEventSubscriber<State, PlatypusPoolParams> {
8
+ private pool;
9
+ static readonly poolInterface: Interface;
10
+ constructor(pool: Address, lens: Lens<DeepReadonly<State>, DeepReadonly<PlatypusPoolParams>>, logger: Logger);
11
+ processLog(state: DeepReadonly<PlatypusPoolParams>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): DeepReadonly<PlatypusPoolParams> | null;
12
+ getGenerateStateMultiCallInputs(): MultiCallInput[];
13
+ generateState(multicallOutputs: MultiCallOutput[], blockNumber?: number | 'latest'): DeepReadonly<PlatypusPoolParams>;
14
+ }
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PlatypusPoolSubscriber = void 0;
7
+ const composed_event_subscriber_1 = require("../../composed-event-subscriber");
8
+ const abi_1 = require("@ethersproject/abi");
9
+ const pool_json_1 = __importDefault(require("../../abi/platypus/pool.json"));
10
+ class PlatypusPoolSubscriber extends composed_event_subscriber_1.PartialEventSubscriber {
11
+ constructor(pool, lens, logger) {
12
+ super([pool], lens, logger);
13
+ this.pool = pool;
14
+ }
15
+ processLog(state, log, blockHeader) {
16
+ try {
17
+ const parsed = PlatypusPoolSubscriber.poolInterface.parseLog(log);
18
+ switch (parsed.name) {
19
+ case 'Paused': {
20
+ return {
21
+ ...state,
22
+ paused: true,
23
+ };
24
+ }
25
+ case 'Unpaused': {
26
+ return {
27
+ ...state,
28
+ paused: false,
29
+ };
30
+ }
31
+ case 'PriceDeviationUpdated': {
32
+ const previousPriceDeviation = BigInt(parsed.args.previousPriceDeviation.toString());
33
+ const newPriceDeviation = BigInt(parsed.args.newPriceDeviation.toString());
34
+ if (state.maxPriceDeviation !== previousPriceDeviation) {
35
+ this.logger.error('state.maxPriceDeviation !== previousPriceDeviation');
36
+ }
37
+ return {
38
+ ...state,
39
+ maxPriceDeviation: newPriceDeviation,
40
+ };
41
+ }
42
+ case 'SlippageParamsUpdated': {
43
+ const previousK = BigInt(parsed.args.previousK.toString());
44
+ const newK = BigInt(parsed.args.newK.toString());
45
+ const previousN = BigInt(parsed.args.previousN.toString());
46
+ const newN = BigInt(parsed.args.newN.toString());
47
+ const previousC1 = BigInt(parsed.args.previousC1.toString());
48
+ const newC1 = BigInt(parsed.args.newC1.toString());
49
+ const previousXThreshold = BigInt(parsed.args.previousXThreshold.toString());
50
+ const newXThreshold = BigInt(parsed.args.newXThreshold.toString());
51
+ if (state.slippageParamK !== previousK) {
52
+ this.logger.error('state.slippageParamK !== previousK');
53
+ }
54
+ if (state.slippageParamN !== previousN) {
55
+ this.logger.error('state.slippageParamN !== previousN');
56
+ }
57
+ if (state.c1 !== previousC1) {
58
+ this.logger.error('state.c1 !== previousC1');
59
+ }
60
+ if (state.xThreshold !== previousXThreshold) {
61
+ this.logger.error('state.xThreshold !== previousXThreshold');
62
+ }
63
+ return {
64
+ ...state,
65
+ slippageParamK: newK,
66
+ slippageParamN: newN,
67
+ c1: newC1,
68
+ xThreshold: newXThreshold,
69
+ };
70
+ }
71
+ case 'HaircutRateUpdated': {
72
+ const previousHaircut = BigInt(parsed.args.previousHaircut.toString());
73
+ const newHaircut = BigInt(parsed.args.newHaircut.toString());
74
+ if (state.haircutRate !== previousHaircut) {
75
+ this.logger.error('state.haircutRate !== previousHaircut');
76
+ }
77
+ return {
78
+ ...state,
79
+ haircutRate: newHaircut,
80
+ };
81
+ }
82
+ case 'RetentionRatioUpdated': {
83
+ const previousRetentionRatio = BigInt(parsed.args.previousRetentionRatio.toString());
84
+ const newRetentionRatio = BigInt(parsed.args.newRetentionRatio.toString());
85
+ if (state.retentionRatio !== previousRetentionRatio) {
86
+ this.logger.error('state.retentionRatio !== previousRetentionRatio');
87
+ }
88
+ return {
89
+ ...state,
90
+ retentionRatio: newRetentionRatio,
91
+ };
92
+ }
93
+ default:
94
+ return null;
95
+ }
96
+ }
97
+ catch (e) {
98
+ this.logger.error('Failed to parse log', e);
99
+ return null;
100
+ }
101
+ }
102
+ getGenerateStateMultiCallInputs() {
103
+ return [
104
+ {
105
+ target: this.pool,
106
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('paused'),
107
+ },
108
+ {
109
+ target: this.pool,
110
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getSlippageParamK'),
111
+ },
112
+ {
113
+ target: this.pool,
114
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getSlippageParamN'),
115
+ },
116
+ {
117
+ target: this.pool,
118
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getC1'),
119
+ },
120
+ {
121
+ target: this.pool,
122
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getXThreshold'),
123
+ },
124
+ {
125
+ target: this.pool,
126
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getHaircutRate'),
127
+ },
128
+ {
129
+ target: this.pool,
130
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getRetentionRatio'),
131
+ },
132
+ {
133
+ target: this.pool,
134
+ callData: PlatypusPoolSubscriber.poolInterface.encodeFunctionData('getMaxPriceDeviation'),
135
+ },
136
+ ];
137
+ }
138
+ generateState(multicallOutputs, blockNumber) {
139
+ return {
140
+ paused: PlatypusPoolSubscriber.poolInterface.decodeFunctionResult('paused', multicallOutputs[0])[0],
141
+ slippageParamK: BigInt(PlatypusPoolSubscriber.poolInterface
142
+ .decodeFunctionResult('getSlippageParamK', multicallOutputs[1])[0]
143
+ .toString()),
144
+ slippageParamN: BigInt(PlatypusPoolSubscriber.poolInterface
145
+ .decodeFunctionResult('getSlippageParamN', multicallOutputs[2])[0]
146
+ .toString()),
147
+ c1: BigInt(PlatypusPoolSubscriber.poolInterface
148
+ .decodeFunctionResult('getC1', multicallOutputs[3])[0]
149
+ .toString()),
150
+ xThreshold: BigInt(PlatypusPoolSubscriber.poolInterface
151
+ .decodeFunctionResult('getXThreshold', multicallOutputs[4])[0]
152
+ .toString()),
153
+ haircutRate: BigInt(PlatypusPoolSubscriber.poolInterface
154
+ .decodeFunctionResult('getHaircutRate', multicallOutputs[5])[0]
155
+ .toString()),
156
+ retentionRatio: BigInt(PlatypusPoolSubscriber.poolInterface
157
+ .decodeFunctionResult('getRetentionRatio', multicallOutputs[6])[0]
158
+ .toString()),
159
+ maxPriceDeviation: BigInt(PlatypusPoolSubscriber.poolInterface
160
+ .decodeFunctionResult('getMaxPriceDeviation', multicallOutputs[7])[0]
161
+ .toString()),
162
+ };
163
+ }
164
+ }
165
+ exports.PlatypusPoolSubscriber = PlatypusPoolSubscriber;
166
+ PlatypusPoolSubscriber.poolInterface = new abi_1.Interface(pool_json_1.default);
167
+ //# sourceMappingURL=pool-subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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 import { PlatypusPoolState, PlatypusPoolConfigInfo } from './types';
4
+ import { PlatypusPoolBase } from './pool-base';
5
+ export declare class PlatypusPool extends PlatypusPoolBase<PlatypusPoolState> {
6
+ constructor(dexKey: string, network: number, name: string, poolAddress: Address, poolCfg: PlatypusPoolConfigInfo, dexHelper: IDexHelper);
7
+ computePrices(srcToken: Token, destToken: Token, amounts: bigint[], state: PlatypusPoolState): bigint[];
8
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatypusPool = void 0;
4
+ const lens_1 = require("../../lens");
5
+ const chainlink_1 = require("../../lib/chainlink");
6
+ const asset_1 = require("./asset");
7
+ const pool_subscriber_1 = require("./pool-subscriber");
8
+ const utils_1 = require("../../utils");
9
+ const pool_base_1 = require("./pool-base");
10
+ class PlatypusPool extends pool_base_1.PlatypusPoolBase {
11
+ constructor(dexKey, network, name, poolAddress, poolCfg, dexHelper) {
12
+ super(dexKey, network, name, dexHelper, [
13
+ new pool_subscriber_1.PlatypusPoolSubscriber(poolAddress, (0, lens_1.lens)().params, dexHelper.getLogger(`${dexKey}-${network} Params ${name}`)),
14
+ ...Object.entries(poolCfg.tokens)
15
+ .map(([tokenAddress, c]) => [
16
+ new asset_1.PlatypusAssetSubscriber(c.assetAddress, (0, lens_1.lens)().asset[tokenAddress], dexHelper.getLogger(`${dexKey}-${network} ${c.tokenSymbol} asset ${name}`)),
17
+ new chainlink_1.ChainLinkSubscriber(c.chainlink.proxyAddress, c.chainlink.aggregatorAddress, (0, lens_1.lens)().chainlink[tokenAddress], dexHelper.getLogger(`${c.tokenSymbol} ChainLink for ${dexKey}-${network} ${name}`)),
18
+ ])
19
+ .flat(),
20
+ ], {
21
+ params: {
22
+ paused: false,
23
+ slippageParamK: 0n,
24
+ slippageParamN: 0n,
25
+ c1: 0n,
26
+ xThreshold: 0n,
27
+ haircutRate: 0n,
28
+ retentionRatio: 0n,
29
+ maxPriceDeviation: 0n,
30
+ },
31
+ asset: {},
32
+ chainlink: {},
33
+ });
34
+ }
35
+ computePrices(srcToken, destToken, amounts, state) {
36
+ const tokenAPrice = state.chainlink[srcToken.address].answer;
37
+ const tokenBPrice = state.chainlink[destToken.address].answer;
38
+ if (tokenBPrice > tokenAPrice) {
39
+ if (((tokenBPrice - tokenAPrice) * pool_base_1.ETH_UNIT) / tokenBPrice >
40
+ state.params.maxPriceDeviation) {
41
+ return Array(amounts.length).fill(0n);
42
+ }
43
+ }
44
+ else {
45
+ if (((tokenAPrice - tokenBPrice) * pool_base_1.ETH_UNIT) / tokenAPrice >
46
+ state.params.maxPriceDeviation) {
47
+ return Array(amounts.length).fill(0n);
48
+ }
49
+ }
50
+ return amounts.map(fromAmount => {
51
+ const idealToAmount = (fromAmount * (0, utils_1.getBigIntPow)(destToken.decimals)) /
52
+ (0, utils_1.getBigIntPow)(srcToken.decimals);
53
+ return (0, pool_base_1.calcPrice)(srcToken, destToken, fromAmount, idealToAmount, state);
54
+ });
55
+ }
56
+ }
57
+ exports.PlatypusPool = PlatypusPool;
58
+ //# sourceMappingURL=pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/dex/platypus/pool.ts"],"names":[],"mappings":";;;AAEA,qCAAkC;AAClC,mDAA0D;AAC1D,mCAAkD;AAClD,uDAA2D;AAG3D,uCAA2C;AAC3C,2CAAoE;AAEpE,MAAa,YAAa,SAAQ,4BAAmC;IACnE,YACE,MAAc,EACd,OAAe,EACf,IAAY,EACZ,WAAoB,EACpB,OAA+B,EAC/B,SAAqB;QAErB,KAAK,CACH,MAAM,EACN,OAAO,EACP,IAAI,EACJ,SAAS,EACT;YACE,IAAI,wCAAsB,CACxB,WAAW,EACX,IAAA,WAAI,GAAmC,CAAC,MAAM,EAC9C,SAAS,CAAC,SAAS,CAAC,GAAG,MAAM,IAAI,OAAO,WAAW,IAAI,EAAE,CAAC,CAC3D;YACD,GAAG,MAAM,CAAC,OAAO,CAA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CAAC,GAAG,oBAAQ,CAAC,GAAG,WAAW;gBACtD,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAC9B;gBACA,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACvC;SACF;aAAM;YACL,IACE,CAAC,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,oBAAQ,CAAC,GAAG,WAAW;gBACtD,KAAK,CAAC,MAAM,CAAC,iBAAiB,EAC9B;gBACA,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACvC;SACF;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YAC9B,MAAM,aAAa,GACjB,CAAC,UAAU,GAAG,IAAA,oBAAY,EAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAC/C,IAAA,oBAAY,EAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClC,OAAO,IAAA,qBAAS,EAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAvFD,oCAuFC"}
@@ -0,0 +1,92 @@
1
+ import { Address } from '../../types';
2
+ import { ChainLinkState } from '../../lib/chainlink';
3
+ import { StakedAvaxState } from '../../lib/benqi/staked-avax';
4
+ export declare enum PlatypusOracleType {
5
+ None = "None",
6
+ ChainLink = "ChainLink",
7
+ StakedAvax = "StakedAvax"
8
+ }
9
+ export declare type PlatypusPoolStateCommon = {
10
+ params: PlatypusPoolParams;
11
+ asset: {
12
+ [underlyingAddress: string]: PlatypusAssetState;
13
+ };
14
+ };
15
+ export declare type PlatypusPoolState = PlatypusPoolStateCommon & {
16
+ chainlink: {
17
+ [underlyingAddress: string]: ChainLinkState;
18
+ };
19
+ };
20
+ export declare type PlatypusPurePoolState = PlatypusPoolStateCommon;
21
+ export declare type PlatypusAvaxPoolState = PlatypusPoolStateCommon & {
22
+ stakedAvax: StakedAvaxState;
23
+ };
24
+ export declare type PlatypusPoolParams = {
25
+ paused: boolean;
26
+ slippageParamK: bigint;
27
+ slippageParamN: bigint;
28
+ c1: bigint;
29
+ xThreshold: bigint;
30
+ haircutRate: bigint;
31
+ retentionRatio: bigint;
32
+ maxPriceDeviation: bigint;
33
+ };
34
+ export declare type PlatypusAssetState = {
35
+ cash: bigint;
36
+ liability: bigint;
37
+ };
38
+ export declare type PlatypusConfigInfo = {
39
+ poolAddresses: Address[];
40
+ pools: {
41
+ [poolAddress: string]: PlatypusPoolConfigInfo | PlatypusPurePoolConfigInfo | PlatypusAvaxPoolConfigInfo;
42
+ };
43
+ };
44
+ export declare type PlatypusPoolConfigInfo = {
45
+ oracleType: PlatypusOracleType.ChainLink;
46
+ priceOracleAddress: Address;
47
+ tokenAddresses: Address[];
48
+ tokens: {
49
+ [tokenAddress: string]: {
50
+ tokenSymbol: string;
51
+ tokenDecimals: number;
52
+ assetAddress: Address;
53
+ chainlink: {
54
+ proxyAddress: Address;
55
+ aggregatorAddress: Address;
56
+ };
57
+ };
58
+ };
59
+ };
60
+ export declare type PlatypusPurePoolConfigInfo = {
61
+ oracleType: PlatypusOracleType.None;
62
+ tokenAddresses: Address[];
63
+ tokens: {
64
+ [tokenAddress: string]: {
65
+ tokenSymbol: string;
66
+ tokenDecimals: number;
67
+ assetAddress: Address;
68
+ };
69
+ };
70
+ };
71
+ export declare type PlatypusAvaxPoolConfigInfo = {
72
+ oracleType: PlatypusOracleType.StakedAvax;
73
+ priceOracleAddress: Address;
74
+ tokenAddresses: Address[];
75
+ tokens: {
76
+ [tokenAddress: string]: {
77
+ tokenSymbol: string;
78
+ tokenDecimals: number;
79
+ assetAddress: Address;
80
+ };
81
+ };
82
+ };
83
+ export declare type PlatypusData = {
84
+ pool: Address;
85
+ };
86
+ export declare type DexParams = {
87
+ pools: {
88
+ address: Address;
89
+ name: string;
90
+ oracleType: PlatypusOracleType;
91
+ }[];
92
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatypusOracleType = void 0;
4
+ var PlatypusOracleType;
5
+ (function (PlatypusOracleType) {
6
+ PlatypusOracleType["None"] = "None";
7
+ PlatypusOracleType["ChainLink"] = "ChainLink";
8
+ PlatypusOracleType["StakedAvax"] = "StakedAvax";
9
+ })(PlatypusOracleType = exports.PlatypusOracleType || (exports.PlatypusOracleType = {}));
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/platypus/types.ts"],"names":[],"mappings":";;;AAIA,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mCAAa,CAAA;IACb,6CAAuB,CAAA;IACvB,+CAAyB,CAAA;AAC3B,CAAC,EAJW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAI7B"}
@@ -0,0 +1,6 @@
1
+ import { IDexHelper } from '../../dex-helper';
2
+ import { QuickSwapV3 } from './quickswap-v3';
3
+ export declare class SpiritSwapV3 extends QuickSwapV3 {
4
+ static dexKeys: string[];
5
+ constructor(dexHelper: IDexHelper);
6
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SpiritSwapV3 = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const config_1 = require("./config");
9
+ const quickswap_v3_1 = require("./quickswap-v3");
10
+ const config = lodash_1.default.pick(config_1.QuickSwapConfig, ['SpiritSwapV3']).SpiritSwapV3;
11
+ class SpiritSwapV3 extends quickswap_v3_1.QuickSwapV3 {
12
+ // public static dexKeysWithNetwork
13
+ constructor(dexHelper) {
14
+ super(dexHelper, 'spiritswapv3', config[dexHelper.config.data.network].router);
15
+ }
16
+ }
17
+ exports.SpiritSwapV3 = SpiritSwapV3;
18
+ SpiritSwapV3.dexKeys = ['spiritswapv3'];
19
+ //# sourceMappingURL=spiritswap-v3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spiritswap-v3.js","sourceRoot":"","sources":["../../../src/dex/quickswap/spiritswap-v3.ts"],"names":[],"mappings":";;;;;;AACA,oDAAuB;AACvB,qCAA2C;AAC3C,iDAA6C;AAE7C,MAAM,MAAM,GAAG,gBAAC,CAAC,IAAI,CAAC,wBAAe,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,YAAY,CAAC;AAEtE,MAAa,YAAa,SAAQ,0BAAW;IAG3C,mCAAmC;IACnC,YAAY,SAAqB;QAC/B,KAAK,CACH,SAAS,EACT,cAAc,EACd,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAC7C,CAAC;IACJ,CAAC;;AAVH,oCAWC;AAVQ,oBAAO,GAAG,CAAC,cAAc,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { SDaiParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ export declare const SDaiConfig: DexConfigMap<SDaiParams>;
4
+ export declare const Adapters: {
5
+ [chainId: number]: {
6
+ [side: string]: {
7
+ name: string;
8
+ index: number;
9
+ }[];
10
+ };
11
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Adapters = exports.SDaiConfig = void 0;
4
+ const constants_1 = require("../../constants");
5
+ const core_1 = require("@paraswap/core");
6
+ exports.SDaiConfig = {
7
+ sdai: {
8
+ [constants_1.Network.MAINNET]: {
9
+ sdaiAddress: '0x83F20F44975D03b1b09e64809B757c47f942BEeA',
10
+ daiAddress: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
11
+ potAddress: '0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7',
12
+ },
13
+ },
14
+ };
15
+ exports.Adapters = {
16
+ [constants_1.Network.MAINNET]: {
17
+ [core_1.SwapSide.SELL]: [{ name: 'Adapter06', index: 1 }],
18
+ [core_1.SwapSide.BUY]: [{ name: 'BuyAdapter02', index: 4 }],
19
+ },
20
+ };
21
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/sdai/config.ts"],"names":[],"mappings":";;;AAEA,+CAA0C;AAC1C,yCAA0C;AAE7B,QAAA,UAAU,GAA6B;IAClD,IAAI,EAAE;QACJ,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,UAAU,EAAE,4CAA4C;YACxD,UAAU,EAAE,4CAA4C;SACzD;KACF;CACF,CAAC;AAEW,QAAA,QAAQ,GAIjB;IACF,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;QACjB,CAAC,eAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAClD,CAAC,eAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;KACrD;CACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const SDAI_DEPOSIT_GAS_COST = 165000;
2
+ export declare const SDAI_REDEEM_GAS_COST = 90000;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDAI_REDEEM_GAS_COST = exports.SDAI_DEPOSIT_GAS_COST = void 0;
4
+ exports.SDAI_DEPOSIT_GAS_COST = 165000;
5
+ exports.SDAI_REDEEM_GAS_COST = 90000;
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/dex/sdai/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,MAAO,CAAC;AAChC,QAAA,oBAAoB,GAAG,KAAM,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* eslint-disable no-console */
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ dotenv_1.default.config();
9
+ const constants_1 = require("../../../constants");
10
+ const dex_helper_1 = require("../../../dex-helper");
11
+ const ethers_1 = require("ethers");
12
+ const sdai_1 = require("../sdai");
13
+ const config_1 = require("../config");
14
+ const utils_1 = require("../utils");
15
+ const abi_1 = require("@ethersproject/abi");
16
+ const pot_json_1 = __importDefault(require("../../../abi/maker-psm/pot.json"));
17
+ const network = constants_1.Network.MAINNET;
18
+ const dexKey = 'sdai';
19
+ const { potAddress } = config_1.SDaiConfig[dexKey][network];
20
+ const blockHeaders = {};
21
+ const dexHelper = new dex_helper_1.DummyDexHelper(network);
22
+ const logger = dexHelper.getLogger(dexKey);
23
+ function preprocessField(value) {
24
+ if (typeof value === 'bigint' ||
25
+ typeof value === 'number' ||
26
+ ethers_1.ethers.BigNumber.isBigNumber(value)) {
27
+ return value.toString();
28
+ }
29
+ return value;
30
+ }
31
+ function compareAndLogDifferences(obj1, obj2, keyNames, checkEachKey = false) {
32
+ let isValid = true;
33
+ let keys = keyNames;
34
+ if (checkEachKey) {
35
+ // find common keys
36
+ const keys1 = Object.keys(obj1);
37
+ const keys2 = new Set(Object.keys(obj2));
38
+ keys = keys1.filter(key => keys2.has(key));
39
+ }
40
+ for (let fieldName of keys) {
41
+ const value1 = preprocessField(obj1[fieldName]);
42
+ const value2 = preprocessField(obj2[fieldName]);
43
+ if (value1 !== value2) {
44
+ console.log(`${fieldName.toString()} mismatch: actual: ${value1} vs pool: ${value2}`);
45
+ isValid = false;
46
+ }
47
+ }
48
+ return isValid;
49
+ }
50
+ async function isPoolStateEqualToReal(state, blockNumber) {
51
+ const expected = await (0, utils_1.getOnChainState)(dexHelper.multiContract, potAddress, new abi_1.Interface(pot_json_1.default), blockNumber);
52
+ const isValidState = compareAndLogDifferences(state, expected, [
53
+ 'rho',
54
+ 'dsr',
55
+ 'dsr',
56
+ ]);
57
+ return isValidState;
58
+ }
59
+ async function checkPoolStateForBlockRange(startBlockNumber, endBlockNumber) {
60
+ const network = constants_1.Network.MAINNET;
61
+ const dexKey = 'sdai';
62
+ const dexHelper = new dex_helper_1.DummyDexHelper(network);
63
+ const sdai = new sdai_1.SDai(network, dexKey, dexHelper);
64
+ const pool = await sdai.eventPool;
65
+ const logsToDispatch = await dexHelper.provider.getLogs({
66
+ fromBlock: startBlockNumber,
67
+ toBlock: endBlockNumber,
68
+ address: potAddress,
69
+ });
70
+ console.log(logsToDispatch.length);
71
+ // group logs by block number
72
+ const logsByBlockNumber = {};
73
+ for (let log of logsToDispatch) {
74
+ if (!logsByBlockNumber[log.blockNumber]) {
75
+ logsByBlockNumber[log.blockNumber] = [];
76
+ }
77
+ logsByBlockNumber[log.blockNumber].push(log);
78
+ }
79
+ const sortedBlocks = Object.keys(logsByBlockNumber)
80
+ .map(Number)
81
+ .sort((a, b) => Number(a) - Number(b));
82
+ for (let blockNumber of sortedBlocks) {
83
+ if (!blockHeaders[blockNumber]) {
84
+ blockHeaders[blockNumber] = await dexHelper.web3Provider.eth.getBlock(blockNumber);
85
+ }
86
+ await pool?.update(logsByBlockNumber[blockNumber], {
87
+ [blockNumber]: blockHeaders[blockNumber],
88
+ });
89
+ }
90
+ const state = pool?.getState(startBlockNumber);
91
+ return isPoolStateEqualToReal(state, endBlockNumber);
92
+ }
93
+ async function main() {
94
+ // use findBreakingBlock to find the block where the state is broken
95
+ // console.log(await findBreakingBlock(startBlockNumber, endBlockNumber));
96
+ // previously broken block 150502863
97
+ console.log(await checkPoolStateForBlockRange(19199247 - 10000, 19199247));
98
+ }
99
+ main()
100
+ .then(() => console.log('Done'))
101
+ .catch(e => console.error(e));
102
+ //# sourceMappingURL=validate-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-state.js","sourceRoot":"","sources":["../../../../src/dex/sdai/scripts/validate-state.ts"],"names":[],"mappings":";;;;;AAAA,+BAA+B;AAC/B,oDAA4B;AAC5B,gBAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,kDAA6C;AAC7C,oDAAqD;AAGrD,mCAAgC;AAChC,kCAA+B;AAC/B,sCAAuC;AACvC,oCAA2C;AAC3C,4CAA+C;AAC/C,+EAAqD;AAErD,MAAM,OAAO,GAAG,mBAAO,CAAC,OAAO,CAAC;AAChC,MAAM,MAAM,GAAG,MAAM,CAAC;AAEtB,MAAM,EAAE,UAAU,EAAE,GAAG,mBAAU,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;AACnD,MAAM,YAAY,GAAgC,EAAE,CAAC;AAErD,MAAM,SAAS,GAAG,IAAI,2BAAc,CAAC,OAAO,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAE3C,SAAS,eAAe,CAAC,KAAU;IACjC,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAO,KAAK,KAAK,QAAQ;QACzB,eAAM,CAAC,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EACnC;QACA,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;KACzB;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,wBAAwB,CAC/B,IAAO,EACP,IAAO,EACP,QAAkC,EAClC,YAAY,GAAG,KAAK;IAEpB,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,IAAI,IAAI,GAAG,QAAQ,CAAC;IAEpB,IAAI,YAAY,EAAE;QAChB,mBAAmB;QACnB,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,KAAK,GAAG,I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,sBAAsB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;AACvD,CAAC;AAED,KAAK,UAAU,IAAI;IACjB,oEAAoE;IACpE,0EAA0E;IAC1E,oCAAoC;IACpC,OAAO,CAAC,GAAG,CAAC,MAAM,2BAA2B,CAAC,QAAQ,GAAG,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,IAAI,EAAE;KACH,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC/B,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
2
+ import { Interface } from '@ethersproject/abi';
3
+ import type { IDexHelper } from '../../dex-helper';
4
+ import type { AsyncOrSync, DeepReadonly } from 'ts-essentials';
5
+ import type { Address, BlockHeader, Log, Logger } from '../../types';
6
+ import type { SDaiPoolState } from './types';
7
+ export declare class SDaiEventPool extends StatefulEventSubscriber<SDaiPoolState> {
8
+ protected dexHelper: IDexHelper;
9
+ private potAddress;
10
+ private potInterface;
11
+ constructor(parentName: string, dexHelper: IDexHelper, potAddress: Address, potInterface: Interface, logger: Logger);
12
+ protected processLog(state: DeepReadonly<SDaiPoolState>, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): AsyncOrSync<DeepReadonly<SDaiPoolState> | null>;
13
+ generateState(blockNumber?: number | 'latest'): Promise<DeepReadonly<SDaiPoolState>>;
14
+ convertToSDai(daiAmount: bigint, blockNumber: number): bigint;
15
+ convertToDai(sdaiAmount: bigint, blockNumber: number): bigint;
16
+ }