-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathroute.ts
43 lines (40 loc) · 1.38 KB
/
route.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// import { Router as FibrousRouter } from "fibrous-router-sdk";
import { Router as FibrousRouter } from "../../../src";
import { parseUnits } from "ethers";
import { BigNumber } from "@ethersproject/bignumber";
async function main() {
// Create a new router instance
const fibrous = new FibrousRouter();
// Build route options
const tokens = await fibrous.supportedTokens("scroll");
try {
/**
* recommended that use the token address directly
* because there may be more than one token with the same symbol.
*/
const tokenInAddress = tokens.get("usdt")?.address;
const tokenOutAddress = tokens.get("usdc")?.address;
const tokenInDecimals = Number(tokens.get("usdt")?.decimals);
if (!tokenInAddress || !tokenOutAddress || !tokenInDecimals) {
throw new Error("Token not found");
}
const inputAmount = BigNumber.from(parseUnits("5", tokenInDecimals));
const reverse = false;
// Converting 5 USDT to USDC
const route = await fibrous.getBestRoute(
inputAmount,
tokenInAddress,
tokenOutAddress,
"scroll",
{
reverse,
},
);
console.log("route", route);
} catch (error) {
console.error(error);
}
}
main().catch((e) => {
console.error("Error: ", e);
});