@paraswap/dex-lib 3.8.26 → 3.8.27-lite-psm-return-amount-pos.0

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 (295) hide show
  1. package/.idea/codeStyles/Project.xml +59 -0
  2. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  3. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/paraswap-dex-lib.iml +12 -0
  6. package/.idea/vcs.xml +6 -0
  7. package/build/dex/lite-psm/lite-psm.js +3 -1
  8. package/build/dex/lite-psm/lite-psm.js.map +1 -1
  9. package/build/dex/zerox/index.d.ts +1 -1
  10. package/build/dex/zerox/index.js.map +1 -1
  11. package/package.json +3 -2
  12. package/src/dex/lite-psm/lite-psm.ts +4 -5
  13. package/.vscode/launch.json +0 -16
  14. package/.vscode/settings.json +0 -3
  15. package/build/abi/AaveV1_lending_pool.json +0 -27
  16. package/build/abi/Uncompressor.json +0 -250
  17. package/build/abi/integral/factory.json +0 -333
  18. package/build/abi/integral/oracle.json +0 -501
  19. package/build/abi/integral/pool.json +0 -1041
  20. package/build/abi/integral/relayer.json +0 -1536
  21. package/build/abi/platypus/asset.json +0 -490
  22. package/build/abi/platypus/avax-pool.json +0 -820
  23. package/build/abi/platypus/oracle.json +0 -119
  24. package/build/abi/platypus/pool.json +0 -677
  25. package/build/abi/smardex/all/smardex-router.json +0 -648
  26. package/build/abi/smardex/layer-1/smardex-factory.json +0 -242
  27. package/build/abi/smardex/layer-1/smardex-pool.json +0 -506
  28. package/build/abi/smardex/layer-2/smardex-factory.json +0 -185
  29. package/build/abi/smardex/layer-2/smardex-pool.json +0 -578
  30. package/build/abi/swaap-v1/pool.json +0 -1346
  31. package/build/dex/aave-v1/aave-v1.d.ts +0 -33
  32. package/build/dex/aave-v1/aave-v1.js +0 -158
  33. package/build/dex/aave-v1/aave-v1.js.map +0 -1
  34. package/build/dex/aave-v1/config.d.ts +0 -11
  35. package/build/dex/aave-v1/config.js +0 -20
  36. package/build/dex/aave-v1/config.js.map +0 -1
  37. package/build/dex/aave-v1/tokens-mainnet.json +0 -134
  38. package/build/dex/aave-v1/tokens.d.ts +0 -3
  39. package/build/dex/aave-v1/tokens.js +0 -50
  40. package/build/dex/aave-v1/tokens.js.map +0 -1
  41. package/build/dex/aave-v1/types.d.ts +0 -12
  42. package/build/dex/aave-v1/types.js +0 -3
  43. package/build/dex/aave-v1/types.js.map +0 -1
  44. package/build/dex/bProtocol.d.ts +0 -18
  45. package/build/dex/bProtocol.js +0 -39
  46. package/build/dex/bProtocol.js.map +0 -1
  47. package/build/dex/bancor.d.ts +0 -26
  48. package/build/dex/bancor.js +0 -58
  49. package/build/dex/bancor.js.map +0 -1
  50. package/build/dex/compound.d.ts +0 -18
  51. package/build/dex/compound.js +0 -46
  52. package/build/dex/compound.js.map +0 -1
  53. package/build/dex/curve-v2.d.ts +0 -58
  54. package/build/dex/curve-v2.js +0 -180
  55. package/build/dex/curve-v2.js.map +0 -1
  56. package/build/dex/dodo-v1.d.ts +0 -33
  57. package/build/dex/dodo-v1.js +0 -63
  58. package/build/dex/dodo-v1.js.map +0 -1
  59. package/build/dex/etherfi/etherfi.d.ts +0 -26
  60. package/build/dex/etherfi/etherfi.js +0 -96
  61. package/build/dex/etherfi/etherfi.js.map +0 -1
  62. package/build/dex/integral/config.d.ts +0 -4
  63. package/build/dex/integral/config.js +0 -20
  64. package/build/dex/integral/config.js.map +0 -1
  65. package/build/dex/integral/context.d.ts +0 -40
  66. package/build/dex/integral/context.js +0 -158
  67. package/build/dex/integral/context.js.map +0 -1
  68. package/build/dex/integral/helpers.d.ts +0 -17
  69. package/build/dex/integral/helpers.js +0 -157
  70. package/build/dex/integral/helpers.js.map +0 -1
  71. package/build/dex/integral/integral-factory.d.ts +0 -24
  72. package/build/dex/integral/integral-factory.js +0 -95
  73. package/build/dex/integral/integral-factory.js.map +0 -1
  74. package/build/dex/integral/integral-pool.d.ts +0 -50
  75. package/build/dex/integral/integral-pool.js +0 -149
  76. package/build/dex/integral/integral-pool.js.map +0 -1
  77. package/build/dex/integral/integral-pricing.d.ts +0 -18
  78. package/build/dex/integral/integral-pricing.js +0 -114
  79. package/build/dex/integral/integral-pricing.js.map +0 -1
  80. package/build/dex/integral/integral-relayer.d.ts +0 -42
  81. package/build/dex/integral/integral-relayer.js +0 -192
  82. package/build/dex/integral/integral-relayer.js.map +0 -1
  83. package/build/dex/integral/integral-token.d.ts +0 -27
  84. package/build/dex/integral/integral-token.js +0 -59
  85. package/build/dex/integral/integral-token.js.map +0 -1
  86. package/build/dex/integral/integral.d.ts +0 -41
  87. package/build/dex/integral/integral.js +0 -376
  88. package/build/dex/integral/integral.js.map +0 -1
  89. package/build/dex/integral/types.d.ts +0 -85
  90. package/build/dex/integral/types.js +0 -9
  91. package/build/dex/integral/types.js.map +0 -1
  92. package/build/dex/integral/utils-e2e.d.ts +0 -9
  93. package/build/dex/integral/utils-e2e.js +0 -131
  94. package/build/dex/integral/utils-e2e.js.map +0 -1
  95. package/build/dex/integral/utils.d.ts +0 -17
  96. package/build/dex/integral/utils.js +0 -94
  97. package/build/dex/integral/utils.js.map +0 -1
  98. package/build/dex/lido.d.ts +0 -19
  99. package/build/dex/lido.js +0 -42
  100. package/build/dex/lido.js.map +0 -1
  101. package/build/dex/onebit.d.ts +0 -25
  102. package/build/dex/onebit.js +0 -42
  103. package/build/dex/onebit.js.map +0 -1
  104. package/build/dex/platypus/asset.d.ts +0 -14
  105. package/build/dex/platypus/asset.js +0 -97
  106. package/build/dex/platypus/asset.js.map +0 -1
  107. package/build/dex/platypus/config.d.ts +0 -11
  108. package/build/dex/platypus/config.js +0 -69
  109. package/build/dex/platypus/config.js.map +0 -1
  110. package/build/dex/platypus/platypus.d.ts +0 -62
  111. package/build/dex/platypus/platypus.js +0 -442
  112. package/build/dex/platypus/platypus.js.map +0 -1
  113. package/build/dex/platypus/pool-avax.d.ts +0 -8
  114. package/build/dex/platypus/pool-avax.js +0 -54
  115. package/build/dex/platypus/pool-avax.js.map +0 -1
  116. package/build/dex/platypus/pool-base.d.ts +0 -19
  117. package/build/dex/platypus/pool-base.js +0 -86
  118. package/build/dex/platypus/pool-base.js.map +0 -1
  119. package/build/dex/platypus/pool-pure.d.ts +0 -8
  120. package/build/dex/platypus/pool-pure.js +0 -37
  121. package/build/dex/platypus/pool-pure.js.map +0 -1
  122. package/build/dex/platypus/pool-subscriber.d.ts +0 -14
  123. package/build/dex/platypus/pool-subscriber.js +0 -167
  124. package/build/dex/platypus/pool-subscriber.js.map +0 -1
  125. package/build/dex/platypus/pool.d.ts +0 -8
  126. package/build/dex/platypus/pool.js +0 -58
  127. package/build/dex/platypus/pool.js.map +0 -1
  128. package/build/dex/platypus/types.d.ts +0 -92
  129. package/build/dex/platypus/types.js +0 -10
  130. package/build/dex/platypus/types.js.map +0 -1
  131. package/build/dex/quickswap/spiritswap-v3.d.ts +0 -6
  132. package/build/dex/quickswap/spiritswap-v3.js +0 -19
  133. package/build/dex/quickswap/spiritswap-v3.js.map +0 -1
  134. package/build/dex/sdai/config.d.ts +0 -11
  135. package/build/dex/sdai/config.js +0 -21
  136. package/build/dex/sdai/config.js.map +0 -1
  137. package/build/dex/sdai/constants.d.ts +0 -2
  138. package/build/dex/sdai/constants.js +0 -6
  139. package/build/dex/sdai/constants.js.map +0 -1
  140. package/build/dex/sdai/scripts/validate-state.d.ts +0 -1
  141. package/build/dex/sdai/scripts/validate-state.js +0 -102
  142. package/build/dex/sdai/scripts/validate-state.js.map +0 -1
  143. package/build/dex/sdai/sdai-pool.d.ts +0 -16
  144. package/build/dex/sdai/sdai-pool.js +0 -85
  145. package/build/dex/sdai/sdai-pool.js.map +0 -1
  146. package/build/dex/sdai/sdai.d.ts +0 -51
  147. package/build/dex/sdai/sdai.js +0 -172
  148. package/build/dex/sdai/sdai.js.map +0 -1
  149. package/build/dex/sdai/types.d.ts +0 -21
  150. package/build/dex/sdai/types.js +0 -11
  151. package/build/dex/sdai/types.js.map +0 -1
  152. package/build/dex/sdai/utils.d.ts +0 -4
  153. package/build/dex/sdai/utils.js +0 -39
  154. package/build/dex/sdai/utils.js.map +0 -1
  155. package/build/dex/smardex/config.d.ts +0 -4
  156. package/build/dex/smardex/config.js +0 -64
  157. package/build/dex/smardex/config.js.map +0 -1
  158. package/build/dex/smardex/constants.d.ts +0 -18
  159. package/build/dex/smardex/constants.js +0 -33
  160. package/build/dex/smardex/constants.js.map +0 -1
  161. package/build/dex/smardex/sdk/constants.d.ts +0 -6
  162. package/build/dex/smardex/sdk/constants.js +0 -13
  163. package/build/dex/smardex/sdk/constants.js.map +0 -1
  164. package/build/dex/smardex/sdk/core.d.ts +0 -113
  165. package/build/dex/smardex/sdk/core.js +0 -499
  166. package/build/dex/smardex/sdk/core.js.map +0 -1
  167. package/build/dex/smardex/sdk/errors.d.ts +0 -15
  168. package/build/dex/smardex/sdk/errors.js +0 -22
  169. package/build/dex/smardex/sdk/errors.js.map +0 -1
  170. package/build/dex/smardex/sdk/types.d.ts +0 -62
  171. package/build/dex/smardex/sdk/types.js +0 -3
  172. package/build/dex/smardex/sdk/types.js.map +0 -1
  173. package/build/dex/smardex/sdk/utils.d.ts +0 -44
  174. package/build/dex/smardex/sdk/utils.js +0 -133
  175. package/build/dex/smardex/sdk/utils.js.map +0 -1
  176. package/build/dex/smardex/smardex-event-pool.d.ts +0 -28
  177. package/build/dex/smardex/smardex-event-pool.js +0 -119
  178. package/build/dex/smardex/smardex-event-pool.js.map +0 -1
  179. package/build/dex/smardex/smardex.d.ts +0 -65
  180. package/build/dex/smardex/smardex.js +0 -519
  181. package/build/dex/smardex/smardex.js.map +0 -1
  182. package/build/dex/smardex/types.d.ts +0 -55
  183. package/build/dex/smardex/types.js +0 -3
  184. package/build/dex/smardex/types.js.map +0 -1
  185. package/build/dex/smoothy.d.ts +0 -26
  186. package/build/dex/smoothy.js +0 -48
  187. package/build/dex/smoothy.js.map +0 -1
  188. package/build/dex/solidly/forks-override/cone.d.ts +0 -22
  189. package/build/dex/solidly/forks-override/cone.js +0 -53
  190. package/build/dex/solidly/forks-override/cone.js.map +0 -1
  191. package/build/dex/solidly/forks-override/solisnek.d.ts +0 -8
  192. package/build/dex/solidly/forks-override/solisnek.js +0 -15
  193. package/build/dex/solidly/forks-override/solisnek.js.map +0 -1
  194. package/build/dex/stable-pool.d.ts +0 -28
  195. package/build/dex/stable-pool.js +0 -62
  196. package/build/dex/stable-pool.js.map +0 -1
  197. package/build/dex/swaap-v1/config.d.ts +0 -17
  198. package/build/dex/swaap-v1/config.js +0 -56
  199. package/build/dex/swaap-v1/config.js.map +0 -1
  200. package/build/dex/swaap-v1/constants.d.ts +0 -6
  201. package/build/dex/swaap-v1/constants.js +0 -17
  202. package/build/dex/swaap-v1/constants.js.map +0 -1
  203. package/build/dex/swaap-v1/libraries/ChainlinkUtils.d.ts +0 -25
  204. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js +0 -62
  205. package/build/dex/swaap-v1/libraries/ChainlinkUtils.js.map +0 -1
  206. package/build/dex/swaap-v1/libraries/Const.d.ts +0 -18
  207. package/build/dex/swaap-v1/libraries/Const.js +0 -26
  208. package/build/dex/swaap-v1/libraries/Const.js.map +0 -1
  209. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.d.ts +0 -77
  210. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js +0 -316
  211. package/build/dex/swaap-v1/libraries/GeometricBrownianMotion.js.map +0 -1
  212. package/build/dex/swaap-v1/libraries/LogExpMath.d.ts +0 -75
  213. package/build/dex/swaap-v1/libraries/LogExpMath.js +0 -418
  214. package/build/dex/swaap-v1/libraries/LogExpMath.js.map +0 -1
  215. package/build/dex/swaap-v1/libraries/MathMMM.d.ts +0 -185
  216. package/build/dex/swaap-v1/libraries/MathMMM.js +0 -453
  217. package/build/dex/swaap-v1/libraries/MathMMM.js.map +0 -1
  218. package/build/dex/swaap-v1/libraries/Num.d.ts +0 -31
  219. package/build/dex/swaap-v1/libraries/Num.js +0 -167
  220. package/build/dex/swaap-v1/libraries/Num.js.map +0 -1
  221. package/build/dex/swaap-v1/libraries/PoolQuotations.d.ts +0 -23
  222. package/build/dex/swaap-v1/libraries/PoolQuotations.js +0 -131
  223. package/build/dex/swaap-v1/libraries/PoolQuotations.js.map +0 -1
  224. package/build/dex/swaap-v1/libraries/Struct.d.ts +0 -56
  225. package/build/dex/swaap-v1/libraries/Struct.js +0 -3
  226. package/build/dex/swaap-v1/libraries/Struct.js.map +0 -1
  227. package/build/dex/swaap-v1/swaap-v1-pool.d.ts +0 -45
  228. package/build/dex/swaap-v1/swaap-v1-pool.js +0 -656
  229. package/build/dex/swaap-v1/swaap-v1-pool.js.map +0 -1
  230. package/build/dex/swaap-v1/swaap-v1.d.ts +0 -61
  231. package/build/dex/swaap-v1/swaap-v1.js +0 -369
  232. package/build/dex/swaap-v1/swaap-v1.js.map +0 -1
  233. package/build/dex/swaap-v1/types.d.ts +0 -106
  234. package/build/dex/swaap-v1/types.js +0 -9
  235. package/build/dex/swaap-v1/types.js.map +0 -1
  236. package/build/dex/trader-joe-v2.1/optimizer.d.ts +0 -2
  237. package/build/dex/trader-joe-v2.1/optimizer.js +0 -44
  238. package/build/dex/trader-joe-v2.1/optimizer.js.map +0 -1
  239. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  240. package/build/dex/trader-joe-v2.1.js +0 -79
  241. package/build/dex/trader-joe-v2.1.js.map +0 -1
  242. package/build/executor/compressor/Compressor.d.ts +0 -23
  243. package/build/executor/compressor/Compressor.js +0 -144
  244. package/build/executor/compressor/Compressor.js.map +0 -1
  245. package/build/executor/compressor/compress.d.ts +0 -17
  246. package/build/executor/compressor/compress.js +0 -187
  247. package/build/executor/compressor/compress.js.map +0 -1
  248. package/build/executor/compressor/compress_functions/addressSubstitution.d.ts +0 -6
  249. package/build/executor/compressor/compress_functions/addressSubstitution.js +0 -29
  250. package/build/executor/compressor/compress_functions/addressSubstitution.js.map +0 -1
  251. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.d.ts +0 -10
  252. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js +0 -40
  253. package/build/executor/compressor/compress_functions/addressSubstitutionFromObject.js.map +0 -1
  254. package/build/executor/compressor/compress_functions/byteSubstitution.d.ts +0 -11
  255. package/build/executor/compressor/compress_functions/byteSubstitution.js +0 -64
  256. package/build/executor/compressor/compress_functions/byteSubstitution.js.map +0 -1
  257. package/build/executor/compressor/compress_functions/ffSubstitution.d.ts +0 -7
  258. package/build/executor/compressor/compress_functions/ffSubstitution.js +0 -54
  259. package/build/executor/compressor/compress_functions/ffSubstitution.js.map +0 -1
  260. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.d.ts +0 -8
  261. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js +0 -67
  262. package/build/executor/compressor/compress_functions/findLongestAndSubstitute.js.map +0 -1
  263. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.d.ts +0 -8
  264. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js +0 -61
  265. package/build/executor/compressor/compress_functions/findLongestAndSubstitute_old.js.map +0 -1
  266. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.d.ts +0 -6
  267. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js +0 -37
  268. package/build/executor/compressor/compress_functions/reverseAddressSubstitution.js.map +0 -1
  269. package/build/executor/compressor/compress_functions/searchUnusedBytes.d.ts +0 -9
  270. package/build/executor/compressor/compress_functions/searchUnusedBytes.js +0 -33
  271. package/build/executor/compressor/compress_functions/searchUnusedBytes.js.map +0 -1
  272. package/build/executor/compressor/fetchSaved.d.ts +0 -0
  273. package/build/executor/compressor/fetchSaved.js +0 -17
  274. package/build/executor/compressor/fetchSaved.js.map +0 -1
  275. package/build/executor/compressor/utils/computeCostL2.d.ts +0 -2
  276. package/build/executor/compressor/utils/computeCostL2.js +0 -14
  277. package/build/executor/compressor/utils/computeCostL2.js.map +0 -1
  278. package/build/executor/compressor/utils/findLongestDuplicatedString.d.ts +0 -2
  279. package/build/executor/compressor/utils/findLongestDuplicatedString.js +0 -30
  280. package/build/executor/compressor/utils/findLongestDuplicatedString.js.map +0 -1
  281. package/build/executor/compressor/utils/getAllIndexes.d.ts +0 -2
  282. package/build/executor/compressor/utils/getAllIndexes.js +0 -12
  283. package/build/executor/compressor/utils/getAllIndexes.js.map +0 -1
  284. package/build/executor/compressor/utils/getByteForAddress.d.ts +0 -2
  285. package/build/executor/compressor/utils/getByteForAddress.js +0 -14
  286. package/build/executor/compressor/utils/getByteForAddress.js.map +0 -1
  287. package/build/executor/compressor/utils/intTo2Bytes.d.ts +0 -2
  288. package/build/executor/compressor/utils/intTo2Bytes.js +0 -14
  289. package/build/executor/compressor/utils/intTo2Bytes.js.map +0 -1
  290. package/build/executor/compressor/utils/intTo3Bytes.d.ts +0 -2
  291. package/build/executor/compressor/utils/intTo3Bytes.js +0 -18
  292. package/build/executor/compressor/utils/intTo3Bytes.js.map +0 -1
  293. package/build/executor/compressor/utils/intToByte.d.ts +0 -2
  294. package/build/executor/compressor/utils/intToByte.js +0 -10
  295. package/build/executor/compressor/utils/intToByte.js.map +0 -1
@@ -1,158 +0,0 @@
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.IntegralContext = void 0;
7
- const integral_pool_1 = require("./integral-pool");
8
- const integral_pricing_1 = require("./integral-pricing");
9
- const integral_factory_1 = require("./integral-factory");
10
- const integral_relayer_1 = require("./integral-relayer");
11
- const integral_token_1 = require("./integral-token");
12
- const utils_1 = require("./utils");
13
- const lodash_1 = __importDefault(require("lodash"));
14
- class IntegralContext {
15
- constructor(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress) {
16
- this.network = network;
17
- this.dexKey = dexKey;
18
- this.dexHelper = dexHelper;
19
- this.erc20Interface = erc20Interface;
20
- this.factoryAddress = factoryAddress;
21
- this.relayerAddress = relayerAddress;
22
- this.pools = {};
23
- this.tokens = {};
24
- this.logger = dexHelper.getLogger(dexKey);
25
- this.factory = new integral_factory_1.IntegralFactory(dexHelper, dexKey, this.factoryAddress, this.onPoolCreatedAddPool, this.logger);
26
- this.relayer = new integral_relayer_1.IntegralRelayer(dexHelper, dexKey, this.erc20Interface, this.relayerAddress, {}, this.onRelayerPoolEnabledSet, this.logger);
27
- }
28
- async addPools(pools, blockNumber, initPhase = false) {
29
- this.relayer.addPools(pools);
30
- if (initPhase) {
31
- await this.relayer.initialize(blockNumber);
32
- }
33
- const _relayerState = this.relayer.getState(blockNumber);
34
- const relayerState = _relayerState
35
- ? _relayerState
36
- : await this.relayer.generateState(blockNumber);
37
- if (!_relayerState) {
38
- this.relayer.setState(relayerState, blockNumber);
39
- }
40
- const poolInitProps = this.removeDisabledPoolInitProps(relayerState, pools);
41
- const bases = Object.entries(poolInitProps).map(([poolAddress, p]) => {
42
- const poolId = (0, utils_1.getPoolIdentifier)(this.dexKey, p.token0, p.token1);
43
- const base = (this.pools[poolId] && this.pools[poolId].base) ||
44
- new integral_pool_1.IntegralEventPool(this.dexKey, this.network, this.dexHelper, poolAddress, p.token0, p.token1, this.logger);
45
- this.pools[poolId] = { base, enabled: true };
46
- return base;
47
- });
48
- await Promise.all(bases.map(base => !base.isInitialized && base.initialize(blockNumber)));
49
- const pricings = await Promise.all(bases.map(async (base) => {
50
- const _poolState = base.getState(blockNumber);
51
- const poolState = _poolState
52
- ? _poolState
53
- : await base.generateState(blockNumber);
54
- const poolId = (0, utils_1.getPoolIdentifier)(this.dexKey, base.token0, base.token1);
55
- const pricing = (this.pools[poolId] && this.pools[poolId].pricing) ||
56
- new integral_pricing_1.IntegralPricing(this.dexHelper, poolId, this.erc20Interface, poolState.uniswapPool, base.token0, base.token1, poolState.uniswapPoolFee, this.logger, this.network);
57
- this.pools[poolId].pricing = pricing;
58
- return pricing;
59
- }));
60
- await Promise.all(pricings.map(pricing => !pricing.isInitialized && pricing.initialize(blockNumber)));
61
- const initIntegralToken = (token) => new integral_token_1.IntegralToken(this.network, this.dexHelper, this.dexKey, this.erc20Interface, token, this.relayerAddress, this.onTransferUpdateBalance, this.logger);
62
- bases.map(base => {
63
- this.tokens[base.token0] =
64
- this.tokens[base.token0] || initIntegralToken(base.token0);
65
- this.tokens[base.token1] =
66
- this.tokens[base.token1] || initIntegralToken(base.token1);
67
- });
68
- await Promise.all(Object.values(this.tokens).map(token => !token.isInitialized && token.initialize(blockNumber)));
69
- }
70
- getPoolAddresses() {
71
- return Object.values(this.pools)
72
- .filter((pool) => !!pool.base && pool.enabled)
73
- .map(({ base }) => base.poolAddress);
74
- }
75
- removeDisabledPoolInitProps(state, props) {
76
- Object.entries(state.pools).forEach(([poolAddress, poolState]) => !poolState.isEnabled && delete props[poolAddress]);
77
- return props;
78
- }
79
- static initialize(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress) {
80
- if (!this.instances[network]) {
81
- this.instances[network] = new IntegralContext(network, dexKey, dexHelper, erc20Interface, factoryAddress, relayerAddress);
82
- }
83
- return this.instances[network];
84
- }
85
- static getInstance(network) {
86
- if (!this.instances[network]) {
87
- throw new Error('IntegralContext instance not initialized');
88
- }
89
- return this.instances[network];
90
- }
91
- async onRelayerPoolEnabledSet(poolAddress, state, blockNumber) {
92
- const poolEntry = (0, utils_1.getPoolBackReferencedFrom)(this, poolAddress);
93
- if (state.isEnabled && (!poolEntry || !poolEntry[1].enabled)) {
94
- const _factoryState = this.factory.getStaleState();
95
- const factoryState = _factoryState
96
- ? _factoryState
97
- : await this.factory.generateState(blockNumber);
98
- const { token0, token1 } = factoryState.pools[poolAddress];
99
- await this.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
100
- }
101
- else if (!state.isEnabled && poolEntry && poolEntry[1].enabled) {
102
- this.pools[poolEntry[0]].enabled = false;
103
- }
104
- }
105
- onRebalanceSellOrderExecuted(blockNumber, orderId) {
106
- this.relayer.executeOrder(orderId, blockNumber);
107
- }
108
- async onPoolCreatedAddPool(token0, token1, poolAddress, blockNumber) {
109
- await this.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
110
- }
111
- async onPoolSwapForRelayer(blockNumber, poolAddress, recipient, amount0Out, amount1Out) {
112
- if (recipient.toLowerCase() === this.relayerAddress.toLowerCase()) {
113
- const pools = this.relayer.getPools();
114
- if (pools[poolAddress.toLowerCase()]) {
115
- const token0 = pools[poolAddress.toLowerCase()].token0;
116
- const token1 = pools[poolAddress.toLowerCase()].token1;
117
- let _state = this.relayer.getStaleState();
118
- if (!_state) {
119
- _state = await this.relayer.generateState(blockNumber);
120
- this.relayer.setState(_state, blockNumber);
121
- return;
122
- }
123
- else {
124
- blockNumber = this.relayer.getStateBlockNumber();
125
- }
126
- const state = lodash_1.default.cloneDeep(_state);
127
- if (amount1Out > 0n) {
128
- state.tokens[token1].balance += amount1Out;
129
- }
130
- else {
131
- state.tokens[token0].balance += amount0Out;
132
- }
133
- this.relayer.setState(state, blockNumber);
134
- }
135
- else {
136
- this.logger.error('Integral Relayer: Pool address not found for', poolAddress);
137
- }
138
- }
139
- }
140
- async onTransferUpdateBalance(token, from, to, amount, blockNumber) {
141
- let _state = this.relayer.getStaleState();
142
- if (!_state) {
143
- this.logger.error('Integral Token: Relayer stale state not found');
144
- return;
145
- }
146
- const state = lodash_1.default.cloneDeep(_state);
147
- if (this.relayer.relayerAddress.toLowerCase() === from) {
148
- state.tokens[token].balance -= amount;
149
- }
150
- else if (this.relayer.relayerAddress.toLowerCase() === to) {
151
- state.tokens[token].balance += amount;
152
- }
153
- this.relayer.setState(state, blockNumber);
154
- }
155
- }
156
- exports.IntegralContext = IntegralContext;
157
- IntegralContext.instances = {};
158
- //# sourceMappingURL=context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/dex/integral/context.ts"],"names":[],"mappings":";;;;;;AACA,mDAAoD;AACpD,yDAAqD;AACrD,yDAAqD;A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,KAAK,EAAE,WAAW,CAAC,CAAC;IAC5C,CAAC;;AAzQH,0CA0QC;AAzQQ,yBAAS,GAA2C,EAAE,CAAC"}
@@ -1,17 +0,0 @@
1
- import { Address } from '../../types';
2
- import { PoolState as UniswapPoolState } from '../uniswap-v3/types';
3
- import { IntegralContext } from './context';
4
- import { PoolStates, RelayerPoolState } from './types';
5
- export declare function sortTokens(srcAddress: Address, destAddress: Address): string[];
6
- export declare function getDecimalsConverter(decimals0: number, decimals1: number, inverted: boolean): bigint;
7
- export declare function getPrice(states: PoolStates, inverted: boolean): bigint;
8
- export declare function getSpotPrice(pricing: UniswapPoolState, decimalsConverter: bigint): bigint;
9
- export declare function getAveragePrice(relayer: RelayerPoolState, pricing: UniswapPoolState, decimalsConverter: bigint): bigint;
10
- export declare function getTickCumulatives(poolState: UniswapPoolState, secondsAgos: bigint[]): bigint[];
11
- export declare function isInverted(tokenIn: Address, tokenOut: Address): boolean;
12
- export declare function getPoolIdentifier(dexKey: string, srcAddress: Address, destAddress: Address): string;
13
- export declare function onPoolSwapForRelayer(blockNumber: number, poolAddress: Address, recipient: Address, amount0Out: bigint, amount1Out: bigint, _context?: IntegralContext): Promise<void>;
14
- export declare function onRelayerPoolEnabledSet(poolAddress: Address, state: RelayerPoolState, blockNumber: number): Promise<void>;
15
- export declare function onRebalanceSellOrderExecuted(blockNumber: number, orderId: bigint): void;
16
- export declare function onPoolCreatedAddPool(token0: Address, token1: Address, poolAddress: Address, blockNumber: number): Promise<void>;
17
- export declare function onTransferUpdateBalance(token: Address, from: Address, to: Address, amount: bigint, blockNumber: number, _context?: IntegralContext): Promise<void>;
@@ -1,157 +0,0 @@
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.onTransferUpdateBalance = exports.onPoolCreatedAddPool = exports.onRebalanceSellOrderExecuted = exports.onRelayerPoolEnabledSet = exports.onPoolSwapForRelayer = exports.getPoolIdentifier = exports.isInverted = exports.getTickCumulatives = exports.getAveragePrice = exports.getSpotPrice = exports.getPrice = exports.getDecimalsConverter = exports.sortTokens = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const utils_1 = require("../../utils");
9
- const FullMath_1 = require("../uniswap-v3/contract-math/FullMath");
10
- const Oracle_1 = require("../uniswap-v3/contract-math/Oracle");
11
- const TickMath_1 = require("../uniswap-v3/contract-math/TickMath");
12
- const context_1 = require("./context");
13
- function sortTokens(srcAddress, destAddress) {
14
- return [srcAddress, destAddress].sort((a, b) => (a < b ? -1 : 1));
15
- }
16
- exports.sortTokens = sortTokens;
17
- function getDecimalsConverter(decimals0, decimals1, inverted) {
18
- return (10n **
19
- (18n + BigInt(inverted ? decimals1 - decimals0 : decimals0 - decimals1)));
20
- }
21
- exports.getDecimalsConverter = getDecimalsConverter;
22
- function getPrice(states, inverted) {
23
- const { base, pricing, relayer } = states;
24
- const decimalsConverter = getDecimalsConverter(base.decimals0, base.decimals1, false);
25
- const spotPrice = getSpotPrice(pricing, decimalsConverter);
26
- const averagePrice = getAveragePrice(relayer, pricing, decimalsConverter);
27
- if (inverted) {
28
- return 10n ** 36n / (spotPrice > averagePrice ? spotPrice : averagePrice);
29
- }
30
- else {
31
- return spotPrice < averagePrice ? spotPrice : averagePrice;
32
- }
33
- }
34
- exports.getPrice = getPrice;
35
- function getSpotPrice(pricing, decimalsConverter) {
36
- const sqrtPriceX96 = pricing.slot0.sqrtPriceX96;
37
- const priceX128 = FullMath_1.FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, 2n ** 64n);
38
- return FullMath_1.FullMath.mulDiv(priceX128, decimalsConverter, 2n ** 128n);
39
- }
40
- exports.getSpotPrice = getSpotPrice;
41
- function getAveragePrice(relayer, pricing, decimalsConverter) {
42
- (0, utils_1._require)(relayer.twapInterval > 0, 'Twap Interval not set');
43
- const secondsAgo = BigInt(relayer.twapInterval);
44
- const secondsAgos = [secondsAgo, 0n];
45
- const tickCumulatives = getTickCumulatives(pricing, secondsAgos);
46
- const delta = tickCumulatives[1] - tickCumulatives[0];
47
- let arithmeticMeanTick = delta / secondsAgo;
48
- if (delta < 0 && delta % secondsAgo != 0n) {
49
- --arithmeticMeanTick;
50
- }
51
- const sqrtRatioX96 = TickMath_1.TickMath.getSqrtRatioAtTick(arithmeticMeanTick);
52
- const ratioX128 = FullMath_1.FullMath.mulDiv(sqrtRatioX96, sqrtRatioX96, 2n ** 64n);
53
- return FullMath_1.FullMath.mulDiv(ratioX128, decimalsConverter, 2n ** 128n);
54
- }
55
- exports.getAveragePrice = getAveragePrice;
56
- function getTickCumulatives(poolState, secondsAgos) {
57
- const { tickCumulatives } = secondsAgos.reduce((memo, secondsAgo, i) => {
58
- [memo.tickCumulatives[i], memo.secondsPerLiquidityCumulativeX128s[i]] =
59
- Oracle_1.Oracle.observeSingle(poolState, BigInt.asUintN(32, poolState.blockTimestamp), secondsAgo, poolState.slot0.tick, poolState.slot0.observationIndex, poolState.liquidity, poolState.slot0.observationCardinality);
60
- return memo;
61
- }, {
62
- tickCumulatives: Array(secondsAgos.length),
63
- secondsPerLiquidityCumulativeX128s: Array(secondsAgos.length),
64
- });
65
- return tickCumulatives;
66
- }
67
- exports.getTickCumulatives = getTickCumulatives;
68
- function isInverted(tokenIn, tokenOut) {
69
- const [, token1] = tokenIn.toLowerCase() < tokenOut.toLowerCase()
70
- ? [tokenIn, tokenOut]
71
- : [tokenOut, tokenIn];
72
- return tokenIn === token1;
73
- }
74
- exports.isInverted = isInverted;
75
- function getPoolIdentifier(dexKey, srcAddress, destAddress) {
76
- const tokenAddresses = sortTokens(srcAddress.toLowerCase(), destAddress.toLowerCase()).join('_');
77
- return `${dexKey}_${tokenAddresses}`;
78
- }
79
- exports.getPoolIdentifier = getPoolIdentifier;
80
- async function onPoolSwapForRelayer(blockNumber, poolAddress, recipient, amount0Out, amount1Out, _context) {
81
- const context = _context || context_1.IntegralContext.getInstance();
82
- if (recipient.toLowerCase() === context.relayerAddress.toLowerCase()) {
83
- const pools = context.relayer.getPools();
84
- if (pools[poolAddress.toLowerCase()]) {
85
- const token0 = pools[poolAddress.toLowerCase()].token0;
86
- const token1 = pools[poolAddress.toLowerCase()].token1;
87
- let _state = context.relayer.getStaleState();
88
- if (!_state) {
89
- _state = await context.relayer.generateState(blockNumber);
90
- context.relayer.setState(_state, blockNumber);
91
- return;
92
- }
93
- else {
94
- blockNumber = context.relayer.getStateBlockNumber();
95
- }
96
- const state = lodash_1.default.cloneDeep(_state);
97
- if (amount1Out > 0n) {
98
- state.tokens[token1].balance += amount1Out;
99
- }
100
- else {
101
- state.tokens[token0].balance += amount0Out;
102
- }
103
- context.relayer.setState(state, blockNumber);
104
- }
105
- else {
106
- context.logger.error('Integral Relayer: Pool address not found for', poolAddress);
107
- }
108
- }
109
- }
110
- exports.onPoolSwapForRelayer = onPoolSwapForRelayer;
111
- function getPoolBackReferencedFrom(context, poolAddress) {
112
- return Object.entries(context.pools).find(([, pool]) => pool.base?.poolAddress === poolAddress);
113
- }
114
- async function onRelayerPoolEnabledSet(poolAddress, state, blockNumber) {
115
- const context = context_1.IntegralContext.getInstance();
116
- const poolEntry = getPoolBackReferencedFrom(context, poolAddress);
117
- if (state.isEnabled && (!poolEntry || !poolEntry[1].enabled)) {
118
- const _factoryState = context.factory.getStaleState();
119
- const factoryState = _factoryState
120
- ? _factoryState
121
- : await context.factory.generateState(blockNumber);
122
- const { token0, token1 } = factoryState.pools[poolAddress];
123
- await context.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
124
- }
125
- else if (!state.isEnabled && poolEntry && poolEntry[1].enabled) {
126
- context.pools[poolEntry[0]].enabled = false;
127
- }
128
- }
129
- exports.onRelayerPoolEnabledSet = onRelayerPoolEnabledSet;
130
- function onRebalanceSellOrderExecuted(blockNumber, orderId) {
131
- const context = context_1.IntegralContext.getInstance();
132
- context.relayer.executeOrder(orderId, blockNumber);
133
- }
134
- exports.onRebalanceSellOrderExecuted = onRebalanceSellOrderExecuted;
135
- async function onPoolCreatedAddPool(token0, token1, poolAddress, blockNumber) {
136
- const context = context_1.IntegralContext.getInstance();
137
- await context.addPools({ [poolAddress]: { token0, token1 } }, blockNumber);
138
- }
139
- exports.onPoolCreatedAddPool = onPoolCreatedAddPool;
140
- async function onTransferUpdateBalance(token, from, to, amount, blockNumber, _context) {
141
- const context = _context || context_1.IntegralContext.getInstance();
142
- let _state = context.relayer.getStaleState();
143
- if (!_state) {
144
- context.logger.error('Integral Token: Relayer stale state not found');
145
- return;
146
- }
147
- const state = lodash_1.default.cloneDeep(_state);
148
- if (context.relayer.relayerAddress.toLowerCase() === from) {
149
- state.tokens[token].balance -= amount;
150
- }
151
- else if (context.relayer.relayerAddress.toLowerCase() === to) {
152
- state.tokens[token].balance += amount;
153
- }
154
- context.relayer.setState(state, blockNumber);
155
- }
156
- exports.onTransferUpdateBalance = onTransferUpdateBalance;
157
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/dex/integral/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AAEvB,uCAAuC;AACvC,mEAAgE;AAChE,+DAA4D;AAC5D,mEAAgE;AAEhE,uCAA4C;AAG5C,SAAgB,UAAU,CAAC,UAAmB,EAAE,WAAoB;IAClE,OAAO,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC;AAFD,gCAEC;AAED,SAAgB,oBAAoB,CAClC,SAAiB,EACjB,SAAiB,EACjB,QAAiB;IAEjB,OAAO,CACL,GAAG;QACH,CAAC,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,CA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,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;AAC7E,CAAC;AARD,oDAQC;AAEM,KAAK,UAAU,uBAAuB,CAC3C,KAAc,EACd,IAAa,EACb,EAAW,EACX,MAAc,EACd,WAAmB,EACnB,QAA0B;IAE1B,MAAM,OAAO,GAAG,QAAQ,IAAI,yBAAe,CAAC,WAAW,EAAE,CAAC;IAC1D,IAAI,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;IAC7C,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACtE,OAAO;KACR;IACD,MAAM,KAAK,GAAiB,gBAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChD,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;QACzD,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;KACvC;SAAM,IAAI,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,WAAW,EAAE,KAAK,EAAE,EAAE;QAC9D,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,IAAI,MAAM,CAAC;KACvC;IACD,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAC/C,CAAC;AArBD,0DAqBC"}
@@ -1,24 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { LogDescription } from 'ethers/lib/utils';
3
- import { IDexHelper } from '../../dex-helper';
4
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
- import { Address, BlockHeader, Log, Logger } from '../../types';
6
- import { FactoryState } from './types';
7
- export declare type OnPoolCreatedCallback = (token0: Address, token1: Address, poolAddress: Address, blockNumber: number) => Promise<void>;
8
- export declare class IntegralFactory extends StatefulEventSubscriber<FactoryState> {
9
- readonly dexHelper: IDexHelper;
10
- protected readonly factoryAddress: Address;
11
- protected readonly onPoolCreated: OnPoolCreatedCallback;
12
- handlers: {
13
- [event: string]: (event: any, state: FactoryState, blockHeader: Readonly<BlockHeader>) => Promise<FactoryState>;
14
- };
15
- logDecoder: (log: Log) => any;
16
- readonly factoryIface: Interface;
17
- constructor(dexHelper: IDexHelper, parentName: string, factoryAddress: Address, onPoolCreated: OnPoolCreatedCallback, logger: Logger, mapKey?: string);
18
- protected getPoolIdentifierData(): {
19
- factory: string;
20
- };
21
- generateState(blockNumber?: number | 'latest'): Promise<FactoryState>;
22
- protected processLog(state: FactoryState, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): Promise<FactoryState>;
23
- handlePairCreated(event: LogDescription, state: FactoryState, blockHeader: Readonly<BlockHeader>): Promise<FactoryState>;
24
- }
@@ -1,95 +0,0 @@
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.IntegralFactory = void 0;
7
- const abi_1 = require("@ethersproject/abi");
8
- const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
9
- const factory_json_1 = __importDefault(require("../../abi/integral/factory.json"));
10
- const pool_json_1 = __importDefault(require("../../abi/integral/pool.json"));
11
- const decoders_1 = require("../../lib/decoders");
12
- class IntegralFactory extends stateful_event_subscriber_1.StatefulEventSubscriber {
13
- constructor(dexHelper, parentName, factoryAddress, onPoolCreated, logger, mapKey = '') {
14
- super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
15
- this.dexHelper = dexHelper;
16
- this.factoryAddress = factoryAddress;
17
- this.onPoolCreated = onPoolCreated;
18
- this.handlers = {};
19
- this.factoryIface = new abi_1.Interface(factory_json_1.default);
20
- this.addressesSubscribed = [factoryAddress];
21
- this.logDecoder = (log) => this.factoryIface.parseLog(log);
22
- this.handlers['PairCreated'] = this.handlePairCreated.bind(this);
23
- }
24
- getPoolIdentifierData() {
25
- return { factory: this.factoryAddress };
26
- }
27
- async generateState(blockNumber) {
28
- const factory = new this.dexHelper.web3Provider.eth.Contract(factory_json_1.default, this.factoryAddress);
29
- const poolCountResult = await factory.methods
30
- .allPairsLength()
31
- .call(undefined, blockNumber);
32
- const poolCount = Number(poolCountResult);
33
- const poolAddressCallDatas = [
34
- ...Array(poolCount),
35
- ].map((_, i) => {
36
- return {
37
- target: this.factoryAddress,
38
- callData: factory.methods.allPairs(i).encodeABI(),
39
- decodeFunction: decoders_1.addressDecode,
40
- };
41
- });
42
- const poolAddresses = await this.dexHelper.multiWrapper.tryAggregate(false, poolAddressCallDatas, blockNumber, this.dexHelper.multiWrapper.defaultBatchSize, false);
43
- const poolIface = new abi_1.Interface(pool_json_1.default);
44
- const poolInfosCallDatas = poolAddresses
45
- .map(poolAddress => {
46
- return [
47
- {
48
- target: poolAddress.returnData,
49
- callData: poolIface.encodeFunctionData('token0', []),
50
- decodeFunction: decoders_1.addressDecode,
51
- },
52
- {
53
- target: poolAddress.returnData,
54
- callData: poolIface.encodeFunctionData('token1', []),
55
- decodeFunction: decoders_1.addressDecode,
56
- },
57
- ];
58
- })
59
- .flat();
60
- const poolInfos = await this.dexHelper.multiWrapper.aggregate(poolInfosCallDatas, blockNumber);
61
- const state = { pools: {} };
62
- poolAddresses.forEach((poolAddress, i) => {
63
- const tokens = [
64
- poolInfos[i * 2].toLowerCase(),
65
- poolInfos[i * 2 + 1].toLowerCase(),
66
- ];
67
- state.pools[poolAddress.returnData.toLowerCase()] = {
68
- token0: tokens[0],
69
- token1: tokens[1],
70
- };
71
- });
72
- return state;
73
- }
74
- async processLog(state, log, blockHeader) {
75
- const event = this.logDecoder(log);
76
- if (event.name in this.handlers) {
77
- return await this.handlers[event.name](event, state, blockHeader);
78
- }
79
- return state;
80
- }
81
- async handlePairCreated(event, state, blockHeader) {
82
- const tokens = [
83
- event.args.token0.toLowerCase(),
84
- event.args.token1.toLowerCase(),
85
- ];
86
- state.pools[event.args.pair.toLowerCase()] = {
87
- token0: tokens[0],
88
- token1: tokens[1],
89
- };
90
- await this.onPoolCreated(tokens[0], tokens[1], event.args.pair.toLowerCase(), blockHeader.number);
91
- return state;
92
- }
93
- }
94
- exports.IntegralFactory = IntegralFactory;
95
- //# sourceMappingURL=integral-factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"integral-factory.js","sourceRoot":"","sources":["../../../src/dex/integral/integral-factory.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAG/C,+EAA0E;AAG1E,mFAAiE;AACjE,6EAA2D;AAC3D,iDAAmD;AAUnD,MAAa,eAAgB,SAAQ,mDAAqC;IAaxE,YACW,SAAqB,EAC9B,UAAkB,EACC,cAAuB,EACvB,aAAoC,EACvD,MAAc,EACd,SAAiB,EAAE;QAEnB,KAAK,CAAC,UAAU,EAAE,GAAG,UAAU,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAPnE,cAAS,GAAT,SAAS,CAAY;QAEX,mBAAc,GAAd,cAAc,CAAS;QACvB,kBAAa,GAAb,aAAa,CAAuB;QAhBzD,aAAQ,GAMJ,EAAE,CAAC;QAIS,iBAAY,GAAG,IAAI,eAAS,CAAC,sBAAkB,CAAC,CAAC;QAY/D,IAAI,CAAC,mBAAmB,GAAG,CAAC,cAAc,CAAC,CAAC;QAE5C,IAAI,CAAC,UAAU,GAAG,CAAC,GAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEhE,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnE,CAAC;IAES,qBAAqB;QAC7B,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,CAA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AAI,CAAC,MAAM,CAAC,WAAW,EAAE;YAC/B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;SAChC,CAAC;QACF,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG;YAC3C,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;YACjB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;SAClB,CAAC;QACF,MAAM,IAAI,CAAC,aAAa,CACtB,MAAM,CAAC,CAAC,CAAC,EACT,MAAM,CAAC,CAAC,CAAC,EACT,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,EAC7B,WAAW,CAAC,MAAM,CACnB,CAAC;QACF,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAnID,0CAmIC"}
@@ -1,50 +0,0 @@
1
- import { Interface } from '@ethersproject/abi';
2
- import { LogDescription } from 'ethers/lib/utils';
3
- import { AsyncOrSync } from 'ts-essentials';
4
- import { BlockHeader, Log, Logger } from '../../types';
5
- import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
6
- import { IDexHelper } from '../../dex-helper/idex-helper';
7
- import { PoolState } from './types';
8
- import { Address } from '../../types';
9
- export declare class IntegralEventPool extends StatefulEventSubscriber<PoolState> {
10
- parentName: string;
11
- protected network: number;
12
- protected dexHelper: IDexHelper;
13
- protected poolIface: Interface;
14
- handlers: {
15
- [event: string]: (event: any, pool: PoolState, blockHeader: Readonly<BlockHeader>) => AsyncOrSync<PoolState>;
16
- };
17
- logDecoder: (log: Log) => any;
18
- addressesSubscribed: string[];
19
- readonly poolAddress: Address;
20
- readonly token0: Address;
21
- readonly token1: Address;
22
- constructor(parentName: string, network: number, dexHelper: IDexHelper, poolAddress: Address, token0: Address, token1: Address, logger: Logger, poolIface?: Interface);
23
- protected getPoolIdentifierData(): {
24
- token0: string;
25
- token1: string;
26
- };
27
- /**
28
- * The function is called every time any of the subscribed
29
- * addresses release log. The function accepts the current
30
- * state, updates the state according to the log, and returns
31
- * the updated state.
32
- * @param state - Current state of event subscriber
33
- * @param log - Log released by one of the subscribed addresses
34
- * @returns Updates state of the event subscriber after the log
35
- */
36
- protected processLog(state: PoolState, log: Readonly<Log>, blockHeader: Readonly<BlockHeader>): Promise<PoolState | null>;
37
- /**
38
- * The function generates state using on-chain calls. This
39
- * function is called to regenerate state if the event based
40
- * system fails to fetch events and the local state is no
41
- * more correct.
42
- * @param blockNumber - Blocknumber for which the state should
43
- * should be generated
44
- * @returns state of the event subscriber at blocknumber
45
- */
46
- generateState(blockNumber: number): Promise<Readonly<PoolState>>;
47
- handleSetSwapFee(event: LogDescription, pool: PoolState): PoolState;
48
- handleSetMintFee(event: LogDescription, pool: PoolState): PoolState;
49
- handleSetBurnFee(event: LogDescription, pool: PoolState): PoolState;
50
- }