@coinbase/agentkit 0.9.1 → 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.
Files changed (36) hide show
  1. package/README.md +106 -54
  2. package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -0
  3. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +43 -0
  4. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +151 -0
  5. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
  6. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +242 -0
  7. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +42 -0
  8. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +132 -0
  9. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
  10. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +199 -0
  11. package/dist/action-providers/cdp/index.d.ts +3 -0
  12. package/dist/action-providers/cdp/index.js +3 -0
  13. package/dist/action-providers/cdp/schemas.d.ts +29 -0
  14. package/dist/action-providers/cdp/schemas.js +32 -1
  15. package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
  16. package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
  17. package/dist/action-providers/index.d.ts +1 -0
  18. package/dist/action-providers/index.js +1 -0
  19. package/dist/action-providers/zerion/constants.d.ts +1 -0
  20. package/dist/action-providers/zerion/constants.js +4 -0
  21. package/dist/action-providers/zerion/index.d.ts +2 -0
  22. package/dist/action-providers/zerion/index.js +18 -0
  23. package/dist/action-providers/zerion/schemas.d.ts +11 -0
  24. package/dist/action-providers/zerion/schemas.js +15 -0
  25. package/dist/action-providers/zerion/types.d.ts +125 -0
  26. package/dist/action-providers/zerion/types.js +16 -0
  27. package/dist/action-providers/zerion/utils.d.ts +3 -0
  28. package/dist/action-providers/zerion/utils.js +45 -0
  29. package/dist/action-providers/zerion/zerionActionProvider.d.ts +57 -0
  30. package/dist/action-providers/zerion/zerionActionProvider.js +159 -0
  31. package/dist/action-providers/zerion/zerionActionProvider.test.d.ts +1 -0
  32. package/dist/action-providers/zerion/zerionActionProvider.test.js +213 -0
  33. package/dist/wallet-providers/cdpShared.d.ts +4 -0
  34. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +8 -1
  35. package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -11
  36. package/package.json +2 -2
@@ -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,3 @@
1
+ import { ZerionFungiblePosition, ZerionPortfolio } from "./types";
2
+ export declare const formatPortfolioData: (data: ZerionPortfolio) => string;
3
+ export declare const formatPositionsData: (data: ZerionFungiblePosition[]) => string;
@@ -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&currency=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&currency=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,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
+ });
@@ -40,6 +40,10 @@ export interface CdpSmartWalletProviderConfig extends CdpWalletProviderConfig {
40
40
  * The name of the smart wallet.
41
41
  */
42
42
  smartAccountName?: string;
43
+ /**
44
+ * The paymaster URL for gasless transactions.
45
+ */
46
+ paymasterUrl?: string;
43
47
  }
44
48
  /**
45
49
  * A wallet provider that can be used to interact with the CDP.
@@ -1,4 +1,4 @@
1
- import { CdpClient } from "@coinbase/cdp-sdk";
1
+ import { CdpClient, EvmSmartAccount } from "@coinbase/cdp-sdk";
2
2
  import { Abi, Address, ContractFunctionArgs, ContractFunctionName, Hex, ReadContractParameters, ReadContractReturnType, TransactionRequest } from "viem";
3
3
  import { Network } from "../network";
4
4
  import { EvmWalletProvider } from "./evmWalletProvider";
@@ -8,6 +8,7 @@ import { WalletProviderWithClient, CdpSmartWalletProviderConfig } from "./cdpSha
8
8
  */
9
9
  export declare class CdpSmartWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
10
10
  #private;
11
+ smartAccount: EvmSmartAccount;
11
12
  /**
12
13
  * Constructs a new CdpSmartWalletProvider.
13
14
  *
@@ -84,6 +85,12 @@ export declare class CdpSmartWalletProvider extends EvmWalletProvider implements
84
85
  * @returns The CDP client.
85
86
  */
86
87
  getClient(): CdpClient;
88
+ /**
89
+ * Gets the paymaster URL for gasless transactions.
90
+ *
91
+ * @returns The paymaster URL if configured, undefined otherwise.
92
+ */
93
+ getPaymasterUrl(): string | undefined;
87
94
  /**
88
95
  * Gets the balance of the smart wallet.
89
96
  *