@coinbase/agentkit 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -40
- package/dist/action-providers/across/schemas.d.ts +1 -1
- package/dist/action-providers/baseAccount/baseAccountActionProvider.d.ts +46 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +404 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.d.ts +1 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.js +325 -0
- package/dist/action-providers/baseAccount/index.d.ts +2 -0
- package/dist/action-providers/baseAccount/index.js +18 -0
- package/dist/action-providers/baseAccount/schemas.d.ts +43 -0
- package/dist/action-providers/baseAccount/schemas.js +62 -0
- package/dist/action-providers/baseAccount/types.d.ts +17 -0
- package/dist/action-providers/baseAccount/types.js +2 -0
- package/dist/action-providers/baseAccount/utils.d.ts +14 -0
- package/dist/action-providers/baseAccount/utils.js +57 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +2 -1
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +3 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +2 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +3 -1
- package/dist/action-providers/cdp/swapUtils.d.ts +0 -9
- package/dist/action-providers/cdp/swapUtils.js +0 -36
- package/dist/action-providers/clanker/schemas.d.ts +2 -2
- package/dist/action-providers/flaunch/client_utils.d.ts +25 -0
- package/dist/action-providers/flaunch/client_utils.js +62 -0
- package/dist/action-providers/flaunch/constants.d.ts +41 -20
- package/dist/action-providers/flaunch/constants.js +111 -36
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +4 -43
- package/dist/action-providers/flaunch/flaunchActionProvider.js +132 -200
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +108 -13
- package/dist/action-providers/flaunch/metadata_utils.d.ts +12 -0
- package/dist/action-providers/flaunch/metadata_utils.js +216 -0
- package/dist/action-providers/flaunch/schemas.d.ts +39 -3
- package/dist/action-providers/flaunch/schemas.js +62 -10
- package/dist/action-providers/flaunch/{utils.d.ts → swap_utils.d.ts} +17 -19
- package/dist/action-providers/flaunch/{utils.js → swap_utils.js} +137 -172
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/pyth/pythActionProvider.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +83 -31
- package/dist/action-providers/pyth/pythActionProvider.test.js +178 -26
- package/dist/action-providers/pyth/schemas.d.ts +6 -0
- package/dist/action-providers/pyth/schemas.js +9 -1
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +5 -4
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +2 -1
- package/dist/action-providers/superfluid/utils/parseLogs.js +6 -3
- package/dist/action-providers/wallet/walletActionProvider.js +3 -0
- package/dist/action-providers/x402/schemas.d.ts +7 -0
- package/dist/action-providers/x402/schemas.js +11 -1
- package/dist/action-providers/x402/utils.d.ts +55 -0
- package/dist/action-providers/x402/utils.js +160 -0
- package/dist/action-providers/x402/x402ActionProvider.d.ts +9 -9
- package/dist/action-providers/x402/x402ActionProvider.js +158 -39
- package/dist/action-providers/x402/x402ActionProvider.test.js +116 -10
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +43 -13
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.js +14 -21
- package/dist/wallet-providers/cdpEvmWalletProvider.test.js +7 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -6
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +6 -10
- package/dist/wallet-providers/evmWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/evmWalletProvider.js +4 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +11 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.js +16 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.test.js +6 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +27 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +11 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +8 -1
- package/dist/wallet-providers/viemWalletProvider.js +21 -1
- package/dist/wallet-providers/viemWalletProvider.test.js +21 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/zeroDevWalletProvider.js +12 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +10 -0
- package/package.json +6 -4
|
@@ -9,39 +9,180 @@ describe("PythActionProvider", () => {
|
|
|
9
9
|
jest.resetAllMocks().restoreAllMocks();
|
|
10
10
|
});
|
|
11
11
|
describe("fetchPriceFeed", () => {
|
|
12
|
-
it("should return the first price feed ID that matches the input token symbol", async () => {
|
|
12
|
+
it("should return the first price feed ID that matches the input token symbol for crypto", async () => {
|
|
13
13
|
fetchMock.mockResolvedValueOnce({
|
|
14
14
|
ok: true,
|
|
15
|
-
json: async () => [
|
|
15
|
+
json: async () => [
|
|
16
|
+
{ id: "some-price-feed-id", attributes: { base: "BTC", quote_currency: "USD" } },
|
|
17
|
+
],
|
|
16
18
|
});
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
+
const result = await provider.fetchPriceFeed({
|
|
20
|
+
tokenSymbol: "BTC",
|
|
21
|
+
assetType: "crypto",
|
|
22
|
+
quoteCurrency: "USD",
|
|
23
|
+
});
|
|
24
|
+
const parsed = JSON.parse(result);
|
|
25
|
+
expect(parsed.success).toBe(true);
|
|
26
|
+
expect(parsed.priceFeedID).toEqual("some-price-feed-id");
|
|
27
|
+
});
|
|
28
|
+
it("should return the first price feed ID that matches the input token symbol for metals", async () => {
|
|
29
|
+
fetchMock.mockResolvedValueOnce({
|
|
30
|
+
ok: true,
|
|
31
|
+
json: async () => [
|
|
32
|
+
{ id: "gold-price-feed-id", attributes: { base: "XAU", quote_currency: "USD" } },
|
|
33
|
+
],
|
|
34
|
+
});
|
|
35
|
+
const result = await provider.fetchPriceFeed({
|
|
36
|
+
tokenSymbol: "XAU",
|
|
37
|
+
assetType: "metal",
|
|
38
|
+
quoteCurrency: "USD",
|
|
39
|
+
});
|
|
40
|
+
const parsed = JSON.parse(result);
|
|
41
|
+
expect(parsed.success).toBe(true);
|
|
42
|
+
expect(parsed.priceFeedID).toEqual("gold-price-feed-id");
|
|
43
|
+
});
|
|
44
|
+
it("should return the first price feed ID that matches the input token symbol for commodities", async () => {
|
|
45
|
+
fetchMock.mockResolvedValueOnce({
|
|
46
|
+
ok: true,
|
|
47
|
+
json: async () => [
|
|
48
|
+
{ id: "oil-price-feed-id", attributes: { base: "WTI", quote_currency: "USD" } },
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
const result = await provider.fetchPriceFeed({
|
|
52
|
+
tokenSymbol: "WTI",
|
|
53
|
+
assetType: "metal",
|
|
54
|
+
quoteCurrency: "USD",
|
|
55
|
+
});
|
|
56
|
+
const parsed = JSON.parse(result);
|
|
57
|
+
expect(parsed.success).toBe(true);
|
|
58
|
+
expect(parsed.priceFeedID).toEqual("oil-price-feed-id");
|
|
59
|
+
});
|
|
60
|
+
it("should return the first price feed ID that matches the input token symbol for equities", async () => {
|
|
61
|
+
fetchMock.mockResolvedValueOnce({
|
|
62
|
+
ok: true,
|
|
63
|
+
json: async () => [
|
|
64
|
+
{
|
|
65
|
+
id: "apple-price-feed-id",
|
|
66
|
+
attributes: {
|
|
67
|
+
base: "AAPL",
|
|
68
|
+
quote_currency: "USD",
|
|
69
|
+
symbol: "Equity.US.AAPL/USD",
|
|
70
|
+
display_symbol: "AAPL/USD",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
const result = await provider.fetchPriceFeed({
|
|
76
|
+
tokenSymbol: "AAPL",
|
|
77
|
+
assetType: "equity",
|
|
78
|
+
quoteCurrency: "USD",
|
|
79
|
+
});
|
|
80
|
+
const parsed = JSON.parse(result);
|
|
81
|
+
expect(parsed.success).toBe(true);
|
|
82
|
+
expect(parsed.priceFeedID).toEqual("apple-price-feed-id");
|
|
19
83
|
});
|
|
20
|
-
it("should
|
|
84
|
+
it("should return the first price feed ID that matches the input token symbol for FX", async () => {
|
|
21
85
|
fetchMock.mockResolvedValueOnce({
|
|
22
86
|
ok: true,
|
|
23
|
-
json: async () => [
|
|
87
|
+
json: async () => [
|
|
88
|
+
{ id: "eur-price-feed-id", attributes: { base: "EUR", quote_currency: "USD" } },
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
const result = await provider.fetchPriceFeed({
|
|
92
|
+
tokenSymbol: "EUR",
|
|
93
|
+
assetType: "fx",
|
|
94
|
+
quoteCurrency: "USD",
|
|
24
95
|
});
|
|
25
|
-
|
|
96
|
+
const parsed = JSON.parse(result);
|
|
97
|
+
expect(parsed.success).toBe(true);
|
|
98
|
+
expect(parsed.priceFeedID).toEqual("eur-price-feed-id");
|
|
26
99
|
});
|
|
27
|
-
it("should return
|
|
28
|
-
|
|
29
|
-
|
|
100
|
+
it("should return error if no price feed is found", async () => {
|
|
101
|
+
fetchMock.mockResolvedValueOnce({
|
|
102
|
+
ok: true,
|
|
103
|
+
json: async () => [
|
|
104
|
+
{ id: "some-price-feed-id", attributes: { base: "BTC", quote_currency: "USD" } },
|
|
105
|
+
],
|
|
106
|
+
});
|
|
107
|
+
const result = await provider.fetchPriceFeed({
|
|
108
|
+
tokenSymbol: "SOL",
|
|
109
|
+
assetType: "crypto",
|
|
110
|
+
quoteCurrency: "USD",
|
|
111
|
+
});
|
|
112
|
+
const parsed = JSON.parse(result);
|
|
113
|
+
expect(parsed.success).toBe(false);
|
|
114
|
+
expect(parsed.error).toContain("No price feed found for SOL/USD");
|
|
30
115
|
});
|
|
31
|
-
it("should
|
|
116
|
+
it("should return error if the response is not ok", async () => {
|
|
32
117
|
fetchMock.mockResolvedValueOnce({
|
|
33
118
|
ok: false,
|
|
34
119
|
status: 404,
|
|
35
120
|
});
|
|
36
|
-
await
|
|
121
|
+
const result = await provider.fetchPriceFeed({
|
|
122
|
+
tokenSymbol: "BTC",
|
|
123
|
+
assetType: "crypto",
|
|
124
|
+
quoteCurrency: "USD",
|
|
125
|
+
});
|
|
126
|
+
const parsed = JSON.parse(result);
|
|
127
|
+
expect(parsed.success).toBe(false);
|
|
128
|
+
expect(parsed.error).toContain("HTTP error! status: 404");
|
|
37
129
|
});
|
|
38
|
-
it("should
|
|
130
|
+
it("should return error if response is ok but no data is returned", async () => {
|
|
39
131
|
fetchMock.mockResolvedValueOnce({
|
|
40
132
|
ok: true,
|
|
41
133
|
json: async () => [],
|
|
42
134
|
});
|
|
43
|
-
const
|
|
44
|
-
|
|
135
|
+
const result = await provider.fetchPriceFeed({
|
|
136
|
+
tokenSymbol: "BTC",
|
|
137
|
+
assetType: "crypto",
|
|
138
|
+
quoteCurrency: "USD",
|
|
139
|
+
});
|
|
140
|
+
const parsed = JSON.parse(result);
|
|
141
|
+
expect(parsed.success).toBe(false);
|
|
142
|
+
expect(parsed.error).toContain("No price feed found for BTC");
|
|
143
|
+
});
|
|
144
|
+
it("should prefer regular market hours feed for equities over pre/post market", async () => {
|
|
145
|
+
fetchMock.mockResolvedValueOnce({
|
|
146
|
+
ok: true,
|
|
147
|
+
json: async () => [
|
|
148
|
+
{
|
|
149
|
+
id: "post-market-feed-id",
|
|
150
|
+
attributes: {
|
|
151
|
+
base: "COIN",
|
|
152
|
+
quote_currency: "USD",
|
|
153
|
+
symbol: "Equity.US.COIN/USD.POST",
|
|
154
|
+
display_symbol: "COIN/USD POST MARKET",
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "regular-market-feed-id",
|
|
159
|
+
attributes: {
|
|
160
|
+
base: "COIN",
|
|
161
|
+
quote_currency: "USD",
|
|
162
|
+
symbol: "Equity.US.COIN/USD",
|
|
163
|
+
display_symbol: "COIN/USD",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: "pre-market-feed-id",
|
|
168
|
+
attributes: {
|
|
169
|
+
base: "COIN",
|
|
170
|
+
quote_currency: "USD",
|
|
171
|
+
symbol: "Equity.US.COIN/USD.PRE",
|
|
172
|
+
display_symbol: "COIN/USD PRE MARKET",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
});
|
|
177
|
+
const result = await provider.fetchPriceFeed({
|
|
178
|
+
tokenSymbol: "COIN",
|
|
179
|
+
assetType: "equity",
|
|
180
|
+
quoteCurrency: "USD",
|
|
181
|
+
});
|
|
182
|
+
const parsed = JSON.parse(result);
|
|
183
|
+
expect(parsed.success).toBe(true);
|
|
184
|
+
expect(parsed.priceFeedID).toEqual("regular-market-feed-id");
|
|
185
|
+
expect(parsed.feedType).toEqual("COIN/USD");
|
|
45
186
|
});
|
|
46
187
|
});
|
|
47
188
|
describe("fetchPrice", () => {
|
|
@@ -59,8 +200,10 @@ describe("PythActionProvider", () => {
|
|
|
59
200
|
],
|
|
60
201
|
}),
|
|
61
202
|
});
|
|
62
|
-
const
|
|
63
|
-
|
|
203
|
+
const result = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
204
|
+
const parsed = JSON.parse(result);
|
|
205
|
+
expect(parsed.success).toBe(true);
|
|
206
|
+
expect(parsed.price).toEqual("1");
|
|
64
207
|
});
|
|
65
208
|
it("should return the price for a given price feed ID with a negative exponent", async () => {
|
|
66
209
|
fetchMock.mockResolvedValueOnce({
|
|
@@ -76,9 +219,10 @@ describe("PythActionProvider", () => {
|
|
|
76
219
|
],
|
|
77
220
|
}),
|
|
78
221
|
});
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
expect(
|
|
222
|
+
const result = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
223
|
+
const parsed = JSON.parse(result);
|
|
224
|
+
expect(parsed.success).toBe(true);
|
|
225
|
+
expect(parsed.price).toEqual("1.00");
|
|
82
226
|
});
|
|
83
227
|
it("should handle scaled price starting with a decimal", async () => {
|
|
84
228
|
fetchMock.mockResolvedValueOnce({
|
|
@@ -94,24 +238,32 @@ describe("PythActionProvider", () => {
|
|
|
94
238
|
],
|
|
95
239
|
}),
|
|
96
240
|
});
|
|
97
|
-
const
|
|
98
|
-
|
|
241
|
+
const result = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
242
|
+
const parsed = JSON.parse(result);
|
|
243
|
+
expect(parsed.success).toBe(true);
|
|
244
|
+
expect(parsed.price).toEqual("0.25");
|
|
99
245
|
});
|
|
100
|
-
it("should
|
|
246
|
+
it("should return error if there is no price data", async () => {
|
|
101
247
|
fetchMock.mockResolvedValueOnce({
|
|
102
248
|
ok: true,
|
|
103
249
|
json: async () => ({
|
|
104
250
|
parsed: [],
|
|
105
251
|
}),
|
|
106
252
|
});
|
|
107
|
-
await
|
|
253
|
+
const result = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
254
|
+
const parsed = JSON.parse(result);
|
|
255
|
+
expect(parsed.success).toBe(false);
|
|
256
|
+
expect(parsed.error).toContain("No price data found for some-price-feed-id");
|
|
108
257
|
});
|
|
109
|
-
it("should
|
|
258
|
+
it("should return error if response is not ok", async () => {
|
|
110
259
|
fetchMock.mockResolvedValueOnce({
|
|
111
260
|
ok: false,
|
|
112
261
|
status: 404,
|
|
113
262
|
});
|
|
114
|
-
await
|
|
263
|
+
const result = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
|
|
264
|
+
const parsed = JSON.parse(result);
|
|
265
|
+
expect(parsed.success).toBe(false);
|
|
266
|
+
expect(parsed.error).toContain("HTTP error! status: 404");
|
|
115
267
|
});
|
|
116
268
|
});
|
|
117
269
|
});
|
|
@@ -4,10 +4,16 @@ import { z } from "zod";
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const PythFetchPriceFeedIDSchema: z.ZodObject<{
|
|
6
6
|
tokenSymbol: z.ZodString;
|
|
7
|
+
quoteCurrency: z.ZodDefault<z.ZodString>;
|
|
8
|
+
assetType: z.ZodDefault<z.ZodEnum<["crypto", "equity", "fx", "metal"]>>;
|
|
7
9
|
}, "strict", z.ZodTypeAny, {
|
|
8
10
|
tokenSymbol: string;
|
|
11
|
+
quoteCurrency: string;
|
|
12
|
+
assetType: "crypto" | "equity" | "fx" | "metal";
|
|
9
13
|
}, {
|
|
10
14
|
tokenSymbol: string;
|
|
15
|
+
quoteCurrency?: string | undefined;
|
|
16
|
+
assetType?: "crypto" | "equity" | "fx" | "metal" | undefined;
|
|
11
17
|
}>;
|
|
12
18
|
/**
|
|
13
19
|
* Input schema for Pyth fetch price action.
|
|
@@ -7,7 +7,15 @@ const zod_1 = require("zod");
|
|
|
7
7
|
*/
|
|
8
8
|
exports.PythFetchPriceFeedIDSchema = zod_1.z
|
|
9
9
|
.object({
|
|
10
|
-
tokenSymbol: zod_1.z.string().describe("The
|
|
10
|
+
tokenSymbol: zod_1.z.string().describe("The asset ticker/symbol to fetch the price feed ID for"),
|
|
11
|
+
quoteCurrency: zod_1.z
|
|
12
|
+
.string()
|
|
13
|
+
.default("USD")
|
|
14
|
+
.describe("The quote currency to filter by (defaults to USD)"),
|
|
15
|
+
assetType: zod_1.z
|
|
16
|
+
.enum(["crypto", "equity", "fx", "metal"])
|
|
17
|
+
.default("crypto")
|
|
18
|
+
.describe("The asset type to search for (crypto, equity, fx, metal)"),
|
|
11
19
|
})
|
|
12
20
|
.strict();
|
|
13
21
|
/**
|
|
@@ -74,14 +74,15 @@ class SuperfluidSuperTokenCreatorActionProvider extends actionProvider_1.ActionP
|
|
|
74
74
|
`${symbol}x`,
|
|
75
75
|
],
|
|
76
76
|
});
|
|
77
|
+
const superTokenFactoryAddress = walletProvider.getNetwork().networkId === "base-sepolia"
|
|
78
|
+
? constants_1.SuperTokenFactoryAddress_Base_Sepolia
|
|
79
|
+
: constants_1.SuperTokenFactoryAddress;
|
|
77
80
|
const createSuperTokenHash = await walletProvider.sendTransaction({
|
|
78
|
-
to:
|
|
79
|
-
? constants_1.SuperTokenFactoryAddress_Base_Sepolia
|
|
80
|
-
: constants_1.SuperTokenFactoryAddress,
|
|
81
|
+
to: superTokenFactoryAddress,
|
|
81
82
|
data: createSuperTokenData,
|
|
82
83
|
});
|
|
83
84
|
const receipt = await walletProvider.waitForTransactionReceipt(createSuperTokenHash);
|
|
84
|
-
const superTokenAddress = (0, parseLogs_1.extractCreatedSuperTokenAddressAbi)(receipt);
|
|
85
|
+
const superTokenAddress = (0, parseLogs_1.extractCreatedSuperTokenAddressAbi)(receipt, superTokenFactoryAddress);
|
|
85
86
|
return `Created super token for ${args.erc20TokenAddress}. Super token address at ${superTokenAddress} Transaction hash: ${createSuperTokenHash}`;
|
|
86
87
|
}
|
|
87
88
|
catch (error) {
|
|
@@ -12,7 +12,8 @@ type TxReceipt = {
|
|
|
12
12
|
* Extracts the super token address using the contract abi
|
|
13
13
|
*
|
|
14
14
|
* @param receipt - the transaction receipt from creating the super token
|
|
15
|
+
* @param factoryAddress - the address of the factory that created the super token
|
|
15
16
|
* @returns - The contract address of the created Super Token
|
|
16
17
|
*/
|
|
17
|
-
export declare function extractCreatedSuperTokenAddressAbi(receipt: TxReceipt): `0x${string}`;
|
|
18
|
+
export declare function extractCreatedSuperTokenAddressAbi(receipt: TxReceipt, factoryAddress: `0x${string}`): `0x${string}`;
|
|
18
19
|
export {};
|
|
@@ -46,12 +46,15 @@ function pickTokenLike(args) {
|
|
|
46
46
|
* Extracts the super token address using the contract abi
|
|
47
47
|
*
|
|
48
48
|
* @param receipt - the transaction receipt from creating the super token
|
|
49
|
+
* @param factoryAddress - the address of the factory that created the super token
|
|
49
50
|
* @returns - The contract address of the created Super Token
|
|
50
51
|
*/
|
|
51
|
-
function extractCreatedSuperTokenAddressAbi(receipt) {
|
|
52
|
-
const factory =
|
|
52
|
+
function extractCreatedSuperTokenAddressAbi(receipt, factoryAddress) {
|
|
53
|
+
const factory = factoryAddress.toLowerCase();
|
|
53
54
|
if (!factory)
|
|
54
|
-
throw new Error("Missing
|
|
55
|
+
throw new Error("Missing factory address");
|
|
56
|
+
console.log("factory", factory);
|
|
57
|
+
console.log("receipt.logs", receipt.logs);
|
|
55
58
|
for (const log of receipt.logs) {
|
|
56
59
|
if (log.address.toLowerCase() !== factory)
|
|
57
60
|
continue;
|
|
@@ -69,6 +69,9 @@ class WalletActionProvider extends actionProvider_1.ActionProvider {
|
|
|
69
69
|
"Wallet Details:",
|
|
70
70
|
`- Provider: ${name}`,
|
|
71
71
|
`- Address: ${address}`,
|
|
72
|
+
...(walletProvider instanceof wallet_providers_1.CdpSmartWalletProvider
|
|
73
|
+
? [`- Owner Address: ${walletProvider.ownerAccount.address}`]
|
|
74
|
+
: []),
|
|
72
75
|
"- Network:",
|
|
73
76
|
` * Protocol Family: ${network.protocolFamily}`,
|
|
74
77
|
` * Network ID: ${network.networkId || "N/A"}`,
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
export declare const ListX402ServicesSchema: z.ZodObject<{
|
|
3
|
+
maxUsdcPrice: z.ZodOptional<z.ZodNumber>;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
maxUsdcPrice?: number | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
maxUsdcPrice?: number | undefined;
|
|
8
|
+
}>;
|
|
2
9
|
export declare const HttpRequestSchema: z.ZodObject<{
|
|
3
10
|
url: z.ZodString;
|
|
4
11
|
method: z.ZodDefault<z.ZodNullable<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>>;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DirectX402RequestSchema = exports.RetryWithX402Schema = exports.HttpRequestSchema = void 0;
|
|
3
|
+
exports.DirectX402RequestSchema = exports.RetryWithX402Schema = exports.HttpRequestSchema = exports.ListX402ServicesSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
+
// Schema for listing x402 services
|
|
6
|
+
exports.ListX402ServicesSchema = zod_1.z
|
|
7
|
+
.object({
|
|
8
|
+
maxUsdcPrice: zod_1.z
|
|
9
|
+
.number()
|
|
10
|
+
.optional()
|
|
11
|
+
.describe("Optional maximum price in USDC whole units (e.g., 0.1 for 0.10 USDC). Only USDC payment options will be considered when this filter is applied."),
|
|
12
|
+
})
|
|
13
|
+
.strip()
|
|
14
|
+
.describe("Parameters for listing x402 services with optional filtering");
|
|
5
15
|
// Schema for initial HTTP request
|
|
6
16
|
exports.HttpRequestSchema = zod_1.z
|
|
7
17
|
.object({
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Network } from "../../network";
|
|
2
|
+
import { AxiosError } from "axios";
|
|
3
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
4
|
+
/**
|
|
5
|
+
* Supported network types for x402 protocol
|
|
6
|
+
*/
|
|
7
|
+
export type X402Network = "base" | "base-sepolia" | "solana" | "solana-devnet";
|
|
8
|
+
/**
|
|
9
|
+
* Converts the internal network ID to the format expected by the x402 protocol.
|
|
10
|
+
*
|
|
11
|
+
* @param network - The network to convert
|
|
12
|
+
* @returns The network ID in x402 format
|
|
13
|
+
* @throws Error if the network is not supported
|
|
14
|
+
*/
|
|
15
|
+
export declare function getX402Network(network: Network): X402Network | string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Helper method to handle HTTP errors consistently.
|
|
18
|
+
*
|
|
19
|
+
* @param error - The axios error to handle
|
|
20
|
+
* @param url - The URL that was being accessed when the error occurred
|
|
21
|
+
* @returns A JSON string containing formatted error details
|
|
22
|
+
*/
|
|
23
|
+
export declare function handleHttpError(error: AxiosError, url: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Formats a payment option into a human-readable string.
|
|
26
|
+
*
|
|
27
|
+
* @param option - The payment option to format
|
|
28
|
+
* @param option.asset - The asset address or identifier
|
|
29
|
+
* @param option.maxAmountRequired - The maximum amount required for the payment
|
|
30
|
+
* @param option.network - The network identifier
|
|
31
|
+
* @param walletProvider - The wallet provider for token details lookup
|
|
32
|
+
* @returns A formatted string like "0.1 USDC on base"
|
|
33
|
+
*/
|
|
34
|
+
export declare function formatPaymentOption(option: {
|
|
35
|
+
asset: string;
|
|
36
|
+
maxAmountRequired: string;
|
|
37
|
+
network: string;
|
|
38
|
+
}, walletProvider: EvmWalletProvider): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if an asset is USDC on any supported network.
|
|
41
|
+
*
|
|
42
|
+
* @param asset - The asset address or identifier
|
|
43
|
+
* @param walletProvider - The wallet provider for network context
|
|
44
|
+
* @returns True if the asset is USDC, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
export declare function isUsdcAsset(asset: string, walletProvider: EvmWalletProvider): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Converts whole units to atomic units for a given asset.
|
|
49
|
+
*
|
|
50
|
+
* @param wholeUnits - The amount in whole units (e.g., 0.1 for 0.1 USDC)
|
|
51
|
+
* @param asset - The asset address or identifier
|
|
52
|
+
* @param walletProvider - The wallet provider for token details lookup
|
|
53
|
+
* @returns The amount in atomic units as a string, or null if conversion fails
|
|
54
|
+
*/
|
|
55
|
+
export declare function convertWholeUnitsToAtomic(wholeUnits: number, asset: string, walletProvider: EvmWalletProvider): Promise<string | null>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getX402Network = getX402Network;
|
|
4
|
+
exports.handleHttpError = handleHttpError;
|
|
5
|
+
exports.formatPaymentOption = formatPaymentOption;
|
|
6
|
+
exports.isUsdcAsset = isUsdcAsset;
|
|
7
|
+
exports.convertWholeUnitsToAtomic = convertWholeUnitsToAtomic;
|
|
8
|
+
const utils_1 = require("../erc20/utils");
|
|
9
|
+
const constants_1 = require("../erc20/constants");
|
|
10
|
+
const viem_1 = require("viem");
|
|
11
|
+
/**
|
|
12
|
+
* Converts the internal network ID to the format expected by the x402 protocol.
|
|
13
|
+
*
|
|
14
|
+
* @param network - The network to convert
|
|
15
|
+
* @returns The network ID in x402 format
|
|
16
|
+
* @throws Error if the network is not supported
|
|
17
|
+
*/
|
|
18
|
+
function getX402Network(network) {
|
|
19
|
+
switch (network.networkId) {
|
|
20
|
+
case "base-mainnet":
|
|
21
|
+
return "base";
|
|
22
|
+
case "base-sepolia":
|
|
23
|
+
return "base-sepolia";
|
|
24
|
+
case "solana-mainnet":
|
|
25
|
+
return "solana";
|
|
26
|
+
case "solana-devnet":
|
|
27
|
+
return "solana-devnet";
|
|
28
|
+
default:
|
|
29
|
+
return network.networkId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Helper method to handle HTTP errors consistently.
|
|
34
|
+
*
|
|
35
|
+
* @param error - The axios error to handle
|
|
36
|
+
* @param url - The URL that was being accessed when the error occurred
|
|
37
|
+
* @returns A JSON string containing formatted error details
|
|
38
|
+
*/
|
|
39
|
+
function handleHttpError(error, url) {
|
|
40
|
+
if (error.response) {
|
|
41
|
+
return JSON.stringify({
|
|
42
|
+
error: true,
|
|
43
|
+
message: `HTTP ${error.response.status} error when accessing ${url}`,
|
|
44
|
+
details: error.response.data?.error || error.response.statusText,
|
|
45
|
+
suggestion: "Check if the URL is correct and the API is available.",
|
|
46
|
+
}, null, 2);
|
|
47
|
+
}
|
|
48
|
+
if (error.request) {
|
|
49
|
+
return JSON.stringify({
|
|
50
|
+
error: true,
|
|
51
|
+
message: `Network error when accessing ${url}`,
|
|
52
|
+
details: error.message,
|
|
53
|
+
suggestion: "Check your internet connection and verify the API endpoint is accessible.",
|
|
54
|
+
}, null, 2);
|
|
55
|
+
}
|
|
56
|
+
return JSON.stringify({
|
|
57
|
+
error: true,
|
|
58
|
+
message: `Error making request to ${url}`,
|
|
59
|
+
details: error.message,
|
|
60
|
+
suggestion: "Please check the request parameters and try again.",
|
|
61
|
+
}, null, 2);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Formats a payment option into a human-readable string.
|
|
65
|
+
*
|
|
66
|
+
* @param option - The payment option to format
|
|
67
|
+
* @param option.asset - The asset address or identifier
|
|
68
|
+
* @param option.maxAmountRequired - The maximum amount required for the payment
|
|
69
|
+
* @param option.network - The network identifier
|
|
70
|
+
* @param walletProvider - The wallet provider for token details lookup
|
|
71
|
+
* @returns A formatted string like "0.1 USDC on base"
|
|
72
|
+
*/
|
|
73
|
+
async function formatPaymentOption(option, walletProvider) {
|
|
74
|
+
const { asset, maxAmountRequired, network } = option;
|
|
75
|
+
// Check if this is an EVM network and we can use ERC20 helpers
|
|
76
|
+
const walletNetwork = walletProvider.getNetwork();
|
|
77
|
+
const isEvmNetwork = walletNetwork.protocolFamily === "evm";
|
|
78
|
+
if (isEvmNetwork) {
|
|
79
|
+
const networkId = walletNetwork.networkId;
|
|
80
|
+
const tokenSymbols = constants_1.TOKEN_ADDRESSES_BY_SYMBOLS[networkId];
|
|
81
|
+
if (tokenSymbols) {
|
|
82
|
+
for (const [symbol, address] of Object.entries(tokenSymbols)) {
|
|
83
|
+
if (asset.toLowerCase() === address.toLowerCase()) {
|
|
84
|
+
const decimals = symbol === "USDC" || symbol === "EURC" ? 6 : 18;
|
|
85
|
+
const formattedAmount = (0, viem_1.formatUnits)(BigInt(maxAmountRequired), decimals);
|
|
86
|
+
return `${formattedAmount} ${symbol} on ${network} network`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Fall back to getTokenDetails for unknown tokens
|
|
91
|
+
try {
|
|
92
|
+
const tokenDetails = await (0, utils_1.getTokenDetails)(walletProvider, asset);
|
|
93
|
+
if (tokenDetails) {
|
|
94
|
+
const formattedAmount = (0, viem_1.formatUnits)(BigInt(maxAmountRequired), tokenDetails.decimals);
|
|
95
|
+
return `${formattedAmount} ${tokenDetails.name} on ${network} network`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// If we can't get token details, fall back to raw format
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Fallback to original format for non-EVM networks or when token details can't be fetched
|
|
103
|
+
return `${asset} ${maxAmountRequired} on ${network} network`;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks if an asset is USDC on any supported network.
|
|
107
|
+
*
|
|
108
|
+
* @param asset - The asset address or identifier
|
|
109
|
+
* @param walletProvider - The wallet provider for network context
|
|
110
|
+
* @returns True if the asset is USDC, false otherwise
|
|
111
|
+
*/
|
|
112
|
+
function isUsdcAsset(asset, walletProvider) {
|
|
113
|
+
const walletNetwork = walletProvider.getNetwork();
|
|
114
|
+
const isEvmNetwork = walletNetwork.protocolFamily === "evm";
|
|
115
|
+
if (isEvmNetwork) {
|
|
116
|
+
const networkId = walletNetwork.networkId;
|
|
117
|
+
const tokenSymbols = constants_1.TOKEN_ADDRESSES_BY_SYMBOLS[networkId];
|
|
118
|
+
if (tokenSymbols && tokenSymbols.USDC) {
|
|
119
|
+
return asset.toLowerCase() === tokenSymbols.USDC.toLowerCase();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Converts whole units to atomic units for a given asset.
|
|
126
|
+
*
|
|
127
|
+
* @param wholeUnits - The amount in whole units (e.g., 0.1 for 0.1 USDC)
|
|
128
|
+
* @param asset - The asset address or identifier
|
|
129
|
+
* @param walletProvider - The wallet provider for token details lookup
|
|
130
|
+
* @returns The amount in atomic units as a string, or null if conversion fails
|
|
131
|
+
*/
|
|
132
|
+
async function convertWholeUnitsToAtomic(wholeUnits, asset, walletProvider) {
|
|
133
|
+
// Check if this is an EVM network and we can use ERC20 helpers
|
|
134
|
+
const walletNetwork = walletProvider.getNetwork();
|
|
135
|
+
const isEvmNetwork = walletNetwork.protocolFamily === "evm";
|
|
136
|
+
if (isEvmNetwork) {
|
|
137
|
+
const networkId = walletNetwork.networkId;
|
|
138
|
+
const tokenSymbols = constants_1.TOKEN_ADDRESSES_BY_SYMBOLS[networkId];
|
|
139
|
+
if (tokenSymbols) {
|
|
140
|
+
for (const [symbol, address] of Object.entries(tokenSymbols)) {
|
|
141
|
+
if (asset.toLowerCase() === address.toLowerCase()) {
|
|
142
|
+
const decimals = symbol === "USDC" || symbol === "EURC" ? 6 : 18;
|
|
143
|
+
return (0, viem_1.parseUnits)(wholeUnits.toString(), decimals).toString();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Fall back to getTokenDetails for unknown tokens
|
|
148
|
+
try {
|
|
149
|
+
const tokenDetails = await (0, utils_1.getTokenDetails)(walletProvider, asset);
|
|
150
|
+
if (tokenDetails) {
|
|
151
|
+
return (0, viem_1.parseUnits)(wholeUnits.toString(), tokenDetails.decimals).toString();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// If we can't get token details, fall back to assuming 18 decimals
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Fallback to 18 decimals for unknown tokens or non-EVM networks
|
|
159
|
+
return (0, viem_1.parseUnits)(wholeUnits.toString(), 18).toString();
|
|
160
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { ActionProvider } from "../actionProvider";
|
|
3
3
|
import { Network } from "../../network";
|
|
4
|
-
import { HttpRequestSchema, RetryWithX402Schema, DirectX402RequestSchema } from "./schemas";
|
|
4
|
+
import { HttpRequestSchema, RetryWithX402Schema, DirectX402RequestSchema, ListX402ServicesSchema } from "./schemas";
|
|
5
5
|
import { EvmWalletProvider } from "../../wallet-providers";
|
|
6
6
|
/**
|
|
7
7
|
* X402ActionProvider provides actions for making HTTP requests, with optional x402 payment handling.
|
|
@@ -12,6 +12,14 @@ export declare class X402ActionProvider extends ActionProvider<EvmWalletProvider
|
|
|
12
12
|
* Initializes the provider with x402 capabilities.
|
|
13
13
|
*/
|
|
14
14
|
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Discovers available x402 services with optional filtering.
|
|
17
|
+
*
|
|
18
|
+
* @param walletProvider - The wallet provider to use for network filtering
|
|
19
|
+
* @param args - Optional filters: maxUsdcPrice
|
|
20
|
+
* @returns JSON string with the list of services (filtered by network and description)
|
|
21
|
+
*/
|
|
22
|
+
discoverX402Services(walletProvider: EvmWalletProvider, args: z.infer<typeof ListX402ServicesSchema>): Promise<string>;
|
|
15
23
|
/**
|
|
16
24
|
* Makes a basic HTTP request to an API endpoint.
|
|
17
25
|
*
|
|
@@ -43,13 +51,5 @@ export declare class X402ActionProvider extends ActionProvider<EvmWalletProvider
|
|
|
43
51
|
* @returns True if the network is supported, false otherwise
|
|
44
52
|
*/
|
|
45
53
|
supportsNetwork: (network: Network) => boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Helper method to handle HTTP errors consistently.
|
|
48
|
-
*
|
|
49
|
-
* @param error - The axios error to handle
|
|
50
|
-
* @param url - The URL that was being accessed when the error occurred
|
|
51
|
-
* @returns A JSON string containing formatted error details
|
|
52
|
-
*/
|
|
53
|
-
private handleHttpError;
|
|
54
54
|
}
|
|
55
55
|
export declare const x402ActionProvider: () => X402ActionProvider;
|