@coinbase/agentkit 0.4.0 → 0.5.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 (65) hide show
  1. package/README.md +73 -7
  2. package/dist/action-providers/across/acrossActionProvider.d.ts +50 -0
  3. package/dist/action-providers/across/acrossActionProvider.js +333 -0
  4. package/dist/action-providers/across/acrossActionProvider.test.d.ts +1 -0
  5. package/dist/action-providers/across/acrossActionProvider.test.js +391 -0
  6. package/dist/action-providers/across/constants.d.ts +1 -0
  7. package/dist/action-providers/across/constants.js +2 -0
  8. package/dist/action-providers/across/index.d.ts +1 -0
  9. package/dist/action-providers/across/index.js +17 -0
  10. package/dist/action-providers/across/schemas.d.ts +36 -0
  11. package/dist/action-providers/across/schemas.js +46 -0
  12. package/dist/action-providers/across/utils.d.ts +7 -0
  13. package/dist/action-providers/across/utils.js +25 -0
  14. package/dist/action-providers/erc20/constants.d.ts +2 -0
  15. package/dist/action-providers/erc20/constants.js +12 -1
  16. package/dist/action-providers/erc20/erc20ActionProvider.js +18 -0
  17. package/dist/action-providers/erc20/erc20ActionProvider.test.js +4 -0
  18. package/dist/action-providers/index.d.ts +2 -0
  19. package/dist/action-providers/index.js +2 -0
  20. package/dist/action-providers/messari/constants.d.ts +17 -0
  21. package/dist/action-providers/messari/constants.js +20 -0
  22. package/dist/action-providers/messari/index.d.ts +5 -0
  23. package/dist/action-providers/messari/index.js +21 -0
  24. package/dist/action-providers/messari/messariActionProvider.d.ts +42 -0
  25. package/dist/action-providers/messari/messariActionProvider.js +128 -0
  26. package/dist/action-providers/messari/messariActionProvider.test.d.ts +1 -0
  27. package/dist/action-providers/messari/messariActionProvider.test.js +152 -0
  28. package/dist/action-providers/messari/schemas.d.ts +11 -0
  29. package/dist/action-providers/messari/schemas.js +16 -0
  30. package/dist/action-providers/messari/types.d.ts +40 -0
  31. package/dist/action-providers/messari/types.js +2 -0
  32. package/dist/action-providers/messari/utils.d.ts +22 -0
  33. package/dist/action-providers/messari/utils.js +65 -0
  34. package/dist/wallet-providers/cdpWalletProvider.d.ts +11 -2
  35. package/dist/wallet-providers/cdpWalletProvider.js +24 -0
  36. package/dist/wallet-providers/cdpWalletProvider.test.d.ts +1 -0
  37. package/dist/wallet-providers/cdpWalletProvider.test.js +701 -0
  38. package/dist/wallet-providers/evmWalletProvider.test.d.ts +1 -0
  39. package/dist/wallet-providers/evmWalletProvider.test.js +56 -0
  40. package/dist/wallet-providers/index.d.ts +1 -0
  41. package/dist/wallet-providers/index.js +1 -0
  42. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +167 -0
  43. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +438 -0
  44. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.d.ts +1 -0
  45. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +280 -0
  46. package/dist/wallet-providers/privyEvmWalletProvider.test.d.ts +1 -0
  47. package/dist/wallet-providers/privyEvmWalletProvider.test.js +331 -0
  48. package/dist/wallet-providers/privyShared.d.ts +9 -0
  49. package/dist/wallet-providers/privyShared.js +16 -5
  50. package/dist/wallet-providers/privySvmWalletProvider.test.d.ts +1 -0
  51. package/dist/wallet-providers/privySvmWalletProvider.test.js +310 -0
  52. package/dist/wallet-providers/privyWalletProvider.d.ts +21 -8
  53. package/dist/wallet-providers/privyWalletProvider.js +39 -7
  54. package/dist/wallet-providers/privyWalletProvider.test.d.ts +1 -0
  55. package/dist/wallet-providers/privyWalletProvider.test.js +124 -0
  56. package/dist/wallet-providers/smartWalletProvider.test.d.ts +1 -0
  57. package/dist/wallet-providers/smartWalletProvider.test.js +388 -0
  58. package/dist/wallet-providers/solanaKeypairWalletProvider.test.js +210 -16
  59. package/dist/wallet-providers/svmWalletProvider.test.d.ts +1 -0
  60. package/dist/wallet-providers/svmWalletProvider.test.js +55 -0
  61. package/dist/wallet-providers/viemWalletProvider.test.d.ts +1 -0
  62. package/dist/wallet-providers/viemWalletProvider.test.js +338 -0
  63. package/dist/wallet-providers/walletProvider.test.d.ts +1 -0
  64. package/dist/wallet-providers/walletProvider.test.js +103 -0
  65. package/package.json +24 -20
@@ -0,0 +1,5 @@
1
+ export * from "./messariActionProvider";
2
+ export * from "./schemas";
3
+ export * from "./types";
4
+ export * from "./constants";
5
+ export * from "./utils";
@@ -0,0 +1,21 @@
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("./messariActionProvider"), exports);
18
+ __exportStar(require("./schemas"), exports);
19
+ __exportStar(require("./types"), exports);
20
+ __exportStar(require("./constants"), exports);
21
+ __exportStar(require("./utils"), exports);
@@ -0,0 +1,42 @@
1
+ import { z } from "zod";
2
+ import { ActionProvider } from "../actionProvider";
3
+ import { Network } from "../../network";
4
+ import { MessariResearchQuestionSchema } from "./schemas";
5
+ import { MessariActionProviderConfig } from "./types";
6
+ /**
7
+ * MessariActionProvider is an action provider for Messari AI toolkit interactions.
8
+ * It enables AI agents to ask research questions about crypto markets, protocols, and tokens.
9
+ *
10
+ * @augments ActionProvider
11
+ */
12
+ export declare class MessariActionProvider extends ActionProvider {
13
+ private readonly apiKey;
14
+ /**
15
+ * Constructor for the MessariActionProvider class.
16
+ *
17
+ * @param config - The configuration options for the MessariActionProvider
18
+ */
19
+ constructor(config?: MessariActionProviderConfig);
20
+ /**
21
+ * Makes a request to the Messari AI API with a research question
22
+ *
23
+ * @param args - The arguments containing the research question
24
+ * @returns A string containing the research results or an error message
25
+ */
26
+ researchQuestion(args: z.infer<typeof MessariResearchQuestionSchema>): Promise<string>;
27
+ /**
28
+ * Checks if the action provider supports the given network.
29
+ * Messari research is network-agnostic, so it supports all networks.
30
+ *
31
+ * @param _ - The network to check
32
+ * @returns Always returns true as Messari research is network-agnostic
33
+ */
34
+ supportsNetwork(_: Network): boolean;
35
+ }
36
+ /**
37
+ * Factory function to create a new MessariActionProvider instance.
38
+ *
39
+ * @param config - The configuration options for the MessariActionProvider
40
+ * @returns A new instance of MessariActionProvider
41
+ */
42
+ export declare const messariActionProvider: (config?: MessariActionProviderConfig) => MessariActionProvider;
@@ -0,0 +1,128 @@
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.messariActionProvider = exports.MessariActionProvider = void 0;
13
+ const zod_1 = require("zod");
14
+ const actionProvider_1 = require("../actionProvider");
15
+ const actionDecorator_1 = require("../actionDecorator");
16
+ const schemas_1 = require("./schemas");
17
+ const constants_1 = require("./constants");
18
+ const utils_1 = require("./utils");
19
+ /**
20
+ * MessariActionProvider is an action provider for Messari AI toolkit interactions.
21
+ * It enables AI agents to ask research questions about crypto markets, protocols, and tokens.
22
+ *
23
+ * @augments ActionProvider
24
+ */
25
+ class MessariActionProvider extends actionProvider_1.ActionProvider {
26
+ /**
27
+ * Constructor for the MessariActionProvider class.
28
+ *
29
+ * @param config - The configuration options for the MessariActionProvider
30
+ */
31
+ constructor(config = {}) {
32
+ super("messari", []);
33
+ config.apiKey || (config.apiKey = process.env.MESSARI_API_KEY);
34
+ if (!config.apiKey) {
35
+ throw new Error(constants_1.API_KEY_MISSING_ERROR);
36
+ }
37
+ this.apiKey = config.apiKey;
38
+ }
39
+ /**
40
+ * Makes a request to the Messari AI API with a research question
41
+ *
42
+ * @param args - The arguments containing the research question
43
+ * @returns A string containing the research results or an error message
44
+ */
45
+ async researchQuestion(args) {
46
+ try {
47
+ // Make API request
48
+ const response = await fetch(`${constants_1.MESSARI_BASE_URL}/chat/completions`, {
49
+ method: "POST",
50
+ headers: {
51
+ "Content-Type": "application/json",
52
+ "x-messari-api-key": this.apiKey,
53
+ },
54
+ body: JSON.stringify({
55
+ messages: [
56
+ {
57
+ role: "user",
58
+ content: args.question,
59
+ },
60
+ ],
61
+ }),
62
+ });
63
+ if (!response.ok) {
64
+ throw await (0, utils_1.createMessariError)(response);
65
+ }
66
+ // Parse and validate response
67
+ let data;
68
+ try {
69
+ data = (await response.json());
70
+ }
71
+ catch (jsonError) {
72
+ throw new Error(`Failed to parse API response: ${jsonError instanceof Error ? jsonError.message : String(jsonError)}`);
73
+ }
74
+ if (!data.data?.messages?.[0]?.content) {
75
+ throw new Error("Received invalid response format from Messari API");
76
+ }
77
+ const result = data.data.messages[0].content;
78
+ return `Messari Research Results:\n\n${result}`;
79
+ }
80
+ catch (error) {
81
+ if (error instanceof Error && "responseText" in error) {
82
+ return (0, utils_1.formatMessariApiError)(error);
83
+ }
84
+ return (0, utils_1.formatGenericError)(error);
85
+ }
86
+ }
87
+ /**
88
+ * Checks if the action provider supports the given network.
89
+ * Messari research is network-agnostic, so it supports all networks.
90
+ *
91
+ * @param _ - The network to check
92
+ * @returns Always returns true as Messari research is network-agnostic
93
+ */
94
+ supportsNetwork(_) {
95
+ return true; // Messari research is network-agnostic
96
+ }
97
+ }
98
+ exports.MessariActionProvider = MessariActionProvider;
99
+ __decorate([
100
+ (0, actionDecorator_1.CreateAction)({
101
+ name: "research_question",
102
+ description: `
103
+ This tool queries Messari AI for comprehensive crypto research across these datasets:
104
+ 1. News/Content - Latest crypto news, blogs, podcasts
105
+ 2. Exchanges - CEX/DEX volumes, market share, assets listed
106
+ 3. Onchain Data - Active addresses, transaction fees, total transactions.
107
+ 4. Token Unlocks - Upcoming supply unlocks, vesting schedules, and token emission details
108
+ 5. Market Data - Asset prices, trading volume, market cap, TVL, and historical performance
109
+ 6. Fundraising - Investment data, funding rounds, venture capital activity.
110
+ 7. Protocol Research - Technical analysis of how protocols work, tokenomics, and yield mechanisms
111
+ 8. Social Data - Twitter followers and Reddit subscribers metrics, growth trends
112
+
113
+ Examples: "Which DEXs have the highest trading volume this month?", "When is Arbitrum's next major token unlock?", "How does Morpho generate yield for users?", "Which cryptocurrency has gained the most Twitter followers in 2023?", "What did Vitalik Buterin say about rollups in his recent blog posts?"
114
+ `,
115
+ schema: schemas_1.MessariResearchQuestionSchema,
116
+ }),
117
+ __metadata("design:type", Function),
118
+ __metadata("design:paramtypes", [void 0]),
119
+ __metadata("design:returntype", Promise)
120
+ ], MessariActionProvider.prototype, "researchQuestion", null);
121
+ /**
122
+ * Factory function to create a new MessariActionProvider instance.
123
+ *
124
+ * @param config - The configuration options for the MessariActionProvider
125
+ * @returns A new instance of MessariActionProvider
126
+ */
127
+ const messariActionProvider = (config = {}) => new MessariActionProvider(config);
128
+ exports.messariActionProvider = messariActionProvider;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const messariActionProvider_1 = require("./messariActionProvider");
4
+ const constants_1 = require("./constants");
5
+ const MOCK_API_KEY = "messari-test-key";
6
+ const MOCK_RESEARCH_RESPONSE = {
7
+ data: {
8
+ messages: [
9
+ {
10
+ role: "assistant",
11
+ content: "Ethereum (ETH) has shown strong performance over the past month with a 15% price increase. The current price is approximately $3,500, up from $3,000 at the beginning of the month. Trading volume has also increased by 20% in the same period.",
12
+ },
13
+ ],
14
+ },
15
+ };
16
+ const MOCK_ERROR_RESPONSE = {
17
+ error: "Internal server error, please try again. If the problem persists, please contact support",
18
+ data: null,
19
+ };
20
+ describe("MessariActionProvider", () => {
21
+ let provider;
22
+ beforeEach(() => {
23
+ process.env.MESSARI_API_KEY = MOCK_API_KEY;
24
+ provider = (0, messariActionProvider_1.messariActionProvider)({ apiKey: MOCK_API_KEY });
25
+ jest.restoreAllMocks();
26
+ });
27
+ afterEach(() => {
28
+ jest.clearAllMocks();
29
+ delete process.env.MESSARI_API_KEY;
30
+ });
31
+ describe("constructor", () => {
32
+ it("should initialize with API key from constructor", () => {
33
+ const customProvider = (0, messariActionProvider_1.messariActionProvider)({ apiKey: "custom-key" });
34
+ expect(customProvider["apiKey"]).toBe("custom-key");
35
+ });
36
+ it("should initialize with API key from environment variable", () => {
37
+ process.env.MESSARI_API_KEY = "env-key";
38
+ const envProvider = (0, messariActionProvider_1.messariActionProvider)();
39
+ expect(envProvider["apiKey"]).toBe("env-key");
40
+ });
41
+ it("should throw error if API key is not provided", () => {
42
+ delete process.env.MESSARI_API_KEY;
43
+ expect(() => (0, messariActionProvider_1.messariActionProvider)()).toThrow(constants_1.API_KEY_MISSING_ERROR);
44
+ });
45
+ });
46
+ describe("researchQuestion", () => {
47
+ it("should successfully fetch research results", async () => {
48
+ const fetchMock = jest.spyOn(global, "fetch").mockResolvedValue({
49
+ ok: true,
50
+ json: async () => MOCK_RESEARCH_RESPONSE,
51
+ });
52
+ const question = "What is the current price of Ethereum?";
53
+ const response = await provider.researchQuestion({ question });
54
+ expect(fetchMock).toHaveBeenCalled();
55
+ const [url, options] = fetchMock.mock.calls[0];
56
+ expect(url).toBe("https://api.messari.io/ai/v1/chat/completions");
57
+ expect(options).toEqual(expect.objectContaining({
58
+ method: "POST",
59
+ headers: expect.objectContaining({
60
+ "Content-Type": "application/json",
61
+ "x-messari-api-key": MOCK_API_KEY,
62
+ }),
63
+ body: JSON.stringify({
64
+ messages: [
65
+ {
66
+ role: "user",
67
+ content: question,
68
+ },
69
+ ],
70
+ }),
71
+ }));
72
+ expect(response).toContain("Messari Research Results:");
73
+ expect(response).toContain(MOCK_RESEARCH_RESPONSE.data.messages[0].content);
74
+ });
75
+ it("should handle non-ok response with structured error format", async () => {
76
+ const errorResponseText = JSON.stringify(MOCK_ERROR_RESPONSE);
77
+ jest.spyOn(global, "fetch").mockResolvedValue({
78
+ ok: false,
79
+ status: 500,
80
+ statusText: "Internal Server Error",
81
+ text: async () => errorResponseText,
82
+ });
83
+ const response = await provider.researchQuestion({
84
+ question: "What is the current price of Bitcoin?",
85
+ });
86
+ expect(response).toContain("Messari API Error: Internal server error");
87
+ expect(response).not.toContain("500");
88
+ });
89
+ it("should handle non-ok response with non-JSON error format", async () => {
90
+ const plainTextError = "Rate limit exceeded";
91
+ jest.spyOn(global, "fetch").mockResolvedValue({
92
+ ok: false,
93
+ status: 429,
94
+ statusText: "Too Many Requests",
95
+ text: async () => plainTextError,
96
+ });
97
+ const response = await provider.researchQuestion({
98
+ question: "What is the current price of Bitcoin?",
99
+ });
100
+ expect(response).toContain("Messari API Error:");
101
+ expect(response).toContain("429");
102
+ expect(response).toContain("Too Many Requests");
103
+ expect(response).toContain(plainTextError);
104
+ });
105
+ it("should handle JSON parsing error in successful response", async () => {
106
+ jest.spyOn(global, "fetch").mockResolvedValue({
107
+ ok: true,
108
+ json: async () => {
109
+ throw new Error("Invalid JSON");
110
+ },
111
+ });
112
+ const response = await provider.researchQuestion({
113
+ question: "What is the market cap of Solana?",
114
+ });
115
+ expect(response).toContain("Unexpected error: Failed to parse API response");
116
+ expect(response).toContain("Invalid JSON");
117
+ });
118
+ it("should handle invalid response format", async () => {
119
+ jest.spyOn(global, "fetch").mockResolvedValue({
120
+ ok: true,
121
+ json: async () => ({ data: { messages: [] } }),
122
+ });
123
+ const response = await provider.researchQuestion({
124
+ question: "What is the market cap of Solana?",
125
+ });
126
+ expect(response).toContain("Unexpected error: Received invalid response format from Messari API");
127
+ });
128
+ it("should handle fetch error", async () => {
129
+ const error = new Error("Network error");
130
+ jest.spyOn(global, "fetch").mockRejectedValue(error);
131
+ const response = await provider.researchQuestion({
132
+ question: "What is the market cap of Solana?",
133
+ });
134
+ expect(response).toContain("Unexpected error: Network error");
135
+ });
136
+ it("should handle string error with JSON content", async () => {
137
+ const stringifiedError = JSON.stringify(MOCK_ERROR_RESPONSE);
138
+ jest.spyOn(global, "fetch").mockRejectedValue(stringifiedError);
139
+ const response = await provider.researchQuestion({
140
+ question: "What is the market cap of Solana?",
141
+ });
142
+ expect(response).toContain("Messari API Error: Internal server error");
143
+ });
144
+ });
145
+ describe("supportsNetwork", () => {
146
+ it("should always return true as research is network-agnostic", () => {
147
+ expect(provider.supportsNetwork({ protocolFamily: "evm" })).toBe(true);
148
+ expect(provider.supportsNetwork({ protocolFamily: "solana" })).toBe(true);
149
+ expect(provider.supportsNetwork({ protocolFamily: "unknown" })).toBe(true);
150
+ });
151
+ });
152
+ });
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Input schema for submitting a research question to Messari AI.
4
+ */
5
+ export declare const MessariResearchQuestionSchema: z.ZodObject<{
6
+ question: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ question: string;
9
+ }, {
10
+ question: string;
11
+ }>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessariResearchQuestionSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * Input schema for submitting a research question to Messari AI.
7
+ */
8
+ exports.MessariResearchQuestionSchema = zod_1.z
9
+ .object({
10
+ question: zod_1.z
11
+ .string()
12
+ .min(1, "Research question is required.")
13
+ .describe("The research question about crypto markets, protocols, or tokens"),
14
+ })
15
+ .strip()
16
+ .describe("Input schema for submitting a research question to Messari AI");
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Configuration options for the MessariActionProvider.
3
+ */
4
+ export interface MessariActionProviderConfig {
5
+ /**
6
+ * Messari API Key
7
+ */
8
+ apiKey?: string;
9
+ }
10
+ /**
11
+ * Message format in Messari API responses
12
+ */
13
+ export interface MessariMessage {
14
+ content: string;
15
+ role: string;
16
+ }
17
+ /**
18
+ * Response format from Messari API
19
+ */
20
+ export interface MessariAPIResponse {
21
+ data: {
22
+ messages: MessariMessage[];
23
+ };
24
+ }
25
+ /**
26
+ * Error response format from Messari API
27
+ */
28
+ export interface MessariErrorResponse {
29
+ error?: string;
30
+ data?: null | unknown;
31
+ }
32
+ /**
33
+ * Extended Error interface for Messari API errors
34
+ */
35
+ export interface MessariError extends Error {
36
+ status?: number;
37
+ statusText?: string;
38
+ responseText?: string;
39
+ errorResponse?: MessariErrorResponse;
40
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ import { MessariError } from "./types";
2
+ /**
3
+ * Creates a MessariError from an HTTP response
4
+ *
5
+ * @param response - The fetch Response object
6
+ * @returns A MessariError with response details
7
+ */
8
+ export declare function createMessariError(response: Response): Promise<MessariError>;
9
+ /**
10
+ * Formats error details for API errors
11
+ *
12
+ * @param error - The MessariError to format
13
+ * @returns Formatted error message
14
+ */
15
+ export declare function formatMessariApiError(error: MessariError): string;
16
+ /**
17
+ * Formats generic errors
18
+ *
19
+ * @param error - The error to format
20
+ * @returns Formatted error message
21
+ */
22
+ export declare function formatGenericError(error: unknown): string;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMessariError = createMessariError;
4
+ exports.formatMessariApiError = formatMessariApiError;
5
+ exports.formatGenericError = formatGenericError;
6
+ /**
7
+ * Creates a MessariError from an HTTP response
8
+ *
9
+ * @param response - The fetch Response object
10
+ * @returns A MessariError with response details
11
+ */
12
+ async function createMessariError(response) {
13
+ const error = new Error(`Messari API returned ${response.status} ${response.statusText}`);
14
+ error.status = response.status;
15
+ error.statusText = response.statusText;
16
+ const responseText = await response.text();
17
+ error.responseText = responseText;
18
+ try {
19
+ const errorJson = JSON.parse(responseText);
20
+ error.errorResponse = errorJson;
21
+ }
22
+ catch {
23
+ // If parsing fails, just use the raw text
24
+ }
25
+ return error;
26
+ }
27
+ /**
28
+ * Formats error details for API errors
29
+ *
30
+ * @param error - The MessariError to format
31
+ * @returns Formatted error message
32
+ */
33
+ function formatMessariApiError(error) {
34
+ if (error.errorResponse?.error) {
35
+ return `Messari API Error: ${error.errorResponse.error}`;
36
+ }
37
+ const errorDetails = {
38
+ status: error.status,
39
+ statusText: error.statusText,
40
+ responseText: error.responseText,
41
+ message: error.message,
42
+ };
43
+ return `Messari API Error: ${JSON.stringify(errorDetails, null, 2)}`;
44
+ }
45
+ /**
46
+ * Formats generic errors
47
+ *
48
+ * @param error - The error to format
49
+ * @returns Formatted error message
50
+ */
51
+ function formatGenericError(error) {
52
+ // Check if this might be a JSON string containing an error message
53
+ if (typeof error === "string") {
54
+ try {
55
+ const parsedError = JSON.parse(error);
56
+ if (parsedError.error) {
57
+ return `Messari API Error: ${parsedError.error}`;
58
+ }
59
+ }
60
+ catch {
61
+ // Not valid JSON, continue with normal handling
62
+ }
63
+ }
64
+ return `Unexpected error: ${error instanceof Error ? error.message : String(error)}`;
65
+ }
@@ -1,7 +1,7 @@
1
- import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, Abi, ContractFunctionName, ContractFunctionArgs } from "viem";
1
+ import { ReadContractParameters, ReadContractReturnType, TransactionRequest, TransactionSerializable, Abi, ContractFunctionName, ContractFunctionArgs, Address, Hex } from "viem";
2
2
  import { EvmWalletProvider } from "./evmWalletProvider";
3
3
  import { Network } from "../network";
4
- import { CreateERC20Options, CreateTradeOptions, SmartContract, Trade, Wallet, WalletData } from "@coinbase/coinbase-sdk";
4
+ import { Coinbase, CreateERC20Options, CreateTradeOptions, SmartContract, Trade, Wallet, WalletData } from "@coinbase/coinbase-sdk";
5
5
  /**
6
6
  * Configuration options for the CDP Providers.
7
7
  */
@@ -233,5 +233,14 @@ export declare class CdpWalletProvider extends EvmWalletProvider {
233
233
  * @returns The wallet.
234
234
  */
235
235
  getWallet(): Wallet;
236
+ /**
237
+ * ERC20 transfer method
238
+ *
239
+ * @param assetId - The asset ID to transfer. Either USDC, CBBTC or EURC
240
+ * @param destination - The destination address
241
+ * @param amount - The amount to transfer
242
+ * @returns The transaction hash
243
+ */
244
+ gaslessERC20Transfer(assetId: typeof Coinbase.assets.Usdc | typeof Coinbase.assets.Cbbtc | typeof Coinbase.assets.Eurc, destination: Address, amount: bigint): Promise<Hex>;
236
245
  }
237
246
  export {};
@@ -392,6 +392,30 @@ class CdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
392
392
  }
393
393
  return __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f");
394
394
  }
395
+ /**
396
+ * ERC20 transfer method
397
+ *
398
+ * @param assetId - The asset ID to transfer. Either USDC, CBBTC or EURC
399
+ * @param destination - The destination address
400
+ * @param amount - The amount to transfer
401
+ * @returns The transaction hash
402
+ */
403
+ async gaslessERC20Transfer(assetId, destination, amount) {
404
+ if (!__classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f")) {
405
+ throw new Error("Wallet not initialized");
406
+ }
407
+ const transferResult = await __classPrivateFieldGet(this, _CdpWalletProvider_cdpWallet, "f").createTransfer({
408
+ amount,
409
+ assetId,
410
+ destination,
411
+ gasless: true,
412
+ });
413
+ const result = await transferResult.wait();
414
+ if (!result.getTransactionHash()) {
415
+ throw new Error("Transaction hash not found");
416
+ }
417
+ return result.getTransactionHash();
418
+ }
395
419
  }
396
420
  exports.CdpWalletProvider = CdpWalletProvider;
397
421
  _CdpWalletProvider_cdpWallet = new WeakMap(), _CdpWalletProvider_address = new WeakMap(), _CdpWalletProvider_network = new WeakMap(), _CdpWalletProvider_publicClient = new WeakMap(), _CdpWalletProvider_gasLimitMultiplier = new WeakMap(), _CdpWalletProvider_feePerGasMultiplier = new WeakMap();
@@ -0,0 +1 @@
1
+ export {};