@paraswap/dex-lib 2.36.0 → 2.36.2-cache-invalidation

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 (250) hide show
  1. package/build/abi/api3-proxy.json +7 -0
  2. package/build/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  3. package/build/abi/uniswap-v3/UniswapV3Factory.abi.json +148 -0
  4. package/build/dex/algebra/algebra-factory.d.ts +25 -0
  5. package/build/dex/algebra/algebra-factory.js +43 -0
  6. package/build/dex/algebra/algebra-factory.js.map +1 -0
  7. package/build/dex/algebra/algebra.d.ts +3 -0
  8. package/build/dex/algebra/algebra.js +27 -5
  9. package/build/dex/algebra/algebra.js.map +1 -1
  10. package/build/dex/algebra/config.js +0 -1
  11. package/build/dex/algebra/config.js.map +1 -1
  12. package/build/dex/algebra/types.d.ts +1 -1
  13. package/build/dex/balancer-v2/config.js +1 -1
  14. package/build/dex/curve-v1/config.js +40 -38
  15. package/build/dex/curve-v1/config.js.map +1 -1
  16. package/build/dex/{woo-fi → hello}/config.d.ts +1 -1
  17. package/build/dex/hello/config.js +15 -0
  18. package/build/dex/hello/config.js.map +1 -0
  19. package/build/dex/hello/hello-pool.d.ts +39 -0
  20. package/build/dex/hello/hello-pool.js +64 -0
  21. package/build/dex/hello/hello-pool.js.map +1 -0
  22. package/build/dex/hello/hello.d.ts +37 -0
  23. package/build/dex/hello/hello.js +126 -0
  24. package/build/dex/hello/hello.js.map +1 -0
  25. package/build/dex/hello/types.d.ts +6 -0
  26. package/build/dex/{woo-fi → hello}/types.js.map +1 -1
  27. package/build/dex/{ramses-v2 → my-test-dex}/config.d.ts +1 -1
  28. package/build/dex/my-test-dex/config.js +15 -0
  29. package/build/dex/my-test-dex/config.js.map +1 -0
  30. package/build/dex/my-test-dex/my-test-dex-pool.d.ts +39 -0
  31. package/build/dex/my-test-dex/my-test-dex-pool.js +64 -0
  32. package/build/dex/my-test-dex/my-test-dex-pool.js.map +1 -0
  33. package/build/dex/my-test-dex/my-test-dex.d.ts +37 -0
  34. package/build/dex/my-test-dex/my-test-dex.js +126 -0
  35. package/build/dex/my-test-dex/my-test-dex.js.map +1 -0
  36. package/build/dex/my-test-dex/types.d.ts +6 -0
  37. package/build/dex/{pancakeswap-v3 → my-test-dex}/types.js.map +1 -1
  38. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.d.ts +26 -0
  39. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js +44 -0
  40. package/build/dex/pancakeswap-v3/pancakeswap-v3-factory.js.map +1 -0
  41. package/build/dex/pancakeswap-v3/pancakeswap-v3.d.ts +3 -0
  42. package/build/dex/pancakeswap-v3/pancakeswap-v3.js +26 -2
  43. package/build/dex/pancakeswap-v3/pancakeswap-v3.js.map +1 -1
  44. package/build/dex/quick-perps/pool.js +21 -6
  45. package/build/dex/quick-perps/pool.js.map +1 -1
  46. package/build/dex/quick-perps/quick-perps.js +34 -28
  47. package/build/dex/quick-perps/quick-perps.js.map +1 -1
  48. package/build/dex/solidly/config.js +1 -1
  49. package/build/dex/solidly/forks-override/aerodrome.js.map +1 -1
  50. package/build/dex/uniswap-v3/config.js.map +1 -1
  51. package/build/dex/uniswap-v3/types.d.ts +1 -0
  52. package/build/dex/uniswap-v3/types.js.map +1 -1
  53. package/build/dex/uniswap-v3/uniswap-v3-factory.d.ts +26 -0
  54. package/build/dex/uniswap-v3/uniswap-v3-factory.js +44 -0
  55. package/build/dex/uniswap-v3/uniswap-v3-factory.js.map +1 -0
  56. package/build/dex/uniswap-v3/uniswap-v3.d.ts +3 -0
  57. package/build/dex/uniswap-v3/uniswap-v3.js +26 -2
  58. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  59. package/build/dex-helper/dummy-dex-helper.js +3 -0
  60. package/build/dex-helper/dummy-dex-helper.js.map +1 -1
  61. package/build/dex-helper/icache.d.ts +1 -0
  62. package/build/lib/api3-feed.d.ts +4 -0
  63. package/build/lib/api3-feed.js +18 -0
  64. package/build/lib/api3-feed.js.map +1 -1
  65. package/package.json +1 -1
  66. package/src/abi/api3-proxy.json +7 -0
  67. package/src/abi/pancakeswap-v3/PancakeswapV3Factory.abi.json +300 -0
  68. package/src/dex/algebra/algebra-factory.ts +70 -0
  69. package/src/dex/algebra/algebra.ts +47 -6
  70. package/src/dex/algebra/config.ts +0 -1
  71. package/src/dex/algebra/types.ts +2 -1
  72. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +6 -8
  73. package/src/dex/balancer-v2/config.ts +1 -1
  74. package/src/dex/curve-v1/config.ts +40 -38
  75. package/src/dex/maverick-v1/maverick-v1-e2e.test.ts +1 -7
  76. package/src/dex/pancakeswap-v3/pancakeswap-v3-e2e.test.ts +1 -7
  77. package/src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts +73 -0
  78. package/src/dex/pancakeswap-v3/pancakeswap-v3.ts +50 -2
  79. package/src/dex/quick-perps/pool.ts +42 -7
  80. package/src/dex/quick-perps/quick-perps-events.test.ts +0 -1
  81. package/src/dex/quick-perps/quick-perps.ts +45 -35
  82. package/src/dex/solidly/config.ts +1 -1
  83. package/src/dex/solidly/forks-override/aerodrome.ts +1 -5
  84. package/src/dex/uniswap-v3/config.ts +1 -2
  85. package/src/dex/uniswap-v3/types.ts +2 -0
  86. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +1 -7
  87. package/src/dex/uniswap-v3/uniswap-v3-factory.ts +73 -0
  88. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +0 -2
  89. package/src/dex/uniswap-v3/uniswap-v3.ts +47 -2
  90. package/src/dex-helper/dummy-dex-helper.ts +4 -0
  91. package/src/dex-helper/icache.ts +2 -0
  92. package/src/lib/api3-feed.ts +35 -0
  93. package/.idea/aws.xml +0 -17
  94. package/.idea/codeStyles/Project.xml +0 -19
  95. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  96. package/.idea/misc.xml +0 -6
  97. package/.idea/modules.xml +0 -8
  98. package/.idea/paraswap-dex-lib.iml +0 -9
  99. package/.idea/vcs.xml +0 -6
  100. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  101. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  102. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  103. package/build/abi/sushiswap-v3/QuoterV2.json +0 -267
  104. package/build/abi/sushiswap-v3/RouterProcessor3.json +0 -289
  105. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +0 -193
  106. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +0 -285
  107. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +0 -583
  108. package/build/abi/wBETH.json +0 -1527
  109. package/build/abi/woo-fi/WooFeeManager.abi.json +0 -318
  110. package/build/abi/woo-fi/WooPP.abi.json +0 -548
  111. package/build/abi/woo-fi/Wooracle.abi.json +0 -260
  112. package/build/dex/aave-v3/tokens/arbitrum.json +0 -50
  113. package/build/dex/aave-v3/tokens/avalanche.json +0 -74
  114. package/build/dex/aave-v3/tokens/fantom.json +0 -62
  115. package/build/dex/aave-v3/tokens/optimism.json +0 -50
  116. package/build/dex/aave-v3/tokens/polygon.json +0 -116
  117. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  118. package/build/dex/algebra/algebra-pool.js +0 -336
  119. package/build/dex/algebra/algebra-pool.js.map +0 -1
  120. package/build/dex/balancer-v2/LinearMath.d.ts +0 -19
  121. package/build/dex/balancer-v2/LinearMath.js +0 -179
  122. package/build/dex/balancer-v2/LinearMath.js.map +0 -1
  123. package/build/dex/balancer-v2/LinearPool.d.ts +0 -47
  124. package/build/dex/balancer-v2/LinearPool.js +0 -324
  125. package/build/dex/balancer-v2/LinearPool.js.map +0 -1
  126. package/build/dex/balancer-v2/PhantomStablePool.d.ts +0 -47
  127. package/build/dex/balancer-v2/PhantomStablePool.js +0 -294
  128. package/build/dex/balancer-v2/PhantomStablePool.js.map +0 -1
  129. package/build/dex/balancer-v2/StableMath.d.ts +0 -9
  130. package/build/dex/balancer-v2/StableMath.js +0 -272
  131. package/build/dex/balancer-v2/StableMath.js.map +0 -1
  132. package/build/dex/balancer-v2/balancer-v2-pool.d.ts +0 -75
  133. package/build/dex/balancer-v2/balancer-v2-pool.js +0 -417
  134. package/build/dex/balancer-v2/balancer-v2-pool.js.map +0 -1
  135. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  136. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  137. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  138. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  139. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  140. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  141. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  142. package/build/dex/quickswap/camelot-v3.d.ts +0 -6
  143. package/build/dex/quickswap/camelot-v3.js +0 -19
  144. package/build/dex/quickswap/camelot-v3.js.map +0 -1
  145. package/build/dex/quickswap/zyberswap-v3.d.ts +0 -6
  146. package/build/dex/quickswap/zyberswap-v3.js +0 -19
  147. package/build/dex/quickswap/zyberswap-v3.js.map +0 -1
  148. package/build/dex/quickswap-v3.d.ts +0 -21
  149. package/build/dex/quickswap-v3.js +0 -40
  150. package/build/dex/quickswap-v3.js.map +0 -1
  151. package/build/dex/ramses-v2/config.js +0 -28
  152. package/build/dex/ramses-v2/config.js.map +0 -1
  153. package/build/dex/ramses-v2/constants.d.ts +0 -28
  154. package/build/dex/ramses-v2/constants.js +0 -35
  155. package/build/dex/ramses-v2/constants.js.map +0 -1
  156. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  157. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  158. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  159. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  160. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  161. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  162. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  163. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  164. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  165. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  166. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  167. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  168. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  169. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  170. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  171. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  172. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  173. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  174. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  175. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  176. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  177. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  178. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  179. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  180. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  181. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  182. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  183. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  184. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  185. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  186. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  187. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  188. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  189. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  190. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  191. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  192. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  193. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  194. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  195. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  196. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  197. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  198. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  199. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  200. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  201. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  202. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  203. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  204. package/build/dex/ramses-v2/types.d.ts +0 -154
  205. package/build/dex/ramses-v2/types.js +0 -9
  206. package/build/dex/ramses-v2/types.js.map +0 -1
  207. package/build/dex/ramses-v2/utils.d.ts +0 -6
  208. package/build/dex/ramses-v2/utils.js +0 -71
  209. package/build/dex/ramses-v2/utils.js.map +0 -1
  210. package/build/dex/sushiswap-v3/config.d.ts +0 -4
  211. package/build/dex/sushiswap-v3/config.js +0 -132
  212. package/build/dex/sushiswap-v3/config.js.map +0 -1
  213. package/build/dex/sushiswap-v3/constants.d.ts +0 -4
  214. package/build/dex/sushiswap-v3/constants.js +0 -32
  215. package/build/dex/sushiswap-v3/constants.js.map +0 -1
  216. package/build/dex/sushiswap-v3/sushiswap-v3-original.d.ts +0 -56
  217. package/build/dex/sushiswap-v3/sushiswap-v3-original.js +0 -598
  218. package/build/dex/sushiswap-v3/sushiswap-v3-original.js.map +0 -1
  219. package/build/dex/sushiswap-v3/sushiswap-v3-pool.d.ts +0 -1
  220. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js +0 -6
  221. package/build/dex/sushiswap-v3/sushiswap-v3-pool.js.map +0 -1
  222. package/build/dex/sushiswap-v3/sushiswap-v3.d.ts +0 -21
  223. package/build/dex/sushiswap-v3/sushiswap-v3.js +0 -58
  224. package/build/dex/sushiswap-v3/sushiswap-v3.js.map +0 -1
  225. package/build/dex/sushiswap-v3/token.d.ts +0 -6
  226. package/build/dex/sushiswap-v3/token.js +0 -23
  227. package/build/dex/sushiswap-v3/token.js.map +0 -1
  228. package/build/dex/sushiswap-v3/types.d.ts +0 -15
  229. package/build/dex/sushiswap-v3/types.js +0 -18
  230. package/build/dex/sushiswap-v3/types.js.map +0 -1
  231. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +0 -12
  232. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +0 -23
  233. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +0 -1
  234. package/build/dex/woo-fi/config.js +0 -141
  235. package/build/dex/woo-fi/config.js.map +0 -1
  236. package/build/dex/woo-fi/constants.d.ts +0 -5
  237. package/build/dex/woo-fi/constants.js +0 -20
  238. package/build/dex/woo-fi/constants.js.map +0 -1
  239. package/build/dex/woo-fi/types.d.ts +0 -48
  240. package/build/dex/woo-fi/woo-fi-decimal-math.d.ts +0 -14
  241. package/build/dex/woo-fi/woo-fi-decimal-math.js +0 -42
  242. package/build/dex/woo-fi/woo-fi-decimal-math.js.map +0 -1
  243. package/build/dex/woo-fi/woo-fi-math.d.ts +0 -31
  244. package/build/dex/woo-fi/woo-fi-math.js +0 -300
  245. package/build/dex/woo-fi/woo-fi-math.js.map +0 -1
  246. package/build/dex/woo-fi/woo-fi.d.ts +0 -65
  247. package/build/dex/woo-fi/woo-fi.js +0 -480
  248. package/build/dex/woo-fi/woo-fi.js.map +0 -1
  249. /package/build/dex/{pancakeswap-v3 → hello}/types.js +0 -0
  250. /package/build/dex/{woo-fi → my-test-dex}/types.js +0 -0
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Hello = void 0;
27
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
28
+ const utils_1 = require("../../utils");
29
+ const simple_exchange_1 = require("../simple-exchange");
30
+ const config_1 = require("./config");
31
+ const hello_pool_1 = require("./hello-pool");
32
+ class Hello extends simple_exchange_1.SimpleExchange {
33
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
34
+ super(dexHelper, dexKey);
35
+ this.network = network;
36
+ this.dexKey = dexKey;
37
+ this.dexHelper = dexHelper;
38
+ this.adapters = adapters;
39
+ this.hasConstantPriceLargeAmounts = false;
40
+ // TODO: set true here if protocols works only with wrapped asset
41
+ this.needWrapNative = true;
42
+ this.isFeeOnTransferSupported = false;
43
+ this.logger = dexHelper.getLogger(dexKey);
44
+ this.eventPools = new hello_pool_1.HelloEventPool(dexKey, network, dexHelper, this.logger);
45
+ }
46
+ // Initialize pricing is called once in the start of
47
+ // pricing service. It is intended to setup the integration
48
+ // for pricing requests. It is optional for a DEX to
49
+ // implement this function
50
+ async initializePricing(blockNumber) {
51
+ // TODO: complete me!
52
+ }
53
+ // Returns the list of contract adapters (name and index)
54
+ // for a buy/sell. Return null if there are no adapters.
55
+ getAdapters(side) {
56
+ return this.adapters[side] ? this.adapters[side] : null;
57
+ }
58
+ // Returns list of pool identifiers that can be used
59
+ // for a given swap. poolIdentifiers must be unique
60
+ // across DEXes. It is recommended to use
61
+ // ${dexKey}_${poolAddress} as a poolIdentifier
62
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
63
+ // TODO: complete me!
64
+ return [];
65
+ }
66
+ // Returns pool prices for amounts.
67
+ // If limitPools is defined only pools in limitPools
68
+ // should be used. If limitPools is undefined then
69
+ // any pools can be used.
70
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
71
+ // TODO: complete me!
72
+ return null;
73
+ }
74
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
75
+ getCalldataGasCost(poolPrices) {
76
+ // TODO: update if there is any payload in getAdapterParam
77
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
78
+ }
79
+ // Encode params required by the exchange adapter
80
+ // Used for multiSwap, buy & megaSwap
81
+ // Hint: abiCoder.encodeParameter() could be useful
82
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
83
+ // TODO: complete me!
84
+ const { exchange } = data;
85
+ // Encode here the payload for adapter
86
+ const payload = '';
87
+ return {
88
+ targetExchange: exchange,
89
+ payload,
90
+ networkFee: '0',
91
+ };
92
+ }
93
+ // Encode call data used by simpleSwap like routers
94
+ // Used for simpleSwap & simpleBuy
95
+ // Hint: this.buildSimpleParamWithoutWETHConversion
96
+ // could be useful
97
+ async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
98
+ // TODO: complete me!
99
+ const { exchange } = data;
100
+ // Encode here the transaction arguments
101
+ const swapData = '';
102
+ return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, exchange);
103
+ }
104
+ // This is called once before getTopPoolsForToken is
105
+ // called for multiple tokens. This can be helpful to
106
+ // update common state required for calculating
107
+ // getTopPoolsForToken. It is optional for a DEX
108
+ // to implement this
109
+ async updatePoolState() {
110
+ // TODO: complete me!
111
+ }
112
+ // Returns list of top pools based on liquidity. Max
113
+ // limit number pools should be returned.
114
+ async getTopPoolsForToken(tokenAddress, limit) {
115
+ //TODO: complete me!
116
+ return [];
117
+ }
118
+ // This is optional function in case if your implementation has acquired any resources
119
+ // you need to release for graceful shutdown. For example, it may be any interval timer
120
+ releaseResources() {
121
+ // TODO: complete me!
122
+ }
123
+ }
124
+ exports.Hello = Hello;
125
+ Hello.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.HelloConfig);
126
+ //# sourceMappingURL=hello.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hello.js","sourceRoot":"","sources":["../../../src/dex/hello/hello.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,2EAA6D;AAC7D,uCAAoD;AAIpD,wDAAoD;AACpD,qCAAiD;AACjD,6CAA8C;AAE9C,MAAa,KACX,SAAQ,gCAAc;IAgBtB,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAE5C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAA0B;QAfrC,iCAA4B,GAAG,KAAK,CAAC;QAC9C,iEAAiE;QACxD,mBAAc,GAAG,IAAI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AAE,GAAG,IAAI,CAAC;QAE1B,sCAAsC;QACtC,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,OAAO;YACL,cAAc,EAAE,QAAQ;YACxB,OAAO;YACP,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;IAED,mDAAmD;IACnD,kCAAkC;IAClC,mDAAmD;IACnD,kBAAkB;IAClB,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAe,EACf,IAAc;QAEd,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,wCAAwC;QACxC,MAAM,QAAQ,GAAG,EAAE,CAAC;QAEpB,OAAO,IAAI,CAAC,qCAAqC,CAC/C,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,oDAAoD;IACpD,qDAAqD;IACrD,+CAA+C;IAC/C,gDAAgD;IAChD,oBAAoB;IACpB,KAAK,CAAC,eAAe;QACnB,qBAAqB;IACvB,CAAC;IAED,oDAAoD;IACpD,yCAAyC;IACzC,KAAK,CAAC,mBAAmB,CACvB,YAAqB,EACrB,KAAa;QAEb,oBAAoB;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB;QACd,qBAAqB;IACvB,CAAC;;AAhKH,sBAiKC;AArJe,wBAAkB,GAC9B,IAAA,6BAAqB,EAAC,oBAAW,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Address } from '../../types';
2
+ export declare type PoolState = {};
3
+ export declare type HelloData = {
4
+ exchange: Address;
5
+ };
6
+ export declare type DexParams = {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/woo-fi/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/hello/types.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
1
  import { DexParams } from './types';
2
2
  import { DexConfigMap, AdapterMappings } from '../../types';
3
- export declare const RamsesV2Config: DexConfigMap<DexParams>;
3
+ export declare const MyTestDexConfig: DexConfigMap<DexParams>;
4
4
  export declare const Adapters: Record<number, AdapterMappings>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Adapters = exports.MyTestDexConfig = void 0;
4
+ const constants_1 = require("../../constants");
5
+ exports.MyTestDexConfig = {
6
+ MyTestDex: {
7
+ // TODO: complete me!
8
+ },
9
+ };
10
+ exports.Adapters = {
11
+ // TODO: add adapters for each chain
12
+ // This is an example to copy
13
+ [constants_1.Network.MAINNET]: { [constants_1.SwapSide.SELL]: [{ name: '', index: 0 }] },
14
+ };
15
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/my-test-dex/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,eAAe,GAA4B;IACtD,SAAS,EAAE;IACT,qBAAqB;KACtB;CACF,CAAC;AAEW,QAAA,QAAQ,GAAoC;IACvD,oCAAoC;IACpC,6BAA6B;IAC7B,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,oBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE;CACjE,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { Log, Logger } from '../../types';
4
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
+ import { IDexHelper } from '../../dex-helper/idex-helper';
6
+ import { PoolState } from './types';
7
+ export declare class MyTestDexEventPool extends StatefulEventSubscriber<PoolState> {
8
+ readonly parentName: string;
9
+ protected network: number;
10
+ protected dexHelper: IDexHelper;
11
+ protected myTestDexIface: Interface;
12
+ handlers: {
13
+ [event: string]: (event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>) => DeepReadonly<PoolState> | null;
14
+ };
15
+ logDecoder: (log: Log) => any;
16
+ addressesSubscribed: string[];
17
+ constructor(parentName: string, network: number, dexHelper: IDexHelper, logger: Logger, myTestDexIface?: Interface);
18
+ /**
19
+ * The function is called every time any of the subscribed
20
+ * addresses release log. The function accepts the current
21
+ * state, updates the state according to the log, and returns
22
+ * the updated state.
23
+ * @param state - Current state of event subscriber
24
+ * @param log - Log released by one of the subscribed addresses
25
+ * @returns Updates state of the event subscriber after the log
26
+ */
27
+ protected processLog(state: DeepReadonly<PoolState>, log: Readonly<Log>): DeepReadonly<PoolState> | null;
28
+ /**
29
+ * The function generates state using on-chain calls. This
30
+ * function is called to regenerate state if the event based
31
+ * system fails to fetch events and the local state is no
32
+ * more correct.
33
+ * @param blockNumber - Blocknumber for which the state should
34
+ * should be generated
35
+ * @returns state of the event subscriber at blocknumber
36
+ */
37
+ generateState(blockNumber: number): Promise<DeepReadonly<PoolState>>;
38
+ handleMyEvent(event: any, state: DeepReadonly<PoolState>, log: Readonly<Log>): DeepReadonly<PoolState> | null;
39
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MyTestDexEventPool = void 0;
4
+ const abi_1 = require("@ethersproject/abi");
5
+ const utils_1 = require("../../utils");
6
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
7
+ class MyTestDexEventPool extends stateful_event_subscriber_1.StatefulEventSubscriber {
8
+ constructor(parentName, network, dexHelper, logger, myTestDexIface = new abi_1.Interface('' /* TODO: Import and put here MyTestDex ABI */)) {
9
+ // TODO: Add pool name
10
+ super(parentName, 'POOL_NAME', dexHelper, logger);
11
+ this.parentName = parentName;
12
+ this.network = network;
13
+ this.dexHelper = dexHelper;
14
+ this.myTestDexIface = myTestDexIface;
15
+ this.handlers = {};
16
+ // TODO: make logDecoder decode logs that
17
+ this.logDecoder = (log) => this.myTestDexIface.parseLog(log);
18
+ this.addressesSubscribed = [
19
+ /* subscribed addresses */
20
+ ];
21
+ // Add handlers
22
+ this.handlers['myEvent'] = this.handleMyEvent.bind(this);
23
+ }
24
+ /**
25
+ * The function is called every time any of the subscribed
26
+ * addresses release log. The function accepts the current
27
+ * state, updates the state according to the log, and returns
28
+ * the updated state.
29
+ * @param state - Current state of event subscriber
30
+ * @param log - Log released by one of the subscribed addresses
31
+ * @returns Updates state of the event subscriber after the log
32
+ */
33
+ processLog(state, log) {
34
+ try {
35
+ const event = this.logDecoder(log);
36
+ if (event.name in this.handlers) {
37
+ return this.handlers[event.name](event, state, log);
38
+ }
39
+ }
40
+ catch (e) {
41
+ (0, utils_1.catchParseLogError)(e, this.logger);
42
+ }
43
+ return null;
44
+ }
45
+ /**
46
+ * The function generates state using on-chain calls. This
47
+ * function is called to regenerate state if the event based
48
+ * system fails to fetch events and the local state is no
49
+ * more correct.
50
+ * @param blockNumber - Blocknumber for which the state should
51
+ * should be generated
52
+ * @returns state of the event subscriber at blocknumber
53
+ */
54
+ async generateState(blockNumber) {
55
+ // TODO: complete me!
56
+ return {};
57
+ }
58
+ // Its just a dummy example
59
+ handleMyEvent(event, state, log) {
60
+ return null;
61
+ }
62
+ }
63
+ exports.MyTestDexEventPool = MyTestDexEventPool;
64
+ //# sourceMappingURL=my-test-dex-pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"my-test-dex-pool.js","sourceRoot":"","sources":["../../../src/dex/my-test-dex/my-test-dex-pool.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAG/C,uCAAiD;AACjD,+EAA0E;AAI1E,MAAa,kBAAmB,SAAQ,mDAAkC;IAaxE,YACW,UAAkB,EACjB,OAAe,EACf,SAAqB,EAC/B,MAAc,EACJ,iBAAiB,IAAI,eAAS,CACtC,EAAE,CAAC,6CAA6C,CACjD;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AkFC"}
@@ -0,0 +1,37 @@
1
+ import { AsyncOrSync } from 'ts-essentials';
2
+ import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, SimpleExchangeParam, PoolLiquidity, Logger } from '../../types';
3
+ import { SwapSide, Network } from '../../constants';
4
+ import { IDex } from '../../dex/idex';
5
+ import { IDexHelper } from '../../dex-helper/idex-helper';
6
+ import { MyTestDexData } from './types';
7
+ import { SimpleExchange } from '../simple-exchange';
8
+ import { MyTestDexEventPool } from './my-test-dex-pool';
9
+ export declare class MyTestDex extends SimpleExchange implements IDex<MyTestDexData> {
10
+ readonly network: Network;
11
+ readonly dexKey: string;
12
+ readonly dexHelper: IDexHelper;
13
+ protected adapters: import("../../types").AdapterMappings;
14
+ protected eventPools: MyTestDexEventPool;
15
+ readonly hasConstantPriceLargeAmounts = false;
16
+ readonly needWrapNative = true;
17
+ readonly isFeeOnTransferSupported = false;
18
+ static dexKeysWithNetwork: {
19
+ key: string;
20
+ networks: Network[];
21
+ }[];
22
+ logger: Logger;
23
+ constructor(network: Network, dexKey: string, dexHelper: IDexHelper, adapters?: import("../../types").AdapterMappings);
24
+ initializePricing(blockNumber: number): Promise<void>;
25
+ getAdapters(side: SwapSide): {
26
+ name: string;
27
+ index: number;
28
+ }[] | null;
29
+ getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
30
+ getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<MyTestDexData>>;
31
+ getCalldataGasCost(poolPrices: PoolPrices<MyTestDexData>): number | number[];
32
+ getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: MyTestDexData, side: SwapSide): AdapterExchangeParam;
33
+ getSimpleParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: MyTestDexData, side: SwapSide): Promise<SimpleExchangeParam>;
34
+ updatePoolState(): Promise<void>;
35
+ getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
36
+ releaseResources(): AsyncOrSync<void>;
37
+ }
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.MyTestDex = void 0;
27
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
28
+ const utils_1 = require("../../utils");
29
+ const simple_exchange_1 = require("../simple-exchange");
30
+ const config_1 = require("./config");
31
+ const my_test_dex_pool_1 = require("./my-test-dex-pool");
32
+ class MyTestDex extends simple_exchange_1.SimpleExchange {
33
+ constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}) {
34
+ super(dexHelper, dexKey);
35
+ this.network = network;
36
+ this.dexKey = dexKey;
37
+ this.dexHelper = dexHelper;
38
+ this.adapters = adapters;
39
+ this.hasConstantPriceLargeAmounts = false;
40
+ // TODO: set true here if protocols works only with wrapped asset
41
+ this.needWrapNative = true;
42
+ this.isFeeOnTransferSupported = false;
43
+ this.logger = dexHelper.getLogger(dexKey);
44
+ this.eventPools = new my_test_dex_pool_1.MyTestDexEventPool(dexKey, network, dexHelper, this.logger);
45
+ }
46
+ // Initialize pricing is called once in the start of
47
+ // pricing service. It is intended to setup the integration
48
+ // for pricing requests. It is optional for a DEX to
49
+ // implement this function
50
+ async initializePricing(blockNumber) {
51
+ // TODO: complete me!
52
+ }
53
+ // Returns the list of contract adapters (name and index)
54
+ // for a buy/sell. Return null if there are no adapters.
55
+ getAdapters(side) {
56
+ return this.adapters[side] ? this.adapters[side] : null;
57
+ }
58
+ // Returns list of pool identifiers that can be used
59
+ // for a given swap. poolIdentifiers must be unique
60
+ // across DEXes. It is recommended to use
61
+ // ${dexKey}_${poolAddress} as a poolIdentifier
62
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
63
+ // TODO: complete me!
64
+ return [];
65
+ }
66
+ // Returns pool prices for amounts.
67
+ // If limitPools is defined only pools in limitPools
68
+ // should be used. If limitPools is undefined then
69
+ // any pools can be used.
70
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
71
+ // TODO: complete me!
72
+ return null;
73
+ }
74
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
75
+ getCalldataGasCost(poolPrices) {
76
+ // TODO: update if there is any payload in getAdapterParam
77
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
78
+ }
79
+ // Encode params required by the exchange adapter
80
+ // Used for multiSwap, buy & megaSwap
81
+ // Hint: abiCoder.encodeParameter() could be useful
82
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
83
+ // TODO: complete me!
84
+ const { exchange } = data;
85
+ // Encode here the payload for adapter
86
+ const payload = '';
87
+ return {
88
+ targetExchange: exchange,
89
+ payload,
90
+ networkFee: '0',
91
+ };
92
+ }
93
+ // Encode call data used by simpleSwap like routers
94
+ // Used for simpleSwap & simpleBuy
95
+ // Hint: this.buildSimpleParamWithoutWETHConversion
96
+ // could be useful
97
+ async getSimpleParam(srcToken, destToken, srcAmount, destAmount, data, side) {
98
+ // TODO: complete me!
99
+ const { exchange } = data;
100
+ // Encode here the transaction arguments
101
+ const swapData = '';
102
+ return this.buildSimpleParamWithoutWETHConversion(srcToken, srcAmount, destToken, destAmount, swapData, exchange);
103
+ }
104
+ // This is called once before getTopPoolsForToken is
105
+ // called for multiple tokens. This can be helpful to
106
+ // update common state required for calculating
107
+ // getTopPoolsForToken. It is optional for a DEX
108
+ // to implement this
109
+ async updatePoolState() {
110
+ // TODO: complete me!
111
+ }
112
+ // Returns list of top pools based on liquidity. Max
113
+ // limit number pools should be returned.
114
+ async getTopPoolsForToken(tokenAddress, limit) {
115
+ //TODO: complete me!
116
+ return [];
117
+ }
118
+ // This is optional function in case if your implementation has acquired any resources
119
+ // you need to release for graceful shutdown. For example, it may be any interval timer
120
+ releaseResources() {
121
+ // TODO: complete me!
122
+ }
123
+ }
124
+ exports.MyTestDex = MyTestDex;
125
+ MyTestDex.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.MyTestDexConfig);
126
+ //# sourceMappingURL=my-test-dex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"my-test-dex.js","sourceRoot":"","sources":["../../../src/dex/my-test-dex/my-test-dex.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,2EAA6D;AAC7D,uCAAoD;AAIpD,wDAAoD;AACpD,qCAAqD;AACrD,yDAAwD;AAExD,MAAa,SAAU,SAAQ,gCAAc;IAc3C,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,iBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE;QAE5C,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAA0B;QAfrC,iCAA4B,GAAG,KA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ACnB,IAAc;QAEd,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,sCAAsC;QACtC,MAAM,OAAO,GAAG,EAAE,CAAC;QAEnB,OAAO;YACL,cAAc,EAAE,QAAQ;YACxB,OAAO;YACP,UAAU,EAAE,GAAG;SAChB,CAAC;IACJ,CAAC;IAED,mDAAmD;IACnD,kCAAkC;IAClC,mDAAmD;IACnD,kBAAkB;IAClB,KAAK,CAAC,cAAc,CAClB,QAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,UAAkB,EAClB,IAAmB,EACnB,IAAc;QAEd,qBAAqB;QACrB,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAE1B,wCAAwC;QACxC,MAAM,QAAQ,GAAG,EAAE,CAAC;QAEpB,OAAO,IAAI,CAAC,qCAAqC,CAC/C,QAAQ,EACR,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,oDAAoD;IACpD,qDAAqD;IACrD,+CAA+C;IAC/C,gDAAgD;IAChD,oBAAoB;IACpB,KAAK,CAAC,eAAe;QACnB,qBAAqB;IACvB,CAAC;IAED,oDAAoD;IACpD,yCAAyC;IACzC,KAAK,CAAC,mBAAmB,CACvB,YAAqB,EACrB,KAAa;QAEb,oBAAoB;QACpB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,sFAAsF;IACtF,uFAAuF;IACvF,gBAAgB;QACd,qBAAqB;IACvB,CAAC;;AA3JH,8BA4JC;AAnJe,4BAAkB,GAC9B,IAAA,6BAAqB,EAAC,wBAAe,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { Address } from '../../types';
2
+ export declare type PoolState = {};
3
+ export declare type MyTestDexData = {
4
+ exchange: Address;
5
+ };
6
+ export declare type DexParams = {};
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/pancakeswap-v3/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/my-test-dex/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { DeepReadonly } from 'ts-essentials';
3
+ import { IDexHelper } from '../../dex-helper/idex-helper';
4
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
5
+ import { Address, Log, Logger } from '../../types';
6
+ import { LogDescription } from 'ethers/lib/utils';
7
+ import { FactoryState } from '../uniswap-v3/types';
8
+ export declare type OnPoolCreatedCallback = ({ token0, token1, fee, }: {
9
+ token0: string;
10
+ token1: string;
11
+ fee: bigint;
12
+ }) => Promise<void>;
13
+ export declare class PancakeswapV3Factory extends StatefulEventSubscriber<FactoryState> {
14
+ readonly dexHelper: IDexHelper;
15
+ protected readonly factoryAddress: Address;
16
+ protected readonly onPoolCreated: OnPoolCreatedCallback;
17
+ handlers: {
18
+ [event: string]: (event: any) => Promise<void>;
19
+ };
20
+ logDecoder: (log: Log) => any;
21
+ readonly factoryIface: Interface;
22
+ constructor(dexHelper: IDexHelper, parentName: string, factoryAddress: Address, logger: Logger, onPoolCreated: OnPoolCreatedCallback, mapKey?: string);
23
+ generateState(): FactoryState;
24
+ protected processLog(_: DeepReadonly<FactoryState>, log: Readonly<Log>): Promise<FactoryState>;
25
+ handleNewPool(event: LogDescription): Promise<void>;
26
+ }
@@ -0,0 +1,44 @@
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.PancakeswapV3Factory = void 0;
7
+ const abi_1 = require("@ethersproject/abi");
8
+ const PancakeswapV3Factory_abi_json_1 = __importDefault(require("../../abi/pancakeswap-v3/PancakeswapV3Factory.abi.json"));
9
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
10
+ /*
11
+ * "Stateless" event subscriber in order to capture "PoolCreated" event on new pools created.
12
+ * State is present, but it's a placeholder to actually make the events reach handlers (if there's no previous state - `processBlockLogs` is not called)
13
+ */
14
+ class PancakeswapV3Factory extends stateful_event_subscriber_1.StatefulEventSubscriber {
15
+ constructor(dexHelper, parentName, factoryAddress, logger, onPoolCreated, mapKey = '') {
16
+ super(parentName, `${parentName} Factory`, dexHelper, logger, true, mapKey);
17
+ this.dexHelper = dexHelper;
18
+ this.factoryAddress = factoryAddress;
19
+ this.onPoolCreated = onPoolCreated;
20
+ this.handlers = {};
21
+ this.factoryIface = new abi_1.Interface(PancakeswapV3Factory_abi_json_1.default);
22
+ this.addressesSubscribed = [factoryAddress];
23
+ this.logDecoder = (log) => this.factoryIface.parseLog(log);
24
+ this.handlers['PoolCreated'] = this.handleNewPool.bind(this);
25
+ }
26
+ generateState() {
27
+ return {};
28
+ }
29
+ async processLog(_, log) {
30
+ const event = this.logDecoder(log);
31
+ if (event.name in this.handlers) {
32
+ await this.handlers[event.name](event);
33
+ }
34
+ return {};
35
+ }
36
+ async handleNewPool(event) {
37
+ const token0 = event.args.token0;
38
+ const token1 = event.args.token1;
39
+ const fee = event.args.fee;
40
+ await this.onPoolCreated({ token0, token1, fee });
41
+ }
42
+ }
43
+ exports.PancakeswapV3Factory = PancakeswapV3Factory;
44
+ //# sourceMappingURL=pancakeswap-v3-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pancakeswap-v3-factory.js","sourceRoot":"","sources":["../../../src/dex/pancakeswap-v3/pancakeswap-v3-factory.ts"],"names":[],"mappings":";;;;;;AAAA,4CAA+C;AAE/C,2HAAgF;AAEhF,+EAA0E;AAe1E;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,mDAAqC;IAS7E,YACW,SAAqB,EAC9B,UAAkB,EACC,cAAuB,EAC1C,MAAc,EACK,aAAoC,EACvD,SAAiB,EAAE;QAEnB,KAAK,CAAC,UAAU,EAAE,GAAG,UAAU,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,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per } from '../../dex-helper/idex-helper';
7
7
  import { DexParams, UniswapV3Data } from '../uniswap-v3/types';
8
8
  import { SimpleExchange } from '../simple-exchange';
9
9
  import { PancakeSwapV3EventPool } from './pancakeswap-v3-pool';
10
+ import { OnPoolCreatedCallback } from './pancakeswap-v3-factory';
10
11
  export declare class PancakeswapV3 extends SimpleExchange implements IDex<UniswapV3Data> {
11
12
  protected network: Network;
12
13
  protected dexHelper: IDexHelper;
@@ -14,6 +15,7 @@ export declare class PancakeswapV3 extends SimpleExchange implements IDex<Uniswa
14
15
  readonly routerIface: Interface;
15
16
  readonly quoterIface: Interface;
16
17
  protected config: DexParams;
18
+ private readonly factory;
17
19
  readonly isFeeOnTransferSupported: boolean;
18
20
  readonly eventPools: Record<string, PancakeSwapV3EventPool | null>;
19
21
  readonly hasConstantPriceLargeAmounts = false;
@@ -35,6 +37,7 @@ export declare class PancakeswapV3 extends SimpleExchange implements IDex<Uniswa
35
37
  }[] | null;
36
38
  getPoolIdentifier(srcAddress: Address, destAddress: Address, fee: bigint): string;
37
39
  initializePricing(blockNumber: number): Promise<void>;
40
+ onPoolCreatedDeleteFromNonExistingSet: OnPoolCreatedCallback;
38
41
  getPool(srcAddress: Address, destAddress: Address, fee: bigint, blockNumber: number): Promise<PancakeSwapV3EventPool | null>;
39
42
  addMasterPool(poolKey: string, blockNumber: number): Promise<boolean>;
40
43
  getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
@@ -45,8 +45,9 @@ const constants_2 = require("./constants");
45
45
  const pancakeswap_v3_math_1 = require("./contract-math/pancakeswap-v3-math");
46
46
  const balancer_fetcher_1 = require("../../lib/tokens/balancer-fetcher");
47
47
  const types_2 = require("../../lib/tokens/types");
48
- const PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 60 * 60 * 24 * 1000; // 24 hours
49
- const PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 30 * 60 * 1000; // Once in 30 minutes
48
+ const pancakeswap_v3_factory_1 = require("./pancakeswap-v3-factory");
49
+ const PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS = 3 * 24 * 60 * 60 * 1000; // 3 days
50
+ const PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_INTERVAL_MS = 24 * 60 * 60 * 1000; // Once in a day
50
51
  const PANCAKESWAPV3_QUOTE_GASLIMIT = 200000;
51
52
  class PancakeswapV3 extends simple_exchange_1.SimpleExchange {
52
53
  constructor(network, dexKey, dexHelper, adapters = config_1.Adapters[network] || {}, routerIface = new abi_1.Interface(PancakeswapV3Router_abi_json_1.default), quoterIface = new abi_1.Interface(PancakeswapV3Quoter_abi_json_1.default), config = config_1.PancakeswapV3Config[dexKey][network]) {
@@ -61,6 +62,26 @@ class PancakeswapV3 extends simple_exchange_1.SimpleExchange {
61
62
  this.eventPools = {};
62
63
  this.hasConstantPriceLargeAmounts = false;
63
64
  this.needWrapNative = true;
65
+ /*
66
+ * When a non existing pool is queried, it's blacklisted for an arbitrary long period in order to prevent issuing too many rpc calls
67
+ * Once the pool is created, it gets immediately flagged
68
+ */
69
+ this.onPoolCreatedDeleteFromNonExistingSet = async ({ token0, token1, fee, }) => {
70
+ const logPrefix = '[PancakeV3.onPoolCreatedDeleteFromNonExistingSet]';
71
+ const [_token0, _token1] = this._sortTokens(token0, token1);
72
+ const poolKey = `${token0}_${token1}_${fee}`.toLowerCase();
73
+ // consider doing it only from master pool for less calls to distant cache
74
+ // delete entry locally to let local instance discover the pool
75
+ delete this.eventPools[this.getPoolIdentifier(_token0, _token1, fee)];
76
+ try {
77
+ this.logger.info(`${logPrefix} delete pool from not existing set: ${poolKey}`);
78
+ // delete pool record from set
79
+ await this.dexHelper.cache.zrem(this.notExistingPoolSetKey, [poolKey]);
80
+ }
81
+ catch (error) {
82
+ this.logger.error(`${logPrefix} failed to delete pool from set :${poolKey}`, error);
83
+ }
84
+ };
64
85
  this.logger = dexHelper.getLogger(dexKey + '-' + network);
65
86
  this.uniswapMulti = new this.dexHelper.web3Provider.eth.Contract(UniswapMulti_abi_json_1.default, this.config.uniswapMulticall);
66
87
  this.stateMultiContract = new this.dexHelper.web3Provider.eth.Contract(PancakeV3StateMulticall_abi_json_1.default, this.config.stateMulticall);
@@ -70,6 +91,7 @@ class PancakeswapV3 extends simple_exchange_1.SimpleExchange {
70
91
  this.config = this._toLowerForAllConfigAddresses();
71
92
  this.notExistingPoolSetKey =
72
93
  `${constants_1.CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
94
+ this.factory = new pancakeswap_v3_factory_1.PancakeswapV3Factory(dexHelper, dexKey, this.config.factory, this.logger, this.onPoolCreatedDeleteFromNonExistingSet.bind(this));
73
95
  }
74
96
  get supportedFees() {
75
97
  return this.config.supportedFees;
@@ -82,6 +104,8 @@ class PancakeswapV3 extends simple_exchange_1.SimpleExchange {
82
104
  return `${this.dexKey}_${tokenAddresses}_${fee}`;
83
105
  }
84
106
  async initializePricing(blockNumber) {
107
+ // Init listening to new pools creation
108
+ await this.factory.initialize(blockNumber);
85
109
  if (!this.dexHelper.config.isSlave) {
86
110
  const cleanExpiredNotExistingPoolsKeys = async () => {
87
111
  const maxTimestamp = Date.now() - PANCAKESWAPV3_CLEAN_NOT_EXISTING_POOL_TTL_MS;