@coinbase/agentkit 0.5.0 → 0.6.1

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 (42) hide show
  1. package/README.md +30 -0
  2. package/dist/action-providers/flaunch/constants.d.ts +1078 -0
  3. package/dist/action-providers/flaunch/constants.js +709 -0
  4. package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +102 -0
  5. package/dist/action-providers/flaunch/flaunchActionProvider.js +519 -0
  6. package/dist/action-providers/flaunch/flaunchActionProvider.test.d.ts +1 -0
  7. package/dist/action-providers/flaunch/flaunchActionProvider.test.js +307 -0
  8. package/dist/action-providers/flaunch/index.d.ts +7 -0
  9. package/dist/action-providers/flaunch/index.js +23 -0
  10. package/dist/action-providers/flaunch/schemas.d.ts +77 -0
  11. package/dist/action-providers/flaunch/schemas.js +71 -0
  12. package/dist/action-providers/flaunch/types.d.ts +64 -0
  13. package/dist/action-providers/flaunch/types.js +2 -0
  14. package/dist/action-providers/flaunch/utils.d.ts +60 -0
  15. package/dist/action-providers/flaunch/utils.js +507 -0
  16. package/dist/action-providers/index.d.ts +2 -0
  17. package/dist/action-providers/index.js +2 -0
  18. package/dist/action-providers/onramp/index.d.ts +7 -0
  19. package/dist/action-providers/onramp/index.js +23 -0
  20. package/dist/action-providers/onramp/onrampActionProvider.d.ts +56 -0
  21. package/dist/action-providers/onramp/onrampActionProvider.js +109 -0
  22. package/dist/action-providers/onramp/onrampActionProvider.test.d.ts +1 -0
  23. package/dist/action-providers/onramp/onrampActionProvider.test.js +97 -0
  24. package/dist/action-providers/onramp/schemas.d.ts +12 -0
  25. package/dist/action-providers/onramp/schemas.js +15 -0
  26. package/dist/action-providers/onramp/types.d.ts +107 -0
  27. package/dist/action-providers/onramp/types.js +2 -0
  28. package/dist/action-providers/onramp/utils.d.ts +16 -0
  29. package/dist/action-providers/onramp/utils.js +56 -0
  30. package/dist/action-providers/onramp/version.d.ts +2 -0
  31. package/dist/action-providers/onramp/version.js +5 -0
  32. package/dist/wallet-providers/cdpWalletProvider.js +20 -10
  33. package/dist/wallet-providers/cdpWalletProvider.test.js +37 -3
  34. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +2 -0
  35. package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -0
  36. package/dist/wallet-providers/privyShared.d.ts +3 -5
  37. package/dist/wallet-providers/privySvmWalletProvider.d.ts +2 -0
  38. package/dist/wallet-providers/privySvmWalletProvider.js +4 -1
  39. package/dist/wallet-providers/privySvmWalletProvider.test.js +1 -0
  40. package/dist/wallet-providers/privyWalletProvider.d.ts +6 -5
  41. package/dist/wallet-providers/privyWalletProvider.test.js +30 -0
  42. package/package.json +4 -2
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Flaunch Action Provider
3
+ *
4
+ * This file contains the implementation of the FlaunchActionProvider,
5
+ * which provides actions for flaunch operations.
6
+ *
7
+ * @module flaunch
8
+ */
9
+ import { z } from "zod";
10
+ import { ActionProvider } from "../actionProvider";
11
+ import { Network } from "../../network";
12
+ import { EvmWalletProvider } from "../../wallet-providers";
13
+ import { FlaunchSchema, BuyCoinWithETHInputSchema, BuyCoinWithCoinInputSchema, SellCoinSchema } from "./schemas";
14
+ /**
15
+ * Configuration options for the FarcasterActionProvider.
16
+ */
17
+ export interface FlaunchActionProviderConfig {
18
+ /**
19
+ * Pinata JWT.
20
+ */
21
+ pinataJwt?: string;
22
+ }
23
+ /**
24
+ * FlaunchActionProvider provides actions for flaunch operations.
25
+ *
26
+ * @description
27
+ * This provider is designed to work with EvmWalletProvider for blockchain interactions.
28
+ * It supports all evm networks.
29
+ */
30
+ export declare class FlaunchActionProvider extends ActionProvider<EvmWalletProvider> {
31
+ private readonly pinataJwt;
32
+ /**
33
+ * Constructor for the FlaunchActionProvider.
34
+ *
35
+ * @param config - The configuration options for the FlaunchActionProvider.
36
+ */
37
+ constructor(config?: FlaunchActionProviderConfig);
38
+ /**
39
+ * Example action implementation.
40
+ * Replace or modify this with your actual action.
41
+ *
42
+ * @description
43
+ * This is a template action that demonstrates the basic structure.
44
+ * Replace it with your actual implementation.
45
+ *
46
+ * @param walletProvider - The wallet provider instance for blockchain interactions
47
+ * @param args - Arguments defined by FlaunchSchema
48
+ * @returns A promise that resolves to a string describing the action result
49
+ */
50
+ flaunch(walletProvider: EvmWalletProvider, args: z.infer<typeof FlaunchSchema>): Promise<string>;
51
+ /**
52
+ * Buys a flaunch coin using ETH input.
53
+ *
54
+ * @param walletProvider - The wallet provider instance for blockchain interactions
55
+ * @param args - Arguments defined by BuyCoinSchema
56
+ * @returns A promise that resolves to a string describing the transaction result
57
+ */
58
+ buyCoinWithETHInput(walletProvider: EvmWalletProvider, args: z.infer<typeof BuyCoinWithETHInputSchema>): Promise<string>;
59
+ /**
60
+ * Buys a flaunch coin using Coin input.
61
+ *
62
+ * @param walletProvider - The wallet provider instance for blockchain interactions
63
+ * @param args - Arguments defined by BuyCoinSchema
64
+ * @returns A promise that resolves to a string describing the transaction result
65
+ */
66
+ buyCoinWithCoinInput(walletProvider: EvmWalletProvider, args: z.infer<typeof BuyCoinWithCoinInputSchema>): Promise<string>;
67
+ /**
68
+ * Sells a flaunch coin into ETH.
69
+ *
70
+ * @param walletProvider - The wallet provider instance for blockchain interactions
71
+ * @param args - Arguments defined by SellCoinSchema
72
+ * @returns A promise that resolves to a string describing the transaction result
73
+ */
74
+ sellCoin(walletProvider: EvmWalletProvider, args: z.infer<typeof SellCoinSchema>): Promise<string>;
75
+ /**
76
+ * Checks if this provider supports the given network.
77
+ *
78
+ * @param network - The network to check support for
79
+ * @returns True if the network is supported
80
+ */
81
+ supportsNetwork(network: Network): boolean;
82
+ /**
83
+ * Handles the process of buying a flaunch coin with ETH.
84
+ *
85
+ * @param walletProvider - The wallet provider instance
86
+ * @param coinAddress - The address of the flaunch coin
87
+ * @param swapType - The type of swap (EXACT_IN or EXACT_OUT)
88
+ * @param swapParams - Parameters specific to the swap type
89
+ * @param swapParams.amountIn - The amount of ETH to spend (for EXACT_IN)
90
+ * @param swapParams.amountOut - The amount of coins to buy (for EXACT_OUT)
91
+ * @param slippagePercent - The slippage percentage
92
+ * @returns A promise that resolves to a string describing the transaction result
93
+ */
94
+ private _buyFlaunchCoin;
95
+ }
96
+ /**
97
+ * Factory function to create a new FlaunchActionProvider instance.
98
+ *
99
+ * @param config - Configuration options for the FlaunchActionProvider
100
+ * @returns A new FlaunchActionProvider instance
101
+ */
102
+ export declare const flaunchActionProvider: (config?: FlaunchActionProviderConfig) => FlaunchActionProvider;
@@ -0,0 +1,519 @@
1
+ "use strict";
2
+ /**
3
+ * Flaunch Action Provider
4
+ *
5
+ * This file contains the implementation of the FlaunchActionProvider,
6
+ * which provides actions for flaunch operations.
7
+ *
8
+ * @module flaunch
9
+ */
10
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
11
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
12
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
13
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
14
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
15
+ };
16
+ var __metadata = (this && this.__metadata) || function (k, v) {
17
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.flaunchActionProvider = exports.FlaunchActionProvider = void 0;
21
+ const zod_1 = require("zod");
22
+ const actionProvider_1 = require("../actionProvider");
23
+ const network_1 = require("../../network");
24
+ const actionDecorator_1 = require("../actionDecorator");
25
+ const wallet_providers_1 = require("../../wallet-providers");
26
+ const viem_1 = require("viem");
27
+ const chains_1 = require("viem/chains");
28
+ const schemas_1 = require("./schemas");
29
+ const utils_1 = require("./utils");
30
+ const constants_1 = require("./constants");
31
+ const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
32
+ /**
33
+ * FlaunchActionProvider provides actions for flaunch operations.
34
+ *
35
+ * @description
36
+ * This provider is designed to work with EvmWalletProvider for blockchain interactions.
37
+ * It supports all evm networks.
38
+ */
39
+ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
40
+ /**
41
+ * Constructor for the FlaunchActionProvider.
42
+ *
43
+ * @param config - The configuration options for the FlaunchActionProvider.
44
+ */
45
+ constructor(config = {}) {
46
+ super("flaunch", []);
47
+ const pinataJwt = config.pinataJwt || process.env.PINATA_JWT;
48
+ if (!pinataJwt) {
49
+ throw new Error("PINATA_JWT is not configured.");
50
+ }
51
+ this.pinataJwt = pinataJwt;
52
+ }
53
+ /**
54
+ * Example action implementation.
55
+ * Replace or modify this with your actual action.
56
+ *
57
+ * @description
58
+ * This is a template action that demonstrates the basic structure.
59
+ * Replace it with your actual implementation.
60
+ *
61
+ * @param walletProvider - The wallet provider instance for blockchain interactions
62
+ * @param args - Arguments defined by FlaunchSchema
63
+ * @returns A promise that resolves to a string describing the action result
64
+ */
65
+ async flaunch(walletProvider, args) {
66
+ try {
67
+ const network = walletProvider.getNetwork();
68
+ const networkId = network.networkId;
69
+ const chainId = network.chainId;
70
+ if (!chainId || !networkId) {
71
+ throw new Error("Chain ID is not set.");
72
+ }
73
+ // upload image & token uri to ipfs
74
+ const tokenUri = await (0, utils_1.generateTokenUri)(args.name, {
75
+ pinataConfig: { jwt: this.pinataJwt },
76
+ metadata: {
77
+ imageUrl: args.imageUrl,
78
+ description: args.description,
79
+ websiteUrl: args.websiteUrl,
80
+ discordUrl: args.discordUrl,
81
+ twitterUrl: args.twitterUrl,
82
+ telegramUrl: args.telegramUrl,
83
+ },
84
+ });
85
+ const data = (0, viem_1.encodeFunctionData)({
86
+ abi: constants_1.FAST_FLAUNCH_ZAP_ABI,
87
+ functionName: "flaunch",
88
+ args: [
89
+ {
90
+ name: args.name,
91
+ symbol: args.symbol,
92
+ tokenUri,
93
+ creator: walletProvider.getAddress(),
94
+ },
95
+ ],
96
+ });
97
+ const hash = await walletProvider.sendTransaction({
98
+ to: constants_1.FastFlaunchZapAddress[chainId],
99
+ data,
100
+ });
101
+ const receipt = await walletProvider.waitForTransactionReceipt(hash);
102
+ const filteredPoolCreatedEvent = receipt.logs
103
+ .map(log => {
104
+ try {
105
+ if (log.address.toLowerCase() !== constants_1.FlaunchPositionManagerAddress[chainId].toLowerCase()) {
106
+ return null;
107
+ }
108
+ const event = (0, viem_1.decodeEventLog)({
109
+ abi: constants_1.POSITION_MANAGER_ABI,
110
+ data: log.data,
111
+ topics: log.topics,
112
+ });
113
+ return event.eventName === "PoolCreated" ? event.args : null;
114
+ }
115
+ catch {
116
+ return null;
117
+ }
118
+ })
119
+ .filter((event) => event !== null)[0];
120
+ const memecoinAddress = filteredPoolCreatedEvent._memecoin;
121
+ const chainSlug = Number(chainId) === chains_1.base.id ? "base" : "base-sepolia";
122
+ return `Flaunched\n ${JSON.stringify({
123
+ coinSymbol: `$${args.symbol}`,
124
+ coinName: args.name,
125
+ coinAddress: memecoinAddress,
126
+ flaunchCoinUrl: `https://flaunch.gg/${chainSlug}/coin/${memecoinAddress}`,
127
+ transactionHash: hash,
128
+ transactionUrl: `${network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId].blockExplorers?.default.url}/tx/${hash}`,
129
+ })}`;
130
+ }
131
+ catch (error) {
132
+ return `Error launching coin: ${error}`;
133
+ }
134
+ }
135
+ /**
136
+ * Buys a flaunch coin using ETH input.
137
+ *
138
+ * @param walletProvider - The wallet provider instance for blockchain interactions
139
+ * @param args - Arguments defined by BuyCoinSchema
140
+ * @returns A promise that resolves to a string describing the transaction result
141
+ */
142
+ async buyCoinWithETHInput(walletProvider, args) {
143
+ return this._buyFlaunchCoin(walletProvider, args.coinAddress, "EXACT_IN", { amountIn: args.amountIn }, args.slippagePercent);
144
+ }
145
+ /**
146
+ * Buys a flaunch coin using Coin input.
147
+ *
148
+ * @param walletProvider - The wallet provider instance for blockchain interactions
149
+ * @param args - Arguments defined by BuyCoinSchema
150
+ * @returns A promise that resolves to a string describing the transaction result
151
+ */
152
+ async buyCoinWithCoinInput(walletProvider, args) {
153
+ return this._buyFlaunchCoin(walletProvider, args.coinAddress, "EXACT_OUT", { amountOut: args.amountOut }, args.slippagePercent);
154
+ }
155
+ /**
156
+ * Sells a flaunch coin into ETH.
157
+ *
158
+ * @param walletProvider - The wallet provider instance for blockchain interactions
159
+ * @param args - Arguments defined by SellCoinSchema
160
+ * @returns A promise that resolves to a string describing the transaction result
161
+ */
162
+ async sellCoin(walletProvider, args) {
163
+ const network = walletProvider.getNetwork();
164
+ const chainId = network.chainId;
165
+ const networkId = network.networkId;
166
+ if (!chainId || !networkId) {
167
+ throw new Error("Chain ID is not set.");
168
+ }
169
+ try {
170
+ const amountIn = (0, viem_1.parseEther)(args.amountIn);
171
+ // fetch permit2 allowance
172
+ const [allowance, nonce] = await walletProvider.readContract({
173
+ address: constants_1.Permit2Address[chainId],
174
+ abi: constants_1.PERMIT2_ABI,
175
+ functionName: "allowance",
176
+ args: [
177
+ walletProvider.getAddress(),
178
+ args.coinAddress,
179
+ constants_1.UniversalRouterAddress[chainId],
180
+ ],
181
+ });
182
+ let signature;
183
+ let permitSingle;
184
+ // approve
185
+ if (allowance < amountIn) {
186
+ // 10 years in seconds
187
+ const defaultDeadline = BigInt(Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365 * 10);
188
+ const domain = {
189
+ name: "Permit2",
190
+ chainId: Number(chainId),
191
+ verifyingContract: constants_1.Permit2Address[chainId],
192
+ };
193
+ const message = {
194
+ details: {
195
+ token: args.coinAddress,
196
+ amount: viem_1.maxUint160,
197
+ expiration: Number(defaultDeadline),
198
+ nonce,
199
+ },
200
+ spender: constants_1.UniversalRouterAddress[chainId],
201
+ sigDeadline: defaultDeadline,
202
+ };
203
+ const typedData = {
204
+ primaryType: "PermitSingle",
205
+ domain,
206
+ types: constants_1.PERMIT_TYPES,
207
+ message,
208
+ };
209
+ signature = await walletProvider.signTypedData(typedData);
210
+ permitSingle = message;
211
+ }
212
+ const viemPublicClient = (0, viem_1.createPublicClient)({
213
+ chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
214
+ transport: (0, viem_1.http)(),
215
+ });
216
+ const quoteResult = await viemPublicClient.simulateContract({
217
+ address: constants_1.QuoterAddress[chainId],
218
+ abi: constants_1.QUOTER_ABI,
219
+ functionName: "quoteExactInput",
220
+ args: [
221
+ {
222
+ exactAmount: amountIn,
223
+ exactCurrency: args.coinAddress,
224
+ path: [
225
+ {
226
+ fee: 0,
227
+ tickSpacing: 60,
228
+ hooks: constants_1.FlaunchPositionManagerAddress[chainId],
229
+ hookData: "0x",
230
+ intermediateCurrency: constants_1.FLETHAddress[chainId],
231
+ },
232
+ {
233
+ fee: 0,
234
+ tickSpacing: 60,
235
+ hookData: "0x",
236
+ hooks: constants_1.FLETHHooksAddress[chainId],
237
+ intermediateCurrency: viem_1.zeroAddress,
238
+ },
239
+ ],
240
+ },
241
+ ],
242
+ });
243
+ const ethOutMin = (0, utils_1.getAmountWithSlippage)(quoteResult.result[0], // amountOut
244
+ (args.slippagePercent / 100).toFixed(18).toString(), "EXACT_IN");
245
+ const { commands, inputs } = (0, utils_1.memecoinToEthWithPermit2)({
246
+ chainId: Number(chainId),
247
+ memecoin: args.coinAddress,
248
+ amountIn,
249
+ ethOutMin,
250
+ permitSingle,
251
+ signature,
252
+ referrer: viem_1.zeroAddress,
253
+ });
254
+ const data = (0, viem_1.encodeFunctionData)({
255
+ abi: constants_1.UNIVERSAL_ROUTER_ABI,
256
+ functionName: "execute",
257
+ args: [commands, inputs],
258
+ });
259
+ const hash = await walletProvider.sendTransaction({
260
+ to: constants_1.UniversalRouterAddress[chainId],
261
+ data,
262
+ });
263
+ const receipt = await walletProvider.waitForTransactionReceipt(hash);
264
+ const swapAmounts = (0, utils_1.getSwapAmountsFromReceipt)({
265
+ receipt,
266
+ coinAddress: args.coinAddress,
267
+ chainId: Number(chainId),
268
+ });
269
+ const coinSymbol = await walletProvider.readContract({
270
+ address: args.coinAddress,
271
+ abi: constants_1.ERC20_ABI,
272
+ functionName: "symbol",
273
+ });
274
+ return `Sold ${(0, viem_1.formatEther)(swapAmounts.coinsSold)} $${coinSymbol} for ${(0, viem_1.formatEther)(swapAmounts.ethBought)} ETH\n
275
+ Tx hash: [${hash}](${network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId].blockExplorers?.default.url}/tx/${hash})`;
276
+ }
277
+ catch (error) {
278
+ return `Error selling coin: ${error}`;
279
+ }
280
+ }
281
+ /**
282
+ * Checks if this provider supports the given network.
283
+ *
284
+ * @param network - The network to check support for
285
+ * @returns True if the network is supported
286
+ */
287
+ supportsNetwork(network) {
288
+ // all protocol networks
289
+ return network.protocolFamily === "evm" && SUPPORTED_NETWORKS.includes(network.networkId);
290
+ }
291
+ /**
292
+ * Handles the process of buying a flaunch coin with ETH.
293
+ *
294
+ * @param walletProvider - The wallet provider instance
295
+ * @param coinAddress - The address of the flaunch coin
296
+ * @param swapType - The type of swap (EXACT_IN or EXACT_OUT)
297
+ * @param swapParams - Parameters specific to the swap type
298
+ * @param swapParams.amountIn - The amount of ETH to spend (for EXACT_IN)
299
+ * @param swapParams.amountOut - The amount of coins to buy (for EXACT_OUT)
300
+ * @param slippagePercent - The slippage percentage
301
+ * @returns A promise that resolves to a string describing the transaction result
302
+ */
303
+ async _buyFlaunchCoin(walletProvider, coinAddress, swapType, swapParams, slippagePercent) {
304
+ const network = walletProvider.getNetwork();
305
+ const chainId = network.chainId;
306
+ const networkId = network.networkId;
307
+ if (!chainId || !networkId) {
308
+ throw new Error("Chain ID is not set.");
309
+ }
310
+ try {
311
+ const viemPublicClient = (0, viem_1.createPublicClient)({
312
+ chain: network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId],
313
+ transport: (0, viem_1.http)(),
314
+ });
315
+ let amountIn;
316
+ let amountOutMin;
317
+ let amountOut;
318
+ let amountInMax;
319
+ if (swapType === "EXACT_IN") {
320
+ amountIn = (0, viem_1.parseEther)(swapParams.amountIn);
321
+ const quoteResult = await viemPublicClient.simulateContract({
322
+ address: constants_1.QuoterAddress[chainId],
323
+ abi: constants_1.QUOTER_ABI,
324
+ functionName: "quoteExactInput",
325
+ args: [
326
+ {
327
+ exactAmount: amountIn,
328
+ exactCurrency: viem_1.zeroAddress, // ETH
329
+ path: [
330
+ {
331
+ fee: 0,
332
+ tickSpacing: 60,
333
+ hookData: "0x",
334
+ hooks: constants_1.FLETHHooksAddress[chainId],
335
+ intermediateCurrency: constants_1.FLETHAddress[chainId],
336
+ },
337
+ {
338
+ fee: 0,
339
+ tickSpacing: 60,
340
+ hooks: constants_1.FlaunchPositionManagerAddress[chainId],
341
+ hookData: "0x",
342
+ intermediateCurrency: coinAddress,
343
+ },
344
+ ],
345
+ },
346
+ ],
347
+ });
348
+ amountOutMin = (0, utils_1.getAmountWithSlippage)(quoteResult.result[0], // amountOut
349
+ (slippagePercent / 100).toFixed(18).toString(), swapType);
350
+ }
351
+ else {
352
+ // EXACT_OUT
353
+ amountOut = (0, viem_1.parseEther)(swapParams.amountOut);
354
+ const quoteResult = await viemPublicClient.simulateContract({
355
+ address: constants_1.QuoterAddress[chainId],
356
+ abi: constants_1.QUOTER_ABI,
357
+ functionName: "quoteExactOutput",
358
+ args: [
359
+ {
360
+ path: [
361
+ {
362
+ intermediateCurrency: viem_1.zeroAddress,
363
+ fee: 0,
364
+ tickSpacing: 60,
365
+ hookData: "0x",
366
+ hooks: constants_1.FLETHHooksAddress[chainId],
367
+ },
368
+ {
369
+ intermediateCurrency: constants_1.FLETHAddress[chainId],
370
+ fee: 0,
371
+ tickSpacing: 60,
372
+ hooks: constants_1.FlaunchPositionManagerAddress[chainId],
373
+ hookData: "0x",
374
+ },
375
+ ],
376
+ exactCurrency: coinAddress,
377
+ exactAmount: amountOut,
378
+ },
379
+ ],
380
+ });
381
+ amountInMax = (0, utils_1.getAmountWithSlippage)(quoteResult.result[0], // amountIn
382
+ (slippagePercent / 100).toFixed(18).toString(), swapType);
383
+ }
384
+ const { commands, inputs } = (0, utils_1.ethToMemecoin)({
385
+ sender: walletProvider.getAddress(),
386
+ memecoin: coinAddress,
387
+ chainId: Number(chainId),
388
+ referrer: viem_1.zeroAddress,
389
+ swapType,
390
+ amountIn,
391
+ amountOutMin,
392
+ amountOut,
393
+ amountInMax,
394
+ });
395
+ const data = (0, viem_1.encodeFunctionData)({
396
+ abi: constants_1.UNIVERSAL_ROUTER_ABI,
397
+ functionName: "execute",
398
+ args: [commands, inputs],
399
+ });
400
+ const hash = await walletProvider.sendTransaction({
401
+ to: constants_1.UniversalRouterAddress[chainId],
402
+ data,
403
+ value: swapType === "EXACT_IN" ? amountIn : amountInMax,
404
+ });
405
+ const receipt = await walletProvider.waitForTransactionReceipt(hash);
406
+ const swapAmounts = (0, utils_1.getSwapAmountsFromReceipt)({
407
+ receipt,
408
+ coinAddress: coinAddress,
409
+ chainId: Number(chainId),
410
+ });
411
+ const coinSymbol = await walletProvider.readContract({
412
+ address: coinAddress,
413
+ abi: constants_1.ERC20_ABI,
414
+ functionName: "symbol",
415
+ });
416
+ return `Bought ${(0, viem_1.formatEther)(swapAmounts.coinsBought)} $${coinSymbol} for ${(0, viem_1.formatEther)(swapAmounts.ethSold)} ETH\n
417
+ Tx hash: [${hash}](${network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId].blockExplorers?.default.url}/tx/${hash})`;
418
+ }
419
+ catch (error) {
420
+ return `Error buying coin: ${error}`;
421
+ }
422
+ }
423
+ }
424
+ exports.FlaunchActionProvider = FlaunchActionProvider;
425
+ __decorate([
426
+ (0, actionDecorator_1.CreateAction)({
427
+ name: "flaunch",
428
+ description: `
429
+ This tool allows launching a new memecoin using the flaunch protocol.
430
+
431
+ It takes:
432
+ - name: The name of the token
433
+ - symbol: The symbol of the token
434
+ - imageUrl: URL to the token image
435
+ - description: Description of the token
436
+
437
+ - websiteUrl: (optional) URL to the token website
438
+ - discordUrl: (optional) URL to the token Discord
439
+ - twitterUrl: (optional) URL to the token Twitter
440
+ - telegramUrl: (optional) URL to the token Telegram
441
+
442
+ Note:
443
+ - If the optional fields are not provided, don't include them in the call.
444
+ `,
445
+ schema: schemas_1.FlaunchSchema,
446
+ }),
447
+ __metadata("design:type", Function),
448
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
449
+ __metadata("design:returntype", Promise)
450
+ ], FlaunchActionProvider.prototype, "flaunch", null);
451
+ __decorate([
452
+ (0, actionDecorator_1.CreateAction)({
453
+ name: "buyCoinWithETHInput",
454
+ description: `
455
+ This tool allows buying a flaunch coin using ETH, when the user has specified the ETH amount to spend.
456
+
457
+ It takes:
458
+ - coinAddress: The address of the flaunch coin to buy
459
+ - amountIn: The quantity of ETH to spend on the flaunch coin, in whole units
460
+ Examples:
461
+ - 0.001 ETH
462
+ - 0.01 ETH
463
+ - 1 ETH
464
+ - slippagePercent: (optional) The slippage percentage. Default to 5%
465
+ `,
466
+ schema: schemas_1.BuyCoinWithETHInputSchema,
467
+ }),
468
+ __metadata("design:type", Function),
469
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
470
+ __metadata("design:returntype", Promise)
471
+ ], FlaunchActionProvider.prototype, "buyCoinWithETHInput", null);
472
+ __decorate([
473
+ (0, actionDecorator_1.CreateAction)({
474
+ name: "buyCoinWithCoinInput",
475
+ description: `
476
+ This tool allows buying a flaunch coin using ETH, when the user has specified the Coin amount to buy.
477
+
478
+ It takes:
479
+ - coinAddress: The address of the flaunch coin to buy
480
+ - amountOut: The quantity of the flaunch coin to buy, in whole units
481
+ Examples:
482
+ - 1000 coins
483
+ - 1_000_000 coins
484
+ - slippagePercent: (optional) The slippage percentage. Default to 5%
485
+ `,
486
+ schema: schemas_1.BuyCoinWithCoinInputSchema,
487
+ }),
488
+ __metadata("design:type", Function),
489
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
490
+ __metadata("design:returntype", Promise)
491
+ ], FlaunchActionProvider.prototype, "buyCoinWithCoinInput", null);
492
+ __decorate([
493
+ (0, actionDecorator_1.CreateAction)({
494
+ name: "sellCoin",
495
+ description: `
496
+ This tool allows selling a flaunch coin into ETH, when the user has specified the Coin amount to sell.
497
+
498
+ It takes:
499
+ - coinAddress: The address of the flaunch coin to sell
500
+ - amountIn: The quantity of the flaunch coin to sell, in whole units
501
+ Examples:
502
+ - 1000 coins
503
+ - 1_000_000 coins
504
+ - slippagePercent: (optional) The slippage percentage. Default to 5%
505
+ `,
506
+ schema: schemas_1.SellCoinSchema,
507
+ }),
508
+ __metadata("design:type", Function),
509
+ __metadata("design:paramtypes", [wallet_providers_1.EvmWalletProvider, void 0]),
510
+ __metadata("design:returntype", Promise)
511
+ ], FlaunchActionProvider.prototype, "sellCoin", null);
512
+ /**
513
+ * Factory function to create a new FlaunchActionProvider instance.
514
+ *
515
+ * @param config - Configuration options for the FlaunchActionProvider
516
+ * @returns A new FlaunchActionProvider instance
517
+ */
518
+ const flaunchActionProvider = (config) => new FlaunchActionProvider(config);
519
+ exports.flaunchActionProvider = flaunchActionProvider;