@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
@@ -43,8 +43,10 @@ exports.TOKEN_ADDRESSES_BY_SYMBOLS = {
43
43
  },
44
44
  "arbitrum-mainnet": {
45
45
  USDC: "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
46
+ WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
46
47
  },
47
48
  "optimism-mainnet": {
48
49
  USDC: "0x0b2c639c533813f4aa9d7837caf62653d097ff85",
50
+ WETH: "0x4200000000000000000000000000000000000006",
49
51
  },
50
52
  };
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { ActionProvider } from "../actionProvider";
3
3
  import { Network } from "../../network";
4
- import { GetBalanceSchema, TransferSchema, GetTokenAddressSchema } from "./schemas";
4
+ import { GetBalanceSchema, TransferSchema, GetTokenAddressSchema, ApproveSchema, AllowanceSchema } from "./schemas";
5
5
  import { EvmWalletProvider } from "../../wallet-providers";
6
6
  /**
7
7
  * ERC20ActionProvider is an action provider for ERC20 tokens.
@@ -27,6 +27,22 @@ export declare class ERC20ActionProvider extends ActionProvider<EvmWalletProvide
27
27
  * @returns A message containing the transfer details.
28
28
  */
29
29
  transfer(walletProvider: EvmWalletProvider, args: z.infer<typeof TransferSchema>): Promise<string>;
30
+ /**
31
+ * Approves a spender to transfer a specified amount of tokens.
32
+ *
33
+ * @param walletProvider - The wallet provider to approve from.
34
+ * @param args - The input arguments for the action.
35
+ * @returns A message containing the approval details.
36
+ */
37
+ approve(walletProvider: EvmWalletProvider, args: z.infer<typeof ApproveSchema>): Promise<string>;
38
+ /**
39
+ * Checks the allowance for a spender of an ERC20 token.
40
+ *
41
+ * @param walletProvider - The wallet provider to check the allowance from.
42
+ * @param args - The input arguments containing tokenAddress and spender.
43
+ * @returns A message containing the allowance amount for the spender.
44
+ */
45
+ getAllowance(walletProvider: EvmWalletProvider, args: z.infer<typeof AllowanceSchema>): Promise<string>;
30
46
  /**
31
47
  * Gets the contract address for a token symbol on the current network.
32
48
  *
@@ -117,6 +117,66 @@ class ERC20ActionProvider extends actionProvider_1.ActionProvider {
117
117
  return `Error transferring the asset: ${error}`;
118
118
  }
119
119
  }
120
+ /**
121
+ * Approves a spender to transfer a specified amount of tokens.
122
+ *
123
+ * @param walletProvider - The wallet provider to approve from.
124
+ * @param args - The input arguments for the action.
125
+ * @returns A message containing the approval details.
126
+ */
127
+ async approve(walletProvider, args) {
128
+ try {
129
+ // Get token details for better error messages and validation
130
+ const tokenAddress = (0, viem_1.getAddress)(args.tokenAddress);
131
+ const tokenDetails = await (0, utils_1.getTokenDetails)(walletProvider, args.tokenAddress);
132
+ if (!tokenDetails) {
133
+ return `Error: Could not fetch token details for ${args.tokenAddress}. Please verify the token address is correct.`;
134
+ }
135
+ // Convert amount to wei using token decimals
136
+ const amountInWei = (0, viem_1.parseUnits)(String(args.amount), tokenDetails.decimals);
137
+ const hash = await walletProvider.sendTransaction({
138
+ to: tokenAddress,
139
+ data: (0, viem_1.encodeFunctionData)({
140
+ abi: viem_1.erc20Abi,
141
+ functionName: "approve",
142
+ args: [args.spenderAddress, amountInWei],
143
+ }),
144
+ });
145
+ await walletProvider.waitForTransactionReceipt(hash);
146
+ return `Approved ${args.amount} ${tokenDetails.name} (${args.tokenAddress}) for spender ${args.spenderAddress}.\nTransaction hash: ${hash}`;
147
+ }
148
+ catch (error) {
149
+ return `Error approving tokens: ${error}`;
150
+ }
151
+ }
152
+ /**
153
+ * Checks the allowance for a spender of an ERC20 token.
154
+ *
155
+ * @param walletProvider - The wallet provider to check the allowance from.
156
+ * @param args - The input arguments containing tokenAddress and spender.
157
+ * @returns A message containing the allowance amount for the spender.
158
+ */
159
+ async getAllowance(walletProvider, args) {
160
+ try {
161
+ // Get token details for proper formatting
162
+ const tokenDetails = await (0, utils_1.getTokenDetails)(walletProvider, args.tokenAddress);
163
+ if (!tokenDetails) {
164
+ return `Error: Could not fetch token details for ${args.tokenAddress}. Please verify the token address is correct.`;
165
+ }
166
+ const allowance = await walletProvider.readContract({
167
+ address: args.tokenAddress,
168
+ abi: viem_1.erc20Abi,
169
+ functionName: "allowance",
170
+ args: [walletProvider.getAddress(), args.spenderAddress],
171
+ });
172
+ // Format the allowance using token decimals
173
+ const formattedAllowance = (0, viem_1.formatUnits)(allowance, tokenDetails.decimals);
174
+ return `Allowance for ${args.spenderAddress} to spend ${tokenDetails.name} (${args.tokenAddress}) is ${formattedAllowance} tokens`;
175
+ }
176
+ catch (error) {
177
+ return `Error checking allowance: ${error}`;
178
+ }
179
+ }
120
180
  /**
121
181
  * Gets the contract address for a token symbol on the current network.
122
182
  *
@@ -166,7 +226,7 @@ __decorate([
166
226
  It takes the following inputs:
167
227
  - amount: The amount to transfer in whole units (e.g. 10.5 USDC)
168
228
  - tokenAddress: The contract address of the token to transfer
169
- - destinationAddress: Where to send the funds (can be an onchain address, ENS 'example.eth', or Basename 'example.base.eth')
229
+ - destinationAddress: The address to send the funds to
170
230
  Important notes:
171
231
  - Never assume token or destination addresses, they have to be provided as inputs. If only token symbol is provided, use the get_token_address tool to get the token address first
172
232
  `,
@@ -176,6 +236,48 @@ Important notes:
176
236
  __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
177
237
  __metadata("design:returntype", Promise)
178
238
  ], ERC20ActionProvider.prototype, "transfer", null);
239
+ __decorate([
240
+ (0, actionDecorator_1.CreateAction)({
241
+ name: "approve",
242
+ description: `
243
+ This tool will approve a spender to transfer ERC20 tokens from the wallet.
244
+
245
+ It takes the following inputs:
246
+ - amount: The amount to approve in whole units (e.g. 100 for 100 USDC)
247
+ - tokenAddress: The contract address of the token to approve
248
+ - spenderAddress: The spender address to approve
249
+
250
+ Important notes:
251
+ - This will overwrite any existing allowance
252
+ - To revoke an allowance, set the amount to 0
253
+ - Ensure you trust the spender address before approving
254
+ - Never assume token addresses, they have to be provided as inputs. If only token symbol is provided, use the get_token_address tool to get the token address first
255
+ `,
256
+ schema: schemas_1.ApproveSchema,
257
+ }),
258
+ __metadata("design:type", Function),
259
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
260
+ __metadata("design:returntype", Promise)
261
+ ], ERC20ActionProvider.prototype, "approve", null);
262
+ __decorate([
263
+ (0, actionDecorator_1.CreateAction)({
264
+ name: "get_allowance",
265
+ description: `
266
+ This tool will get the allowance amount for a spender of an ERC20 token.
267
+
268
+ It takes the following inputs:
269
+ - tokenAddress: The contract address of the token to check allowance for
270
+ - spenderAddress: The address to check allowance for
271
+
272
+ Important notes:
273
+ - Never assume token addresses, they have to be provided as inputs. If only token symbol is provided, use the get_token_address tool to get the token address first
274
+ `,
275
+ schema: schemas_1.AllowanceSchema,
276
+ }),
277
+ __metadata("design:type", Function),
278
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
279
+ __metadata("design:returntype", Promise)
280
+ ], ERC20ActionProvider.prototype, "getAllowance", null);
179
281
  __decorate([
180
282
  (0, actionDecorator_1.CreateAction)({
181
283
  name: "get_erc20_token_address",
@@ -7,6 +7,7 @@ const MOCK_DECIMALS = 6;
7
7
  const MOCK_CONTRACT_ADDRESS = "0x1234567890123456789012345678901234567890";
8
8
  const MOCK_DESTINATION = "0x9876543210987654321098765432109876543210";
9
9
  const MOCK_ADDRESS = "0x1234567890123456789012345678901234567890";
10
+ const MOCK_SPENDER = "0xabcdef1234567890123456789012345678901234";
10
11
  describe("Transfer Schema", () => {
11
12
  it("should successfully parse valid input", () => {
12
13
  const validInput = {
@@ -142,6 +143,206 @@ describe("GetTokenAddress Schema", () => {
142
143
  expect(result.success).toBe(false);
143
144
  });
144
145
  });
146
+ describe("Approve Schema", () => {
147
+ it("should successfully parse valid input", () => {
148
+ const validInput = {
149
+ amount: MOCK_AMOUNT.toString(),
150
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
151
+ spenderAddress: MOCK_SPENDER,
152
+ };
153
+ const result = schemas_1.ApproveSchema.safeParse(validInput);
154
+ expect(result.success).toBe(true);
155
+ expect(result.data).toEqual(validInput);
156
+ });
157
+ it("should fail parsing empty input", () => {
158
+ const emptyInput = {};
159
+ const result = schemas_1.ApproveSchema.safeParse(emptyInput);
160
+ expect(result.success).toBe(false);
161
+ });
162
+ it("should fail parsing invalid token address", () => {
163
+ const invalidInput = {
164
+ amount: MOCK_AMOUNT.toString(),
165
+ tokenAddress: "invalid-address",
166
+ spenderAddress: MOCK_SPENDER,
167
+ };
168
+ const result = schemas_1.ApproveSchema.safeParse(invalidInput);
169
+ expect(result.success).toBe(false);
170
+ });
171
+ it("should fail parsing invalid spender address", () => {
172
+ const invalidInput = {
173
+ amount: MOCK_AMOUNT.toString(),
174
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
175
+ spenderAddress: "invalid-address",
176
+ };
177
+ const result = schemas_1.ApproveSchema.safeParse(invalidInput);
178
+ expect(result.success).toBe(false);
179
+ });
180
+ });
181
+ describe("Allowance Schema", () => {
182
+ it("should successfully parse valid input", () => {
183
+ const validInput = {
184
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
185
+ spenderAddress: MOCK_SPENDER,
186
+ };
187
+ const result = schemas_1.AllowanceSchema.safeParse(validInput);
188
+ expect(result.success).toBe(true);
189
+ expect(result.data).toEqual(validInput);
190
+ });
191
+ it("should fail parsing empty input", () => {
192
+ const emptyInput = {};
193
+ const result = schemas_1.AllowanceSchema.safeParse(emptyInput);
194
+ expect(result.success).toBe(false);
195
+ });
196
+ it("should fail parsing invalid token address", () => {
197
+ const invalidInput = {
198
+ tokenAddress: "invalid-address",
199
+ spenderAddress: MOCK_SPENDER,
200
+ };
201
+ const result = schemas_1.AllowanceSchema.safeParse(invalidInput);
202
+ expect(result.success).toBe(false);
203
+ });
204
+ it("should fail parsing invalid spender address", () => {
205
+ const invalidInput = {
206
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
207
+ spenderAddress: "invalid-address",
208
+ };
209
+ const result = schemas_1.AllowanceSchema.safeParse(invalidInput);
210
+ expect(result.success).toBe(false);
211
+ });
212
+ });
213
+ describe("Approve Action", () => {
214
+ const TRANSACTION_HASH = "0xapprove123456789";
215
+ let mockWallet;
216
+ let mockMulticall;
217
+ const actionProvider = (0, erc20ActionProvider_1.erc20ActionProvider)();
218
+ beforeEach(async () => {
219
+ mockMulticall = jest.fn();
220
+ const mockPublicClient = {
221
+ multicall: mockMulticall,
222
+ getCode: jest.fn().mockResolvedValue("0x"),
223
+ };
224
+ mockWallet = {
225
+ sendTransaction: jest.fn(),
226
+ waitForTransactionReceipt: jest.fn(),
227
+ getName: jest.fn().mockReturnValue("evm_wallet_provider"),
228
+ getNetwork: jest.fn().mockReturnValue({
229
+ networkId: "base-mainnet",
230
+ }),
231
+ getPublicClient: jest.fn().mockReturnValue(mockPublicClient),
232
+ getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
233
+ };
234
+ mockWallet.sendTransaction.mockResolvedValue(TRANSACTION_HASH);
235
+ mockWallet.waitForTransactionReceipt.mockResolvedValue({});
236
+ });
237
+ it("should successfully approve tokens", async () => {
238
+ mockMulticall.mockResolvedValueOnce([
239
+ { result: "MockToken" }, // name
240
+ { result: MOCK_DECIMALS }, // decimals
241
+ { result: BigInt(100000 * 10 ** MOCK_DECIMALS) }, // balance
242
+ ]);
243
+ const args = {
244
+ amount: MOCK_AMOUNT.toString(),
245
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
246
+ spenderAddress: MOCK_SPENDER,
247
+ };
248
+ const response = await actionProvider.approve(mockWallet, args);
249
+ expect(mockMulticall).toHaveBeenCalled();
250
+ expect(mockWallet.sendTransaction).toHaveBeenCalled();
251
+ expect(mockWallet.waitForTransactionReceipt).toHaveBeenCalledWith(TRANSACTION_HASH);
252
+ expect(response).toContain(`Approved ${MOCK_AMOUNT} MockToken (${MOCK_CONTRACT_ADDRESS}) for spender ${MOCK_SPENDER}`);
253
+ expect(response).toContain(`Transaction hash: ${TRANSACTION_HASH}`);
254
+ });
255
+ it("should fail with an error when token details cannot be fetched", async () => {
256
+ mockMulticall.mockRejectedValue(new Error("Failed to get token details"));
257
+ const args = {
258
+ amount: MOCK_AMOUNT.toString(),
259
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
260
+ spenderAddress: MOCK_SPENDER,
261
+ };
262
+ const response = await actionProvider.approve(mockWallet, args);
263
+ expect(mockMulticall).toHaveBeenCalled();
264
+ expect(response).toContain("Error: Could not fetch token details");
265
+ });
266
+ it("should fail with an error when transaction fails", async () => {
267
+ mockMulticall.mockResolvedValueOnce([
268
+ { result: "MockToken" }, // name
269
+ { result: MOCK_DECIMALS }, // decimals
270
+ { result: BigInt(100000 * 10 ** MOCK_DECIMALS) }, // balance
271
+ ]);
272
+ mockWallet.sendTransaction.mockRejectedValue(new Error("Transaction failed"));
273
+ const args = {
274
+ amount: MOCK_AMOUNT.toString(),
275
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
276
+ spenderAddress: MOCK_SPENDER,
277
+ };
278
+ const response = await actionProvider.approve(mockWallet, args);
279
+ expect(response).toContain("Error approving tokens: Error: Transaction failed");
280
+ });
281
+ });
282
+ describe("Get Allowance Action", () => {
283
+ let mockWallet;
284
+ let mockMulticall;
285
+ let mockReadContract;
286
+ const actionProvider = (0, erc20ActionProvider_1.erc20ActionProvider)();
287
+ beforeEach(async () => {
288
+ mockMulticall = jest.fn();
289
+ mockReadContract = jest.fn();
290
+ const mockPublicClient = {
291
+ multicall: mockMulticall,
292
+ getCode: jest.fn().mockResolvedValue("0x"),
293
+ };
294
+ mockWallet = {
295
+ readContract: mockReadContract,
296
+ getName: jest.fn().mockReturnValue("evm_wallet_provider"),
297
+ getNetwork: jest.fn().mockReturnValue({
298
+ networkId: "base-mainnet",
299
+ }),
300
+ getPublicClient: jest.fn().mockReturnValue(mockPublicClient),
301
+ getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
302
+ };
303
+ });
304
+ it("should successfully get allowance", async () => {
305
+ const allowanceAmount = BigInt(MOCK_AMOUNT * 10 ** MOCK_DECIMALS);
306
+ mockMulticall.mockResolvedValueOnce([
307
+ { result: "MockToken" }, // name
308
+ { result: MOCK_DECIMALS }, // decimals
309
+ { result: BigInt(100000 * 10 ** MOCK_DECIMALS) }, // balance
310
+ ]);
311
+ mockReadContract.mockResolvedValue(allowanceAmount);
312
+ const args = {
313
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
314
+ spenderAddress: MOCK_SPENDER,
315
+ };
316
+ const response = await actionProvider.getAllowance(mockWallet, args);
317
+ expect(mockMulticall).toHaveBeenCalled();
318
+ expect(mockReadContract).toHaveBeenCalled();
319
+ expect(response).toContain(`Allowance for ${MOCK_SPENDER} to spend MockToken (${MOCK_CONTRACT_ADDRESS}) is ${MOCK_AMOUNT}`);
320
+ });
321
+ it("should fail with an error when token details cannot be fetched", async () => {
322
+ mockMulticall.mockRejectedValue(new Error("Failed to get token details"));
323
+ const args = {
324
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
325
+ spenderAddress: MOCK_SPENDER,
326
+ };
327
+ const response = await actionProvider.getAllowance(mockWallet, args);
328
+ expect(mockMulticall).toHaveBeenCalled();
329
+ expect(response).toContain("Error: Could not fetch token details");
330
+ });
331
+ it("should fail with an error when allowance read fails", async () => {
332
+ mockMulticall.mockResolvedValueOnce([
333
+ { result: "MockToken" }, // name
334
+ { result: MOCK_DECIMALS }, // decimals
335
+ { result: BigInt(100000 * 10 ** MOCK_DECIMALS) }, // balance
336
+ ]);
337
+ mockReadContract.mockRejectedValue(new Error("Allowance read failed"));
338
+ const args = {
339
+ tokenAddress: MOCK_CONTRACT_ADDRESS,
340
+ spenderAddress: MOCK_SPENDER,
341
+ };
342
+ const response = await actionProvider.getAllowance(mockWallet, args);
343
+ expect(response).toContain("Error checking allowance: Error: Allowance read failed");
344
+ });
345
+ });
145
346
  describe("Get Token Address Action", () => {
146
347
  let mockWallet;
147
348
  const actionProvider = (0, erc20ActionProvider_1.erc20ActionProvider)();
@@ -28,6 +28,35 @@ export declare const GetBalanceSchema: z.ZodObject<{
28
28
  tokenAddress: string;
29
29
  address?: string | undefined;
30
30
  }>;
31
+ /**
32
+ * Input schema for approve action.
33
+ */
34
+ export declare const ApproveSchema: z.ZodObject<{
35
+ amount: z.ZodString;
36
+ tokenAddress: z.ZodString;
37
+ spenderAddress: z.ZodString;
38
+ }, "strip", z.ZodTypeAny, {
39
+ amount: string;
40
+ tokenAddress: string;
41
+ spenderAddress: string;
42
+ }, {
43
+ amount: string;
44
+ tokenAddress: string;
45
+ spenderAddress: string;
46
+ }>;
47
+ /**
48
+ * Input schema for allowance action.
49
+ */
50
+ export declare const AllowanceSchema: z.ZodObject<{
51
+ tokenAddress: z.ZodString;
52
+ spenderAddress: z.ZodString;
53
+ }, "strip", z.ZodTypeAny, {
54
+ tokenAddress: string;
55
+ spenderAddress: string;
56
+ }, {
57
+ tokenAddress: string;
58
+ spenderAddress: string;
59
+ }>;
31
60
  /**
32
61
  * Input schema for get token address action.
33
62
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GetTokenAddressSchema = exports.GetBalanceSchema = exports.TransferSchema = void 0;
3
+ exports.GetTokenAddressSchema = exports.AllowanceSchema = exports.ApproveSchema = exports.GetBalanceSchema = exports.TransferSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  /**
6
6
  * Input schema for transfer action.
@@ -38,6 +38,39 @@ exports.GetBalanceSchema = zod_1.z
38
38
  })
39
39
  .strip()
40
40
  .describe("Instructions for getting wallet balance");
41
+ /**
42
+ * Input schema for approve action.
43
+ */
44
+ exports.ApproveSchema = zod_1.z
45
+ .object({
46
+ amount: zod_1.z.string().describe("The amount to approve in whole units (e.g. 100 for 100 USDC)"),
47
+ tokenAddress: zod_1.z
48
+ .string()
49
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
50
+ .describe("The contract address of the token"),
51
+ spenderAddress: zod_1.z
52
+ .string()
53
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
54
+ .describe("The address to approve for spending tokens"),
55
+ })
56
+ .strip()
57
+ .describe("Instructions for approving token spending");
58
+ /**
59
+ * Input schema for allowance action.
60
+ */
61
+ exports.AllowanceSchema = zod_1.z
62
+ .object({
63
+ tokenAddress: zod_1.z
64
+ .string()
65
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
66
+ .describe("The contract address of the token"),
67
+ spenderAddress: zod_1.z
68
+ .string()
69
+ .regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
70
+ .describe("The address to check allowance for"),
71
+ })
72
+ .strip()
73
+ .describe("Instructions for checking token allowance");
41
74
  /**
42
75
  * Input schema for get token address action.
43
76
  */
@@ -0,0 +1,25 @@
1
+ import { Address, Hex, TransactionReceipt } from "viem";
2
+ import { EvmWalletProvider } from "../../wallet-providers";
3
+ /**
4
+ * Gets the memecoin address from the transaction receipt
5
+ *
6
+ * @param receipt - The transaction receipt
7
+ * @param chainId - The chain id
8
+ * @returns The memecoin address
9
+ */
10
+ export declare function getMemecoinAddressFromReceipt(receipt: TransactionReceipt, chainId: string): Address;
11
+ /**
12
+ * Calculates the ETH required to flaunch a token, takes into account the ETH for premine and the flaunching fee
13
+ *
14
+ * @param walletProvider - The EVM wallet provider
15
+ * @param params - The flaunch parameters
16
+ * @param params.premineAmount - The amount to premine
17
+ * @param params.initialPriceParams - The initial price parameters
18
+ * @param params.slippagePercent - The slippage percentage (optional, defaults to 5%)
19
+ * @returns Promise that resolves to the ETH amount required
20
+ */
21
+ export declare function ethRequiredToFlaunch(walletProvider: EvmWalletProvider, params: {
22
+ premineAmount: bigint;
23
+ initialPriceParams: Hex;
24
+ slippagePercent?: number;
25
+ }): Promise<bigint>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMemecoinAddressFromReceipt = getMemecoinAddressFromReceipt;
4
+ exports.ethRequiredToFlaunch = ethRequiredToFlaunch;
5
+ const viem_1 = require("viem");
6
+ const constants_1 = require("./constants");
7
+ /**
8
+ * Gets the memecoin address from the transaction receipt
9
+ *
10
+ * @param receipt - The transaction receipt
11
+ * @param chainId - The chain id
12
+ * @returns The memecoin address
13
+ */
14
+ function getMemecoinAddressFromReceipt(receipt, chainId) {
15
+ const filteredPoolCreatedEvent = receipt.logs
16
+ .map(log => {
17
+ try {
18
+ if (log.address.toLowerCase() !== constants_1.FlaunchPositionManagerV1_1Address[chainId].toLowerCase()) {
19
+ return null;
20
+ }
21
+ const event = (0, viem_1.decodeEventLog)({
22
+ abi: constants_1.POSITION_MANAGERV1_1_ABI,
23
+ data: log.data,
24
+ topics: log.topics,
25
+ });
26
+ return event.eventName === "PoolCreated" ? event.args : null;
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ })
32
+ .filter((event) => event !== null)[0];
33
+ if (!filteredPoolCreatedEvent) {
34
+ throw new Error("Could not find PoolCreated event in transaction receipt");
35
+ }
36
+ return filteredPoolCreatedEvent._memecoin;
37
+ }
38
+ /**
39
+ * Calculates the ETH required to flaunch a token, takes into account the ETH for premine and the flaunching fee
40
+ *
41
+ * @param walletProvider - The EVM wallet provider
42
+ * @param params - The flaunch parameters
43
+ * @param params.premineAmount - The amount to premine
44
+ * @param params.initialPriceParams - The initial price parameters
45
+ * @param params.slippagePercent - The slippage percentage (optional, defaults to 5%)
46
+ * @returns Promise that resolves to the ETH amount required
47
+ */
48
+ function ethRequiredToFlaunch(walletProvider, params) {
49
+ const chainId = walletProvider.getNetwork().chainId;
50
+ if (!chainId)
51
+ throw new Error("Chain ID is not set.");
52
+ return walletProvider.readContract({
53
+ address: constants_1.FlaunchZapAddress[chainId],
54
+ abi: constants_1.FLAUNCH_ZAP_ABI,
55
+ functionName: "calculateFee",
56
+ args: [
57
+ params.premineAmount ?? 0n,
58
+ BigInt(params.slippagePercent ?? 5 * 100),
59
+ params.initialPriceParams,
60
+ ],
61
+ });
62
+ }
@@ -1,34 +1,52 @@
1
1
  import { Addresses } from "./types";
2
2
  import { erc20Abi as ERC20_ABI } from "viem";
3
3
  export { ERC20_ABI };
4
+ export declare const TOTAL_SUPPLY: bigint;
4
5
  export declare const FastFlaunchZapAddress: Addresses;
5
- export declare const FlaunchPositionManagerAddress: Addresses;
6
+ export declare const FlaunchZapAddress: Addresses;
7
+ export declare const RevenueManagerAddress: Addresses;
8
+ export declare const AddressFeeSplitManagerAddress: Addresses;
9
+ export declare const FlaunchPositionManagerV1_1Address: Addresses;
6
10
  export declare const FLETHAddress: Addresses;
7
11
  export declare const FLETHHooksAddress: Addresses;
8
12
  export declare const QuoterAddress: Addresses;
9
13
  export declare const UniversalRouterAddress: Addresses;
10
14
  export declare const Permit2Address: Addresses;
11
- export declare const FAST_FLAUNCH_ZAP_ABI: {
12
- type: string;
13
- name: string;
15
+ export declare const FLAUNCH_ZAP_ABI: ({
14
16
  inputs: {
17
+ internalType: string;
15
18
  name: string;
16
19
  type: string;
20
+ }[];
21
+ name: string;
22
+ outputs: {
17
23
  internalType: string;
24
+ name: string;
25
+ type: string;
26
+ }[];
27
+ stateMutability: string;
28
+ type: string;
29
+ } | {
30
+ inputs: {
18
31
  components: {
32
+ internalType: string;
19
33
  name: string;
20
34
  type: string;
21
- internalType: string;
22
35
  }[];
36
+ internalType: string;
37
+ name: string;
38
+ type: string;
23
39
  }[];
40
+ name: string;
24
41
  outputs: {
42
+ internalType: string;
25
43
  name: string;
26
44
  type: string;
27
- internalType: string;
28
45
  }[];
29
46
  stateMutability: string;
30
- }[];
31
- export declare const POSITION_MANAGER_ABI: readonly [{
47
+ type: string;
48
+ })[];
49
+ export declare const POSITION_MANAGERV1_1_ABI: readonly [{
32
50
  readonly name: "PoolCreated";
33
51
  readonly type: "event";
34
52
  readonly inputs: readonly [{
@@ -64,6 +82,9 @@ export declare const POSITION_MANAGER_ABI: readonly [{
64
82
  }, {
65
83
  readonly type: "uint256";
66
84
  readonly name: "initialTokenFairLaunch";
85
+ }, {
86
+ readonly type: "uint256";
87
+ readonly name: "fairLaunchDuration";
67
88
  }, {
68
89
  readonly type: "uint256";
69
90
  readonly name: "premineAmount";
@@ -93,41 +114,41 @@ export declare const POSITION_MANAGER_ABI: readonly [{
93
114
  readonly name: "poolId";
94
115
  readonly indexed: true;
95
116
  }, {
96
- readonly name: "flAmount0";
97
117
  readonly type: "int256";
118
+ readonly name: "flAmount0";
98
119
  }, {
99
- readonly name: "flAmount1";
100
120
  readonly type: "int256";
121
+ readonly name: "flAmount1";
101
122
  }, {
102
- readonly name: "flFee0";
103
123
  readonly type: "int256";
124
+ readonly name: "flFee0";
104
125
  }, {
105
- readonly name: "flFee1";
106
126
  readonly type: "int256";
127
+ readonly name: "flFee1";
107
128
  }, {
108
- readonly name: "ispAmount0";
109
129
  readonly type: "int256";
130
+ readonly name: "ispAmount0";
110
131
  }, {
111
- readonly name: "ispAmount1";
112
132
  readonly type: "int256";
133
+ readonly name: "ispAmount1";
113
134
  }, {
114
- readonly name: "ispFee0";
115
135
  readonly type: "int256";
136
+ readonly name: "ispFee0";
116
137
  }, {
117
- readonly name: "ispFee1";
118
138
  readonly type: "int256";
139
+ readonly name: "ispFee1";
119
140
  }, {
120
- readonly name: "uniAmount0";
121
141
  readonly type: "int256";
142
+ readonly name: "uniAmount0";
122
143
  }, {
123
- readonly name: "uniAmount1";
124
144
  readonly type: "int256";
145
+ readonly name: "uniAmount1";
125
146
  }, {
126
- readonly name: "uniFee0";
127
147
  readonly type: "int256";
148
+ readonly name: "uniFee0";
128
149
  }, {
129
- readonly name: "uniFee1";
130
150
  readonly type: "int256";
151
+ readonly name: "uniFee1";
131
152
  }];
132
153
  }];
133
154
  export declare const QUOTER_ABI: readonly [{