@agentek/tools
Version:
Blockchain tools for AI agents
70 lines • 2.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAcrossFeeQuote = void 0;
const client_js_1 = require("../client.js");
const zod_1 = require("zod");
const chains_1 = require("viem/chains");
const viem_1 = require("viem");
/**
* It calls the endpoint at:
* https://across.to/api/suggested-fees
*/
exports.getAcrossFeeQuote = (0, client_js_1.createTool)({
name: "getAcrossFeeQuote",
description: "Fetches a suggested fee quote for a cross-chain asset bridge using the Across Protocol REST API.",
parameters: zod_1.z.object({
inputToken: zod_1.z
.string()
.describe("The token contract address on the origin chain (e.g., WETH address)."),
outputToken: zod_1.z
.string()
.describe("The token contract address on the destination chain (e.g., corresponding WETH address)."),
originChainId: zod_1.z
.number()
.describe("Chain ID where the input token exists."),
destinationChainId: zod_1.z
.number()
.describe("Chain ID of the destination chain."),
amount: zod_1.z.string().describe("Amount of tokens to bridge (in ether)"),
recipient: zod_1.z
.string()
.describe("Recipient address on the destination chain."),
}),
supportedChains: [chains_1.mainnet, chains_1.polygon, chains_1.arbitrum, chains_1.optimism, chains_1.base],
async execute(client, args) {
const publicClient = client.getPublicClient(args.originChainId);
const decimals = await publicClient.readContract({
address: args.inputToken,
abi: viem_1.erc20Abi,
functionName: "decimals",
});
const queryParams = new URLSearchParams({
inputToken: args.inputToken,
outputToken: args.outputToken,
originChainId: args.originChainId.toString(),
destinationChainId: args.destinationChainId.toString(),
amount: (0, viem_1.parseUnits)(args.amount, decimals).toString(),
});
if (args.recipient)
queryParams.append("recipient", args.recipient);
const apiUrl = `https://across.to/api/suggested-fees?${queryParams.toString()}`;
try {
const response = await fetch(apiUrl, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Across REST API error: ${response.status} ${response.statusText} - ${errorText}`);
}
const result = await response.json();
return result;
}
catch (err) {
throw new Error(`Across fee quote retrieval failed: ${err.message}`);
}
},
});
//# sourceMappingURL=tools.js.map