@coinbase/agentkit 0.9.1 → 0.10.1
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 +181 -54
- package/dist/action-providers/across/acrossActionProvider.js +3 -3
- package/dist/action-providers/cdp/cdpApiActionProvider.d.ts +3 -12
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -79
- package/dist/action-providers/cdp/cdpApiActionProvider.test.js +0 -125
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +58 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +351 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +520 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +57 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +337 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +463 -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 +38 -9
- package/dist/action-providers/cdp/schemas.js +49 -6
- package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
- package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
- package/dist/action-providers/cdp/swapUtils.d.ts +32 -0
- package/dist/action-providers/cdp/swapUtils.js +142 -0
- package/dist/action-providers/clanker/clankerActionProvider.d.ts +43 -0
- package/dist/action-providers/clanker/clankerActionProvider.js +130 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.d.ts +4 -0
- package/dist/action-providers/clanker/clankerActionProvider.test.js +119 -0
- package/dist/action-providers/clanker/index.d.ts +2 -0
- package/dist/action-providers/clanker/index.js +18 -0
- package/dist/action-providers/clanker/schemas.d.ts +56 -0
- package/dist/action-providers/clanker/schemas.js +47 -0
- package/dist/action-providers/clanker/utils.d.ts +9 -0
- package/dist/action-providers/clanker/utils.js +23 -0
- package/dist/action-providers/compound/constants.d.ts +1 -1
- package/dist/action-providers/compound/constants.js +2 -2
- package/dist/action-providers/erc20/constants.d.ts +35 -135
- package/dist/action-providers/erc20/constants.js +37 -189
- package/dist/action-providers/erc20/erc20ActionProvider.d.ts +9 -1
- package/dist/action-providers/erc20/erc20ActionProvider.js +87 -35
- package/dist/action-providers/erc20/erc20ActionProvider.test.js +115 -52
- package/dist/action-providers/erc20/schemas.d.ts +25 -12
- package/dist/action-providers/erc20/schemas.js +34 -6
- package/dist/action-providers/erc20/utils.d.ts +19 -0
- package/dist/action-providers/erc20/utils.js +54 -0
- package/dist/action-providers/flaunch/constants.d.ts +1 -1
- package/dist/action-providers/flaunch/constants.js +2 -2
- package/dist/action-providers/flaunch/flaunchActionProvider.js +3 -11
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +5 -0
- package/dist/action-providers/index.d.ts +4 -0
- package/dist/action-providers/index.js +4 -0
- package/dist/action-providers/jupiter/schemas.d.ts +1 -1
- package/dist/action-providers/moonwell/schemas.d.ts +2 -2
- package/dist/action-providers/morpho/morphoActionProvider.js +5 -5
- package/dist/action-providers/morpho/schemas.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +5 -0
- package/dist/action-providers/pyth/pythActionProvider.test.js +5 -1
- package/dist/action-providers/superfluid/constants.d.ts +814 -0
- package/dist/action-providers/superfluid/constants.js +2826 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.d.ts +2 -0
- package/dist/action-providers/superfluid/graphQueries/endpoints.js +5 -0
- package/dist/action-providers/superfluid/graphQueries/queries.d.ts +1 -0
- package/dist/action-providers/superfluid/graphQueries/queries.js +35 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.d.ts +8 -0
- package/dist/action-providers/superfluid/graphQueries/superfluidGraphQueries.js +24 -0
- package/dist/action-providers/superfluid/graphQueries/types.d.ts +27 -0
- package/dist/action-providers/superfluid/graphQueries/types.js +2 -0
- package/dist/action-providers/superfluid/index.d.ts +7 -0
- package/dist/action-providers/superfluid/index.js +23 -0
- package/dist/action-providers/superfluid/schemas.d.ts +86 -0
- package/dist/action-providers/superfluid/schemas.js +103 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.d.ts +20 -0
- package/dist/action-providers/superfluid/superfluidActionProvider.js +36 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.d.ts +46 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.js +143 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidPoolActionProvider.test.js +92 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.d.ts +27 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.js +71 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidQueryActionProvider.test.js +57 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.d.ts +56 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.js +191 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidStreamActionProvider.test.js +80 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.d.ts +30 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +108 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.test.js +75 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.d.ts +32 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.js +101 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.d.ts +1 -0
- package/dist/action-providers/superfluid/superfluidWrapperActionProvider.test.js +85 -0
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +18 -0
- package/dist/action-providers/superfluid/utils/parseLogs.js +78 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +4 -16
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +20 -41
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +11 -33
- package/dist/action-providers/wallet/walletActionProvider.js +21 -10
- package/dist/action-providers/wallet/walletActionProvider.test.js +6 -2
- 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/zeroX/index.d.ts +1 -0
- package/dist/action-providers/zeroX/index.js +17 -0
- package/dist/action-providers/zeroX/schemas.d.ts +51 -0
- package/dist/action-providers/zeroX/schemas.js +82 -0
- package/dist/action-providers/zeroX/utils.d.ts +23 -0
- package/dist/action-providers/zeroX/utils.js +106 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.d.ts +57 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.js +407 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zeroX/zeroXActionProvider.test.js +445 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +20 -2
- package/dist/wallet-providers/cdpEvmWalletProvider.js +40 -15
- package/dist/wallet-providers/cdpShared.d.ts +9 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +29 -3
- package/dist/wallet-providers/cdpSmartWalletProvider.js +64 -28
- package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/cdpSolanaWalletProvider.js +7 -7
- package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +15 -12
- package/dist/wallet-providers/evmWalletProvider.d.ts +5 -1
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +12 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +12 -2
- package/dist/wallet-providers/legacyCdpWalletProvider.js +11 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +10 -2
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +12 -3
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -1
- package/dist/wallet-providers/privyEvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmWalletProvider.js +2 -1
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/solanaKeypairWalletProvider.js +3 -4
- package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +4 -2
- package/dist/wallet-providers/viemWalletProvider.d.ts +12 -2
- package/dist/wallet-providers/viemWalletProvider.js +12 -3
- package/dist/wallet-providers/viemWalletProvider.test.js +6 -5
- package/dist/wallet-providers/walletProvider.d.ts +1 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +10 -2
- package/dist/wallet-providers/zeroDevWalletProvider.js +14 -5
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +2 -2
- package/package.json +4 -2
|
@@ -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 {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zerionActionProvider_1 = require("./zerionActionProvider");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
// Mocks for fetch and utils
|
|
6
|
+
global.fetch = jest.fn();
|
|
7
|
+
jest.mock("./utils", () => ({
|
|
8
|
+
formatPortfolioData: jest.fn(() => "formatted portfolio"),
|
|
9
|
+
formatPositionsData: jest.fn(() => "formatted positions"),
|
|
10
|
+
}));
|
|
11
|
+
describe("ZerionActionProvider", () => {
|
|
12
|
+
const mockApiKey = "test-api-key";
|
|
13
|
+
const originalEnv = process.env.ZERION_API_KEY;
|
|
14
|
+
const mockFungiblePositionResponse = {
|
|
15
|
+
links: {
|
|
16
|
+
self: "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/positions/",
|
|
17
|
+
},
|
|
18
|
+
data: [
|
|
19
|
+
{
|
|
20
|
+
type: "positions",
|
|
21
|
+
id: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa-polygon-asset-none-",
|
|
22
|
+
attributes: {
|
|
23
|
+
parent: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa-polygon-asset-none-",
|
|
24
|
+
protocol: null,
|
|
25
|
+
pool_address: "0x109830a1aaad605bbf02a9dfa7b0b92ec2fb7daa",
|
|
26
|
+
name: "Asset",
|
|
27
|
+
group_id: "0a771a0064dad468045899032c7fb01a971f973f7dff0a5cdc3ce199f45e94d7",
|
|
28
|
+
position_type: "deposit",
|
|
29
|
+
quantity: {
|
|
30
|
+
int: "12345678",
|
|
31
|
+
decimals: 5,
|
|
32
|
+
float: 123.45678,
|
|
33
|
+
numeric: "123.45678",
|
|
34
|
+
},
|
|
35
|
+
value: 5.384656557642683,
|
|
36
|
+
price: 0.043615722,
|
|
37
|
+
changes: {
|
|
38
|
+
absolute_1d: 0.272309794,
|
|
39
|
+
percent_1d: 5.326512552079021,
|
|
40
|
+
},
|
|
41
|
+
fungible_info: {
|
|
42
|
+
name: "Bankless BED Index",
|
|
43
|
+
symbol: "BED",
|
|
44
|
+
description: "The BED index is meant to track crypto’s top 3 investab...",
|
|
45
|
+
icon: {
|
|
46
|
+
url: "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png",
|
|
47
|
+
},
|
|
48
|
+
flags: {
|
|
49
|
+
verified: true,
|
|
50
|
+
},
|
|
51
|
+
implementations: [
|
|
52
|
+
{
|
|
53
|
+
chain_id: "ethereum",
|
|
54
|
+
address: "0x2af1df3ab0ab157e1e2ad8f88a7d04fbea0c7dc6",
|
|
55
|
+
decimals: 18,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
flags: {
|
|
60
|
+
displayable: true,
|
|
61
|
+
is_trash: true,
|
|
62
|
+
},
|
|
63
|
+
updated_at: "2023-11-10T23:00:00Z",
|
|
64
|
+
updated_at_block: 0,
|
|
65
|
+
application_metadata: {
|
|
66
|
+
name: "AAVE",
|
|
67
|
+
icon: {
|
|
68
|
+
url: "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png",
|
|
69
|
+
},
|
|
70
|
+
url: "https://app.aave.com/",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
relationships: {
|
|
74
|
+
chain: {
|
|
75
|
+
links: {
|
|
76
|
+
related: "https://api.zerion.io/v1/chains/polygon",
|
|
77
|
+
},
|
|
78
|
+
data: {
|
|
79
|
+
type: "chains",
|
|
80
|
+
id: "polygon",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
fungible: {
|
|
84
|
+
links: {
|
|
85
|
+
related: "https://api.zerion.io/v1/fungibles/0x111c47865ade3b172a928df8f990bc7f2a3b9aaa",
|
|
86
|
+
},
|
|
87
|
+
data: {
|
|
88
|
+
type: "fungibles",
|
|
89
|
+
id: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
dapp: {
|
|
93
|
+
data: {
|
|
94
|
+
type: "dapps",
|
|
95
|
+
id: "aave-v3",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
const mockPortfolioResponse = {
|
|
103
|
+
links: {
|
|
104
|
+
self: "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio",
|
|
105
|
+
},
|
|
106
|
+
data: {
|
|
107
|
+
type: "portfolio",
|
|
108
|
+
id: "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990",
|
|
109
|
+
attributes: {
|
|
110
|
+
positions_distribution_by_type: {
|
|
111
|
+
wallet: 1864.774102420957,
|
|
112
|
+
deposited: 78.04192492782934,
|
|
113
|
+
borrowed: 0.9751475798305564,
|
|
114
|
+
locked: 5.780032725068765,
|
|
115
|
+
staked: 66.13183205505294,
|
|
116
|
+
},
|
|
117
|
+
positions_distribution_by_chain: {
|
|
118
|
+
arbitrum: 458.3555051522226,
|
|
119
|
+
aurora: 72.01031337463428,
|
|
120
|
+
avalanche: 17.128850607339444,
|
|
121
|
+
base: 55.01550749900544,
|
|
122
|
+
"binance-smart-chain": 5.561075880033699,
|
|
123
|
+
celo: 31.293849330045006,
|
|
124
|
+
ethereum: 1214.009900354964,
|
|
125
|
+
fantom: 84.58514074264951,
|
|
126
|
+
linea: 8.258227109505139,
|
|
127
|
+
optimism: 573.032664994399,
|
|
128
|
+
polygon: 64.31407562634853,
|
|
129
|
+
xdai: 113.1679493137936,
|
|
130
|
+
"zksync-era": 9.451002156306377,
|
|
131
|
+
},
|
|
132
|
+
total: {
|
|
133
|
+
positions: 2017.4858230069574,
|
|
134
|
+
},
|
|
135
|
+
changes: {
|
|
136
|
+
absolute_1d: 102.0271468171374,
|
|
137
|
+
percent_1d: 5.326512552079021,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
beforeEach(() => {
|
|
143
|
+
jest.clearAllMocks();
|
|
144
|
+
process.env.ZERION_API_KEY = mockApiKey;
|
|
145
|
+
});
|
|
146
|
+
afterAll(() => {
|
|
147
|
+
process.env.ZERION_API_KEY = originalEnv;
|
|
148
|
+
});
|
|
149
|
+
it("should throw if no API key is provided", () => {
|
|
150
|
+
delete process.env.ZERION_API_KEY;
|
|
151
|
+
expect(() => new zerionActionProvider_1.ZerionActionProvider()).toThrow("ZERION_API_KEY is not configured.");
|
|
152
|
+
});
|
|
153
|
+
it("should use provided API key from config", () => {
|
|
154
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: "foo" });
|
|
155
|
+
expect(provider).toBeDefined();
|
|
156
|
+
});
|
|
157
|
+
// supportsNetwork tests
|
|
158
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
|
|
159
|
+
it("should support the protocol family", () => {
|
|
160
|
+
expect(provider.supportsNetwork({ protocolFamily: "evm" })).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
it("should not support other protocol families", () => {
|
|
163
|
+
expect(provider.supportsNetwork({ protocolFamily: "other-protocol-family" })).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
it("should handle invalid network objects", () => {
|
|
166
|
+
expect(provider.supportsNetwork({ protocolFamily: "invalid-protocol" })).toBe(false);
|
|
167
|
+
expect(provider.supportsNetwork({})).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
describe("getPortfolioOverview", () => {
|
|
170
|
+
const validAddress = "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990";
|
|
171
|
+
const invalidAddress = "invalid-address";
|
|
172
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
|
|
173
|
+
it("returns error for invalid address", async () => {
|
|
174
|
+
const result = await provider.getPortfolioOverview({ walletAddress: invalidAddress });
|
|
175
|
+
expect(result).toMatch(/Invalid wallet address/);
|
|
176
|
+
});
|
|
177
|
+
it("returns formatted data for valid address", async () => {
|
|
178
|
+
global.fetch.mockResolvedValueOnce({
|
|
179
|
+
json: jest.fn().mockResolvedValue(mockPortfolioResponse),
|
|
180
|
+
});
|
|
181
|
+
const result = await provider.getPortfolioOverview({ walletAddress: validAddress });
|
|
182
|
+
expect(utils_1.formatPortfolioData).toHaveBeenCalledWith(mockPortfolioResponse.data);
|
|
183
|
+
expect(result).toBe("formatted portfolio");
|
|
184
|
+
});
|
|
185
|
+
it("returns error on fetch failure", async () => {
|
|
186
|
+
global.fetch.mockRejectedValueOnce(new Error("fail"));
|
|
187
|
+
const result = await provider.getPortfolioOverview({ walletAddress: validAddress });
|
|
188
|
+
expect(result).toMatch(/Error fetching portfolio overview/);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe("getFungiblePositions", () => {
|
|
192
|
+
const validAddress = "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990";
|
|
193
|
+
const invalidAddress = "invalid-address";
|
|
194
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
|
|
195
|
+
it("returns error for invalid address", async () => {
|
|
196
|
+
const result = await provider.getFungiblePositions({ walletAddress: invalidAddress });
|
|
197
|
+
expect(result).toMatch(/Invalid wallet address/);
|
|
198
|
+
});
|
|
199
|
+
it("returns formatted data for valid address", async () => {
|
|
200
|
+
global.fetch.mockResolvedValueOnce({
|
|
201
|
+
json: jest.fn().mockResolvedValue(mockFungiblePositionResponse),
|
|
202
|
+
});
|
|
203
|
+
const result = await provider.getFungiblePositions({ walletAddress: validAddress });
|
|
204
|
+
expect(utils_1.formatPositionsData).toHaveBeenCalledWith(mockFungiblePositionResponse.data);
|
|
205
|
+
expect(result).toBe("formatted positions");
|
|
206
|
+
});
|
|
207
|
+
it("returns error on fetch failure", async () => {
|
|
208
|
+
global.fetch.mockRejectedValueOnce(new Error("fail"));
|
|
209
|
+
const result = await provider.getFungiblePositions({ walletAddress: validAddress });
|
|
210
|
+
expect(result).toMatch(/Error fetching fungible positions/);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./zeroXActionProvider";
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./zeroXActionProvider"), exports);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for getting a swap price.
|
|
4
|
+
*/
|
|
5
|
+
export declare const GetSwapPriceSchema: z.ZodObject<{
|
|
6
|
+
sellToken: z.ZodString;
|
|
7
|
+
buyToken: z.ZodString;
|
|
8
|
+
sellAmount: z.ZodString;
|
|
9
|
+
slippageBps: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
10
|
+
swapFeeRecipient: z.ZodOptional<z.ZodString>;
|
|
11
|
+
swapFeeBps: z.ZodDefault<z.ZodNumber>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
slippageBps: number;
|
|
14
|
+
buyToken: string;
|
|
15
|
+
sellToken: string;
|
|
16
|
+
sellAmount: string;
|
|
17
|
+
swapFeeBps: number;
|
|
18
|
+
swapFeeRecipient?: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
buyToken: string;
|
|
21
|
+
sellToken: string;
|
|
22
|
+
sellAmount: string;
|
|
23
|
+
slippageBps?: number | undefined;
|
|
24
|
+
swapFeeRecipient?: string | undefined;
|
|
25
|
+
swapFeeBps?: number | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Input schema for executing a swap.
|
|
29
|
+
*/
|
|
30
|
+
export declare const ExecuteSwapSchema: z.ZodObject<{
|
|
31
|
+
sellToken: z.ZodString;
|
|
32
|
+
buyToken: z.ZodString;
|
|
33
|
+
sellAmount: z.ZodString;
|
|
34
|
+
slippageBps: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
35
|
+
swapFeeRecipient: z.ZodOptional<z.ZodString>;
|
|
36
|
+
swapFeeBps: z.ZodDefault<z.ZodNumber>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
slippageBps: number;
|
|
39
|
+
buyToken: string;
|
|
40
|
+
sellToken: string;
|
|
41
|
+
sellAmount: string;
|
|
42
|
+
swapFeeBps: number;
|
|
43
|
+
swapFeeRecipient?: string | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
buyToken: string;
|
|
46
|
+
sellToken: string;
|
|
47
|
+
sellAmount: string;
|
|
48
|
+
slippageBps?: number | undefined;
|
|
49
|
+
swapFeeRecipient?: string | undefined;
|
|
50
|
+
swapFeeBps?: number | undefined;
|
|
51
|
+
}>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExecuteSwapSchema = exports.GetSwapPriceSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
/**
|
|
6
|
+
* Input schema for getting a swap price.
|
|
7
|
+
*/
|
|
8
|
+
exports.GetSwapPriceSchema = zod_1.z
|
|
9
|
+
.object({
|
|
10
|
+
sellToken: zod_1.z
|
|
11
|
+
.string()
|
|
12
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
13
|
+
.describe("The token contract address to sell"),
|
|
14
|
+
buyToken: zod_1.z
|
|
15
|
+
.string()
|
|
16
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
17
|
+
.describe("The token contract address to buy"),
|
|
18
|
+
sellAmount: zod_1.z
|
|
19
|
+
.string()
|
|
20
|
+
.describe("The amount of sellToken to sell in whole units (e.g., 1.5 WETH, 10 USDC)"),
|
|
21
|
+
slippageBps: zod_1.z
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.min(0)
|
|
25
|
+
.max(10000)
|
|
26
|
+
.optional()
|
|
27
|
+
.default(100)
|
|
28
|
+
.describe("The maximum acceptable slippage in basis points (0-10000, default: 100)"),
|
|
29
|
+
swapFeeRecipient: zod_1.z
|
|
30
|
+
.string()
|
|
31
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
32
|
+
.optional()
|
|
33
|
+
.describe("The wallet address to receive an affiliate fee on the trade"),
|
|
34
|
+
swapFeeBps: zod_1.z
|
|
35
|
+
.number()
|
|
36
|
+
.int()
|
|
37
|
+
.min(0)
|
|
38
|
+
.max(1000)
|
|
39
|
+
.default(100)
|
|
40
|
+
.describe("The amount in basis points (0-1000) of the sellToken to charge as trading fee (defaults to 100 = 1%), only used if swapFeeRecipient is provided"),
|
|
41
|
+
})
|
|
42
|
+
.strip()
|
|
43
|
+
.describe("Get a price quote for swapping one token for another");
|
|
44
|
+
/**
|
|
45
|
+
* Input schema for executing a swap.
|
|
46
|
+
*/
|
|
47
|
+
exports.ExecuteSwapSchema = zod_1.z
|
|
48
|
+
.object({
|
|
49
|
+
sellToken: zod_1.z
|
|
50
|
+
.string()
|
|
51
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
52
|
+
.describe("The token contract address to sell"),
|
|
53
|
+
buyToken: zod_1.z
|
|
54
|
+
.string()
|
|
55
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
56
|
+
.describe("The token contract address to buy"),
|
|
57
|
+
sellAmount: zod_1.z
|
|
58
|
+
.string()
|
|
59
|
+
.describe("The amount of sellToken to sell in whole units (e.g., 1.5 WETH, 10 USDC)"),
|
|
60
|
+
slippageBps: zod_1.z
|
|
61
|
+
.number()
|
|
62
|
+
.int()
|
|
63
|
+
.min(0)
|
|
64
|
+
.max(10000)
|
|
65
|
+
.optional()
|
|
66
|
+
.default(100)
|
|
67
|
+
.describe("The maximum acceptable slippage in basis points (0-10000, default: 100)"),
|
|
68
|
+
swapFeeRecipient: zod_1.z
|
|
69
|
+
.string()
|
|
70
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
71
|
+
.optional()
|
|
72
|
+
.describe("The wallet address to receive an affiliate fee on the trade"),
|
|
73
|
+
swapFeeBps: zod_1.z
|
|
74
|
+
.number()
|
|
75
|
+
.int()
|
|
76
|
+
.min(0)
|
|
77
|
+
.max(1000)
|
|
78
|
+
.default(100)
|
|
79
|
+
.describe("The amount in basis points (0-1000) of the sellToken to charge as trading fee (defaults to 100 = 1%), only used if swapFeeRecipient is provided"),
|
|
80
|
+
})
|
|
81
|
+
.strip()
|
|
82
|
+
.describe("Execute a swap between two tokens");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
2
|
+
export declare const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a token is native ETH.
|
|
5
|
+
*
|
|
6
|
+
* @param token - The token address to check.
|
|
7
|
+
* @returns True if the token is native ETH, false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isNativeEth(token: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the details (decimals and name) for both fromToken and toToken
|
|
12
|
+
*
|
|
13
|
+
* @param walletProvider - The EVM wallet provider to read contracts
|
|
14
|
+
* @param fromToken - The contract address of the from token
|
|
15
|
+
* @param toToken - The contract address of the to token
|
|
16
|
+
* @returns Promise<{fromTokenDecimals: number, toTokenDecimals: number, fromTokenName: string, toTokenName: string}>
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTokenDetails(walletProvider: EvmWalletProvider, fromToken: string, toToken: string): Promise<{
|
|
19
|
+
fromTokenDecimals: number;
|
|
20
|
+
toTokenDecimals: number;
|
|
21
|
+
fromTokenName: string;
|
|
22
|
+
toTokenName: string;
|
|
23
|
+
}>;
|