routing-finder-lane 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.
- package/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/php.xml +19 -0
- package/.idea/ratex-sdk.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE-MIT +21 -0
- package/README.md +209 -0
- package/contracts/abi/BalancerHelperAbi.ts +1 -0
- package/contracts/abi/CamelotHelperAbi.ts +1 -0
- package/contracts/abi/RateXAbi.ts +482 -0
- package/contracts/abi/SushiSwapHelperAbi.ts +1 -0
- package/contracts/abi/UniswapHelperAbi.ts +1 -0
- package/contracts/abi/UniswapV2HelperAbi.ts +1 -0
- package/contracts/addresses-arbitrum.ts +8 -0
- package/contracts/addresses-mainnet.ts +7 -0
- package/contracts/addresses-polkadot.ts +9 -0
- package/contracts/addresses-sei.ts +9 -0
- package/contracts/rateX/BalancerHelper.ts +13 -0
- package/contracts/rateX/CamelotHelper.ts +13 -0
- package/contracts/rateX/SushiSwapHelper.ts +13 -0
- package/contracts/rateX/UniswapHelper.ts +19 -0
- package/contracts/rateX/UniswapV2Helper.ts +19 -0
- package/dexes/dexIdsList.ts +9 -0
- package/dexes/graph_queries/BalancerV2.ts +150 -0
- package/dexes/graph_queries/CamelotV2.ts +202 -0
- package/dexes/graph_queries/SushiSwapV2.ts +283 -0
- package/dexes/graph_queries/UniswapV2.ts +214 -0
- package/dexes/graph_queries/UniswapV3.ts +182 -0
- package/dexes/graph_queries/x_template.ts +67 -0
- package/dexes/pools/Balancer/BalancerState.ts +34 -0
- package/dexes/pools/Balancer/BalancerWeightedPool.ts +96 -0
- package/dexes/pools/Camelot.ts +164 -0
- package/dexes/pools/SushiSwapV2.ts +35 -0
- package/dexes/pools/UniswapV2.ts +36 -0
- package/dexes/pools/uniswap/UniswapV3.ts +40 -0
- package/dexes/pools/uniswap/testUniswapOffchainQuoter.ts +169 -0
- package/dexes/pools/uniswap/types.ts +174 -0
- package/dexes/pools/uniswap/uniswapOffchainQuoter.ts +173 -0
- package/dexes/pools/uniswap/uniswapState.ts +56 -0
- package/dexes/pools/uniswap/utils.ts +71 -0
- package/dist/contracts/abi/BalancerHelperAbi.d.ts +25 -0
- package/dist/contracts/abi/BalancerHelperAbi.js +4 -0
- package/dist/contracts/abi/CamelotHelperAbi.d.ts +45 -0
- package/dist/contracts/abi/CamelotHelperAbi.js +4 -0
- package/dist/contracts/abi/RateXAbi.d.ts +71 -0
- package/dist/contracts/abi/RateXAbi.js +485 -0
- package/dist/contracts/abi/SushiSwapHelperAbi.d.ts +45 -0
- package/dist/contracts/abi/SushiSwapHelperAbi.js +4 -0
- package/dist/contracts/abi/UniswapHelperAbi.d.ts +39 -0
- package/dist/contracts/abi/UniswapHelperAbi.js +4 -0
- package/dist/contracts/abi/UniswapV2HelperAbi.d.ts +45 -0
- package/dist/contracts/abi/UniswapV2HelperAbi.js +4 -0
- package/dist/contracts/addresses-arbitrum.d.ts +6 -0
- package/dist/contracts/addresses-arbitrum.js +10 -0
- package/dist/contracts/addresses-mainnet.d.ts +6 -0
- package/dist/contracts/addresses-mainnet.js +10 -0
- package/dist/contracts/addresses-polkadot.d.ts +6 -0
- package/dist/contracts/addresses-polkadot.js +10 -0
- package/dist/contracts/addresses-sei.d.ts +6 -0
- package/dist/contracts/addresses-sei.js +10 -0
- package/dist/contracts/rateX/BalancerHelper.d.ts +26 -0
- package/dist/contracts/rateX/BalancerHelper.js +14 -0
- package/dist/contracts/rateX/CamelotHelper.d.ts +46 -0
- package/dist/contracts/rateX/CamelotHelper.js +14 -0
- package/dist/contracts/rateX/SushiSwapHelper.d.ts +46 -0
- package/dist/contracts/rateX/SushiSwapHelper.js +14 -0
- package/dist/contracts/rateX/UniswapHelper.d.ts +40 -0
- package/dist/contracts/rateX/UniswapHelper.js +22 -0
- package/dist/contracts/rateX/UniswapV2Helper.d.ts +46 -0
- package/dist/contracts/rateX/UniswapV2Helper.js +22 -0
- package/dist/dexes/dexIdsList.d.ts +9 -0
- package/dist/dexes/dexIdsList.js +12 -0
- package/dist/dexes/graph_queries/BalancerV2.d.ts +14 -0
- package/dist/dexes/graph_queries/BalancerV2.js +141 -0
- package/dist/dexes/graph_queries/CamelotV2.d.ts +14 -0
- package/dist/dexes/graph_queries/CamelotV2.js +183 -0
- package/dist/dexes/graph_queries/SushiSwapV2.d.ts +14 -0
- package/dist/dexes/graph_queries/SushiSwapV2.js +263 -0
- package/dist/dexes/graph_queries/UniswapV2.d.ts +14 -0
- package/dist/dexes/graph_queries/UniswapV2.js +184 -0
- package/dist/dexes/graph_queries/UniswapV3.d.ts +14 -0
- package/dist/dexes/graph_queries/UniswapV3.js +164 -0
- package/dist/dexes/graph_queries/x_template.d.ts +12 -0
- package/dist/dexes/graph_queries/x_template.js +57 -0
- package/dist/dexes/pools/Balancer/BalancerState.d.ts +6 -0
- package/dist/dexes/pools/Balancer/BalancerState.js +32 -0
- package/dist/dexes/pools/Balancer/BalancerWeightedPool.d.ts +12 -0
- package/dist/dexes/pools/Balancer/BalancerWeightedPool.js +109 -0
- package/dist/dexes/pools/Camelot.d.ts +12 -0
- package/dist/dexes/pools/Camelot.js +135 -0
- package/dist/dexes/pools/SushiSwapV2.d.ts +9 -0
- package/dist/dexes/pools/SushiSwapV2.js +34 -0
- package/dist/dexes/pools/UniswapV2.d.ts +9 -0
- package/dist/dexes/pools/UniswapV2.js +34 -0
- package/dist/dexes/pools/uniswap/UniswapV3.d.ts +7 -0
- package/dist/dexes/pools/uniswap/UniswapV3.js +36 -0
- package/dist/dexes/pools/uniswap/types.d.ts +76 -0
- package/dist/dexes/pools/uniswap/types.js +111 -0
- package/dist/dexes/pools/uniswap/uniswapOffchainQuoter.d.ts +13 -0
- package/dist/dexes/pools/uniswap/uniswapOffchainQuoter.js +121 -0
- package/dist/dexes/pools/uniswap/uniswapState.d.ts +14 -0
- package/dist/dexes/pools/uniswap/uniswapState.js +51 -0
- package/dist/dexes/pools/uniswap/utils.d.ts +3 -0
- package/dist/dexes/pools/uniswap/utils.js +41 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +41 -0
- package/dist/routes.d.ts +1 -0
- package/dist/routes.js +20 -0
- package/dist/routing/iterative_spliting/main.d.ts +3 -0
- package/dist/routing/iterative_spliting/main.js +104 -0
- package/dist/routing/iterative_spliting/multiHopSwap.d.ts +4 -0
- package/dist/routing/iterative_spliting/multiHopSwap.js +83 -0
- package/dist/routing/main.d.ts +2 -0
- package/dist/routing/main.js +22 -0
- package/dist/routing/uni_like_algo/algo_config.d.ts +2 -0
- package/dist/routing/uni_like_algo/algo_config.js +8 -0
- package/dist/routing/uni_like_algo/amount_distribution.d.ts +2 -0
- package/dist/routing/uni_like_algo/amount_distribution.js +17 -0
- package/dist/routing/uni_like_algo/compute_routes_backtrack.d.ts +3 -0
- package/dist/routing/uni_like_algo/compute_routes_backtrack.js +44 -0
- package/dist/routing/uni_like_algo/main.d.ts +2 -0
- package/dist/routing/uni_like_algo/main.js +49 -0
- package/dist/routing/uni_like_algo/routes_quoter.d.ts +21 -0
- package/dist/routing/uni_like_algo/routes_quoter.js +53 -0
- package/dist/routing/uni_like_algo/swap_finder.d.ts +25 -0
- package/dist/routing/uni_like_algo/swap_finder.js +154 -0
- package/dist/routing/uni_like_algo/types.d.ts +40 -0
- package/dist/routing/uni_like_algo/types.js +12 -0
- package/dist/swap/graph_communication.d.ts +5 -0
- package/dist/swap/graph_communication.js +187 -0
- package/dist/swap/my_local_storage.d.ts +8 -0
- package/dist/swap/my_local_storage.js +16 -0
- package/dist/utils/addresses.d.ts +24 -0
- package/dist/utils/addresses.js +60 -0
- package/dist/utils/math/fixed-points.d.ts +14 -0
- package/dist/utils/math/fixed-points.js +123 -0
- package/dist/utils/math/log-exp.d.ts +5 -0
- package/dist/utils/math/log-exp.js +385 -0
- package/dist/utils/math/math.d.ts +12 -0
- package/dist/utils/math/math.js +50 -0
- package/dist/utils/types/types.d.ts +51 -0
- package/dist/utils/types/types.js +25 -0
- package/dist/utils/utils.d.ts +20 -0
- package/dist/utils/utils.js +72 -0
- package/images/decenter_logo.png +0 -0
- package/index.ts +50 -0
- package/package.json +41 -0
- package/routes.ts +28 -0
- package/routing/iterative_spliting/main.ts +131 -0
- package/routing/iterative_spliting/multiHopSwap.ts +98 -0
- package/routing/main.ts +22 -0
- package/routing/uni_like_algo/algo_config.ts +7 -0
- package/routing/uni_like_algo/amount_distribution.ts +16 -0
- package/routing/uni_like_algo/compute_routes_backtrack.ts +81 -0
- package/routing/uni_like_algo/main.ts +65 -0
- package/routing/uni_like_algo/routes_quoter.ts +63 -0
- package/routing/uni_like_algo/swap_finder.ts +185 -0
- package/routing/uni_like_algo/types.ts +54 -0
- package/swap/graph_communication.ts +212 -0
- package/swap/my_local_storage.ts +27 -0
- package/tsconfig.json +26 -0
- package/utils/addresses.ts +64 -0
- package/utils/math/fixed-points.ts +88 -0
- package/utils/math/log-exp.ts +469 -0
- package/utils/math/math.ts +46 -0
- package/utils/types/types.ts +100 -0
- package/utils/utils.ts +125 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/ratex-sdk.iml" filepath="$PROJECT_DIR$/.idea/ratex-sdk.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/php.xml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="MessDetectorOptionsConfiguration">
|
|
4
|
+
<option name="transferred" value="true" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="PHPCSFixerOptionsConfiguration">
|
|
7
|
+
<option name="transferred" value="true" />
|
|
8
|
+
</component>
|
|
9
|
+
<component name="PHPCodeSnifferOptionsConfiguration">
|
|
10
|
+
<option name="highlightLevel" value="WARNING" />
|
|
11
|
+
<option name="transferred" value="true" />
|
|
12
|
+
</component>
|
|
13
|
+
<component name="PhpStanOptionsConfiguration">
|
|
14
|
+
<option name="transferred" value="true" />
|
|
15
|
+
</component>
|
|
16
|
+
<component name="PsalmOptionsConfiguration">
|
|
17
|
+
<option name="transferred" value="true" />
|
|
18
|
+
</component>
|
|
19
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$" />
|
|
5
|
+
<orderEntry type="inheritedJdk" />
|
|
6
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
+
</component>
|
|
8
|
+
</module>
|
package/.idea/vcs.xml
ADDED
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 DecenterApps
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# 💡 RateX SDK
|
|
2
|
+
|
|
3
|
+
<div style='flex: 0.2; align="center"'>
|
|
4
|
+
<img src="https://raw.githubusercontent.com/DecenterApps/RateX/main/images/decenter_logo.png" alt="Decenter Logo" style="max-width: 100%;" />
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
## 🌟 Introduction
|
|
8
|
+
|
|
9
|
+
RateX SDK is a tool for developers to seamlessly integrate DEX aggregation functionality into their applications on Ethereum and Arbitrum. This open-source SDK helps you find optimal swap routes across multiple decentralized exchanges, offering competitive rates without taking positive slippage or fees. With RateX SDK, you can fetch quotes and generate transaction data for executing swaps through our smart contracts, while ensuring transparency and control over the routing process.
|
|
10
|
+
|
|
11
|
+
### Why are we making this?
|
|
12
|
+
|
|
13
|
+
Current DEX aggregators may not charge fees but often take positive slippage, which is the difference between the expected price and the actual execution price of a trade. Additionally, their routing algorithms are typically closed source, leaving users vulnerable if these services start charging fees.
|
|
14
|
+
|
|
15
|
+
Our goal is to create a competitive alternative by:
|
|
16
|
+
|
|
17
|
+
- Not taking positive slippage or fees
|
|
18
|
+
- Making our routing algorithm open source
|
|
19
|
+
- Running the code (SDK) directly on the user's machine (in browser), rather than on a server
|
|
20
|
+
|
|
21
|
+
## ✨ Features
|
|
22
|
+
|
|
23
|
+
- 🔍 **Best route finding** across multiple DEXes
|
|
24
|
+
- 💰 **No fees or positive slippage** taken
|
|
25
|
+
- 🖥️ **Client-side execution** instead of servers
|
|
26
|
+
- 🔓 **Open-source routing algorithm**
|
|
27
|
+
- ⚡ **Support for Arbitrum and Ethereum networks**
|
|
28
|
+
|
|
29
|
+
## 🛠️ Supported DEXes
|
|
30
|
+
|
|
31
|
+
| DEX | Supported |
|
|
32
|
+
| ------------------------- | :-------: |
|
|
33
|
+
| Uniswap V2 | ✅ |
|
|
34
|
+
| Uniswap V3 | ✅ |
|
|
35
|
+
| Sushiswap V2 | ✅ |
|
|
36
|
+
| Balancer (weighted pools) | ✅ |
|
|
37
|
+
| Camelot | ✅ |
|
|
38
|
+
|
|
39
|
+
## 🌐 RateX Contracts
|
|
40
|
+
|
|
41
|
+
| Contract Name | Ethereum ⚫ | Arbitrum 🔵 |
|
|
42
|
+
| ----------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| RateX | [0xAC64cF5B37124e62Ad716e664faF711Bd0882056](https://etherscan.io/address/0xAC64cF5B37124e62Ad716e664faF711Bd0882056) | [0x1D3ac829f8b0056972491095342730710e956629](https://arbiscan.io/address/0x1D3ac829f8b0056972491095342730710e956629) |
|
|
44
|
+
| Uniswap Helper | [0xBFA0CAC4e1FC4958Ef24732F5b1e063637D20704](https://etherscan.io/address/0xBFA0CAC4e1FC4958Ef24732F5b1e063637D20704) | [0xBf70F85011047C4cF31696780BdB6db752527d7c](https://arbiscan.io/address/0xBf70F85011047C4cF31696780BdB6db752527d7c) |
|
|
45
|
+
| Sushiswap Helper | [0xAc62F8Ff99B1fEa563Cf8D47Ce1B9fE76F3AC5b8](https://etherscan.io/address/0xAc62F8Ff99B1fEa563Cf8D47Ce1B9fE76F3AC5b8) | [0x141fc598Ed85a23e78f2b58ABe95AC013d196249](https://arbiscan.io/address/0x141fc598Ed85a23e78f2b58ABe95AC013d196249) |
|
|
46
|
+
| Balancer Helper | [0xf77f3E6ed19DAFe90f90c3C1609207902C7414f9](https://etherscan.io/address/0xf77f3E6ed19DAFe90f90c3C1609207902C7414f9) | [0xd1dFeDe71160a0a1e869e2D3F428A47531726BfE](https://arbiscan.io/address/0xd1dFeDe71160a0a1e869e2D3F428A47531726BfE) |
|
|
47
|
+
| Uniswap V2 Helper | [0x043EEB82faC75641146955Fea5509C824b2AD22A](https://etherscan.io/address/0x043EEB82faC75641146955Fea5509C824b2AD22A) | [0x24725a85903e83A4829F51287B8E0BD321121DbC](https://arbiscan.io/address/0x24725a85903e83A4829F51287B8E0BD321121DbC) |
|
|
48
|
+
| Camelot Helper | N/A | [0x91DE0353a4f93BD460dE3a373Feb50c53571c078](https://arbiscan.io/address/0x91DE0353a4f93BD460dE3a373Feb50c53571c078) |
|
|
49
|
+
|
|
50
|
+
Note: Camelot Helper is not available on Ethereum mainnet.
|
|
51
|
+
|
|
52
|
+
## Requirements
|
|
53
|
+
|
|
54
|
+
Before you begin, ensure you have the following tools installed:
|
|
55
|
+
|
|
56
|
+
- [Node.js (>= v18)](https://nodejs.org/en/download/)
|
|
57
|
+
|
|
58
|
+
## 📦 Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npm install ratex-sdk
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
or with yarn
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
yarn add ratex-sdk
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🚀 Quick Start
|
|
71
|
+
|
|
72
|
+
### JavaScript
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
const { RateX, Dexes } = require("ratex-sdk");
|
|
76
|
+
|
|
77
|
+
async function main() {
|
|
78
|
+
const rateX = new RateX({
|
|
79
|
+
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
|
80
|
+
chainId: 42161,
|
|
81
|
+
dexes: [Dexes.UNISWAP_V2, Dexes.UNISWAP_V3],
|
|
82
|
+
graphApiKey: "YOUR_GRAPH_API_KEY",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const tokenIn = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; // WETH
|
|
86
|
+
const tokenOut = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; // DAI
|
|
87
|
+
const amountIn = BigInt("1000000000000000000"); // 1 WETH
|
|
88
|
+
|
|
89
|
+
const quote = await rateX.getQuote(tokenIn, tokenOut, amountIn);
|
|
90
|
+
console.log("Best quote:", quote);
|
|
91
|
+
|
|
92
|
+
const swapParams = await rateX.getSwapParameters(
|
|
93
|
+
tokenIn,
|
|
94
|
+
tokenOut,
|
|
95
|
+
amountIn,
|
|
96
|
+
1, // 1% slippage
|
|
97
|
+
"0xYourAddress",
|
|
98
|
+
30 // 30 minutes deadline
|
|
99
|
+
);
|
|
100
|
+
console.log("Swap parameters:", swapParams);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
main().catch(console.error);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### TypeScript
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { RateX, Dexes } from "ratex-sdk";
|
|
110
|
+
|
|
111
|
+
async function main() {
|
|
112
|
+
const rateX = new RateX({
|
|
113
|
+
rpcUrl: "https://arb1.arbitrum.io/rpc",
|
|
114
|
+
chainId: 42161,
|
|
115
|
+
dexes: [Dexes.UNISWAP_V2, Dexes.UNISWAP_V3],
|
|
116
|
+
graphApiKey: "YOUR_GRAPH_API_KEY",
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const tokenIn: string = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"; // WETH
|
|
120
|
+
const tokenOut: string = "0x6B175474E89094C44Da98b954EedeAC495271d0F"; // DAI
|
|
121
|
+
const amountIn: bigint = BigInt("1000000000000000000"); // 1 WETH
|
|
122
|
+
|
|
123
|
+
const quote = await rateX.getQuote(tokenIn, tokenOut, amountIn);
|
|
124
|
+
console.log("Best quote:", quote);
|
|
125
|
+
|
|
126
|
+
const swapParams = await rateX.getSwapParameters(
|
|
127
|
+
tokenIn,
|
|
128
|
+
tokenOut,
|
|
129
|
+
amountIn,
|
|
130
|
+
1, // 1% slippage
|
|
131
|
+
"0xYourAddress",
|
|
132
|
+
30 // 30 minutes deadline
|
|
133
|
+
);
|
|
134
|
+
console.log("Swap parameters:", swapParams);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
main().catch(console.error);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 📚 API Reference
|
|
141
|
+
|
|
142
|
+
### `RateX`
|
|
143
|
+
|
|
144
|
+
#### Constructor
|
|
145
|
+
|
|
146
|
+
```javascript
|
|
147
|
+
new RateX(config: RateXConfig)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
- `config.rpcUrl`: RPC URL for the Arbitrum network
|
|
151
|
+
- `config.chainId`: Chain ID (42161 for Arbitrum One)
|
|
152
|
+
- `config.dexes`: Array of DEXes to include in routing (optional)
|
|
153
|
+
- `config.graphApiKey`: Your Graph API key
|
|
154
|
+
|
|
155
|
+
#### Methods
|
|
156
|
+
|
|
157
|
+
##### `getQuote`
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
async getQuote(tokenIn: string, tokenOut: string, amountIn: bigint): Promise<Quote>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Finds the best swap route and returns a quote.
|
|
164
|
+
|
|
165
|
+
##### `getSwapCalldata`
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
async getSwapCalldata(
|
|
169
|
+
tokenIn: string,
|
|
170
|
+
tokenOut: string,
|
|
171
|
+
amountIn: bigint,
|
|
172
|
+
slippagePercentage: number,
|
|
173
|
+
recipient: string,
|
|
174
|
+
deadlineInMinutes: number
|
|
175
|
+
): Promise<string>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Generates the calldata for executing the swap.
|
|
179
|
+
|
|
180
|
+
##### `getSwapParameters`
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
async getSwapParameters(
|
|
184
|
+
tokenIn: string,
|
|
185
|
+
tokenOut: string,
|
|
186
|
+
amountIn: bigint,
|
|
187
|
+
slippagePercentage: number,
|
|
188
|
+
recipient: string,
|
|
189
|
+
deadlineInMinutes: number
|
|
190
|
+
): Promise<SwapParams>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Prepares the parameters for calling the RateX contract.
|
|
194
|
+
|
|
195
|
+
## 📄 License
|
|
196
|
+
|
|
197
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE-MIT) file for details.
|
|
198
|
+
|
|
199
|
+
## 🙏 Acknowledgements
|
|
200
|
+
|
|
201
|
+
Special thanks to [Decenter](https://www.decenter.com/) internship teams for supporting this project and all the contributors who made this possible.
|
|
202
|
+
|
|
203
|
+
## 📬 Contact
|
|
204
|
+
|
|
205
|
+
For any questions or support, please open an issue on our [GitHub repository](https://github.com/your-repo-link).
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
Built with ❤️ by the RateX team
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const BalancerHelperAbi = [{"inputs":[{"internalType":"address","name":"_balancerVault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32","name":"_poolId","type":"bytes32"}],"name":"getWeightedPoolInfo","outputs":[{"internalType":"uint8","name":"decimals","type":"uint8"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"uint256[]","name":"balances","type":"uint256[]"},{"internalType":"uint256[]","name":"weights","type":"uint256[]"},{"internalType":"uint256","name":"feePercentage","type":"uint256"}],"stateMutability":"view","type":"function"}]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CamelotHelperAbi = [{"inputs":[{"components":[{"internalType":"address","name":"poolId","type":"address"},{"internalType":"string","name":"dexId","type":"string"},{"components":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"decimals","type":"uint256"}],"internalType":"struct IHelperState.Token[]","name":"tokens","type":"tuple[]"}],"internalType":"struct IHelperState.PoolInfo[]","name":"poolsInfo","type":"tuple[]"}],"name":"getPoolsData","outputs":[{"components":[{"internalType":"address","name":"poolId","type":"address"},{"internalType":"string","name":"dexId","type":"string"},{"components":[{"internalType":"address","name":"_address","type":"address"},{"internalType":"uint256","name":"decimals","type":"uint256"}],"internalType":"struct IHelperState.Token[]","name":"tokens","type":"tuple[]"},{"internalType":"uint112[2]","name":"reserves","type":"uint112[2]"},{"internalType":"uint16[2]","name":"fees","type":"uint16[2]"},{"internalType":"bool","name":"stableSwap","type":"bool"}],"internalType":"struct CamelotHelper.CamelotPool[]","name":"pools","type":"tuple[]"}],"stateMutability":"view","type":"function"}]
|