@coinbase/agentkit 0.9.0 → 0.10.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/README.md +137 -55
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +151 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +242 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +42 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +132 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +199 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +3 -0
- package/dist/action-providers/cdp/schemas.d.ts +29 -0
- package/dist/action-providers/cdp/schemas.js +32 -1
- package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
- package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
- package/dist/action-providers/farcaster/schemas.d.ts +13 -0
- package/dist/action-providers/farcaster/schemas.js +6 -0
- package/dist/action-providers/index.d.ts +3 -0
- package/dist/action-providers/index.js +3 -0
- package/dist/action-providers/truemarkets/constants.d.ts +179 -0
- package/dist/action-providers/truemarkets/constants.js +46 -0
- package/dist/action-providers/truemarkets/index.d.ts +1 -0
- package/dist/action-providers/truemarkets/index.js +17 -0
- package/dist/action-providers/truemarkets/schemas.d.ts +21 -0
- package/dist/action-providers/truemarkets/schemas.js +29 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +51 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +469 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.d.ts +1 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +217 -0
- package/dist/action-providers/truemarkets/utils.d.ts +10 -0
- package/dist/action-providers/truemarkets/utils.js +9 -0
- package/dist/action-providers/twitter/schemas.d.ts +16 -0
- package/dist/action-providers/twitter/schemas.js +23 -1
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
- package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
- package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
- package/dist/action-providers/weth/constants.d.ts +9 -0
- package/dist/action-providers/weth/constants.js +12 -0
- package/dist/action-providers/weth/schemas.d.ts +7 -0
- package/dist/action-providers/weth/schemas.js +7 -1
- package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
- package/dist/action-providers/weth/wethActionProvider.js +50 -1
- package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
- package/dist/action-providers/zerion/constants.d.ts +1 -0
- package/dist/action-providers/zerion/constants.js +4 -0
- package/dist/action-providers/zerion/index.d.ts +2 -0
- package/dist/action-providers/zerion/index.js +18 -0
- package/dist/action-providers/zerion/schemas.d.ts +11 -0
- package/dist/action-providers/zerion/schemas.js +15 -0
- package/dist/action-providers/zerion/types.d.ts +125 -0
- package/dist/action-providers/zerion/types.js +16 -0
- package/dist/action-providers/zerion/utils.d.ts +3 -0
- package/dist/action-providers/zerion/utils.js +45 -0
- package/dist/action-providers/zerion/zerionActionProvider.d.ts +57 -0
- package/dist/action-providers/zerion/zerionActionProvider.js +159 -0
- package/dist/action-providers/zerion/zerionActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zerion/zerionActionProvider.test.js +213 -0
- package/dist/action-providers/zora/index.d.ts +3 -0
- package/dist/action-providers/zora/index.js +19 -0
- package/dist/action-providers/zora/schemas.d.ts +29 -0
- package/dist/action-providers/zora/schemas.js +31 -0
- package/dist/action-providers/zora/utils.d.ts +28 -0
- package/dist/action-providers/zora/utils.js +200 -0
- package/dist/action-providers/zora/zoraActionProvider.d.ts +36 -0
- package/dist/action-providers/zora/zoraActionProvider.js +151 -0
- package/dist/action-providers/zora/zoraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zora/zoraActionProvider.test.js +205 -0
- package/dist/wallet-providers/cdpShared.d.ts +4 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +8 -1
- package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -11
- package/package.json +3 -2
|
@@ -58,6 +58,30 @@ class WethActionProvider extends actionProvider_1.ActionProvider {
|
|
|
58
58
|
return `Error wrapping ETH: ${error}`;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Unwraps WETH to ETH.
|
|
63
|
+
*
|
|
64
|
+
* @param walletProvider - The wallet provider to use for the action.
|
|
65
|
+
* @param args - The input arguments for the action.
|
|
66
|
+
* @returns A message containing the transaction hash.
|
|
67
|
+
*/
|
|
68
|
+
async unwrapEth(walletProvider, args) {
|
|
69
|
+
try {
|
|
70
|
+
const hash = await walletProvider.sendTransaction({
|
|
71
|
+
to: constants_1.WETH_ADDRESS,
|
|
72
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
73
|
+
abi: constants_1.WETH_ABI,
|
|
74
|
+
functionName: "withdraw",
|
|
75
|
+
args: [BigInt(args.amountToUnwrap)],
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
79
|
+
return `Unwrapped WETH with transaction hash: ${hash}`;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return `Error unwrapping WETH: ${error}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
61
85
|
}
|
|
62
86
|
exports.WethActionProvider = WethActionProvider;
|
|
63
87
|
__decorate([
|
|
@@ -74,7 +98,7 @@ Important notes:
|
|
|
74
98
|
- The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
|
|
75
99
|
- Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
|
|
76
100
|
- 1 wei = 0.000000000000000001 WETH
|
|
77
|
-
- Minimum purchase amount is
|
|
101
|
+
- Minimum purchase amount is 100000000000 wei (0.0000001 WETH)
|
|
78
102
|
- Only supported on the following networks:
|
|
79
103
|
- Base Sepolia (ie, 'base-sepolia')
|
|
80
104
|
- Base Mainnet (ie, 'base', 'base-mainnet')
|
|
@@ -85,5 +109,30 @@ Important notes:
|
|
|
85
109
|
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
86
110
|
__metadata("design:returntype", Promise)
|
|
87
111
|
], WethActionProvider.prototype, "wrapEth", null);
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, actionDecorator_1.CreateAction)({
|
|
114
|
+
name: "unwrap_eth",
|
|
115
|
+
description: `
|
|
116
|
+
This tool can only be used to unwrap WETH to ETH.
|
|
117
|
+
Do not use this tool for any other purpose, or trading other assets.
|
|
118
|
+
|
|
119
|
+
Inputs:
|
|
120
|
+
- Amount of WETH to unwrap.
|
|
121
|
+
|
|
122
|
+
Important notes:
|
|
123
|
+
- The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
|
|
124
|
+
- Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
|
|
125
|
+
- 1 wei = 0.000000000000000001 WETH
|
|
126
|
+
- Minimum unwrap amount is 100000000000 wei (0.0000001 WETH)
|
|
127
|
+
- Only supported on the following networks:
|
|
128
|
+
- Base Sepolia (ie, 'base-sepolia')
|
|
129
|
+
- Base Mainnet (ie, 'base', 'base-mainnet')
|
|
130
|
+
`,
|
|
131
|
+
schema: schemas_1.UnwrapEthSchema,
|
|
132
|
+
}),
|
|
133
|
+
__metadata("design:type", Function),
|
|
134
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
135
|
+
__metadata("design:returntype", Promise)
|
|
136
|
+
], WethActionProvider.prototype, "unwrapEth", null);
|
|
88
137
|
const wethActionProvider = () => new WethActionProvider();
|
|
89
138
|
exports.wethActionProvider = wethActionProvider;
|
|
@@ -21,6 +21,21 @@ describe("Wrap Eth Schema", () => {
|
|
|
21
21
|
expect(result.success).toBe(false);
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
|
+
describe("Unwrap Eth Schema", () => {
|
|
25
|
+
it("should successfully parse valid input", () => {
|
|
26
|
+
const validInput = {
|
|
27
|
+
amountToUnwrap: MOCK_AMOUNT,
|
|
28
|
+
};
|
|
29
|
+
const result = schemas_1.UnwrapEthSchema.safeParse(validInput);
|
|
30
|
+
expect(result.success).toBe(true);
|
|
31
|
+
expect(result.data).toEqual(validInput);
|
|
32
|
+
});
|
|
33
|
+
it("should fail parsing empty input", () => {
|
|
34
|
+
const emptyInput = {};
|
|
35
|
+
const result = schemas_1.UnwrapEthSchema.safeParse(emptyInput);
|
|
36
|
+
expect(result.success).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
24
39
|
describe("Wrap Eth Action", () => {
|
|
25
40
|
let mockWallet;
|
|
26
41
|
const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
|
|
@@ -66,6 +81,51 @@ describe("Wrap Eth Action", () => {
|
|
|
66
81
|
expect(response).toContain(`Error wrapping ETH: ${error}`);
|
|
67
82
|
});
|
|
68
83
|
});
|
|
84
|
+
describe("Unwrap Eth Action", () => {
|
|
85
|
+
let mockWallet;
|
|
86
|
+
const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
|
|
87
|
+
beforeEach(async () => {
|
|
88
|
+
mockWallet = {
|
|
89
|
+
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
90
|
+
sendTransaction: jest.fn(),
|
|
91
|
+
waitForTransactionReceipt: jest.fn(),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
it("should successfully respond", async () => {
|
|
95
|
+
const args = {
|
|
96
|
+
amountToUnwrap: MOCK_AMOUNT,
|
|
97
|
+
};
|
|
98
|
+
const hash = "0x1234567890123456789012345678901234567890";
|
|
99
|
+
mockWallet.sendTransaction.mockResolvedValue(hash);
|
|
100
|
+
const response = await actionProvider.unwrapEth(mockWallet, args);
|
|
101
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
|
|
102
|
+
to: constants_1.WETH_ADDRESS,
|
|
103
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
104
|
+
abi: constants_1.WETH_ABI,
|
|
105
|
+
functionName: "withdraw",
|
|
106
|
+
args: [BigInt(MOCK_AMOUNT)],
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
expect(response).toContain(`Unwrapped WETH with transaction hash: ${hash}`);
|
|
110
|
+
});
|
|
111
|
+
it("should fail with an error", async () => {
|
|
112
|
+
const args = {
|
|
113
|
+
amountToUnwrap: MOCK_AMOUNT,
|
|
114
|
+
};
|
|
115
|
+
const error = new Error("Failed to unwrap WETH");
|
|
116
|
+
mockWallet.sendTransaction.mockRejectedValue(error);
|
|
117
|
+
const response = await actionProvider.unwrapEth(mockWallet, args);
|
|
118
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
|
|
119
|
+
to: constants_1.WETH_ADDRESS,
|
|
120
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
121
|
+
abi: constants_1.WETH_ABI,
|
|
122
|
+
functionName: "withdraw",
|
|
123
|
+
args: [BigInt(MOCK_AMOUNT)],
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
expect(response).toContain(`Error unwrapping WETH: ${error}`);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
69
129
|
describe("supportsNetwork", () => {
|
|
70
130
|
const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
|
|
71
131
|
it("should return true for base-mainnet", () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ZERION_V1_BASE_URL = "https://api.zerion.io/v1";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zerionActionProvider"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for getting wallet portfolio.
|
|
4
|
+
*/
|
|
5
|
+
export declare const GetWalletPortfolioSchema: z.ZodObject<{
|
|
6
|
+
walletAddress: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
walletAddress: string;
|
|
9
|
+
}, {
|
|
10
|
+
walletAddress: string;
|
|
11
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GetWalletPortfolioSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for getting wallet portfolio.
|
|
7
|
+
*/
|
|
8
|
+
exports.GetWalletPortfolioSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
walletAddress: zod_1.z
|
|
11
|
+
.string()
|
|
12
|
+
.describe("The wallet address to fetch portfolio for. Defaults is empty string, which will raise an error later if not provided."),
|
|
13
|
+
})
|
|
14
|
+
.strip()
|
|
15
|
+
.describe("Input schema for fetching wallet portfolio");
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export interface ZerionFungiblePositionsResponse {
|
|
2
|
+
links: {
|
|
3
|
+
self: string;
|
|
4
|
+
};
|
|
5
|
+
data: ZerionFungiblePosition[];
|
|
6
|
+
}
|
|
7
|
+
export interface ZerionPortfolioResponse {
|
|
8
|
+
links: {
|
|
9
|
+
self: string;
|
|
10
|
+
};
|
|
11
|
+
data: ZerionPortfolio;
|
|
12
|
+
}
|
|
13
|
+
export interface ZerionPortfolio {
|
|
14
|
+
type: string;
|
|
15
|
+
id: string;
|
|
16
|
+
attributes: PortfolioAttributes;
|
|
17
|
+
}
|
|
18
|
+
export interface PortfolioAttributes {
|
|
19
|
+
positions_distribution_by_type: {
|
|
20
|
+
wallet: number;
|
|
21
|
+
deposited: number;
|
|
22
|
+
borrowed: number;
|
|
23
|
+
locked: number;
|
|
24
|
+
staked: number;
|
|
25
|
+
};
|
|
26
|
+
positions_distribution_by_chain: {
|
|
27
|
+
[key: string]: number;
|
|
28
|
+
};
|
|
29
|
+
total: {
|
|
30
|
+
positions: number;
|
|
31
|
+
};
|
|
32
|
+
changes: {
|
|
33
|
+
absolute_1d: number;
|
|
34
|
+
percent_1d: number;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export interface ZerionFungiblePosition {
|
|
38
|
+
type: string;
|
|
39
|
+
id: string;
|
|
40
|
+
attributes: FungibleAttributes;
|
|
41
|
+
relationships: Relationships;
|
|
42
|
+
}
|
|
43
|
+
export interface FungibleAttributes {
|
|
44
|
+
parent: null | string;
|
|
45
|
+
protocol: null | string;
|
|
46
|
+
pool_address?: string;
|
|
47
|
+
group_id?: string;
|
|
48
|
+
name: string;
|
|
49
|
+
position_type: PositionType;
|
|
50
|
+
quantity: Quantity;
|
|
51
|
+
value: number | null;
|
|
52
|
+
price: number;
|
|
53
|
+
changes: Changes | null;
|
|
54
|
+
fungible_info: FungibleInfo;
|
|
55
|
+
flags: AttributesFlags;
|
|
56
|
+
updated_at: Date;
|
|
57
|
+
updated_at_block: number | null;
|
|
58
|
+
application_metadata?: ApplicationMetadata;
|
|
59
|
+
}
|
|
60
|
+
export interface ApplicationMetadata {
|
|
61
|
+
name: string;
|
|
62
|
+
icon: Icon;
|
|
63
|
+
url: string;
|
|
64
|
+
}
|
|
65
|
+
export interface Icon {
|
|
66
|
+
url: string;
|
|
67
|
+
}
|
|
68
|
+
export interface Changes {
|
|
69
|
+
absolute_1d: number;
|
|
70
|
+
percent_1d: number;
|
|
71
|
+
}
|
|
72
|
+
export interface AttributesFlags {
|
|
73
|
+
displayable: boolean;
|
|
74
|
+
is_trash: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface FungibleInfo {
|
|
77
|
+
name: string;
|
|
78
|
+
symbol: string;
|
|
79
|
+
icon: Icon | null;
|
|
80
|
+
flags: FungibleInfoFlags;
|
|
81
|
+
implementations: Implementation[];
|
|
82
|
+
}
|
|
83
|
+
export interface FungibleInfoFlags {
|
|
84
|
+
verified: boolean;
|
|
85
|
+
}
|
|
86
|
+
export interface Implementation {
|
|
87
|
+
chain_id: string;
|
|
88
|
+
address: null | string;
|
|
89
|
+
decimals: number;
|
|
90
|
+
}
|
|
91
|
+
export declare enum PositionType {
|
|
92
|
+
Deposit = "deposit",
|
|
93
|
+
Reward = "reward",
|
|
94
|
+
Staked = "staked",
|
|
95
|
+
Wallet = "wallet"
|
|
96
|
+
}
|
|
97
|
+
export interface Quantity {
|
|
98
|
+
int: string;
|
|
99
|
+
decimals: number;
|
|
100
|
+
float: number;
|
|
101
|
+
numeric: string;
|
|
102
|
+
}
|
|
103
|
+
export interface Relationships {
|
|
104
|
+
chain: Chain;
|
|
105
|
+
dapp?: Dapp;
|
|
106
|
+
fungible: Chain;
|
|
107
|
+
}
|
|
108
|
+
export interface Dapp {
|
|
109
|
+
data: Data;
|
|
110
|
+
}
|
|
111
|
+
export interface Chain {
|
|
112
|
+
links: {
|
|
113
|
+
related: string;
|
|
114
|
+
};
|
|
115
|
+
data: Data;
|
|
116
|
+
}
|
|
117
|
+
export interface Data {
|
|
118
|
+
type: DataType;
|
|
119
|
+
id: string;
|
|
120
|
+
}
|
|
121
|
+
export declare enum DataType {
|
|
122
|
+
Chains = "chains",
|
|
123
|
+
Dapps = "dapps",
|
|
124
|
+
Fungibles = "fungibles"
|
|
125
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataType = exports.PositionType = void 0;
|
|
4
|
+
var PositionType;
|
|
5
|
+
(function (PositionType) {
|
|
6
|
+
PositionType["Deposit"] = "deposit";
|
|
7
|
+
PositionType["Reward"] = "reward";
|
|
8
|
+
PositionType["Staked"] = "staked";
|
|
9
|
+
PositionType["Wallet"] = "wallet";
|
|
10
|
+
})(PositionType || (exports.PositionType = PositionType = {}));
|
|
11
|
+
var DataType;
|
|
12
|
+
(function (DataType) {
|
|
13
|
+
DataType["Chains"] = "chains";
|
|
14
|
+
DataType["Dapps"] = "dapps";
|
|
15
|
+
DataType["Fungibles"] = "fungibles";
|
|
16
|
+
})(DataType || (exports.DataType = DataType = {}));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatPositionsData = exports.formatPortfolioData = void 0;
|
|
4
|
+
const formatPortfolioData = (data) => {
|
|
5
|
+
// Total value
|
|
6
|
+
const totalValue = data.attributes.total.positions;
|
|
7
|
+
const totalValueStr = `$${totalValue.toFixed(2)}`;
|
|
8
|
+
// 24h change
|
|
9
|
+
const changePercent = data.attributes.changes.percent_1d;
|
|
10
|
+
const changeStr = `${changePercent.toFixed(2)}%`;
|
|
11
|
+
// Positions by type (filter out 0)
|
|
12
|
+
const types = Object.entries(data.attributes.positions_distribution_by_type)
|
|
13
|
+
.filter(([_, v]) => v > 0)
|
|
14
|
+
.map(([type, value]) => `${type}: $${value.toFixed(2)}`)
|
|
15
|
+
.join(", ");
|
|
16
|
+
// Positions by chain (top 5 by value)
|
|
17
|
+
const topChains = Object.entries(data.attributes.positions_distribution_by_chain)
|
|
18
|
+
.sort(([, a], [, b]) => b - a)
|
|
19
|
+
.slice(0, 5)
|
|
20
|
+
.map(([chain, value]) => `${chain}: $${value.toFixed(2)}`)
|
|
21
|
+
.join(", ");
|
|
22
|
+
// Final summary string
|
|
23
|
+
return `Wallet Portfolio Overview:
|
|
24
|
+
- Total Value: ${totalValueStr}
|
|
25
|
+
- 24h Change: ${changeStr}
|
|
26
|
+
- Position Types: ${types}
|
|
27
|
+
- Top Chains: ${topChains}`;
|
|
28
|
+
};
|
|
29
|
+
exports.formatPortfolioData = formatPortfolioData;
|
|
30
|
+
const formatPositionsData = (data) => {
|
|
31
|
+
const filtered = data.filter(pos => pos.attributes.value !== null);
|
|
32
|
+
// Sort by value (descending)
|
|
33
|
+
const sorted = filtered.sort((a, b) => b.attributes.value - a.attributes.value);
|
|
34
|
+
const lines = [];
|
|
35
|
+
let totalValue = 0;
|
|
36
|
+
for (const pos of sorted) {
|
|
37
|
+
const { value, position_type, fungible_info, application_metadata } = pos.attributes;
|
|
38
|
+
const chain = pos.relationships.chain.data.id;
|
|
39
|
+
const protocolLine = application_metadata?.name ? `via ${application_metadata.name}` : "";
|
|
40
|
+
lines.push(`- ${fungible_info.symbol} (${fungible_info.name}) on ${chain} — $${value.toFixed(2)} [${position_type}${protocolLine ? " " + protocolLine : ""}]`);
|
|
41
|
+
totalValue += value;
|
|
42
|
+
}
|
|
43
|
+
return `Total Value: $${totalValue.toFixed(2)}\n\nToken Positions (>$1):\n${lines.join("\n")}`;
|
|
44
|
+
};
|
|
45
|
+
exports.formatPositionsData = formatPositionsData;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { Network } from "../../network";
|
|
3
|
+
import { ActionProvider } from "../actionProvider";
|
|
4
|
+
import { GetWalletPortfolioSchema } from "./schemas";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration options for the ZerionActionProvider.
|
|
7
|
+
*/
|
|
8
|
+
export interface ZerionActionProviderConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Zerion API Key. Request new at https://zerion.io/api
|
|
11
|
+
*/
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* ZerionActionProvider provides actions for zerion operations.
|
|
16
|
+
*
|
|
17
|
+
* @description
|
|
18
|
+
* This provider is designed to provide EVM-based operations.
|
|
19
|
+
* It supports all EVM-based networks.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ZerionActionProvider extends ActionProvider {
|
|
22
|
+
private readonly apiKey;
|
|
23
|
+
/**
|
|
24
|
+
* Constructor for the ZerionActionProvider.
|
|
25
|
+
*
|
|
26
|
+
* @param config - The configuration options for the ZerionActionProvider.
|
|
27
|
+
*/
|
|
28
|
+
constructor(config?: ZerionActionProviderConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Fetches and summarizes a crypto wallet's portfolio in USD.
|
|
31
|
+
*
|
|
32
|
+
* @param args - Arguments defined by GetWalletPortfolioSchema
|
|
33
|
+
* @returns A promise that resolves to a string describing the action result
|
|
34
|
+
*/
|
|
35
|
+
getPortfolioOverview(args: z.infer<typeof GetWalletPortfolioSchema>): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves and summarizes a wallet's fungible token holdings.
|
|
38
|
+
*
|
|
39
|
+
* @param args - Arguments defined by GetWalletPortfolioSchema
|
|
40
|
+
* @returns A promise that resolves to a string describing the action result
|
|
41
|
+
*/
|
|
42
|
+
getFungiblePositions(args: z.infer<typeof GetWalletPortfolioSchema>): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Checks if this provider supports the given network.
|
|
45
|
+
*
|
|
46
|
+
* @param network - The network to check support for
|
|
47
|
+
* @returns True if the network is supported
|
|
48
|
+
*/
|
|
49
|
+
supportsNetwork(network: Network): boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Factory function to create a new ZerionActionProvider instance.
|
|
53
|
+
*
|
|
54
|
+
* @param config - The configuration options for the ZerionActionProvider.
|
|
55
|
+
* @returns A new ZerionActionProvider instance
|
|
56
|
+
*/
|
|
57
|
+
export declare const zerionActionProvider: (config?: ZerionActionProviderConfig) => ZerionActionProvider;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.zerionActionProvider = exports.ZerionActionProvider = void 0;
|
|
13
|
+
const viem_1 = require("viem");
|
|
14
|
+
const zod_1 = require("zod");
|
|
15
|
+
const actionDecorator_1 = require("../actionDecorator");
|
|
16
|
+
const actionProvider_1 = require("../actionProvider");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
const schemas_1 = require("./schemas");
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
|
+
/**
|
|
21
|
+
* ZerionActionProvider provides actions for zerion operations.
|
|
22
|
+
*
|
|
23
|
+
* @description
|
|
24
|
+
* This provider is designed to provide EVM-based operations.
|
|
25
|
+
* It supports all EVM-based networks.
|
|
26
|
+
*/
|
|
27
|
+
class ZerionActionProvider extends actionProvider_1.ActionProvider {
|
|
28
|
+
/**
|
|
29
|
+
* Constructor for the ZerionActionProvider.
|
|
30
|
+
*
|
|
31
|
+
* @param config - The configuration options for the ZerionActionProvider.
|
|
32
|
+
*/
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
super("zerion", []);
|
|
35
|
+
const apiKey = config.apiKey || process.env.ZERION_API_KEY;
|
|
36
|
+
if (!apiKey) {
|
|
37
|
+
throw new Error("ZERION_API_KEY is not configured.");
|
|
38
|
+
}
|
|
39
|
+
const encodedKey = Buffer.from(`${apiKey}:`).toString("base64");
|
|
40
|
+
this.apiKey = encodedKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Fetches and summarizes a crypto wallet's portfolio in USD.
|
|
44
|
+
*
|
|
45
|
+
* @param args - Arguments defined by GetWalletPortfolioSchema
|
|
46
|
+
* @returns A promise that resolves to a string describing the action result
|
|
47
|
+
*/
|
|
48
|
+
async getPortfolioOverview(args) {
|
|
49
|
+
try {
|
|
50
|
+
const address = args.walletAddress || "";
|
|
51
|
+
if (!(0, viem_1.isAddress)(address)) {
|
|
52
|
+
return `Invalid wallet address: ${address}`;
|
|
53
|
+
}
|
|
54
|
+
const options = {
|
|
55
|
+
method: "GET",
|
|
56
|
+
headers: {
|
|
57
|
+
accept: "application/json",
|
|
58
|
+
authorization: `Basic ${this.apiKey}`,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const url = `${constants_1.ZERION_V1_BASE_URL}/wallets/${args.walletAddress}/portfolio?filter[positions]=no_filter¤cy=usd`;
|
|
62
|
+
const response = await fetch(url, options);
|
|
63
|
+
const { data } = await response.json();
|
|
64
|
+
return (0, utils_1.formatPortfolioData)(data);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return `Error fetching portfolio overview for wallet ${args.walletAddress}: ${error}`;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves and summarizes a wallet's fungible token holdings.
|
|
72
|
+
*
|
|
73
|
+
* @param args - Arguments defined by GetWalletPortfolioSchema
|
|
74
|
+
* @returns A promise that resolves to a string describing the action result
|
|
75
|
+
*/
|
|
76
|
+
async getFungiblePositions(args) {
|
|
77
|
+
try {
|
|
78
|
+
const address = args.walletAddress || "";
|
|
79
|
+
if (!(0, viem_1.isAddress)(address)) {
|
|
80
|
+
return `Invalid wallet address: ${address}`;
|
|
81
|
+
}
|
|
82
|
+
const options = {
|
|
83
|
+
method: "GET",
|
|
84
|
+
headers: {
|
|
85
|
+
accept: "application/json",
|
|
86
|
+
authorization: `Basic ${this.apiKey}`,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
const url = `${constants_1.ZERION_V1_BASE_URL}/wallets/${args.walletAddress}/positions?filter[positions]=no_filter¤cy=usd&filter[trash]=only_non_trash&sort=value`;
|
|
90
|
+
const response = await fetch(url, options);
|
|
91
|
+
const { data } = await response.json();
|
|
92
|
+
return (0, utils_1.formatPositionsData)(data);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return `Error fetching fungible positions for wallet ${args.walletAddress}: ${error}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Checks if this provider supports the given network.
|
|
100
|
+
*
|
|
101
|
+
* @param network - The network to check support for
|
|
102
|
+
* @returns True if the network is supported
|
|
103
|
+
*/
|
|
104
|
+
supportsNetwork(network) {
|
|
105
|
+
// all protocol networks
|
|
106
|
+
return network.protocolFamily === "evm";
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.ZerionActionProvider = ZerionActionProvider;
|
|
110
|
+
__decorate([
|
|
111
|
+
(0, actionDecorator_1.CreateAction)({
|
|
112
|
+
name: "get_portfolio_overview",
|
|
113
|
+
description: `
|
|
114
|
+
Fetches and summarizes a crypto wallet's portfolio in USD.
|
|
115
|
+
The tool returns a human-readable overview of the wallet's total value, value distribution across blockchains, position types (e.g., staked, deposited), and 24-hour performance change.
|
|
116
|
+
Useful for providing quick insights into a wallet's DeFi and cross-chain holdings.
|
|
117
|
+
Input:
|
|
118
|
+
- walletAddress: The wallet address to fetch portfolio overview for.
|
|
119
|
+
Output a structured text summary with:
|
|
120
|
+
- Total portfolio value in USD
|
|
121
|
+
- 24h percentage change in value
|
|
122
|
+
- Breakdown of value by position types (e.g., wallet, deposited, staked, locked, borrowed)
|
|
123
|
+
- Top 5 chains by value distribution
|
|
124
|
+
`,
|
|
125
|
+
schema: schemas_1.GetWalletPortfolioSchema,
|
|
126
|
+
}),
|
|
127
|
+
__metadata("design:type", Function),
|
|
128
|
+
__metadata("design:paramtypes", [void 0]),
|
|
129
|
+
__metadata("design:returntype", Promise)
|
|
130
|
+
], ZerionActionProvider.prototype, "getPortfolioOverview", null);
|
|
131
|
+
__decorate([
|
|
132
|
+
(0, actionDecorator_1.CreateAction)({
|
|
133
|
+
name: "get_fungible_positions",
|
|
134
|
+
description: `
|
|
135
|
+
Retrieves and summarizes a wallet's fungible token holdings.
|
|
136
|
+
For each token, it includes metadata such as symbol, name, holding value, associated protocol (if applicable), and the type of position (e.g., deposit, wallet, reward).
|
|
137
|
+
The summary also reports the total USD value of all qualifying token positions.
|
|
138
|
+
Input:
|
|
139
|
+
- walletAddress: The wallet address to fetch fungible positions for.
|
|
140
|
+
Output a readable text summary including:
|
|
141
|
+
- All token positions
|
|
142
|
+
- For each: token name, symbol, USD value, chain, position type
|
|
143
|
+
- If applicable: protocol used and type of action (e.g. staked, deposited via protocol)
|
|
144
|
+
- A final total value in USD across all included positions
|
|
145
|
+
`,
|
|
146
|
+
schema: schemas_1.GetWalletPortfolioSchema,
|
|
147
|
+
}),
|
|
148
|
+
__metadata("design:type", Function),
|
|
149
|
+
__metadata("design:paramtypes", [void 0]),
|
|
150
|
+
__metadata("design:returntype", Promise)
|
|
151
|
+
], ZerionActionProvider.prototype, "getFungiblePositions", null);
|
|
152
|
+
/**
|
|
153
|
+
* Factory function to create a new ZerionActionProvider instance.
|
|
154
|
+
*
|
|
155
|
+
* @param config - The configuration options for the ZerionActionProvider.
|
|
156
|
+
* @returns A new ZerionActionProvider instance
|
|
157
|
+
*/
|
|
158
|
+
const zerionActionProvider = (config) => new ZerionActionProvider(config);
|
|
159
|
+
exports.zerionActionProvider = zerionActionProvider;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|