@marko00/routing-finder-mare 1.0.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 (173) hide show
  1. package/.idea/copilot.data.migration.agent.xml +6 -0
  2. package/.idea/copilot.data.migration.ask.xml +6 -0
  3. package/.idea/copilot.data.migration.ask2agent.xml +6 -0
  4. package/.idea/copilot.data.migration.edit.xml +6 -0
  5. package/.idea/modules.xml +8 -0
  6. package/.idea/php.xml +19 -0
  7. package/.idea/ratex-sdk.iml +8 -0
  8. package/.idea/vcs.xml +6 -0
  9. package/LICENSE-MIT +21 -0
  10. package/README.md +209 -0
  11. package/contracts/abi/BalancerHelperAbi.ts +1 -0
  12. package/contracts/abi/CamelotHelperAbi.ts +1 -0
  13. package/contracts/abi/RateXAbi.ts +482 -0
  14. package/contracts/abi/SushiSwapHelperAbi.ts +1 -0
  15. package/contracts/abi/UniswapHelperAbi.ts +1 -0
  16. package/contracts/abi/UniswapV2HelperAbi.ts +1 -0
  17. package/contracts/addresses-arbitrum.ts +8 -0
  18. package/contracts/addresses-mainnet.ts +7 -0
  19. package/contracts/addresses-polkadot.ts +9 -0
  20. package/contracts/addresses-sei.ts +9 -0
  21. package/contracts/rateX/BalancerHelper.ts +13 -0
  22. package/contracts/rateX/CamelotHelper.ts +13 -0
  23. package/contracts/rateX/SushiSwapHelper.ts +13 -0
  24. package/contracts/rateX/UniswapHelper.ts +19 -0
  25. package/contracts/rateX/UniswapV2Helper.ts +19 -0
  26. package/dexes/dexIdsList.ts +9 -0
  27. package/dexes/graph_queries/BalancerV2.ts +150 -0
  28. package/dexes/graph_queries/CamelotV2.ts +202 -0
  29. package/dexes/graph_queries/SushiSwapV2.ts +283 -0
  30. package/dexes/graph_queries/UniswapV2.ts +252 -0
  31. package/dexes/graph_queries/UniswapV3.ts +229 -0
  32. package/dexes/graph_queries/graphQueryFilters.ts +41 -0
  33. package/dexes/graph_queries/x_template.ts +67 -0
  34. package/dexes/pools/Balancer/BalancerState.ts +34 -0
  35. package/dexes/pools/Balancer/BalancerWeightedPool.ts +96 -0
  36. package/dexes/pools/Camelot.ts +164 -0
  37. package/dexes/pools/SushiSwapV2.ts +35 -0
  38. package/dexes/pools/UniswapV2.ts +36 -0
  39. package/dexes/pools/uniswap/UniswapV3.ts +40 -0
  40. package/dexes/pools/uniswap/testUniswapOffchainQuoter.ts +169 -0
  41. package/dexes/pools/uniswap/types.ts +174 -0
  42. package/dexes/pools/uniswap/uniswapOffchainQuoter.ts +173 -0
  43. package/dexes/pools/uniswap/uniswapState.ts +56 -0
  44. package/dexes/pools/uniswap/utils.ts +71 -0
  45. package/dist/contracts/abi/BalancerHelperAbi.d.ts +25 -0
  46. package/dist/contracts/abi/BalancerHelperAbi.js +4 -0
  47. package/dist/contracts/abi/CamelotHelperAbi.d.ts +45 -0
  48. package/dist/contracts/abi/CamelotHelperAbi.js +4 -0
  49. package/dist/contracts/abi/RateXAbi.d.ts +71 -0
  50. package/dist/contracts/abi/RateXAbi.js +485 -0
  51. package/dist/contracts/abi/SushiSwapHelperAbi.d.ts +45 -0
  52. package/dist/contracts/abi/SushiSwapHelperAbi.js +4 -0
  53. package/dist/contracts/abi/UniswapHelperAbi.d.ts +39 -0
  54. package/dist/contracts/abi/UniswapHelperAbi.js +4 -0
  55. package/dist/contracts/abi/UniswapV2HelperAbi.d.ts +45 -0
  56. package/dist/contracts/abi/UniswapV2HelperAbi.js +4 -0
  57. package/dist/contracts/addresses-arbitrum.d.ts +6 -0
  58. package/dist/contracts/addresses-arbitrum.js +10 -0
  59. package/dist/contracts/addresses-mainnet.d.ts +6 -0
  60. package/dist/contracts/addresses-mainnet.js +10 -0
  61. package/dist/contracts/addresses-polkadot.d.ts +6 -0
  62. package/dist/contracts/addresses-polkadot.js +10 -0
  63. package/dist/contracts/addresses-sei.d.ts +6 -0
  64. package/dist/contracts/addresses-sei.js +10 -0
  65. package/dist/contracts/rateX/BalancerHelper.d.ts +26 -0
  66. package/dist/contracts/rateX/BalancerHelper.js +14 -0
  67. package/dist/contracts/rateX/CamelotHelper.d.ts +46 -0
  68. package/dist/contracts/rateX/CamelotHelper.js +14 -0
  69. package/dist/contracts/rateX/SushiSwapHelper.d.ts +46 -0
  70. package/dist/contracts/rateX/SushiSwapHelper.js +14 -0
  71. package/dist/contracts/rateX/UniswapHelper.d.ts +40 -0
  72. package/dist/contracts/rateX/UniswapHelper.js +22 -0
  73. package/dist/contracts/rateX/UniswapV2Helper.d.ts +46 -0
  74. package/dist/contracts/rateX/UniswapV2Helper.js +22 -0
  75. package/dist/dexes/dexIdsList.d.ts +9 -0
  76. package/dist/dexes/dexIdsList.js +12 -0
  77. package/dist/dexes/graph_queries/BalancerV2.d.ts +14 -0
  78. package/dist/dexes/graph_queries/BalancerV2.js +141 -0
  79. package/dist/dexes/graph_queries/CamelotV2.d.ts +14 -0
  80. package/dist/dexes/graph_queries/CamelotV2.js +183 -0
  81. package/dist/dexes/graph_queries/SushiSwapV2.d.ts +14 -0
  82. package/dist/dexes/graph_queries/SushiSwapV2.js +263 -0
  83. package/dist/dexes/graph_queries/UniswapV2.d.ts +14 -0
  84. package/dist/dexes/graph_queries/UniswapV2.js +217 -0
  85. package/dist/dexes/graph_queries/UniswapV3.d.ts +14 -0
  86. package/dist/dexes/graph_queries/UniswapV3.js +198 -0
  87. package/dist/dexes/graph_queries/graphQueryFilters.d.ts +19 -0
  88. package/dist/dexes/graph_queries/graphQueryFilters.js +40 -0
  89. package/dist/dexes/graph_queries/x_template.d.ts +12 -0
  90. package/dist/dexes/graph_queries/x_template.js +57 -0
  91. package/dist/dexes/pools/Balancer/BalancerState.d.ts +6 -0
  92. package/dist/dexes/pools/Balancer/BalancerState.js +32 -0
  93. package/dist/dexes/pools/Balancer/BalancerWeightedPool.d.ts +12 -0
  94. package/dist/dexes/pools/Balancer/BalancerWeightedPool.js +109 -0
  95. package/dist/dexes/pools/Camelot.d.ts +12 -0
  96. package/dist/dexes/pools/Camelot.js +135 -0
  97. package/dist/dexes/pools/SushiSwapV2.d.ts +9 -0
  98. package/dist/dexes/pools/SushiSwapV2.js +34 -0
  99. package/dist/dexes/pools/UniswapV2.d.ts +9 -0
  100. package/dist/dexes/pools/UniswapV2.js +34 -0
  101. package/dist/dexes/pools/uniswap/UniswapV3.d.ts +7 -0
  102. package/dist/dexes/pools/uniswap/UniswapV3.js +36 -0
  103. package/dist/dexes/pools/uniswap/types.d.ts +76 -0
  104. package/dist/dexes/pools/uniswap/types.js +111 -0
  105. package/dist/dexes/pools/uniswap/uniswapOffchainQuoter.d.ts +13 -0
  106. package/dist/dexes/pools/uniswap/uniswapOffchainQuoter.js +121 -0
  107. package/dist/dexes/pools/uniswap/uniswapState.d.ts +14 -0
  108. package/dist/dexes/pools/uniswap/uniswapState.js +51 -0
  109. package/dist/dexes/pools/uniswap/utils.d.ts +3 -0
  110. package/dist/dexes/pools/uniswap/utils.js +41 -0
  111. package/dist/index.d.ts +26 -0
  112. package/dist/index.js +41 -0
  113. package/dist/routes.d.ts +1 -0
  114. package/dist/routes.js +20 -0
  115. package/dist/routing/iterative_spliting/main.d.ts +3 -0
  116. package/dist/routing/iterative_spliting/main.js +104 -0
  117. package/dist/routing/iterative_spliting/multiHopSwap.d.ts +4 -0
  118. package/dist/routing/iterative_spliting/multiHopSwap.js +83 -0
  119. package/dist/routing/main.d.ts +2 -0
  120. package/dist/routing/main.js +22 -0
  121. package/dist/routing/uni_like_algo/algo_config.d.ts +2 -0
  122. package/dist/routing/uni_like_algo/algo_config.js +8 -0
  123. package/dist/routing/uni_like_algo/amount_distribution.d.ts +2 -0
  124. package/dist/routing/uni_like_algo/amount_distribution.js +17 -0
  125. package/dist/routing/uni_like_algo/compute_routes_backtrack.d.ts +3 -0
  126. package/dist/routing/uni_like_algo/compute_routes_backtrack.js +44 -0
  127. package/dist/routing/uni_like_algo/main.d.ts +2 -0
  128. package/dist/routing/uni_like_algo/main.js +49 -0
  129. package/dist/routing/uni_like_algo/routes_quoter.d.ts +21 -0
  130. package/dist/routing/uni_like_algo/routes_quoter.js +53 -0
  131. package/dist/routing/uni_like_algo/swap_finder.d.ts +25 -0
  132. package/dist/routing/uni_like_algo/swap_finder.js +154 -0
  133. package/dist/routing/uni_like_algo/types.d.ts +40 -0
  134. package/dist/routing/uni_like_algo/types.js +12 -0
  135. package/dist/swap/graph_communication.d.ts +5 -0
  136. package/dist/swap/graph_communication.js +187 -0
  137. package/dist/swap/my_local_storage.d.ts +8 -0
  138. package/dist/swap/my_local_storage.js +16 -0
  139. package/dist/utils/addresses.d.ts +24 -0
  140. package/dist/utils/addresses.js +60 -0
  141. package/dist/utils/math/fixed-points.d.ts +14 -0
  142. package/dist/utils/math/fixed-points.js +123 -0
  143. package/dist/utils/math/log-exp.d.ts +5 -0
  144. package/dist/utils/math/log-exp.js +385 -0
  145. package/dist/utils/math/math.d.ts +12 -0
  146. package/dist/utils/math/math.js +50 -0
  147. package/dist/utils/types/types.d.ts +51 -0
  148. package/dist/utils/types/types.js +25 -0
  149. package/dist/utils/utils.d.ts +20 -0
  150. package/dist/utils/utils.js +72 -0
  151. package/images/decenter_logo.png +0 -0
  152. package/index.ts +50 -0
  153. package/package.json +39 -0
  154. package/routes.ts +27 -0
  155. package/routing/iterative_spliting/main.ts +131 -0
  156. package/routing/iterative_spliting/multiHopSwap.ts +98 -0
  157. package/routing/main.ts +22 -0
  158. package/routing/uni_like_algo/algo_config.ts +7 -0
  159. package/routing/uni_like_algo/amount_distribution.ts +16 -0
  160. package/routing/uni_like_algo/compute_routes_backtrack.ts +81 -0
  161. package/routing/uni_like_algo/main.ts +65 -0
  162. package/routing/uni_like_algo/routes_quoter.ts +63 -0
  163. package/routing/uni_like_algo/swap_finder.ts +185 -0
  164. package/routing/uni_like_algo/types.ts +54 -0
  165. package/swap/graph_communication.ts +212 -0
  166. package/swap/my_local_storage.ts +27 -0
  167. package/tsconfig.json +26 -0
  168. package/utils/addresses.ts +64 -0
  169. package/utils/math/fixed-points.ts +88 -0
  170. package/utils/math/log-exp.ts +469 -0
  171. package/utils/math/math.ts +46 -0
  172. package/utils/types/types.ts +100 -0
  173. package/utils/utils.ts +125 -0
@@ -0,0 +1,6 @@
1
+ export declare const RATE_X_ADDRESS = "0xCfA0D6244c4Ca91aA3F4d700b98B2f2b08c89478";
2
+ export declare const SUSHISWAP_HELPER_ADDRESS = "0x141fc598Ed85a23e78f2b58ABe95AC013d196249";
3
+ export declare const CAMELOT_HELPER_ADDRESS = "0x91DE0353a4f93BD460dE3a373Feb50c53571c078";
4
+ export declare const BALANCER_HELPER_ADDRESS = "0xd1dFeDe71160a0a1e869e2D3F428A47531726BfE";
5
+ export declare const UNISWAP_HELPER_ADDRESS = "0x5F8eD01104fb64eA66dE025dd52bD674Cee31e51";
6
+ export declare const UNISWAP_V2_HELPER_ADDRESS = "0xEaCd7162b506a7Ee0F31A15BDce6B03fF06c6f8b";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNISWAP_V2_HELPER_ADDRESS = exports.UNISWAP_HELPER_ADDRESS = exports.BALANCER_HELPER_ADDRESS = exports.CAMELOT_HELPER_ADDRESS = exports.SUSHISWAP_HELPER_ADDRESS = exports.RATE_X_ADDRESS = void 0;
4
+ // chainId: 420420417
5
+ exports.RATE_X_ADDRESS = "0xCfA0D6244c4Ca91aA3F4d700b98B2f2b08c89478";
6
+ exports.SUSHISWAP_HELPER_ADDRESS = "0x141fc598Ed85a23e78f2b58ABe95AC013d196249";
7
+ exports.CAMELOT_HELPER_ADDRESS = "0x91DE0353a4f93BD460dE3a373Feb50c53571c078";
8
+ exports.BALANCER_HELPER_ADDRESS = "0xd1dFeDe71160a0a1e869e2D3F428A47531726BfE";
9
+ exports.UNISWAP_HELPER_ADDRESS = "0x5F8eD01104fb64eA66dE025dd52bD674Cee31e51";
10
+ exports.UNISWAP_V2_HELPER_ADDRESS = "0xEaCd7162b506a7Ee0F31A15BDce6B03fF06c6f8b";
@@ -0,0 +1,6 @@
1
+ export declare const RATE_X_ADDRESS = "0x1D3ac829f8b0056972491095342730710e956629";
2
+ export declare const SUSHISWAP_HELPER_ADDRESS = "0x141fc598Ed85a23e78f2b58ABe95AC013d196249";
3
+ export declare const CAMELOT_HELPER_ADDRESS = "0x91DE0353a4f93BD460dE3a373Feb50c53571c078";
4
+ export declare const BALANCER_HELPER_ADDRESS = "0xd1dFeDe71160a0a1e869e2D3F428A47531726BfE";
5
+ export declare const UNISWAP_HELPER_ADDRESS = "0x32400EbaC2e81dAd18aaBCc9C37Ef992f1CC833F";
6
+ export declare const UNISWAP_V2_HELPER_ADDRESS = "0x32191e4724670D8683e22C9463a23D9eB8C0fb73";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UNISWAP_V2_HELPER_ADDRESS = exports.UNISWAP_HELPER_ADDRESS = exports.BALANCER_HELPER_ADDRESS = exports.CAMELOT_HELPER_ADDRESS = exports.SUSHISWAP_HELPER_ADDRESS = exports.RATE_X_ADDRESS = void 0;
4
+ // chainId: 42161
5
+ exports.RATE_X_ADDRESS = "0x1D3ac829f8b0056972491095342730710e956629";
6
+ exports.SUSHISWAP_HELPER_ADDRESS = "0x141fc598Ed85a23e78f2b58ABe95AC013d196249";
7
+ exports.CAMELOT_HELPER_ADDRESS = "0x91DE0353a4f93BD460dE3a373Feb50c53571c078";
8
+ exports.BALANCER_HELPER_ADDRESS = "0xd1dFeDe71160a0a1e869e2D3F428A47531726BfE";
9
+ exports.UNISWAP_HELPER_ADDRESS = "0x32400EbaC2e81dAd18aaBCc9C37Ef992f1CC833F";
10
+ exports.UNISWAP_V2_HELPER_ADDRESS = "0x32191e4724670D8683e22C9463a23D9eB8C0fb73";
@@ -0,0 +1,26 @@
1
+ import Web3 from 'web3';
2
+ export declare function CreateBalancerHelperContract(chainId: number, web3: Web3): import("web3").Contract<({
3
+ inputs: {
4
+ internalType: string;
5
+ name: string;
6
+ type: string;
7
+ }[];
8
+ stateMutability: string;
9
+ type: string;
10
+ name?: undefined;
11
+ outputs?: undefined;
12
+ } | {
13
+ inputs: {
14
+ internalType: string;
15
+ name: string;
16
+ type: string;
17
+ }[];
18
+ name: string;
19
+ outputs: {
20
+ internalType: string;
21
+ name: string;
22
+ type: string;
23
+ }[];
24
+ stateMutability: string;
25
+ type: string;
26
+ })[]>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateBalancerHelperContract = CreateBalancerHelperContract;
4
+ const BalancerHelperAbi_1 = require("../abi/BalancerHelperAbi");
5
+ const addresses_mainnet_1 = require("../addresses-mainnet");
6
+ const addresses_arbitrum_1 = require("../addresses-arbitrum");
7
+ function CreateBalancerHelperContract(chainId, web3) {
8
+ if (chainId === 1) {
9
+ return new web3.eth.Contract(BalancerHelperAbi_1.BalancerHelperAbi, addresses_mainnet_1.BALANCER_HELPER_ADDRESS);
10
+ }
11
+ else {
12
+ return new web3.eth.Contract(BalancerHelperAbi_1.BalancerHelperAbi, addresses_arbitrum_1.BALANCER_HELPER_ADDRESS);
13
+ }
14
+ }
@@ -0,0 +1,46 @@
1
+ import Web3 from 'web3';
2
+ export declare function CreateCamelotHelperContract(chainId: number, web3: Web3): import("web3").Contract<{
3
+ inputs: {
4
+ components: ({
5
+ internalType: string;
6
+ name: string;
7
+ type: string;
8
+ components?: undefined;
9
+ } | {
10
+ components: {
11
+ internalType: string;
12
+ name: string;
13
+ type: string;
14
+ }[];
15
+ internalType: string;
16
+ name: string;
17
+ type: string;
18
+ })[];
19
+ internalType: string;
20
+ name: string;
21
+ type: string;
22
+ }[];
23
+ name: string;
24
+ outputs: {
25
+ components: ({
26
+ internalType: string;
27
+ name: string;
28
+ type: string;
29
+ components?: undefined;
30
+ } | {
31
+ components: {
32
+ internalType: string;
33
+ name: string;
34
+ type: string;
35
+ }[];
36
+ internalType: string;
37
+ name: string;
38
+ type: string;
39
+ })[];
40
+ internalType: string;
41
+ name: string;
42
+ type: string;
43
+ }[];
44
+ stateMutability: string;
45
+ type: string;
46
+ }[]>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateCamelotHelperContract = CreateCamelotHelperContract;
4
+ const CamelotHelperAbi_1 = require("../abi/CamelotHelperAbi");
5
+ const addresses_mainnet_1 = require("../addresses-mainnet");
6
+ const addresses_arbitrum_1 = require("../addresses-arbitrum");
7
+ function CreateCamelotHelperContract(chainId, web3) {
8
+ if (chainId === 1) {
9
+ return new web3.eth.Contract(CamelotHelperAbi_1.CamelotHelperAbi, addresses_mainnet_1.CAMELOT_HELPER_ADDRESS);
10
+ }
11
+ else {
12
+ return new web3.eth.Contract(CamelotHelperAbi_1.CamelotHelperAbi, addresses_arbitrum_1.CAMELOT_HELPER_ADDRESS);
13
+ }
14
+ }
@@ -0,0 +1,46 @@
1
+ import Web3 from 'web3';
2
+ export declare function CreateSushiSwapHelperContract(chainId: number, web3: Web3): import("web3").Contract<{
3
+ inputs: {
4
+ components: ({
5
+ internalType: string;
6
+ name: string;
7
+ type: string;
8
+ components?: undefined;
9
+ } | {
10
+ components: {
11
+ internalType: string;
12
+ name: string;
13
+ type: string;
14
+ }[];
15
+ internalType: string;
16
+ name: string;
17
+ type: string;
18
+ })[];
19
+ internalType: string;
20
+ name: string;
21
+ type: string;
22
+ }[];
23
+ name: string;
24
+ outputs: {
25
+ components: ({
26
+ internalType: string;
27
+ name: string;
28
+ type: string;
29
+ components?: undefined;
30
+ } | {
31
+ components: {
32
+ internalType: string;
33
+ name: string;
34
+ type: string;
35
+ }[];
36
+ internalType: string;
37
+ name: string;
38
+ type: string;
39
+ })[];
40
+ internalType: string;
41
+ name: string;
42
+ type: string;
43
+ }[];
44
+ stateMutability: string;
45
+ type: string;
46
+ }[]>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateSushiSwapHelperContract = CreateSushiSwapHelperContract;
4
+ const SushiSwapHelperAbi_1 = require("../abi/SushiSwapHelperAbi");
5
+ const addresses_mainnet_1 = require("../addresses-mainnet");
6
+ const addresses_arbitrum_1 = require("../addresses-arbitrum");
7
+ function CreateSushiSwapHelperContract(chainId, web3) {
8
+ if (chainId === 1) {
9
+ return new web3.eth.Contract(SushiSwapHelperAbi_1.SushiSwapHelperAbi, addresses_mainnet_1.SUSHISWAP_HELPER_ADDRESS);
10
+ }
11
+ else {
12
+ return new web3.eth.Contract(SushiSwapHelperAbi_1.SushiSwapHelperAbi, addresses_arbitrum_1.SUSHISWAP_HELPER_ADDRESS);
13
+ }
14
+ }
@@ -0,0 +1,40 @@
1
+ import Web3 from 'web3';
2
+ export declare function CreateUniswapHelperContract(chainId: number, web3: Web3): import("web3").Contract<({
3
+ inputs: {
4
+ internalType: string;
5
+ name: string;
6
+ type: string;
7
+ }[];
8
+ name: string;
9
+ outputs: {
10
+ internalType: string;
11
+ name: string;
12
+ type: string;
13
+ }[];
14
+ stateMutability: string;
15
+ type: string;
16
+ } | {
17
+ inputs: {
18
+ internalType: string;
19
+ name: string;
20
+ type: string;
21
+ }[];
22
+ name: string;
23
+ outputs: {
24
+ components: {
25
+ components: {
26
+ internalType: string;
27
+ name: string;
28
+ type: string;
29
+ }[];
30
+ internalType: string;
31
+ name: string;
32
+ type: string;
33
+ }[];
34
+ internalType: string;
35
+ name: string;
36
+ type: string;
37
+ }[];
38
+ stateMutability: string;
39
+ type: string;
40
+ })[]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateUniswapHelperContract = CreateUniswapHelperContract;
4
+ const UniswapHelperAbi_1 = require("../abi/UniswapHelperAbi");
5
+ const addresses_mainnet_1 = require("../addresses-mainnet");
6
+ const addresses_arbitrum_1 = require("../addresses-arbitrum");
7
+ const addresses_sei_1 = require("../addresses-sei");
8
+ const addresses_polkadot_1 = require("../addresses-polkadot");
9
+ function CreateUniswapHelperContract(chainId, web3) {
10
+ if (chainId === 1) {
11
+ return new web3.eth.Contract(UniswapHelperAbi_1.UniswapHelperAbi, addresses_mainnet_1.UNISWAP_HELPER_ADDRESS);
12
+ }
13
+ else if (chainId === 1329) {
14
+ return new web3.eth.Contract(UniswapHelperAbi_1.UniswapHelperAbi, addresses_sei_1.UNISWAP_HELPER_ADDRESS);
15
+ }
16
+ else if (chainId === 420420417) {
17
+ return new web3.eth.Contract(UniswapHelperAbi_1.UniswapHelperAbi, addresses_polkadot_1.UNISWAP_HELPER_ADDRESS);
18
+ }
19
+ else {
20
+ return new web3.eth.Contract(UniswapHelperAbi_1.UniswapHelperAbi, addresses_arbitrum_1.UNISWAP_HELPER_ADDRESS);
21
+ }
22
+ }
@@ -0,0 +1,46 @@
1
+ import Web3 from 'web3';
2
+ export declare function CreateUniswapV2HelperContract(chainId: number, web3: Web3): import("web3").Contract<{
3
+ inputs: {
4
+ components: ({
5
+ internalType: string;
6
+ name: string;
7
+ type: string;
8
+ components?: undefined;
9
+ } | {
10
+ components: {
11
+ internalType: string;
12
+ name: string;
13
+ type: string;
14
+ }[];
15
+ internalType: string;
16
+ name: string;
17
+ type: string;
18
+ })[];
19
+ internalType: string;
20
+ name: string;
21
+ type: string;
22
+ }[];
23
+ name: string;
24
+ outputs: {
25
+ components: ({
26
+ internalType: string;
27
+ name: string;
28
+ type: string;
29
+ components?: undefined;
30
+ } | {
31
+ components: {
32
+ internalType: string;
33
+ name: string;
34
+ type: string;
35
+ }[];
36
+ internalType: string;
37
+ name: string;
38
+ type: string;
39
+ })[];
40
+ internalType: string;
41
+ name: string;
42
+ type: string;
43
+ }[];
44
+ stateMutability: string;
45
+ type: string;
46
+ }[]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateUniswapV2HelperContract = CreateUniswapV2HelperContract;
4
+ const UniswapV2HelperAbi_1 = require("../abi/UniswapV2HelperAbi");
5
+ const addresses_mainnet_1 = require("../addresses-mainnet");
6
+ const addresses_arbitrum_1 = require("../addresses-arbitrum");
7
+ const addresses_sei_1 = require("../addresses-sei");
8
+ const addresses_polkadot_1 = require("../addresses-polkadot");
9
+ function CreateUniswapV2HelperContract(chainId, web3) {
10
+ if (chainId === 1) {
11
+ return new web3.eth.Contract(UniswapV2HelperAbi_1.UniswapV2HelperAbi, addresses_mainnet_1.UNISWAP_V2_HELPER_ADDRESS);
12
+ }
13
+ else if (chainId === 1329) {
14
+ return new web3.eth.Contract(UniswapV2HelperAbi_1.UniswapV2HelperAbi, addresses_sei_1.UNISWAP_V2_HELPER_ADDRESS);
15
+ }
16
+ else if (chainId === 420420417) {
17
+ return new web3.eth.Contract(UniswapV2HelperAbi_1.UniswapV2HelperAbi, addresses_polkadot_1.UNISWAP_V2_HELPER_ADDRESS);
18
+ }
19
+ else {
20
+ return new web3.eth.Contract(UniswapV2HelperAbi_1.UniswapV2HelperAbi, addresses_arbitrum_1.UNISWAP_V2_HELPER_ADDRESS);
21
+ }
22
+ }
@@ -0,0 +1,9 @@
1
+ export declare const dexIds: {
2
+ SUSHI_V2: string;
3
+ UNI_V3: string;
4
+ CAMELOT: string;
5
+ BALANCER_V2: string;
6
+ UNI_V2: string;
7
+ };
8
+ export declare const balancerWeightedPoolTypes: string[];
9
+ export declare const balancerStablePoolTypes: string[];
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.balancerStablePoolTypes = exports.balancerWeightedPoolTypes = exports.dexIds = void 0;
4
+ exports.dexIds = {
5
+ SUSHI_V2: 'SUSHI_V2',
6
+ UNI_V3: 'UNI_V3',
7
+ CAMELOT: 'CAMELOT',
8
+ BALANCER_V2: 'BALANCER_V2',
9
+ UNI_V2: 'UNI_V2'
10
+ };
11
+ exports.balancerWeightedPoolTypes = ['Weighted', 'Managed', 'LiquidityBootstrapping'];
12
+ exports.balancerStablePoolTypes = ['Stable', 'MetaStable', 'ComposableStable'];
@@ -0,0 +1,14 @@
1
+ import { Pool, PoolInfo, DEXGraphFunctionality } from '../../utils/types/types';
2
+ import Web3 from 'web3';
3
+ export default class BalancerV2 implements DEXGraphFunctionality {
4
+ endpoint: string;
5
+ dexId: string;
6
+ chainId: number;
7
+ myLocalStorage: null;
8
+ static initialize(myLocalStorage: any): DEXGraphFunctionality;
9
+ setEndpoint(chainId: number, graphApiKey: string): void;
10
+ getTopPools(numPools: number): Promise<PoolInfo[]>;
11
+ getPoolsWithTokenPair(tokenA: string, tokenB: string, numPools: number): Promise<PoolInfo[]>;
12
+ getPoolsWithToken(token: string, numPools: number): Promise<PoolInfo[]>;
13
+ getAdditionalPoolDataFromSolidity(poolInfos: PoolInfo[], rpcProvider: Web3): Promise<Pool[]>;
14
+ }
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const graphql_request_1 = require("graphql-request");
5
+ const dexIdsList_1 = require("../dexIdsList");
6
+ const BalancerState_1 = require("../pools/Balancer/BalancerState");
7
+ class BalancerV2 {
8
+ constructor() {
9
+ this.endpoint = ``;
10
+ this.dexId = dexIdsList_1.dexIds.BALANCER_V2;
11
+ this.chainId = 1;
12
+ this.myLocalStorage = null;
13
+ }
14
+ static initialize(myLocalStorage) {
15
+ const object = new BalancerV2();
16
+ object.myLocalStorage = myLocalStorage;
17
+ return object;
18
+ }
19
+ setEndpoint(chainId, graphApiKey) {
20
+ if (chainId == 1) {
21
+ this.endpoint = `https://gateway-arbitrum.network.thegraph.com/api/${graphApiKey}/subgraphs/id/C4ayEZP2yTXRAB8vSaTrgN4m9anTe9Mdm2ViyiAuV9TV`;
22
+ }
23
+ if (chainId == 42161) {
24
+ this.endpoint = `https://gateway-arbitrum.network.thegraph.com/api/${graphApiKey}/subgraphs/id/itkjv6Vdh22HtNEPQuk5c9M3T7VeGLQtXxcH8rFi1vc`;
25
+ }
26
+ this.chainId = chainId;
27
+ }
28
+ async getTopPools(numPools) {
29
+ const poolsInfo = [];
30
+ const queryResult = await (0, graphql_request_1.request)(this.endpoint, queryTopPools(numPools));
31
+ queryResult.pools.forEach((pool) => {
32
+ try {
33
+ poolsInfo.push(createPoolFromGraph(pool, this.dexId));
34
+ }
35
+ catch (e) { }
36
+ });
37
+ return poolsInfo;
38
+ }
39
+ async getPoolsWithTokenPair(tokenA, tokenB, numPools) {
40
+ const poolsInfo = [];
41
+ const queryResult = await (0, graphql_request_1.request)(this.endpoint, queryPoolsWithTokenPair(tokenA, tokenB, numPools));
42
+ queryResult.pools.forEach((pool) => {
43
+ try {
44
+ poolsInfo.push(createPoolFromGraph(pool, this.dexId));
45
+ }
46
+ catch (e) { }
47
+ });
48
+ return poolsInfo;
49
+ }
50
+ async getPoolsWithToken(token, numPools) {
51
+ const poolsInfo = [];
52
+ const queryResult = await (0, graphql_request_1.request)(this.endpoint, queryPoolsWithToken(token, numPools));
53
+ queryResult.pools.forEach((pool) => {
54
+ try {
55
+ poolsInfo.push(createPoolFromGraph(pool, this.dexId));
56
+ }
57
+ catch (e) { }
58
+ });
59
+ return poolsInfo;
60
+ }
61
+ async getAdditionalPoolDataFromSolidity(poolInfos, rpcProvider) {
62
+ const pools = await BalancerState_1.BalancerState.getPoolDataFromContract(poolInfos, this.chainId, rpcProvider);
63
+ for (const pool of pools)
64
+ // @ts-ignore
65
+ this.myLocalStorage.setItem(pool.poolId.toLowerCase(), pool);
66
+ return pools;
67
+ }
68
+ }
69
+ exports.default = BalancerV2;
70
+ function queryTopPools(numPools) {
71
+ return (0, graphql_1.parse)((0, graphql_request_1.gql) `{
72
+ pools(first: ${numPools}, orderBy: totalLiquidity, orderDirection: desc, where: {totalLiquidity_not: "0"}) {
73
+ id
74
+ name
75
+ poolType
76
+ tokens {
77
+ id
78
+ decimals
79
+ name
80
+ }
81
+ }
82
+ }
83
+ `);
84
+ }
85
+ function queryPoolsWithTokenPair(tokenA, tokenB, numPools) {
86
+ return (0, graphql_1.parse)((0, graphql_request_1.gql) `{
87
+ pools(first: ${numPools}, orderBy: totalLiquidity, orderDirection: desc, where: {
88
+ and: [
89
+ {tokens_: {address: "${tokenA.toLowerCase()}"}},
90
+ {tokens_: {address: "${tokenB.toLowerCase()}"}},
91
+ {totalLiquidity_not: "0"}
92
+ ],
93
+ }
94
+ ) {
95
+ id
96
+ poolType
97
+ tokens {
98
+ id
99
+ decimals
100
+ name
101
+ }
102
+ }
103
+ }
104
+ `);
105
+ }
106
+ function queryPoolsWithToken(token, numPools) {
107
+ return (0, graphql_1.parse)((0, graphql_request_1.gql) `{
108
+ pools(first: ${numPools}, orderBy: totalLiquidity, orderDirection: desc, where:
109
+ {
110
+ tokens_: {address_contains: "${token.toLowerCase()}"},
111
+ totalLiquidity_not: "0"
112
+ }
113
+ ) {
114
+ id
115
+ poolType
116
+ tokens {
117
+ id
118
+ decimals
119
+ name
120
+ }
121
+ }
122
+ }
123
+ `);
124
+ }
125
+ function createPoolFromGraph(jsonData, dexId) {
126
+ const isWeighted = dexIdsList_1.balancerWeightedPoolTypes.includes(jsonData.poolType);
127
+ if (!isWeighted)
128
+ throw new Error('BALANCER: Pool type not supported');
129
+ const pool = {
130
+ poolId: jsonData.id,
131
+ dexId: dexId,
132
+ tokens: jsonData.tokens.map((token) => {
133
+ return {
134
+ _address: token.id,
135
+ decimals: token.decimals,
136
+ name: token.name,
137
+ };
138
+ }),
139
+ };
140
+ return pool;
141
+ }
@@ -0,0 +1,14 @@
1
+ import { Pool, PoolInfo, DEXGraphFunctionality } from '../../utils/types/types';
2
+ import Web3 from 'web3';
3
+ export default class CamelotV2 implements DEXGraphFunctionality {
4
+ endpoint: string;
5
+ dexId: string;
6
+ chainId: number;
7
+ myLocalStorage: null;
8
+ static initialize(myLocalStorage: any): DEXGraphFunctionality;
9
+ setEndpoint(chainId: number, graphApiKey: string): void;
10
+ getTopPools(numPools: number): Promise<PoolInfo[]>;
11
+ getPoolsWithTokenPair(token1: string, token2: string, first: number): Promise<PoolInfo[]>;
12
+ getPoolsWithToken(token: string, numPools: number): Promise<PoolInfo[]>;
13
+ getAdditionalPoolDataFromSolidity(poolInfos: PoolInfo[], rpcProvider: Web3): Promise<Pool[]>;
14
+ }