@coinbase/agentkit 0.6.1 → 0.6.2
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/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/vaultsfyi/api/actions.d.ts +41 -0
- package/dist/action-providers/vaultsfyi/api/actions.js +28 -0
- package/dist/action-providers/vaultsfyi/api/types.d.ts +34 -0
- package/dist/action-providers/vaultsfyi/api/types.js +2 -0
- package/dist/action-providers/vaultsfyi/api/vaults.d.ts +38 -0
- package/dist/action-providers/vaultsfyi/api/vaults.js +39 -0
- package/dist/action-providers/vaultsfyi/constants.d.ts +12 -0
- package/dist/action-providers/vaultsfyi/constants.js +15 -0
- package/dist/action-providers/vaultsfyi/index.d.ts +7 -0
- package/dist/action-providers/vaultsfyi/index.js +23 -0
- package/dist/action-providers/vaultsfyi/schemas.d.ts +94 -0
- package/dist/action-providers/vaultsfyi/schemas.js +49 -0
- package/dist/action-providers/vaultsfyi/utils.d.ts +34 -0
- package/dist/action-providers/vaultsfyi/utils.js +69 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.d.ts +98 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.js +383 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.d.ts +1 -0
- package/dist/action-providers/vaultsfyi/vaultsfyiActionProvider.test.js +438 -0
- package/package.json +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { claimActionSchema, depositActionSchema, redeemActionSchema } from "../schemas";
|
|
3
|
+
import { ApiError } from "./types";
|
|
4
|
+
import { Address, Hex } from "viem";
|
|
5
|
+
type FetchVaultActionsParams = ({
|
|
6
|
+
action: "deposit";
|
|
7
|
+
args: z.infer<typeof depositActionSchema>;
|
|
8
|
+
} | {
|
|
9
|
+
action: "redeem";
|
|
10
|
+
args: z.infer<typeof redeemActionSchema>;
|
|
11
|
+
} | {
|
|
12
|
+
action: "claim-rewards";
|
|
13
|
+
args: z.infer<typeof claimActionSchema>;
|
|
14
|
+
}) & {
|
|
15
|
+
sender: string;
|
|
16
|
+
apiKey: string;
|
|
17
|
+
};
|
|
18
|
+
export type Actions = {
|
|
19
|
+
actions: {
|
|
20
|
+
tx: {
|
|
21
|
+
to: Address;
|
|
22
|
+
data: Hex;
|
|
23
|
+
value: string;
|
|
24
|
+
chainId: number;
|
|
25
|
+
};
|
|
26
|
+
description: string;
|
|
27
|
+
}[];
|
|
28
|
+
currentActionIndex: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Fetches a list of actions for a vault from the vaultsfyi API.
|
|
32
|
+
*
|
|
33
|
+
* @param root0 - The fetch parameters
|
|
34
|
+
* @param root0.action - The action to fetch
|
|
35
|
+
* @param root0.args - The action parameters
|
|
36
|
+
* @param root0.sender - The sender address
|
|
37
|
+
* @param root0.apiKey - The vaultsfyi API key
|
|
38
|
+
* @returns The list of actions
|
|
39
|
+
*/
|
|
40
|
+
export declare function fetchVaultActions({ action, args, sender, apiKey, }: FetchVaultActionsParams): Promise<Actions | ApiError>;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchVaultActions = fetchVaultActions;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a list of actions for a vault from the vaultsfyi API.
|
|
8
|
+
*
|
|
9
|
+
* @param root0 - The fetch parameters
|
|
10
|
+
* @param root0.action - The action to fetch
|
|
11
|
+
* @param root0.args - The action parameters
|
|
12
|
+
* @param root0.sender - The sender address
|
|
13
|
+
* @param root0.apiKey - The vaultsfyi API key
|
|
14
|
+
* @returns The list of actions
|
|
15
|
+
*/
|
|
16
|
+
async function fetchVaultActions({ action, args, sender, apiKey, }) {
|
|
17
|
+
const params = (0, utils_1.createSearchParams)({
|
|
18
|
+
...args,
|
|
19
|
+
sender,
|
|
20
|
+
});
|
|
21
|
+
const response = await fetch(`${constants_1.VAULTS_API_URL}/transactions/vaults/${action}?${params}`, {
|
|
22
|
+
method: "GET",
|
|
23
|
+
headers: {
|
|
24
|
+
"x-api-key": apiKey,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return (await response.json());
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type ApiError = {
|
|
2
|
+
statusCode: number;
|
|
3
|
+
error: string;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
export type Balances = {
|
|
7
|
+
[network: string]: {
|
|
8
|
+
address: string;
|
|
9
|
+
name: string;
|
|
10
|
+
symbol: string;
|
|
11
|
+
balance: string;
|
|
12
|
+
decimals: number;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
export type Positions = {
|
|
16
|
+
[network: string]: {
|
|
17
|
+
vaultName: string;
|
|
18
|
+
vaultAddress: string;
|
|
19
|
+
asset: {
|
|
20
|
+
assetAddress: string;
|
|
21
|
+
name: string;
|
|
22
|
+
symbol: string;
|
|
23
|
+
decimals: number;
|
|
24
|
+
};
|
|
25
|
+
balanceNative: string;
|
|
26
|
+
balanceLp: string;
|
|
27
|
+
unclaimedUsd: string;
|
|
28
|
+
apy: {
|
|
29
|
+
base: number;
|
|
30
|
+
rewards: number;
|
|
31
|
+
total: number;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { VaultsActionSchema } from "../schemas";
|
|
3
|
+
import { ApiError } from "./types";
|
|
4
|
+
export type ApiVault = {
|
|
5
|
+
name: string;
|
|
6
|
+
address: string;
|
|
7
|
+
network: string;
|
|
8
|
+
protocol: string;
|
|
9
|
+
tvlDetails: {
|
|
10
|
+
tvlUsd: string;
|
|
11
|
+
};
|
|
12
|
+
token: {
|
|
13
|
+
name: string;
|
|
14
|
+
assetAddress: string;
|
|
15
|
+
symbol: string;
|
|
16
|
+
decimals: number;
|
|
17
|
+
};
|
|
18
|
+
apy: {
|
|
19
|
+
base: {
|
|
20
|
+
"7day": number;
|
|
21
|
+
};
|
|
22
|
+
rewards: {
|
|
23
|
+
"7day": number;
|
|
24
|
+
};
|
|
25
|
+
total: {
|
|
26
|
+
"7day": number;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
isTransactional: boolean;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Fetches a list of vaults from the vaultsfyi API.
|
|
33
|
+
*
|
|
34
|
+
* @param args - The action parameters
|
|
35
|
+
* @param apiKey - The vaultsfyi API key
|
|
36
|
+
* @returns The list of vaults
|
|
37
|
+
*/
|
|
38
|
+
export declare function fetchVaults(args: z.infer<typeof VaultsActionSchema>, apiKey: string): Promise<ApiVault[] | ApiError>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchVaults = fetchVaults;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a list of vaults from the vaultsfyi API.
|
|
8
|
+
*
|
|
9
|
+
* @param args - The action parameters
|
|
10
|
+
* @param apiKey - The vaultsfyi API key
|
|
11
|
+
* @returns The list of vaults
|
|
12
|
+
*/
|
|
13
|
+
async function fetchVaults(args, apiKey) {
|
|
14
|
+
const vaults = [];
|
|
15
|
+
const params = (0, utils_1.createSearchParams)({
|
|
16
|
+
per_page: 250,
|
|
17
|
+
token: args.token,
|
|
18
|
+
network: args.network,
|
|
19
|
+
tvl_min: args.minTvl ?? 100000,
|
|
20
|
+
transactional_only: true,
|
|
21
|
+
});
|
|
22
|
+
for (let i = 0; i < 10; i++) {
|
|
23
|
+
const response = await fetch(`${constants_1.VAULTS_API_URL}/detailed/vaults?${params}`, {
|
|
24
|
+
method: "GET",
|
|
25
|
+
headers: {
|
|
26
|
+
"x-api-key": apiKey,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const data = (await response.json());
|
|
30
|
+
if ("error" in data)
|
|
31
|
+
return data;
|
|
32
|
+
vaults.push(...data.data);
|
|
33
|
+
if (!data.next_page)
|
|
34
|
+
break;
|
|
35
|
+
else
|
|
36
|
+
params.set("page", data.next_page);
|
|
37
|
+
}
|
|
38
|
+
return vaults;
|
|
39
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const VAULTS_API_URL = "https://api.vaults.fyi/v1";
|
|
2
|
+
export declare const VAULTSFYI_SUPPORTED_CHAINS: {
|
|
3
|
+
readonly 1: "mainnet";
|
|
4
|
+
readonly 42161: "arbitrum";
|
|
5
|
+
readonly 10: "optimism";
|
|
6
|
+
readonly 137: "polygon";
|
|
7
|
+
readonly 100: "gnosis";
|
|
8
|
+
readonly 8453: "base";
|
|
9
|
+
readonly 130: "unichain";
|
|
10
|
+
readonly 1923: "swellchain";
|
|
11
|
+
readonly 42220: "celo";
|
|
12
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VAULTSFYI_SUPPORTED_CHAINS = exports.VAULTS_API_URL = void 0;
|
|
4
|
+
exports.VAULTS_API_URL = "https://api.vaults.fyi/v1";
|
|
5
|
+
exports.VAULTSFYI_SUPPORTED_CHAINS = {
|
|
6
|
+
1: "mainnet",
|
|
7
|
+
42161: "arbitrum",
|
|
8
|
+
10: "optimism",
|
|
9
|
+
137: "polygon",
|
|
10
|
+
100: "gnosis",
|
|
11
|
+
8453: "base",
|
|
12
|
+
130: "unichain",
|
|
13
|
+
1923: "swellchain",
|
|
14
|
+
42220: "celo",
|
|
15
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Exports for vaultsfyi action provider
|
|
4
|
+
*
|
|
5
|
+
* @module vaultsfyi
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./vaultsfyiActionProvider"), exports);
|
|
23
|
+
__exportStar(require("./schemas"), exports);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Vaults list action schema.
|
|
4
|
+
*/
|
|
5
|
+
export declare const VaultsActionSchema: z.ZodObject<{
|
|
6
|
+
token: z.ZodOptional<z.ZodString>;
|
|
7
|
+
protocol: z.ZodOptional<z.ZodString>;
|
|
8
|
+
network: z.ZodOptional<z.ZodEnum<[string, ...string[]]>>;
|
|
9
|
+
minTvl: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
sort: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
field: z.ZodOptional<z.ZodEnum<["tvl", "apy", "name"]>>;
|
|
12
|
+
direction: z.ZodOptional<z.ZodEnum<["asc", "desc"]>>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
field?: "name" | "tvl" | "apy" | undefined;
|
|
15
|
+
direction?: "asc" | "desc" | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
field?: "name" | "tvl" | "apy" | undefined;
|
|
18
|
+
direction?: "asc" | "desc" | undefined;
|
|
19
|
+
}>>;
|
|
20
|
+
take: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
sort?: {
|
|
24
|
+
field?: "name" | "tvl" | "apy" | undefined;
|
|
25
|
+
direction?: "asc" | "desc" | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
network?: string | undefined;
|
|
28
|
+
token?: string | undefined;
|
|
29
|
+
protocol?: string | undefined;
|
|
30
|
+
minTvl?: number | undefined;
|
|
31
|
+
take?: number | undefined;
|
|
32
|
+
page?: number | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
sort?: {
|
|
35
|
+
field?: "name" | "tvl" | "apy" | undefined;
|
|
36
|
+
direction?: "asc" | "desc" | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
network?: string | undefined;
|
|
39
|
+
token?: string | undefined;
|
|
40
|
+
protocol?: string | undefined;
|
|
41
|
+
minTvl?: number | undefined;
|
|
42
|
+
take?: number | undefined;
|
|
43
|
+
page?: number | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
export declare const depositActionSchema: z.ZodObject<{
|
|
46
|
+
vaultAddress: z.ZodString;
|
|
47
|
+
assetAddress: z.ZodString;
|
|
48
|
+
network: z.ZodEnum<[string, ...string[]]>;
|
|
49
|
+
amount: z.ZodNumber;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
amount: number;
|
|
52
|
+
network: string;
|
|
53
|
+
vaultAddress: string;
|
|
54
|
+
assetAddress: string;
|
|
55
|
+
}, {
|
|
56
|
+
amount: number;
|
|
57
|
+
network: string;
|
|
58
|
+
vaultAddress: string;
|
|
59
|
+
assetAddress: string;
|
|
60
|
+
}>;
|
|
61
|
+
export declare const redeemActionSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
62
|
+
vaultAddress: z.ZodString;
|
|
63
|
+
assetAddress: z.ZodString;
|
|
64
|
+
network: z.ZodEnum<[string, ...string[]]>;
|
|
65
|
+
amount: z.ZodNumber;
|
|
66
|
+
}, {
|
|
67
|
+
all: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
}>, "strip", z.ZodTypeAny, {
|
|
69
|
+
amount: number;
|
|
70
|
+
network: string;
|
|
71
|
+
vaultAddress: string;
|
|
72
|
+
assetAddress: string;
|
|
73
|
+
all?: boolean | undefined;
|
|
74
|
+
}, {
|
|
75
|
+
amount: number;
|
|
76
|
+
network: string;
|
|
77
|
+
vaultAddress: string;
|
|
78
|
+
assetAddress: string;
|
|
79
|
+
all?: boolean | undefined;
|
|
80
|
+
}>;
|
|
81
|
+
export declare const claimActionSchema: z.ZodObject<Omit<{
|
|
82
|
+
vaultAddress: z.ZodString;
|
|
83
|
+
assetAddress: z.ZodString;
|
|
84
|
+
network: z.ZodEnum<[string, ...string[]]>;
|
|
85
|
+
amount: z.ZodNumber;
|
|
86
|
+
}, "amount">, "strip", z.ZodTypeAny, {
|
|
87
|
+
network: string;
|
|
88
|
+
vaultAddress: string;
|
|
89
|
+
assetAddress: string;
|
|
90
|
+
}, {
|
|
91
|
+
network: string;
|
|
92
|
+
vaultAddress: string;
|
|
93
|
+
assetAddress: string;
|
|
94
|
+
}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.claimActionSchema = exports.redeemActionSchema = exports.depositActionSchema = exports.VaultsActionSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
/**
|
|
7
|
+
* Action schemas for the vaultsfyi action provider.
|
|
8
|
+
*
|
|
9
|
+
* This file contains the Zod schemas that define the shape and validation
|
|
10
|
+
* rules for action parameters in the vaultsfyi action provider.
|
|
11
|
+
*/
|
|
12
|
+
const NetworkSchema = zod_1.z.enum(Object.values(constants_1.VAULTSFYI_SUPPORTED_CHAINS));
|
|
13
|
+
/**
|
|
14
|
+
* Vaults list action schema.
|
|
15
|
+
*/
|
|
16
|
+
exports.VaultsActionSchema = zod_1.z.object({
|
|
17
|
+
token: zod_1.z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe("Optional: Name or symbol of the token to filter vaults by"),
|
|
21
|
+
protocol: zod_1.z.string().optional().describe("Optional: Protocol to filter vaults by"),
|
|
22
|
+
network: NetworkSchema.optional().describe("Optional: Network name to filter vaults by. Supported networks: mainnet, arbitrum, optimism, polygon, base, gnosis, unichain"),
|
|
23
|
+
minTvl: zod_1.z.number().optional().describe("Optional: Minimum TVL to filter vaults by"),
|
|
24
|
+
sort: zod_1.z
|
|
25
|
+
.object({
|
|
26
|
+
field: zod_1.z.enum(["tvl", "apy", "name"]).optional().describe("Sort field"),
|
|
27
|
+
direction: zod_1.z.enum(["asc", "desc"]).optional().describe("Sort direction"),
|
|
28
|
+
})
|
|
29
|
+
.optional()
|
|
30
|
+
.describe("Sort options"),
|
|
31
|
+
take: zod_1.z.number().optional().describe("Optional: Limit the number of results"),
|
|
32
|
+
page: zod_1.z.number().optional().describe("Optional: Page number"),
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Base transaction params schema.
|
|
36
|
+
*/
|
|
37
|
+
const TransactionActionSchema = zod_1.z.object({
|
|
38
|
+
vaultAddress: zod_1.z.string().describe("The address of the vault to interact with"),
|
|
39
|
+
assetAddress: zod_1.z.string().describe("The address of the vault's underlying token"),
|
|
40
|
+
network: NetworkSchema.describe("The network of the vault"),
|
|
41
|
+
amount: zod_1.z.number().describe("The amount of assets to use"),
|
|
42
|
+
});
|
|
43
|
+
exports.depositActionSchema = TransactionActionSchema;
|
|
44
|
+
exports.redeemActionSchema = TransactionActionSchema.extend({
|
|
45
|
+
all: zod_1.z.boolean().optional().describe("Should redeem all assets"),
|
|
46
|
+
});
|
|
47
|
+
exports.claimActionSchema = TransactionActionSchema.omit({
|
|
48
|
+
amount: true,
|
|
49
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
2
|
+
import { ApiVault } from "./api/vaults";
|
|
3
|
+
import { Actions } from "./api/actions";
|
|
4
|
+
/**
|
|
5
|
+
* Get the link to the vaults.fyi page for a vault
|
|
6
|
+
*
|
|
7
|
+
* @param vault - The vault
|
|
8
|
+
* @returns The link to the vaults.fyi page
|
|
9
|
+
*/
|
|
10
|
+
export declare function getVaultsLink(vault: ApiVault): string;
|
|
11
|
+
/**
|
|
12
|
+
* Execute a list of actions
|
|
13
|
+
*
|
|
14
|
+
* @param wallet - The wallet provider
|
|
15
|
+
* @param actions - The list of actions to execute
|
|
16
|
+
* @returns nothing
|
|
17
|
+
*/
|
|
18
|
+
export declare function executeActions(wallet: EvmWalletProvider, actions: Actions): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a URLSearchParams object from an object
|
|
21
|
+
*
|
|
22
|
+
* @param obj - The object to convert
|
|
23
|
+
* @returns The URLSearchParams object
|
|
24
|
+
*/
|
|
25
|
+
export declare function createSearchParams(obj: Record<string, string | number | boolean | undefined>): URLSearchParams;
|
|
26
|
+
/**
|
|
27
|
+
* Parse an asset amount with decimals
|
|
28
|
+
*
|
|
29
|
+
* @param wallet - The wallet provider
|
|
30
|
+
* @param assetAddress - The address of the asset
|
|
31
|
+
* @param amount - The amount to parse
|
|
32
|
+
* @returns The parsed amount
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseAssetAmount(wallet: EvmWalletProvider, assetAddress: string, amount: number): Promise<number>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVaultsLink = getVaultsLink;
|
|
4
|
+
exports.executeActions = executeActions;
|
|
5
|
+
exports.createSearchParams = createSearchParams;
|
|
6
|
+
exports.parseAssetAmount = parseAssetAmount;
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
/**
|
|
9
|
+
* Get the link to the vaults.fyi page for a vault
|
|
10
|
+
*
|
|
11
|
+
* @param vault - The vault
|
|
12
|
+
* @returns The link to the vaults.fyi page
|
|
13
|
+
*/
|
|
14
|
+
function getVaultsLink(vault) {
|
|
15
|
+
if (vault.isTransactional) {
|
|
16
|
+
return `https://app.vaults.fyi/opportunity/${vault.network}/${vault.address}`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return `https://analytics.vaults.fyi/vaults/${vault.network}/${vault.address}`;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Execute a list of actions
|
|
24
|
+
*
|
|
25
|
+
* @param wallet - The wallet provider
|
|
26
|
+
* @param actions - The list of actions to execute
|
|
27
|
+
* @returns nothing
|
|
28
|
+
*/
|
|
29
|
+
async function executeActions(wallet, actions) {
|
|
30
|
+
for (let i = actions.currentActionIndex; i < actions.actions.length; i++) {
|
|
31
|
+
const action = actions.actions[i];
|
|
32
|
+
const txHash = await wallet.sendTransaction({
|
|
33
|
+
...action.tx,
|
|
34
|
+
value: action.tx.value ? BigInt(action.tx.value) : undefined,
|
|
35
|
+
});
|
|
36
|
+
await wallet.waitForTransactionReceipt(txHash);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a URLSearchParams object from an object
|
|
41
|
+
*
|
|
42
|
+
* @param obj - The object to convert
|
|
43
|
+
* @returns The URLSearchParams object
|
|
44
|
+
*/
|
|
45
|
+
function createSearchParams(obj) {
|
|
46
|
+
const params = new URLSearchParams();
|
|
47
|
+
for (const key in obj) {
|
|
48
|
+
if (obj[key] !== undefined) {
|
|
49
|
+
params.append(key, obj[key].toString());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return params;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse an asset amount with decimals
|
|
56
|
+
*
|
|
57
|
+
* @param wallet - The wallet provider
|
|
58
|
+
* @param assetAddress - The address of the asset
|
|
59
|
+
* @param amount - The amount to parse
|
|
60
|
+
* @returns The parsed amount
|
|
61
|
+
*/
|
|
62
|
+
async function parseAssetAmount(wallet, assetAddress, amount) {
|
|
63
|
+
const decimals = await wallet.readContract({
|
|
64
|
+
address: assetAddress,
|
|
65
|
+
abi: viem_1.erc20Abi,
|
|
66
|
+
functionName: "decimals",
|
|
67
|
+
});
|
|
68
|
+
return Math.floor(amount * 10 ** decimals);
|
|
69
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vaultsfyi Action Provider
|
|
3
|
+
*
|
|
4
|
+
* This file contains the implementation of the VaultsfyiActionProvider,
|
|
5
|
+
* which provides actions for vaultsfyi operations.
|
|
6
|
+
*
|
|
7
|
+
* @module vaultsfyi
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { ActionProvider } from "../actionProvider";
|
|
11
|
+
import { Network } from "../../network";
|
|
12
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
13
|
+
import { claimActionSchema, depositActionSchema, redeemActionSchema, VaultsActionSchema } from "./schemas";
|
|
14
|
+
/**
|
|
15
|
+
* Configuration options for the OpenseaActionProvider.
|
|
16
|
+
*/
|
|
17
|
+
export interface VaultsfyiActionProviderConfig {
|
|
18
|
+
/**
|
|
19
|
+
* vaults.fyi API Key.
|
|
20
|
+
*/
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* VaultsfyiActionProvider provides actions for vaultsfyi operations.
|
|
25
|
+
*
|
|
26
|
+
* @description
|
|
27
|
+
* This provider is designed to work with EvmWalletProvider for blockchain interactions.
|
|
28
|
+
* It supports all evm networks.
|
|
29
|
+
*/
|
|
30
|
+
export declare class VaultsfyiActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
31
|
+
private readonly apiKey;
|
|
32
|
+
/**
|
|
33
|
+
* Constructor for the VaultsfyiActionProvider.
|
|
34
|
+
*
|
|
35
|
+
* @param config - Configuration options for the provider
|
|
36
|
+
*/
|
|
37
|
+
constructor(config?: VaultsfyiActionProviderConfig);
|
|
38
|
+
/**
|
|
39
|
+
* vaults action
|
|
40
|
+
*
|
|
41
|
+
* @param wallet - The wallet provider instance for blockchain interactions
|
|
42
|
+
* @param args - Input arguments: token, network, transactionalOnly...
|
|
43
|
+
* @returns A list of vaults.
|
|
44
|
+
*/
|
|
45
|
+
vaults(wallet: EvmWalletProvider, args: z.infer<typeof VaultsActionSchema>): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Deposit action
|
|
48
|
+
*
|
|
49
|
+
* @param wallet - The wallet provider instance for blockchain interactions
|
|
50
|
+
* @param args - Input arguments
|
|
51
|
+
* @returns A result message
|
|
52
|
+
*/
|
|
53
|
+
deposit(wallet: EvmWalletProvider, args: z.infer<typeof depositActionSchema>): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Redeem action
|
|
56
|
+
*
|
|
57
|
+
* @param wallet - The wallet provider instance for blockchain interactions
|
|
58
|
+
* @param args - Input arguments
|
|
59
|
+
* @returns A result message
|
|
60
|
+
*/
|
|
61
|
+
redeem(wallet: EvmWalletProvider, args: z.infer<typeof redeemActionSchema>): Promise<string>;
|
|
62
|
+
/**
|
|
63
|
+
* Claim rewards action
|
|
64
|
+
*
|
|
65
|
+
* @param wallet - The wallet provider instance for blockchain interactions
|
|
66
|
+
* @param args - Input arguments
|
|
67
|
+
* @returns A result message
|
|
68
|
+
*/
|
|
69
|
+
claim(wallet: EvmWalletProvider, args: z.infer<typeof claimActionSchema>): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the users wallet token balances.
|
|
72
|
+
*
|
|
73
|
+
* @param wallet - The wallet provider instance for blockchain interactions
|
|
74
|
+
* @returns A record of the users balances
|
|
75
|
+
*/
|
|
76
|
+
balances(wallet: EvmWalletProvider): Promise<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Returns the users positions.
|
|
79
|
+
*
|
|
80
|
+
* @param wallet - The wallet provider instance for blockchain interactions
|
|
81
|
+
* @returns A record of the users positions
|
|
82
|
+
*/
|
|
83
|
+
positions(wallet: EvmWalletProvider): Promise<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if this provider supports the given network.
|
|
86
|
+
*
|
|
87
|
+
* @param network - The network to check support for
|
|
88
|
+
* @returns True if the network is supported
|
|
89
|
+
*/
|
|
90
|
+
supportsNetwork(network: Network): boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Factory function to create a new VaultsfyiActionProvider instance.
|
|
94
|
+
*
|
|
95
|
+
* @param config - Configuration options for the provider
|
|
96
|
+
* @returns A new VaultsfyiActionProvider instance
|
|
97
|
+
*/
|
|
98
|
+
export declare const vaultsfyiActionProvider: (config: VaultsfyiActionProviderConfig) => VaultsfyiActionProvider;
|