@coinbase/agentkit
Version:
Coinbase AgentKit core primitives
58 lines (57 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchVaults = fetchVaults;
exports.fetchVault = fetchVault;
const utils_1 = require("../utils");
const constants_1 = require("../constants");
/**
* Fetches a list of vaults from the vaultsfyi API.
*
* @param args - The action parameters
* @param apiKey - The vaultsfyi API key
* @returns The list of vaults
*/
async function fetchVaults(args, apiKey) {
const vaults = [];
const params = (0, utils_1.createSearchParams)({
per_page: 250,
token: args.token,
network: args.network,
tvl_min: args.minTvl ?? 100000,
transactionalOnly: true,
});
for (let i = 0; i < 10; i++) {
const response = await fetch(`${constants_1.VAULTS_API_URL}/detailed/vaults?${params}`, {
method: "GET",
headers: {
"x-api-key": apiKey,
},
});
const data = (await response.json());
if ("error" in data)
return data;
vaults.push(...data.data);
if (!data.next_page)
break;
else
params.set("page", data.next_page);
}
return vaults;
}
/**
* Fetches the details of a specific vault from the vaultsfyi API.
*
* @param args - The action parameters
* @param apiKey - The vaultsfyi API key
* @returns The vault details
*/
async function fetchVault(args, apiKey) {
const response = await fetch(`${constants_1.VAULTS_API_URL}/vaults/${args.network}/${args.vaultAddress}`, {
method: "GET",
headers: {
"x-api-key": apiKey,
},
});
const data = (await response.json());
return data;
}