@coinbase/agentkit 0.10.1 → 0.10.3

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 (127) hide show
  1. package/README.md +179 -40
  2. package/dist/action-providers/across/schemas.d.ts +1 -1
  3. package/dist/action-providers/baseAccount/baseAccountActionProvider.d.ts +46 -0
  4. package/dist/action-providers/baseAccount/baseAccountActionProvider.js +404 -0
  5. package/dist/action-providers/baseAccount/baseAccountActionProvider.test.d.ts +1 -0
  6. package/dist/action-providers/baseAccount/baseAccountActionProvider.test.js +325 -0
  7. package/dist/action-providers/baseAccount/index.d.ts +2 -0
  8. package/dist/action-providers/baseAccount/index.js +18 -0
  9. package/dist/action-providers/baseAccount/schemas.d.ts +43 -0
  10. package/dist/action-providers/baseAccount/schemas.js +62 -0
  11. package/dist/action-providers/baseAccount/types.d.ts +17 -0
  12. package/dist/action-providers/baseAccount/types.js +2 -0
  13. package/dist/action-providers/baseAccount/utils.d.ts +14 -0
  14. package/dist/action-providers/baseAccount/utils.js +57 -0
  15. package/dist/action-providers/cdp/cdpApiActionProvider.js +7 -30
  16. package/dist/action-providers/cdp/cdpApiActionProvider.test.js +2 -8
  17. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +2 -1
  18. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +3 -1
  19. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +2 -1
  20. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +3 -1
  21. package/dist/action-providers/cdp/faucetUtils.d.ts +38 -0
  22. package/dist/action-providers/cdp/faucetUtils.js +81 -0
  23. package/dist/action-providers/cdp/swapUtils.d.ts +0 -9
  24. package/dist/action-providers/cdp/swapUtils.js +0 -36
  25. package/dist/action-providers/clanker/schemas.d.ts +6 -6
  26. package/dist/action-providers/enso/constants.d.ts +4 -0
  27. package/dist/action-providers/enso/constants.js +10 -0
  28. package/dist/action-providers/enso/ensoActionProvider.d.ts +34 -0
  29. package/dist/action-providers/enso/ensoActionProvider.js +125 -0
  30. package/dist/action-providers/enso/ensoActionProvider.test.d.ts +1 -0
  31. package/dist/action-providers/enso/ensoActionProvider.test.js +141 -0
  32. package/dist/action-providers/enso/index.d.ts +1 -0
  33. package/dist/action-providers/enso/index.js +17 -0
  34. package/dist/action-providers/enso/schemas.d.ts +23 -0
  35. package/dist/action-providers/enso/schemas.js +22 -0
  36. package/dist/action-providers/erc20/constants.d.ts +2 -0
  37. package/dist/action-providers/erc20/constants.js +2 -0
  38. package/dist/action-providers/erc20/erc20ActionProvider.d.ts +17 -1
  39. package/dist/action-providers/erc20/erc20ActionProvider.js +103 -1
  40. package/dist/action-providers/erc20/erc20ActionProvider.test.js +201 -0
  41. package/dist/action-providers/erc20/schemas.d.ts +29 -0
  42. package/dist/action-providers/erc20/schemas.js +34 -1
  43. package/dist/action-providers/flaunch/client_utils.d.ts +25 -0
  44. package/dist/action-providers/flaunch/client_utils.js +62 -0
  45. package/dist/action-providers/flaunch/constants.d.ts +41 -20
  46. package/dist/action-providers/flaunch/constants.js +111 -36
  47. package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +4 -43
  48. package/dist/action-providers/flaunch/flaunchActionProvider.js +132 -200
  49. package/dist/action-providers/flaunch/flaunchActionProvider.test.js +108 -13
  50. package/dist/action-providers/flaunch/metadata_utils.d.ts +12 -0
  51. package/dist/action-providers/flaunch/metadata_utils.js +216 -0
  52. package/dist/action-providers/flaunch/schemas.d.ts +39 -3
  53. package/dist/action-providers/flaunch/schemas.js +62 -10
  54. package/dist/action-providers/flaunch/{utils.d.ts → swap_utils.d.ts} +17 -19
  55. package/dist/action-providers/flaunch/{utils.js → swap_utils.js} +137 -172
  56. package/dist/action-providers/index.d.ts +4 -1
  57. package/dist/action-providers/index.js +4 -1
  58. package/dist/action-providers/pyth/pythActionProvider.d.ts +2 -2
  59. package/dist/action-providers/pyth/pythActionProvider.js +83 -31
  60. package/dist/action-providers/pyth/pythActionProvider.test.js +178 -26
  61. package/dist/action-providers/pyth/schemas.d.ts +6 -0
  62. package/dist/action-providers/pyth/schemas.js +9 -1
  63. package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +5 -4
  64. package/dist/action-providers/superfluid/utils/parseLogs.d.ts +2 -1
  65. package/dist/action-providers/superfluid/utils/parseLogs.js +6 -3
  66. package/dist/action-providers/wallet/walletActionProvider.js +4 -1
  67. package/dist/action-providers/weth/constants.d.ts +0 -1
  68. package/dist/action-providers/weth/constants.js +1 -2
  69. package/dist/action-providers/weth/schemas.js +6 -2
  70. package/dist/action-providers/weth/wethActionProvider.d.ts +7 -0
  71. package/dist/action-providers/weth/wethActionProvider.js +57 -32
  72. package/dist/action-providers/weth/wethActionProvider.test.js +60 -11
  73. package/dist/action-providers/x402/schemas.d.ts +7 -0
  74. package/dist/action-providers/x402/schemas.js +11 -1
  75. package/dist/action-providers/x402/utils.d.ts +55 -0
  76. package/dist/action-providers/x402/utils.js +197 -0
  77. package/dist/action-providers/x402/x402ActionProvider.d.ts +14 -14
  78. package/dist/action-providers/x402/x402ActionProvider.js +179 -45
  79. package/dist/action-providers/x402/x402ActionProvider.test.js +162 -12
  80. package/dist/action-providers/yelay/constants.d.ts +64 -0
  81. package/dist/action-providers/yelay/constants.js +137 -0
  82. package/dist/action-providers/yelay/index.d.ts +2 -0
  83. package/dist/action-providers/yelay/index.js +18 -0
  84. package/dist/action-providers/yelay/schemas.d.ts +47 -0
  85. package/dist/action-providers/yelay/schemas.js +59 -0
  86. package/dist/action-providers/yelay/types.d.ts +24 -0
  87. package/dist/action-providers/yelay/types.js +2 -0
  88. package/dist/action-providers/yelay/yelayActionProvider.d.ts +70 -0
  89. package/dist/action-providers/yelay/yelayActionProvider.js +329 -0
  90. package/dist/action-providers/yelay/yelayActionProvider.test.d.ts +1 -0
  91. package/dist/action-providers/yelay/yelayActionProvider.test.js +302 -0
  92. package/dist/utils.d.ts +10 -0
  93. package/dist/utils.js +43 -13
  94. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +7 -0
  95. package/dist/wallet-providers/cdpEvmWalletProvider.js +14 -21
  96. package/dist/wallet-providers/cdpEvmWalletProvider.test.js +7 -0
  97. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +7 -0
  98. package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -8
  99. package/dist/wallet-providers/cdpSmartWalletProvider.test.js +6 -10
  100. package/dist/wallet-providers/cdpSolanaWalletProvider.d.ts +14 -0
  101. package/dist/wallet-providers/cdpSolanaWalletProvider.js +39 -3
  102. package/dist/wallet-providers/cdpSolanaWalletProvider.test.js +16 -0
  103. package/dist/wallet-providers/evmWalletProvider.d.ts +9 -2
  104. package/dist/wallet-providers/evmWalletProvider.js +4 -0
  105. package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -0
  106. package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +11 -0
  107. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +7 -0
  108. package/dist/wallet-providers/legacyCdpWalletProvider.js +16 -0
  109. package/dist/wallet-providers/legacyCdpWalletProvider.test.js +6 -0
  110. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +7 -0
  111. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +27 -0
  112. package/dist/wallet-providers/privyEvmWalletProvider.test.js +11 -0
  113. package/dist/wallet-providers/privySvmWalletProvider.d.ts +14 -0
  114. package/dist/wallet-providers/privySvmWalletProvider.js +17 -0
  115. package/dist/wallet-providers/privySvmWalletProvider.test.js +10 -0
  116. package/dist/wallet-providers/solanaKeypairWalletProvider.d.ts +14 -0
  117. package/dist/wallet-providers/solanaKeypairWalletProvider.js +17 -0
  118. package/dist/wallet-providers/svmWalletProvider.d.ts +34 -0
  119. package/dist/wallet-providers/svmWalletProvider.js +43 -0
  120. package/dist/wallet-providers/svmWalletProvider.test.js +10 -0
  121. package/dist/wallet-providers/viemWalletProvider.d.ts +8 -1
  122. package/dist/wallet-providers/viemWalletProvider.js +21 -1
  123. package/dist/wallet-providers/viemWalletProvider.test.js +21 -1
  124. package/dist/wallet-providers/zeroDevWalletProvider.d.ts +7 -0
  125. package/dist/wallet-providers/zeroDevWalletProvider.js +12 -0
  126. package/dist/wallet-providers/zeroDevWalletProvider.test.js +10 -0
  127. package/package.json +8 -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 () => [{ id: "some-price-feed-id", attributes: { base: "BTC" } }],
15
+ json: async () => [
16
+ { id: "some-price-feed-id", attributes: { base: "BTC", quote_currency: "USD" } },
17
+ ],
16
18
  });
17
- const priceFeedId = await provider.fetchPriceFeed({ tokenSymbol: "BTC" });
18
- expect(priceFeedId).toEqual("some-price-feed-id");
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 throw an error if no price feed is found", async () => {
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 () => [{ id: "some-price-feed-id", attributes: { base: "BTC" } }],
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
- await expect(provider.fetchPriceFeed({ tokenSymbol: "SOL" })).rejects.toThrow("No price feed found for SOL");
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 hardcoded price feed ID for ETH", async () => {
28
- const priceFeedId = await provider.fetchPriceFeed({ tokenSymbol: "ETH" });
29
- expect(priceFeedId).toEqual("0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace");
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 throw an error if the response is not ok", async () => {
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 expect(provider.fetchPriceFeed({ tokenSymbol: "BTC" })).rejects.toThrow("HTTP error! status: 404");
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 throw an error if response is ok but no data is returned", async () => {
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 provider = (0, pythActionProvider_1.pythActionProvider)();
44
- await expect(provider.fetchPriceFeed({ tokenSymbol: "BTC" })).rejects.toThrow("No price feed found for BTC");
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 price = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
63
- expect(price).toEqual("1");
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 provider = (0, pythActionProvider_1.pythActionProvider)();
80
- const price = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
81
- expect(price).toEqual("1.00");
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 price = await provider.fetchPrice({ priceFeedID: "some-price-feed-id" });
98
- expect(price).toEqual("0.25");
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 throw an error if there is no price data", async () => {
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 expect(provider.fetchPrice({ priceFeedID: "some-price-feed-id" })).rejects.toThrow("No price data found for some-price-feed-id");
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 throw an error if response is not ok", async () => {
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 expect(provider.fetchPrice({ priceFeedID: "some-price-feed-id" })).rejects.toThrow("HTTP error! status: 404");
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 token symbol to fetch the price feed ID for"),
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: walletProvider.getNetwork().networkId === "base-sepolia"
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 = receipt.to?.toLowerCase();
52
+ function extractCreatedSuperTokenAddressAbi(receipt, factoryAddress) {
53
+ const factory = factoryAddress.toLowerCase();
53
54
  if (!factory)
54
- throw new Error("Missing receipt.to (factory address)");
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"}`,
@@ -130,7 +133,7 @@ __decorate([
130
133
  (0, actionDecorator_1.CreateAction)({
131
134
  name: "native_transfer",
132
135
  description: `
133
- This tool will transfer (send) native tokens from the wallet to another onchain address.
136
+ This tool will transfer (send) native tokens (ETH for EVM networks, SOL for SVM networks) from the wallet to another onchain address.
134
137
 
135
138
  It takes the following inputs:
136
139
  - amount: The amount to transfer in whole units (e.g. 4.2 ETH, 0.1 SOL)
@@ -1,4 +1,3 @@
1
- export declare const WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
2
1
  export declare const WETH_ABI: readonly [{
3
2
  readonly inputs: readonly [];
4
3
  readonly name: "deposit";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WETH_ABI = exports.WETH_ADDRESS = void 0;
4
- exports.WETH_ADDRESS = "0x4200000000000000000000000000000000000006";
3
+ exports.WETH_ABI = void 0;
5
4
  exports.WETH_ABI = [
6
5
  {
7
6
  inputs: [],
@@ -4,13 +4,17 @@ exports.UnwrapEthSchema = exports.WrapEthSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.WrapEthSchema = zod_1.z
6
6
  .object({
7
- amountToWrap: zod_1.z.string().describe("Amount of ETH to wrap in wei"),
7
+ amountToWrap: zod_1.z
8
+ .string()
9
+ .describe("Amount of ETH to wrap in human-readable format (e.g., 0.1 for 0.1 ETH)"),
8
10
  })
9
11
  .strip()
10
12
  .describe("Instructions for wrapping ETH to WETH");
11
13
  exports.UnwrapEthSchema = zod_1.z
12
14
  .object({
13
- amountToUnwrap: zod_1.z.string().describe("Amount of WETH to unwrap in wei"),
15
+ amountToUnwrap: zod_1.z
16
+ .string()
17
+ .describe("Amount of WETH to unwrap in human-readable format (e.g., 0.1 for 0.1 WETH)"),
14
18
  })
15
19
  .strip()
16
20
  .describe("Instructions for unwrapping WETH to ETH");
@@ -3,6 +3,13 @@ import { ActionProvider } from "../actionProvider";
3
3
  import { Network } from "../../network";
4
4
  import { WrapEthSchema, UnwrapEthSchema } from "./schemas";
5
5
  import { EvmWalletProvider } from "../../wallet-providers";
6
+ /**
7
+ * Gets the WETH address for the given network.
8
+ *
9
+ * @param network - The network to get the WETH address for.
10
+ * @returns The WETH address for the network, or undefined if not supported.
11
+ */
12
+ export declare const getWethAddress: (network: Network) => string | undefined;
6
13
  /**
7
14
  * WethActionProvider is an action provider for WETH.
8
15
  */
@@ -9,14 +9,26 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.wethActionProvider = exports.WethActionProvider = void 0;
12
+ exports.wethActionProvider = exports.WethActionProvider = exports.getWethAddress = void 0;
13
13
  const zod_1 = require("zod");
14
14
  const actionProvider_1 = require("../actionProvider");
15
15
  const actionDecorator_1 = require("../actionDecorator");
16
16
  const schemas_1 = require("./schemas");
17
17
  const constants_1 = require("./constants");
18
+ const constants_2 = require("../erc20/constants");
18
19
  const viem_1 = require("viem");
19
20
  const wallet_providers_1 = require("../../wallet-providers");
21
+ /**
22
+ * Gets the WETH address for the given network.
23
+ *
24
+ * @param network - The network to get the WETH address for.
25
+ * @returns The WETH address for the network, or undefined if not supported.
26
+ */
27
+ const getWethAddress = (network) => {
28
+ const networkTokens = constants_2.TOKEN_ADDRESSES_BY_SYMBOLS[network.networkId];
29
+ return networkTokens && "WETH" in networkTokens ? networkTokens.WETH : undefined;
30
+ };
31
+ exports.getWethAddress = getWethAddress;
20
32
  /**
21
33
  * WethActionProvider is an action provider for WETH.
22
34
  */
@@ -32,7 +44,9 @@ class WethActionProvider extends actionProvider_1.ActionProvider {
32
44
  * @param network - The network to check.
33
45
  * @returns True if the Weth action provider supports the network, false otherwise.
34
46
  */
35
- this.supportsNetwork = (network) => network.networkId === "base-mainnet" || network.networkId === "base-sepolia";
47
+ this.supportsNetwork = (network) => {
48
+ return (0, exports.getWethAddress)(network) !== undefined;
49
+ };
36
50
  }
37
51
  /**
38
52
  * Wraps ETH to WETH.
@@ -42,17 +56,30 @@ class WethActionProvider extends actionProvider_1.ActionProvider {
42
56
  * @returns A message containing the transaction hash.
43
57
  */
44
58
  async wrapEth(walletProvider, args) {
59
+ const network = walletProvider.getNetwork();
60
+ const wethAddress = (0, exports.getWethAddress)(network);
61
+ if (!wethAddress) {
62
+ return `Error: WETH not supported on network ${network.networkId}`;
63
+ }
45
64
  try {
65
+ // Convert human-readable ETH amount to wei (ETH has 18 decimals)
66
+ const amountInWei = (0, viem_1.parseUnits)(args.amountToWrap, 18);
67
+ // Check ETH balance before wrapping
68
+ const ethBalance = await walletProvider.getBalance();
69
+ if (ethBalance < amountInWei) {
70
+ const ethBalanceFormatted = (0, viem_1.formatUnits)(ethBalance, 18);
71
+ return `Error: Insufficient ETH balance. Requested to wrap ${args.amountToWrap} ETH, but only ${ethBalanceFormatted} ETH is available.`;
72
+ }
46
73
  const hash = await walletProvider.sendTransaction({
47
- to: constants_1.WETH_ADDRESS,
74
+ to: wethAddress,
48
75
  data: (0, viem_1.encodeFunctionData)({
49
76
  abi: constants_1.WETH_ABI,
50
77
  functionName: "deposit",
51
78
  }),
52
- value: BigInt(args.amountToWrap),
79
+ value: amountInWei,
53
80
  });
54
81
  await walletProvider.waitForTransactionReceipt(hash);
55
- return `Wrapped ETH with transaction hash: ${hash}`;
82
+ return `Wrapped ${args.amountToWrap} ETH to WETH. Transaction hash: ${hash}`;
56
83
  }
57
84
  catch (error) {
58
85
  return `Error wrapping ETH: ${error}`;
@@ -66,17 +93,35 @@ class WethActionProvider extends actionProvider_1.ActionProvider {
66
93
  * @returns A message containing the transaction hash.
67
94
  */
68
95
  async unwrapEth(walletProvider, args) {
96
+ const network = walletProvider.getNetwork();
97
+ const wethAddress = (0, exports.getWethAddress)(network);
98
+ if (!wethAddress) {
99
+ return `Error: WETH not supported on network ${network.networkId}`;
100
+ }
69
101
  try {
102
+ // Convert human-readable WETH amount to wei (WETH has 18 decimals)
103
+ const amountInWei = (0, viem_1.parseUnits)(args.amountToUnwrap, 18);
104
+ // Check WETH balance before unwrapping
105
+ const wethBalance = await walletProvider.readContract({
106
+ address: wethAddress,
107
+ abi: viem_1.erc20Abi,
108
+ functionName: "balanceOf",
109
+ args: [walletProvider.getAddress()],
110
+ });
111
+ if (wethBalance < amountInWei) {
112
+ const wethBalanceFormatted = (0, viem_1.formatUnits)(wethBalance, 18);
113
+ return `Error: Insufficient WETH balance. Requested to unwrap ${args.amountToUnwrap} WETH, but only ${wethBalanceFormatted} WETH is available.`;
114
+ }
70
115
  const hash = await walletProvider.sendTransaction({
71
- to: constants_1.WETH_ADDRESS,
116
+ to: wethAddress,
72
117
  data: (0, viem_1.encodeFunctionData)({
73
118
  abi: constants_1.WETH_ABI,
74
119
  functionName: "withdraw",
75
- args: [BigInt(args.amountToUnwrap)],
120
+ args: [amountInWei],
76
121
  }),
77
122
  });
78
123
  await walletProvider.waitForTransactionReceipt(hash);
79
- return `Unwrapped WETH with transaction hash: ${hash}`;
124
+ return `Unwrapped ${args.amountToUnwrap} WETH to ETH. Transaction hash: ${hash}`;
80
125
  }
81
126
  catch (error) {
82
127
  return `Error unwrapping WETH: ${error}`;
@@ -88,20 +133,10 @@ __decorate([
88
133
  (0, actionDecorator_1.CreateAction)({
89
134
  name: "wrap_eth",
90
135
  description: `
91
- This tool can only be used to wrap ETH to WETH.
92
- Do not use this tool for any other purpose, or trading other assets.
136
+ This tool wraps ETH to WETH.
93
137
 
94
138
  Inputs:
95
- - Amount of ETH to wrap.
96
-
97
- Important notes:
98
- - The amount is a string and cannot have any decimal points, since the unit of measurement is wei.
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.
100
- - 1 wei = 0.000000000000000001 WETH
101
- - Minimum purchase amount is 100000000000 wei (0.0000001 WETH)
102
- - Only supported on the following networks:
103
- - Base Sepolia (ie, 'base-sepolia')
104
- - Base Mainnet (ie, 'base', 'base-mainnet')
139
+ - Amount of ETH to wrap in human-readable format (e.g., 0.1 for 0.1 ETH).
105
140
  `,
106
141
  schema: schemas_1.WrapEthSchema,
107
142
  }),
@@ -113,20 +148,10 @@ __decorate([
113
148
  (0, actionDecorator_1.CreateAction)({
114
149
  name: "unwrap_eth",
115
150
  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.
151
+ This tool unwraps WETH to ETH.
118
152
 
119
153
  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')
154
+ - Amount of WETH to unwrap in human-readable format (e.g., 0.1 for 0.1 WETH).
130
155
  `,
131
156
  schema: schemas_1.UnwrapEthSchema,
132
157
  }),