@coinbase/agentkit 0.0.0-nightly-20250717210412 → 0.0.0-nightly-20250725210423
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 +31 -1
- package/dist/action-providers/cdp/index.d.ts +0 -3
- package/dist/action-providers/cdp/index.js +0 -3
- package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
- package/dist/action-providers/farcaster/schemas.d.ts +13 -0
- package/dist/action-providers/farcaster/schemas.js +6 -0
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/truemarkets/constants.d.ts +179 -0
- package/dist/action-providers/truemarkets/constants.js +46 -0
- package/dist/action-providers/truemarkets/index.d.ts +1 -0
- package/dist/action-providers/truemarkets/index.js +17 -0
- package/dist/action-providers/truemarkets/schemas.d.ts +21 -0
- package/dist/action-providers/truemarkets/schemas.js +29 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +51 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +469 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.d.ts +1 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +217 -0
- package/dist/action-providers/truemarkets/utils.d.ts +10 -0
- package/dist/action-providers/truemarkets/utils.js +9 -0
- package/dist/action-providers/twitter/schemas.d.ts +16 -0
- package/dist/action-providers/twitter/schemas.js +23 -1
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
- package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
- package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
- package/dist/action-providers/weth/constants.d.ts +9 -0
- package/dist/action-providers/weth/constants.js +12 -0
- package/dist/action-providers/weth/schemas.d.ts +7 -0
- package/dist/action-providers/weth/schemas.js +7 -1
- package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
- package/dist/action-providers/weth/wethActionProvider.js +50 -1
- package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
- package/dist/action-providers/x402/schemas.d.ts +9 -45
- package/dist/action-providers/x402/schemas.js +53 -17
- package/dist/action-providers/x402/x402ActionProvider.js +24 -19
- package/dist/action-providers/x402/x402ActionProvider.test.js +4 -35
- package/dist/action-providers/zora/index.d.ts +3 -0
- package/dist/action-providers/zora/index.js +19 -0
- package/dist/action-providers/zora/schemas.d.ts +29 -0
- package/dist/action-providers/zora/schemas.js +31 -0
- package/dist/action-providers/zora/utils.d.ts +28 -0
- package/dist/action-providers/zora/utils.js +200 -0
- package/dist/action-providers/zora/zoraActionProvider.d.ts +36 -0
- package/dist/action-providers/zora/zoraActionProvider.js +151 -0
- package/dist/action-providers/zora/zoraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zora/zoraActionProvider.test.js +205 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +4 -4
- package/dist/wallet-providers/cdpEvmWalletProvider.js +4 -4
- package/dist/wallet-providers/cdpShared.d.ts +2 -2
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +2 -2
- package/dist/wallet-providers/cdpSmartWalletProvider.js +11 -4
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +31 -11
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +1 -1
- package/dist/wallet-providers/legacyCdpWalletProvider.js +1 -1
- package/package.json +3 -2
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +0 -17
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +0 -20
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +0 -17
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +0 -20
- package/dist/action-providers/cdp/cdpSolanaWalletActionProvider.d.ts +0 -17
- package/dist/action-providers/cdp/cdpSolanaWalletActionProvider.js +0 -20
|
@@ -58,6 +58,30 @@ class WethActionProvider extends actionProvider_1.ActionProvider {
|
|
|
58
58
|
return `Error wrapping ETH: ${error}`;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Unwraps WETH to ETH.
|
|
63
|
+
*
|
|
64
|
+
* @param walletProvider - The wallet provider to use for the action.
|
|
65
|
+
* @param args - The input arguments for the action.
|
|
66
|
+
* @returns A message containing the transaction hash.
|
|
67
|
+
*/
|
|
68
|
+
async unwrapEth(walletProvider, args) {
|
|
69
|
+
try {
|
|
70
|
+
const hash = await walletProvider.sendTransaction({
|
|
71
|
+
to: constants_1.WETH_ADDRESS,
|
|
72
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
73
|
+
abi: constants_1.WETH_ABI,
|
|
74
|
+
functionName: "withdraw",
|
|
75
|
+
args: [BigInt(args.amountToUnwrap)],
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
79
|
+
return `Unwrapped WETH with transaction hash: ${hash}`;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return `Error unwrapping WETH: ${error}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
61
85
|
}
|
|
62
86
|
exports.WethActionProvider = WethActionProvider;
|
|
63
87
|
__decorate([
|
|
@@ -74,7 +98,7 @@ Important notes:
|
|
|
74
98
|
- The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
|
|
75
99
|
- Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
|
|
76
100
|
- 1 wei = 0.000000000000000001 WETH
|
|
77
|
-
- Minimum purchase amount is
|
|
101
|
+
- Minimum purchase amount is 100000000000 wei (0.0000001 WETH)
|
|
78
102
|
- Only supported on the following networks:
|
|
79
103
|
- Base Sepolia (ie, 'base-sepolia')
|
|
80
104
|
- Base Mainnet (ie, 'base', 'base-mainnet')
|
|
@@ -85,5 +109,30 @@ Important notes:
|
|
|
85
109
|
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
86
110
|
__metadata("design:returntype", Promise)
|
|
87
111
|
], WethActionProvider.prototype, "wrapEth", null);
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, actionDecorator_1.CreateAction)({
|
|
114
|
+
name: "unwrap_eth",
|
|
115
|
+
description: `
|
|
116
|
+
This tool can only be used to unwrap WETH to ETH.
|
|
117
|
+
Do not use this tool for any other purpose, or trading other assets.
|
|
118
|
+
|
|
119
|
+
Inputs:
|
|
120
|
+
- Amount of WETH to unwrap.
|
|
121
|
+
|
|
122
|
+
Important notes:
|
|
123
|
+
- The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
|
|
124
|
+
- Make sure to use the exact amount provided, and if there's any doubt, check by getting more information before continuing with the action.
|
|
125
|
+
- 1 wei = 0.000000000000000001 WETH
|
|
126
|
+
- Minimum unwrap amount is 100000000000 wei (0.0000001 WETH)
|
|
127
|
+
- Only supported on the following networks:
|
|
128
|
+
- Base Sepolia (ie, 'base-sepolia')
|
|
129
|
+
- Base Mainnet (ie, 'base', 'base-mainnet')
|
|
130
|
+
`,
|
|
131
|
+
schema: schemas_1.UnwrapEthSchema,
|
|
132
|
+
}),
|
|
133
|
+
__metadata("design:type", Function),
|
|
134
|
+
__metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
|
|
135
|
+
__metadata("design:returntype", Promise)
|
|
136
|
+
], WethActionProvider.prototype, "unwrapEth", null);
|
|
88
137
|
const wethActionProvider = () => new WethActionProvider();
|
|
89
138
|
exports.wethActionProvider = wethActionProvider;
|
|
@@ -21,6 +21,21 @@ describe("Wrap Eth Schema", () => {
|
|
|
21
21
|
expect(result.success).toBe(false);
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
|
+
describe("Unwrap Eth Schema", () => {
|
|
25
|
+
it("should successfully parse valid input", () => {
|
|
26
|
+
const validInput = {
|
|
27
|
+
amountToUnwrap: MOCK_AMOUNT,
|
|
28
|
+
};
|
|
29
|
+
const result = schemas_1.UnwrapEthSchema.safeParse(validInput);
|
|
30
|
+
expect(result.success).toBe(true);
|
|
31
|
+
expect(result.data).toEqual(validInput);
|
|
32
|
+
});
|
|
33
|
+
it("should fail parsing empty input", () => {
|
|
34
|
+
const emptyInput = {};
|
|
35
|
+
const result = schemas_1.UnwrapEthSchema.safeParse(emptyInput);
|
|
36
|
+
expect(result.success).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
24
39
|
describe("Wrap Eth Action", () => {
|
|
25
40
|
let mockWallet;
|
|
26
41
|
const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
|
|
@@ -66,6 +81,51 @@ describe("Wrap Eth Action", () => {
|
|
|
66
81
|
expect(response).toContain(`Error wrapping ETH: ${error}`);
|
|
67
82
|
});
|
|
68
83
|
});
|
|
84
|
+
describe("Unwrap Eth Action", () => {
|
|
85
|
+
let mockWallet;
|
|
86
|
+
const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
|
|
87
|
+
beforeEach(async () => {
|
|
88
|
+
mockWallet = {
|
|
89
|
+
getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
|
|
90
|
+
sendTransaction: jest.fn(),
|
|
91
|
+
waitForTransactionReceipt: jest.fn(),
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
it("should successfully respond", async () => {
|
|
95
|
+
const args = {
|
|
96
|
+
amountToUnwrap: MOCK_AMOUNT,
|
|
97
|
+
};
|
|
98
|
+
const hash = "0x1234567890123456789012345678901234567890";
|
|
99
|
+
mockWallet.sendTransaction.mockResolvedValue(hash);
|
|
100
|
+
const response = await actionProvider.unwrapEth(mockWallet, args);
|
|
101
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
|
|
102
|
+
to: constants_1.WETH_ADDRESS,
|
|
103
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
104
|
+
abi: constants_1.WETH_ABI,
|
|
105
|
+
functionName: "withdraw",
|
|
106
|
+
args: [BigInt(MOCK_AMOUNT)],
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
expect(response).toContain(`Unwrapped WETH with transaction hash: ${hash}`);
|
|
110
|
+
});
|
|
111
|
+
it("should fail with an error", async () => {
|
|
112
|
+
const args = {
|
|
113
|
+
amountToUnwrap: MOCK_AMOUNT,
|
|
114
|
+
};
|
|
115
|
+
const error = new Error("Failed to unwrap WETH");
|
|
116
|
+
mockWallet.sendTransaction.mockRejectedValue(error);
|
|
117
|
+
const response = await actionProvider.unwrapEth(mockWallet, args);
|
|
118
|
+
expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
|
|
119
|
+
to: constants_1.WETH_ADDRESS,
|
|
120
|
+
data: (0, viem_1.encodeFunctionData)({
|
|
121
|
+
abi: constants_1.WETH_ABI,
|
|
122
|
+
functionName: "withdraw",
|
|
123
|
+
args: [BigInt(MOCK_AMOUNT)],
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
expect(response).toContain(`Error unwrapping WETH: ${error}`);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
69
129
|
describe("supportsNetwork", () => {
|
|
70
130
|
const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
|
|
71
131
|
it("should return true for base-mainnet", () => {
|
|
@@ -15,85 +15,49 @@ export declare const HttpRequestSchema: z.ZodObject<{
|
|
|
15
15
|
body?: any;
|
|
16
16
|
headers?: Record<string, string> | null | undefined;
|
|
17
17
|
}>;
|
|
18
|
-
export declare const RetryWithX402Schema: z.ZodObject<
|
|
18
|
+
export declare const RetryWithX402Schema: z.ZodObject<{
|
|
19
19
|
url: z.ZodString;
|
|
20
20
|
method: z.ZodDefault<z.ZodNullable<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>>;
|
|
21
|
-
headers: z.
|
|
22
|
-
body: z.
|
|
23
|
-
|
|
24
|
-
paymentOption: z.ZodObject<{
|
|
21
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
22
|
+
body: z.ZodOptional<z.ZodAny>;
|
|
23
|
+
selectedPaymentOption: z.ZodObject<{
|
|
25
24
|
scheme: z.ZodString;
|
|
26
25
|
network: z.ZodString;
|
|
27
26
|
maxAmountRequired: z.ZodString;
|
|
28
|
-
resource: z.ZodString;
|
|
29
|
-
description: z.ZodString;
|
|
30
|
-
mimeType: z.ZodString;
|
|
31
|
-
outputSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
32
|
-
payTo: z.ZodString;
|
|
33
|
-
maxTimeoutSeconds: z.ZodNumber;
|
|
34
27
|
asset: z.ZodString;
|
|
35
|
-
extra: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
|
|
36
28
|
}, "strip", z.ZodTypeAny, {
|
|
37
|
-
description: string;
|
|
38
29
|
scheme: string;
|
|
39
30
|
network: string;
|
|
40
31
|
asset: string;
|
|
41
32
|
maxAmountRequired: string;
|
|
42
|
-
resource: string;
|
|
43
|
-
mimeType: string;
|
|
44
|
-
outputSchema: Record<string, any>;
|
|
45
|
-
payTo: string;
|
|
46
|
-
maxTimeoutSeconds: number;
|
|
47
|
-
extra?: Record<string, any> | null | undefined;
|
|
48
33
|
}, {
|
|
49
|
-
description: string;
|
|
50
34
|
scheme: string;
|
|
51
35
|
network: string;
|
|
52
36
|
asset: string;
|
|
53
37
|
maxAmountRequired: string;
|
|
54
|
-
resource: string;
|
|
55
|
-
mimeType: string;
|
|
56
|
-
outputSchema: Record<string, any>;
|
|
57
|
-
payTo: string;
|
|
58
|
-
maxTimeoutSeconds: number;
|
|
59
|
-
extra?: Record<string, any> | null | undefined;
|
|
60
38
|
}>;
|
|
61
|
-
}
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
40
|
method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null;
|
|
63
41
|
url: string;
|
|
64
|
-
|
|
65
|
-
description: string;
|
|
42
|
+
selectedPaymentOption: {
|
|
66
43
|
scheme: string;
|
|
67
44
|
network: string;
|
|
68
45
|
asset: string;
|
|
69
46
|
maxAmountRequired: string;
|
|
70
|
-
resource: string;
|
|
71
|
-
mimeType: string;
|
|
72
|
-
outputSchema: Record<string, any>;
|
|
73
|
-
payTo: string;
|
|
74
|
-
maxTimeoutSeconds: number;
|
|
75
|
-
extra?: Record<string, any> | null | undefined;
|
|
76
47
|
};
|
|
77
48
|
body?: any;
|
|
78
|
-
headers?: Record<string, string> |
|
|
49
|
+
headers?: Record<string, string> | undefined;
|
|
79
50
|
}, {
|
|
80
51
|
url: string;
|
|
81
|
-
|
|
82
|
-
description: string;
|
|
52
|
+
selectedPaymentOption: {
|
|
83
53
|
scheme: string;
|
|
84
54
|
network: string;
|
|
85
55
|
asset: string;
|
|
86
56
|
maxAmountRequired: string;
|
|
87
|
-
resource: string;
|
|
88
|
-
mimeType: string;
|
|
89
|
-
outputSchema: Record<string, any>;
|
|
90
|
-
payTo: string;
|
|
91
|
-
maxTimeoutSeconds: number;
|
|
92
|
-
extra?: Record<string, any> | null | undefined;
|
|
93
57
|
};
|
|
94
58
|
method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null | undefined;
|
|
95
59
|
body?: any;
|
|
96
|
-
headers?: Record<string, string> |
|
|
60
|
+
headers?: Record<string, string> | undefined;
|
|
97
61
|
}>;
|
|
98
62
|
export declare const DirectX402RequestSchema: z.ZodObject<{
|
|
99
63
|
url: z.ZodString;
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DirectX402RequestSchema = exports.RetryWithX402Schema = exports.HttpRequestSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
// Schema for initial HTTP request
|
|
6
|
+
exports.HttpRequestSchema = zod_1.z
|
|
7
|
+
.object({
|
|
8
|
+
url: zod_1.z
|
|
9
|
+
.string()
|
|
10
|
+
.url()
|
|
11
|
+
.describe("The URL of the API endpoint (can be localhost for development)"),
|
|
8
12
|
method: zod_1.z
|
|
9
13
|
.enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
|
|
10
14
|
.nullable()
|
|
@@ -15,29 +19,61 @@ const BaseHttpRequestSchema = zod_1.z.object({
|
|
|
15
19
|
.optional()
|
|
16
20
|
.nullable()
|
|
17
21
|
.describe("Optional headers to include in the request"),
|
|
18
|
-
body: zod_1.z
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
body: zod_1.z
|
|
23
|
+
.any()
|
|
24
|
+
.optional()
|
|
25
|
+
.nullable()
|
|
26
|
+
.describe("Optional request body for POST/PUT/PATCH requests"),
|
|
27
|
+
})
|
|
28
|
+
.strip()
|
|
29
|
+
.describe("Instructions for making a basic HTTP request");
|
|
22
30
|
// Schema for retrying a failed request with x402 payment
|
|
23
|
-
exports.RetryWithX402Schema =
|
|
24
|
-
|
|
31
|
+
exports.RetryWithX402Schema = zod_1.z
|
|
32
|
+
.object({
|
|
33
|
+
url: zod_1.z
|
|
34
|
+
.string()
|
|
35
|
+
.url()
|
|
36
|
+
.describe("The URL of the API endpoint (can be localhost for development)"),
|
|
37
|
+
method: zod_1.z
|
|
38
|
+
.enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
|
|
39
|
+
.nullable()
|
|
40
|
+
.default("GET")
|
|
41
|
+
.describe("The HTTP method to use for the request"),
|
|
42
|
+
headers: zod_1.z.record(zod_1.z.string()).optional().describe("Optional headers to include in the request"),
|
|
43
|
+
body: zod_1.z.any().optional().describe("Optional request body for POST/PUT/PATCH requests"),
|
|
44
|
+
selectedPaymentOption: zod_1.z
|
|
25
45
|
.object({
|
|
26
46
|
scheme: zod_1.z.string(),
|
|
27
47
|
network: zod_1.z.string(),
|
|
28
48
|
maxAmountRequired: zod_1.z.string(),
|
|
29
|
-
resource: zod_1.z.string(),
|
|
30
|
-
description: zod_1.z.string(),
|
|
31
|
-
mimeType: zod_1.z.string(),
|
|
32
|
-
outputSchema: zod_1.z.record(zod_1.z.any()),
|
|
33
|
-
payTo: zod_1.z.string(),
|
|
34
|
-
maxTimeoutSeconds: zod_1.z.number(),
|
|
35
49
|
asset: zod_1.z.string(),
|
|
36
|
-
extra: zod_1.z.record(zod_1.z.any()).optional().nullable(),
|
|
37
50
|
})
|
|
38
51
|
.describe("The payment option to use for this request"),
|
|
39
52
|
})
|
|
40
53
|
.strip()
|
|
41
54
|
.describe("Instructions for retrying a request with x402 payment after receiving a 402 response");
|
|
42
55
|
// Schema for direct x402 payment request (with warning)
|
|
43
|
-
exports.DirectX402RequestSchema =
|
|
56
|
+
exports.DirectX402RequestSchema = zod_1.z
|
|
57
|
+
.object({
|
|
58
|
+
url: zod_1.z
|
|
59
|
+
.string()
|
|
60
|
+
.url()
|
|
61
|
+
.describe("The URL of the API endpoint (can be localhost for development)"),
|
|
62
|
+
method: zod_1.z
|
|
63
|
+
.enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
|
|
64
|
+
.nullable()
|
|
65
|
+
.default("GET")
|
|
66
|
+
.describe("The HTTP method to use for the request"),
|
|
67
|
+
headers: zod_1.z
|
|
68
|
+
.record(zod_1.z.string())
|
|
69
|
+
.optional()
|
|
70
|
+
.nullable()
|
|
71
|
+
.describe("Optional headers to include in the request"),
|
|
72
|
+
body: zod_1.z
|
|
73
|
+
.any()
|
|
74
|
+
.optional()
|
|
75
|
+
.nullable()
|
|
76
|
+
.describe("Optional request body for POST/PUT/PATCH requests"),
|
|
77
|
+
})
|
|
78
|
+
.strip()
|
|
79
|
+
.describe("Instructions for making an HTTP request with automatic x402 payment handling. WARNING: This bypasses user confirmation - only use when explicitly told to skip confirmation!");
|
|
@@ -20,7 +20,6 @@ const schemas_1 = require("./schemas");
|
|
|
20
20
|
const wallet_providers_1 = require("../../wallet-providers");
|
|
21
21
|
const axios_1 = __importDefault(require("axios"));
|
|
22
22
|
const x402_axios_1 = require("x402-axios");
|
|
23
|
-
const types_1 = require("x402/types");
|
|
24
23
|
const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
|
|
25
24
|
/**
|
|
26
25
|
* X402ActionProvider provides actions for making HTTP requests, with optional x402 payment handling.
|
|
@@ -65,13 +64,12 @@ class X402ActionProvider extends actionProvider_1.ActionProvider {
|
|
|
65
64
|
data: response.data,
|
|
66
65
|
}, null, 2);
|
|
67
66
|
}
|
|
68
|
-
const paymentRequirements = response.data.accepts.map(accept => types_1.PaymentRequirementsSchema.parse(accept));
|
|
69
67
|
return JSON.stringify({
|
|
70
68
|
status: "error_402_payment_required",
|
|
71
|
-
acceptablePaymentOptions:
|
|
69
|
+
acceptablePaymentOptions: response.data.accepts,
|
|
72
70
|
nextSteps: [
|
|
73
71
|
"Inform the user that the requested server replied with a 402 Payment Required response.",
|
|
74
|
-
`The payment options are: ${
|
|
72
|
+
`The payment options are: ${response.data.accepts.map(option => `${option.asset} ${option.maxAmountRequired} ${option.network}`).join(", ")}`,
|
|
75
73
|
"Ask the user if they want to retry the request with payment.",
|
|
76
74
|
`Use retry_http_request_with_x402 to retry the request with payment.`,
|
|
77
75
|
],
|
|
@@ -90,20 +88,27 @@ class X402ActionProvider extends actionProvider_1.ActionProvider {
|
|
|
90
88
|
*/
|
|
91
89
|
async retryWithX402(walletProvider, args) {
|
|
92
90
|
try {
|
|
93
|
-
// Validate the payment option matches the URL
|
|
94
|
-
if (args.paymentOption.resource !== args.url) {
|
|
95
|
-
return JSON.stringify({
|
|
96
|
-
status: "error_invalid_payment_option",
|
|
97
|
-
message: "The payment option resource does not match the request URL",
|
|
98
|
-
details: {
|
|
99
|
-
expected: args.url,
|
|
100
|
-
received: args.paymentOption.resource,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
91
|
// Make the request with payment handling
|
|
105
92
|
const account = walletProvider.toSigner();
|
|
106
|
-
const
|
|
93
|
+
const paymentSelector = (accepts) => {
|
|
94
|
+
const { scheme, network, maxAmountRequired, asset } = args.selectedPaymentOption;
|
|
95
|
+
let paymentRequirements = accepts.find(accept => accept.scheme === scheme &&
|
|
96
|
+
accept.network === network &&
|
|
97
|
+
accept.maxAmountRequired <= maxAmountRequired &&
|
|
98
|
+
accept.asset === asset);
|
|
99
|
+
if (paymentRequirements) {
|
|
100
|
+
return paymentRequirements;
|
|
101
|
+
}
|
|
102
|
+
paymentRequirements = accepts.find(accept => accept.scheme === scheme &&
|
|
103
|
+
accept.network === network &&
|
|
104
|
+
accept.maxAmountRequired <= maxAmountRequired &&
|
|
105
|
+
accept.asset === asset);
|
|
106
|
+
if (paymentRequirements) {
|
|
107
|
+
return paymentRequirements;
|
|
108
|
+
}
|
|
109
|
+
return accepts[0];
|
|
110
|
+
};
|
|
111
|
+
const api = (0, x402_axios_1.withPaymentInterceptor)(axios_1.default.create({}), account, paymentSelector);
|
|
107
112
|
const response = await api.request({
|
|
108
113
|
url: args.url,
|
|
109
114
|
method: args.method ?? "GET",
|
|
@@ -122,9 +127,9 @@ class X402ActionProvider extends actionProvider_1.ActionProvider {
|
|
|
122
127
|
url: args.url,
|
|
123
128
|
method: args.method,
|
|
124
129
|
paymentUsed: {
|
|
125
|
-
network: args.
|
|
126
|
-
asset: args.
|
|
127
|
-
amount: args.
|
|
130
|
+
network: args.selectedPaymentOption.network,
|
|
131
|
+
asset: args.selectedPaymentOption.asset,
|
|
132
|
+
amount: args.selectedPaymentOption.maxAmountRequired,
|
|
128
133
|
},
|
|
129
134
|
paymentProof: paymentProof
|
|
130
135
|
? {
|
|
@@ -225,20 +225,15 @@ describe("X402ActionProvider", () => {
|
|
|
225
225
|
const result = await provider.retryWithX402(mockWalletProvider, {
|
|
226
226
|
url: "https://www.x402.org/protected",
|
|
227
227
|
method: "GET",
|
|
228
|
-
|
|
228
|
+
selectedPaymentOption: {
|
|
229
229
|
scheme: "exact",
|
|
230
230
|
network: "base-sepolia",
|
|
231
231
|
maxAmountRequired: "10000",
|
|
232
|
-
resource: "https://www.x402.org/protected",
|
|
233
|
-
description: "Access to protected content",
|
|
234
|
-
mimeType: "application/json",
|
|
235
|
-
payTo: "0x123",
|
|
236
|
-
maxTimeoutSeconds: 300,
|
|
237
232
|
asset: "0x456",
|
|
238
|
-
outputSchema: {},
|
|
239
233
|
},
|
|
240
234
|
});
|
|
241
|
-
|
|
235
|
+
// Update expectation to accept the payment selector function
|
|
236
|
+
expect(mockWithPaymentInterceptor).toHaveBeenCalledWith(mockAxiosInstance, "mock-signer", expect.any(Function));
|
|
242
237
|
const parsedResult = JSON.parse(result);
|
|
243
238
|
expect(parsedResult.status).toBe("success");
|
|
244
239
|
expect(parsedResult.details.paymentProof).toEqual({
|
|
@@ -247,26 +242,6 @@ describe("X402ActionProvider", () => {
|
|
|
247
242
|
payer: MOCK_PAYMENT_RESPONSE.payer,
|
|
248
243
|
});
|
|
249
244
|
});
|
|
250
|
-
it("should reject if payment option resource doesn't match URL", async () => {
|
|
251
|
-
const result = await provider.retryWithX402(mockWalletProvider, {
|
|
252
|
-
url: "https://www.x402.org/protected",
|
|
253
|
-
method: "GET",
|
|
254
|
-
paymentOption: {
|
|
255
|
-
scheme: "exact",
|
|
256
|
-
network: "base-sepolia",
|
|
257
|
-
maxAmountRequired: "10000",
|
|
258
|
-
resource: "https://different.url/protected", // Mismatched URL
|
|
259
|
-
description: "Access to protected content",
|
|
260
|
-
mimeType: "application/json",
|
|
261
|
-
payTo: "0x123",
|
|
262
|
-
maxTimeoutSeconds: 300,
|
|
263
|
-
asset: "0x456",
|
|
264
|
-
outputSchema: {},
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
const parsedResult = JSON.parse(result);
|
|
268
|
-
expect(parsedResult.status).toBe("error_invalid_payment_option");
|
|
269
|
-
});
|
|
270
245
|
it("should handle network errors during payment", async () => {
|
|
271
246
|
const error = new Error("Network error");
|
|
272
247
|
error.isAxiosError = true;
|
|
@@ -275,17 +250,11 @@ describe("X402ActionProvider", () => {
|
|
|
275
250
|
const result = await provider.retryWithX402(mockWalletProvider, {
|
|
276
251
|
url: "https://www.x402.org/protected",
|
|
277
252
|
method: "GET",
|
|
278
|
-
|
|
253
|
+
selectedPaymentOption: {
|
|
279
254
|
scheme: "exact",
|
|
280
255
|
network: "base-sepolia",
|
|
281
256
|
maxAmountRequired: "10000",
|
|
282
|
-
resource: "https://www.x402.org/protected",
|
|
283
|
-
description: "Access to protected content",
|
|
284
|
-
mimeType: "application/json",
|
|
285
|
-
payTo: "0x123",
|
|
286
|
-
maxTimeoutSeconds: 300,
|
|
287
257
|
asset: "0x456",
|
|
288
|
-
outputSchema: {},
|
|
289
258
|
},
|
|
290
259
|
});
|
|
291
260
|
const parsedResult = JSON.parse(result);
|
|
@@ -0,0 +1,19 @@
|
|
|
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("./zoraActionProvider"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CreateCoinSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
symbol: z.ZodString;
|
|
5
|
+
description: z.ZodString;
|
|
6
|
+
image: z.ZodString;
|
|
7
|
+
category: z.ZodDefault<z.ZodString>;
|
|
8
|
+
payoutRecipient: z.ZodOptional<z.ZodString>;
|
|
9
|
+
platformReferrer: z.ZodOptional<z.ZodString>;
|
|
10
|
+
currency: z.ZodDefault<z.ZodEnum<["ZORA", "ETH"]>>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
symbol: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
currency: "ETH" | "ZORA";
|
|
16
|
+
image: string;
|
|
17
|
+
category: string;
|
|
18
|
+
platformReferrer?: string | undefined;
|
|
19
|
+
payoutRecipient?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
symbol: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
image: string;
|
|
25
|
+
currency?: "ETH" | "ZORA" | undefined;
|
|
26
|
+
platformReferrer?: string | undefined;
|
|
27
|
+
category?: string | undefined;
|
|
28
|
+
payoutRecipient?: string | undefined;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateCoinSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.CreateCoinSchema = zod_1.z
|
|
6
|
+
.object({
|
|
7
|
+
name: zod_1.z.string().describe("The name of the coin to create"),
|
|
8
|
+
symbol: zod_1.z.string().describe("The symbol of the coin to create"),
|
|
9
|
+
description: zod_1.z.string().describe("The description of the coin"),
|
|
10
|
+
image: zod_1.z.string().describe("Local image file path or URI (ipfs:// or https://)"),
|
|
11
|
+
category: zod_1.z
|
|
12
|
+
.string()
|
|
13
|
+
.default("social")
|
|
14
|
+
.describe("The category of the coin, optional, defaults to 'social'"),
|
|
15
|
+
payoutRecipient: zod_1.z
|
|
16
|
+
.string()
|
|
17
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("The address that will receive creator earnings, defaults to wallet address"),
|
|
20
|
+
platformReferrer: zod_1.z
|
|
21
|
+
.string()
|
|
22
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("The address that will receive platform referrer fees, optional"),
|
|
25
|
+
currency: zod_1.z
|
|
26
|
+
.enum(["ZORA", "ETH"])
|
|
27
|
+
.default("ZORA")
|
|
28
|
+
.describe("Currency to be used for the trading pair, optional, defaults to 'ZORA'."),
|
|
29
|
+
})
|
|
30
|
+
.strip()
|
|
31
|
+
.describe("Instructions for creating a new coin on Zora");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for Pinata
|
|
3
|
+
*/
|
|
4
|
+
interface PinataConfig {
|
|
5
|
+
jwt: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parameters for generating token URI
|
|
9
|
+
*/
|
|
10
|
+
interface TokenUriParams {
|
|
11
|
+
name: string;
|
|
12
|
+
symbol: string;
|
|
13
|
+
description: string;
|
|
14
|
+
image: string;
|
|
15
|
+
category?: string;
|
|
16
|
+
pinataConfig: PinataConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates a Zora token URI by handling local file or URI
|
|
20
|
+
*
|
|
21
|
+
* @param params - Parameters for generating the token URI
|
|
22
|
+
* @returns A promise that resolves to object containing the IPFS URI
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateZoraTokenUri(params: TokenUriParams): Promise<{
|
|
25
|
+
uri: string;
|
|
26
|
+
imageUri: string;
|
|
27
|
+
}>;
|
|
28
|
+
export {};
|