@coinbase/agentkit 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -40
- package/dist/action-providers/across/schemas.d.ts +1 -1
- package/dist/action-providers/baseAccount/baseAccountActionProvider.d.ts +46 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.js +404 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.d.ts +1 -0
- package/dist/action-providers/baseAccount/baseAccountActionProvider.test.js +325 -0
- package/dist/action-providers/baseAccount/index.d.ts +2 -0
- package/dist/action-providers/baseAccount/index.js +18 -0
- package/dist/action-providers/baseAccount/schemas.d.ts +43 -0
- package/dist/action-providers/baseAccount/schemas.js +62 -0
- package/dist/action-providers/baseAccount/types.d.ts +17 -0
- package/dist/action-providers/baseAccount/types.js +2 -0
- package/dist/action-providers/baseAccount/utils.d.ts +14 -0
- package/dist/action-providers/baseAccount/utils.js +57 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +2 -1
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +3 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +2 -1
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +3 -1
- package/dist/action-providers/cdp/swapUtils.d.ts +0 -9
- package/dist/action-providers/cdp/swapUtils.js +0 -36
- package/dist/action-providers/clanker/schemas.d.ts +2 -2
- package/dist/action-providers/flaunch/client_utils.d.ts +25 -0
- package/dist/action-providers/flaunch/client_utils.js +62 -0
- package/dist/action-providers/flaunch/constants.d.ts +41 -20
- package/dist/action-providers/flaunch/constants.js +111 -36
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +4 -43
- package/dist/action-providers/flaunch/flaunchActionProvider.js +132 -200
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +108 -13
- package/dist/action-providers/flaunch/metadata_utils.d.ts +12 -0
- package/dist/action-providers/flaunch/metadata_utils.js +216 -0
- package/dist/action-providers/flaunch/schemas.d.ts +39 -3
- package/dist/action-providers/flaunch/schemas.js +62 -10
- package/dist/action-providers/flaunch/{utils.d.ts → swap_utils.d.ts} +17 -19
- package/dist/action-providers/flaunch/{utils.js → swap_utils.js} +137 -172
- package/dist/action-providers/index.d.ts +1 -0
- package/dist/action-providers/index.js +1 -0
- package/dist/action-providers/pyth/pythActionProvider.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +83 -31
- package/dist/action-providers/pyth/pythActionProvider.test.js +178 -26
- package/dist/action-providers/pyth/schemas.d.ts +6 -0
- package/dist/action-providers/pyth/schemas.js +9 -1
- package/dist/action-providers/superfluid/superfluidSuperTokenCreatorActionProvider.js +5 -4
- package/dist/action-providers/superfluid/utils/parseLogs.d.ts +2 -1
- package/dist/action-providers/superfluid/utils/parseLogs.js +6 -3
- package/dist/action-providers/wallet/walletActionProvider.js +3 -0
- package/dist/action-providers/x402/schemas.d.ts +7 -0
- package/dist/action-providers/x402/schemas.js +11 -1
- package/dist/action-providers/x402/utils.d.ts +55 -0
- package/dist/action-providers/x402/utils.js +160 -0
- package/dist/action-providers/x402/x402ActionProvider.d.ts +9 -9
- package/dist/action-providers/x402/x402ActionProvider.js +158 -39
- package/dist/action-providers/x402/x402ActionProvider.test.js +116 -10
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +43 -13
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.js +14 -21
- package/dist/wallet-providers/cdpEvmWalletProvider.test.js +7 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -6
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +6 -10
- package/dist/wallet-providers/evmWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/evmWalletProvider.js +4 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +11 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.js +16 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.test.js +6 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +27 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +11 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +8 -1
- package/dist/wallet-providers/viemWalletProvider.js +21 -1
- package/dist/wallet-providers/viemWalletProvider.test.js +21 -1
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/zeroDevWalletProvider.js +12 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +10 -0
- package/package.json +6 -4
|
@@ -1,12 +1,4 @@
|
|
|
1
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
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
11
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -26,7 +18,9 @@ const wallet_providers_1 = require("../../wallet-providers");
|
|
|
26
18
|
const viem_1 = require("viem");
|
|
27
19
|
const chains_1 = require("viem/chains");
|
|
28
20
|
const schemas_1 = require("./schemas");
|
|
29
|
-
const
|
|
21
|
+
const metadata_utils_1 = require("./metadata_utils");
|
|
22
|
+
const client_utils_1 = require("./client_utils");
|
|
23
|
+
const swap_utils_1 = require("./swap_utils");
|
|
30
24
|
const constants_1 = require("./constants");
|
|
31
25
|
const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
|
|
32
26
|
/**
|
|
@@ -34,33 +28,21 @@ const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
|
|
|
34
28
|
*
|
|
35
29
|
* @description
|
|
36
30
|
* This provider is designed to work with EvmWalletProvider for blockchain interactions.
|
|
37
|
-
* It supports all evm networks.
|
|
38
31
|
*/
|
|
39
32
|
class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
40
33
|
/**
|
|
41
34
|
* Constructor for the FlaunchActionProvider.
|
|
42
35
|
*
|
|
43
|
-
* @param config - The configuration options for the FlaunchActionProvider.
|
|
44
36
|
*/
|
|
45
|
-
constructor(
|
|
37
|
+
constructor() {
|
|
46
38
|
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
39
|
}
|
|
53
40
|
/**
|
|
54
|
-
*
|
|
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.
|
|
41
|
+
* Launches a new memecoin using the flaunch protocol.
|
|
60
42
|
*
|
|
61
43
|
* @param walletProvider - The wallet provider instance for blockchain interactions
|
|
62
44
|
* @param args - Arguments defined by FlaunchSchema
|
|
63
|
-
* @returns A promise that resolves to a string describing the
|
|
45
|
+
* @returns A promise that resolves to a string describing the transaction result
|
|
64
46
|
*/
|
|
65
47
|
async flaunch(walletProvider, args) {
|
|
66
48
|
try {
|
|
@@ -70,11 +52,34 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
70
52
|
if (!chainId || !networkId) {
|
|
71
53
|
throw new Error("Chain ID is not set.");
|
|
72
54
|
}
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
// Validate that premineAmount does not exceed fairLaunchPercent
|
|
56
|
+
if (args.preminePercent > args.fairLaunchPercent) {
|
|
57
|
+
throw new Error(`premineAmount (${args.preminePercent}%) cannot exceed fairLaunchPercent (${args.fairLaunchPercent}%)`);
|
|
58
|
+
}
|
|
59
|
+
// Prepare launch parameters
|
|
60
|
+
const initialMCapInUSDCWei = (0, viem_1.parseUnits)(args.initialMarketCapUSD.toString(), 6);
|
|
61
|
+
const initialPriceParams = (0, viem_1.encodeAbiParameters)([{ type: "uint256" }], [initialMCapInUSDCWei]);
|
|
62
|
+
const fairLaunchInBps = BigInt(args.fairLaunchPercent * 100);
|
|
63
|
+
// Convert premine percentage to token amount and calculate ETH required
|
|
64
|
+
const premineAmount = (constants_1.TOTAL_SUPPLY * BigInt(Math.floor(args.preminePercent * 100))) / 10000n;
|
|
65
|
+
const ethRequired = args.preminePercent > 0
|
|
66
|
+
? await (0, client_utils_1.ethRequiredToFlaunch)(walletProvider, {
|
|
67
|
+
premineAmount,
|
|
68
|
+
initialPriceParams,
|
|
69
|
+
slippagePercent: 5,
|
|
70
|
+
})
|
|
71
|
+
: 0n;
|
|
72
|
+
// Check ETH balance
|
|
73
|
+
if (ethRequired > 0n) {
|
|
74
|
+
const ethBalance = await walletProvider.getBalance();
|
|
75
|
+
if (ethBalance < ethRequired) {
|
|
76
|
+
throw new Error(`Insufficient ETH balance. Required: ${(0, viem_1.formatEther)(ethRequired)} ETH, Available: ${(0, viem_1.formatEther)(ethBalance)} ETH`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Upload image & token uri to ipfs
|
|
80
|
+
const tokenUri = await (0, metadata_utils_1.generateTokenUri)(args.name, args.symbol, {
|
|
76
81
|
metadata: {
|
|
77
|
-
|
|
82
|
+
image: args.image,
|
|
78
83
|
description: args.description,
|
|
79
84
|
websiteUrl: args.websiteUrl,
|
|
80
85
|
discordUrl: args.discordUrl,
|
|
@@ -82,42 +87,92 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
82
87
|
telegramUrl: args.telegramUrl,
|
|
83
88
|
},
|
|
84
89
|
});
|
|
90
|
+
// Fee split configuration
|
|
91
|
+
const creatorFeeAllocationInBps = args.creatorFeeAllocationPercent * 100;
|
|
92
|
+
let creatorShare = 10000000n;
|
|
93
|
+
let recipientShares = [];
|
|
94
|
+
if (args.creatorSplitPercent !== undefined && args.splitReceivers !== undefined) {
|
|
95
|
+
const VALID_SHARE_TOTAL = 10000000n; // 5 decimals as BigInt, 100 * 10^5
|
|
96
|
+
creatorShare = (BigInt(args.creatorSplitPercent) * VALID_SHARE_TOTAL) / 100n;
|
|
97
|
+
recipientShares = args.splitReceivers.map(receiver => {
|
|
98
|
+
return {
|
|
99
|
+
recipient: receiver.address,
|
|
100
|
+
share: (BigInt(receiver.percent) * VALID_SHARE_TOTAL) / 100n,
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
const totalRecipientShares = recipientShares.reduce((acc, curr) => acc + curr.share, 0n);
|
|
104
|
+
const totalRecipientPercent = (totalRecipientShares * 100n) / VALID_SHARE_TOTAL;
|
|
105
|
+
// Check that recipient shares add up to 100%
|
|
106
|
+
if (totalRecipientPercent !== 100n) {
|
|
107
|
+
throw new Error(`Recipient shares must add up to exactly 100%, but they add up to ${totalRecipientPercent}%`);
|
|
108
|
+
}
|
|
109
|
+
const remainderShares = VALID_SHARE_TOTAL - totalRecipientShares;
|
|
110
|
+
creatorShare += remainderShares;
|
|
111
|
+
}
|
|
112
|
+
const initializeData = (0, viem_1.encodeAbiParameters)([
|
|
113
|
+
{
|
|
114
|
+
type: "tuple",
|
|
115
|
+
name: "params",
|
|
116
|
+
components: [
|
|
117
|
+
{ type: "uint256", name: "creatorShare" },
|
|
118
|
+
{
|
|
119
|
+
type: "tuple[]",
|
|
120
|
+
name: "recipientShares",
|
|
121
|
+
components: [
|
|
122
|
+
{ type: "address", name: "recipient" },
|
|
123
|
+
{ type: "uint256", name: "share" },
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
], [
|
|
129
|
+
{
|
|
130
|
+
creatorShare,
|
|
131
|
+
recipientShares,
|
|
132
|
+
},
|
|
133
|
+
]);
|
|
134
|
+
const flaunchParams = {
|
|
135
|
+
name: args.name,
|
|
136
|
+
symbol: args.symbol,
|
|
137
|
+
tokenUri,
|
|
138
|
+
initialTokenFairLaunch: (constants_1.TOTAL_SUPPLY * fairLaunchInBps) / 10000n,
|
|
139
|
+
fairLaunchDuration: BigInt(args.fairLaunchDuration * 60),
|
|
140
|
+
premineAmount,
|
|
141
|
+
creator: walletProvider.getAddress(),
|
|
142
|
+
creatorFeeAllocation: creatorFeeAllocationInBps,
|
|
143
|
+
flaunchAt: 0n,
|
|
144
|
+
initialPriceParams,
|
|
145
|
+
feeCalculatorParams: "0x",
|
|
146
|
+
};
|
|
147
|
+
const treasuryManagerParams = {
|
|
148
|
+
manager: constants_1.AddressFeeSplitManagerAddress[chainId],
|
|
149
|
+
initializeData,
|
|
150
|
+
depositData: "0x",
|
|
151
|
+
};
|
|
152
|
+
const whitelistParams = {
|
|
153
|
+
merkleRoot: viem_1.zeroHash,
|
|
154
|
+
merkleIPFSHash: "",
|
|
155
|
+
maxTokens: 0n,
|
|
156
|
+
};
|
|
157
|
+
const airdropParams = {
|
|
158
|
+
airdropIndex: 0n,
|
|
159
|
+
airdropAmount: 0n,
|
|
160
|
+
airdropEndTime: 0n,
|
|
161
|
+
merkleRoot: viem_1.zeroHash,
|
|
162
|
+
merkleIPFSHash: "",
|
|
163
|
+
};
|
|
85
164
|
const data = (0, viem_1.encodeFunctionData)({
|
|
86
|
-
abi: constants_1.
|
|
165
|
+
abi: constants_1.FLAUNCH_ZAP_ABI,
|
|
87
166
|
functionName: "flaunch",
|
|
88
|
-
args: [
|
|
89
|
-
{
|
|
90
|
-
name: args.name,
|
|
91
|
-
symbol: args.symbol,
|
|
92
|
-
tokenUri,
|
|
93
|
-
creator: walletProvider.getAddress(),
|
|
94
|
-
},
|
|
95
|
-
],
|
|
167
|
+
args: [flaunchParams, whitelistParams, airdropParams, treasuryManagerParams],
|
|
96
168
|
});
|
|
97
169
|
const hash = await walletProvider.sendTransaction({
|
|
98
|
-
to: constants_1.
|
|
170
|
+
to: constants_1.FlaunchZapAddress[chainId],
|
|
99
171
|
data,
|
|
172
|
+
value: ethRequired,
|
|
100
173
|
});
|
|
101
174
|
const receipt = await walletProvider.waitForTransactionReceipt(hash);
|
|
102
|
-
const
|
|
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;
|
|
175
|
+
const memecoinAddress = (0, client_utils_1.getMemecoinAddressFromReceipt)(receipt, chainId);
|
|
121
176
|
const chainSlug = Number(chainId) === chains_1.base.id ? "base" : "base-sepolia";
|
|
122
177
|
return `Flaunched\n ${JSON.stringify({
|
|
123
178
|
coinSymbol: `$${args.symbol}`,
|
|
@@ -140,7 +195,7 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
140
195
|
* @returns A promise that resolves to a string describing the transaction result
|
|
141
196
|
*/
|
|
142
197
|
async buyCoinWithETHInput(walletProvider, args) {
|
|
143
|
-
return
|
|
198
|
+
return (0, swap_utils_1.buyFlaunchCoin)(walletProvider, args.coinAddress, "EXACT_IN", { amountIn: args.amountIn }, args.slippagePercent);
|
|
144
199
|
}
|
|
145
200
|
/**
|
|
146
201
|
* Buys a flaunch coin using Coin input.
|
|
@@ -150,7 +205,7 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
150
205
|
* @returns A promise that resolves to a string describing the transaction result
|
|
151
206
|
*/
|
|
152
207
|
async buyCoinWithCoinInput(walletProvider, args) {
|
|
153
|
-
return
|
|
208
|
+
return (0, swap_utils_1.buyFlaunchCoin)(walletProvider, args.coinAddress, "EXACT_OUT", { amountOut: args.amountOut }, args.slippagePercent);
|
|
154
209
|
}
|
|
155
210
|
/**
|
|
156
211
|
* Sells a flaunch coin into ETH.
|
|
@@ -221,7 +276,7 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
221
276
|
{
|
|
222
277
|
fee: 0,
|
|
223
278
|
tickSpacing: 60,
|
|
224
|
-
hooks: constants_1.
|
|
279
|
+
hooks: constants_1.FlaunchPositionManagerV1_1Address[chainId],
|
|
225
280
|
hookData: "0x",
|
|
226
281
|
intermediateCurrency: constants_1.FLETHAddress[chainId],
|
|
227
282
|
},
|
|
@@ -236,9 +291,9 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
236
291
|
},
|
|
237
292
|
],
|
|
238
293
|
});
|
|
239
|
-
const ethOutMin = (0,
|
|
294
|
+
const ethOutMin = (0, swap_utils_1.getAmountWithSlippage)(quoteResult.result[0], // amountOut
|
|
240
295
|
(args.slippagePercent / 100).toFixed(18).toString(), "EXACT_IN");
|
|
241
|
-
const { commands, inputs } = (0,
|
|
296
|
+
const { commands, inputs } = (0, swap_utils_1.memecoinToEthWithPermit2)({
|
|
242
297
|
chainId: Number(chainId),
|
|
243
298
|
memecoin: args.coinAddress,
|
|
244
299
|
amountIn,
|
|
@@ -257,7 +312,7 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
257
312
|
data,
|
|
258
313
|
});
|
|
259
314
|
const receipt = await walletProvider.waitForTransactionReceipt(hash);
|
|
260
|
-
const swapAmounts = (0,
|
|
315
|
+
const swapAmounts = (0, swap_utils_1.getSwapAmountsFromReceipt)({
|
|
261
316
|
receipt,
|
|
262
317
|
coinAddress: args.coinAddress,
|
|
263
318
|
chainId: Number(chainId),
|
|
@@ -284,134 +339,6 @@ class FlaunchActionProvider extends actionProvider_1.ActionProvider {
|
|
|
284
339
|
// all protocol networks
|
|
285
340
|
return network.protocolFamily === "evm" && SUPPORTED_NETWORKS.includes(network.networkId);
|
|
286
341
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Handles the process of buying a flaunch coin with ETH.
|
|
289
|
-
*
|
|
290
|
-
* @param walletProvider - The wallet provider instance
|
|
291
|
-
* @param coinAddress - The address of the flaunch coin
|
|
292
|
-
* @param swapType - The type of swap (EXACT_IN or EXACT_OUT)
|
|
293
|
-
* @param swapParams - Parameters specific to the swap type
|
|
294
|
-
* @param swapParams.amountIn - The amount of ETH to spend (for EXACT_IN)
|
|
295
|
-
* @param swapParams.amountOut - The amount of coins to buy (for EXACT_OUT)
|
|
296
|
-
* @param slippagePercent - The slippage percentage
|
|
297
|
-
* @returns A promise that resolves to a string describing the transaction result
|
|
298
|
-
*/
|
|
299
|
-
async _buyFlaunchCoin(walletProvider, coinAddress, swapType, swapParams, slippagePercent) {
|
|
300
|
-
const network = walletProvider.getNetwork();
|
|
301
|
-
const chainId = network.chainId;
|
|
302
|
-
const networkId = network.networkId;
|
|
303
|
-
if (!chainId || !networkId) {
|
|
304
|
-
throw new Error("Chain ID is not set.");
|
|
305
|
-
}
|
|
306
|
-
try {
|
|
307
|
-
let amountIn;
|
|
308
|
-
let amountOutMin;
|
|
309
|
-
let amountOut;
|
|
310
|
-
let amountInMax;
|
|
311
|
-
if (swapType === "EXACT_IN") {
|
|
312
|
-
amountIn = (0, viem_1.parseEther)(swapParams.amountIn);
|
|
313
|
-
const quoteResult = await walletProvider.getPublicClient().simulateContract({
|
|
314
|
-
address: constants_1.QuoterAddress[chainId],
|
|
315
|
-
abi: constants_1.QUOTER_ABI,
|
|
316
|
-
functionName: "quoteExactInput",
|
|
317
|
-
args: [
|
|
318
|
-
{
|
|
319
|
-
exactAmount: amountIn,
|
|
320
|
-
exactCurrency: viem_1.zeroAddress, // ETH
|
|
321
|
-
path: [
|
|
322
|
-
{
|
|
323
|
-
fee: 0,
|
|
324
|
-
tickSpacing: 60,
|
|
325
|
-
hookData: "0x",
|
|
326
|
-
hooks: constants_1.FLETHHooksAddress[chainId],
|
|
327
|
-
intermediateCurrency: constants_1.FLETHAddress[chainId],
|
|
328
|
-
},
|
|
329
|
-
{
|
|
330
|
-
fee: 0,
|
|
331
|
-
tickSpacing: 60,
|
|
332
|
-
hooks: constants_1.FlaunchPositionManagerAddress[chainId],
|
|
333
|
-
hookData: "0x",
|
|
334
|
-
intermediateCurrency: coinAddress,
|
|
335
|
-
},
|
|
336
|
-
],
|
|
337
|
-
},
|
|
338
|
-
],
|
|
339
|
-
});
|
|
340
|
-
amountOutMin = (0, utils_1.getAmountWithSlippage)(quoteResult.result[0], // amountOut
|
|
341
|
-
(slippagePercent / 100).toFixed(18).toString(), swapType);
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
// EXACT_OUT
|
|
345
|
-
amountOut = (0, viem_1.parseEther)(swapParams.amountOut);
|
|
346
|
-
const quoteResult = await walletProvider.getPublicClient().simulateContract({
|
|
347
|
-
address: constants_1.QuoterAddress[chainId],
|
|
348
|
-
abi: constants_1.QUOTER_ABI,
|
|
349
|
-
functionName: "quoteExactOutput",
|
|
350
|
-
args: [
|
|
351
|
-
{
|
|
352
|
-
path: [
|
|
353
|
-
{
|
|
354
|
-
intermediateCurrency: viem_1.zeroAddress,
|
|
355
|
-
fee: 0,
|
|
356
|
-
tickSpacing: 60,
|
|
357
|
-
hookData: "0x",
|
|
358
|
-
hooks: constants_1.FLETHHooksAddress[chainId],
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
intermediateCurrency: constants_1.FLETHAddress[chainId],
|
|
362
|
-
fee: 0,
|
|
363
|
-
tickSpacing: 60,
|
|
364
|
-
hooks: constants_1.FlaunchPositionManagerAddress[chainId],
|
|
365
|
-
hookData: "0x",
|
|
366
|
-
},
|
|
367
|
-
],
|
|
368
|
-
exactCurrency: coinAddress,
|
|
369
|
-
exactAmount: amountOut,
|
|
370
|
-
},
|
|
371
|
-
],
|
|
372
|
-
});
|
|
373
|
-
amountInMax = (0, utils_1.getAmountWithSlippage)(quoteResult.result[0], // amountIn
|
|
374
|
-
(slippagePercent / 100).toFixed(18).toString(), swapType);
|
|
375
|
-
}
|
|
376
|
-
const { commands, inputs } = (0, utils_1.ethToMemecoin)({
|
|
377
|
-
sender: walletProvider.getAddress(),
|
|
378
|
-
memecoin: coinAddress,
|
|
379
|
-
chainId: Number(chainId),
|
|
380
|
-
referrer: viem_1.zeroAddress,
|
|
381
|
-
swapType,
|
|
382
|
-
amountIn,
|
|
383
|
-
amountOutMin,
|
|
384
|
-
amountOut,
|
|
385
|
-
amountInMax,
|
|
386
|
-
});
|
|
387
|
-
const data = (0, viem_1.encodeFunctionData)({
|
|
388
|
-
abi: constants_1.UNIVERSAL_ROUTER_ABI,
|
|
389
|
-
functionName: "execute",
|
|
390
|
-
args: [commands, inputs],
|
|
391
|
-
});
|
|
392
|
-
const hash = await walletProvider.sendTransaction({
|
|
393
|
-
to: constants_1.UniversalRouterAddress[chainId],
|
|
394
|
-
data,
|
|
395
|
-
value: swapType === "EXACT_IN" ? amountIn : amountInMax,
|
|
396
|
-
});
|
|
397
|
-
const receipt = await walletProvider.waitForTransactionReceipt(hash);
|
|
398
|
-
const swapAmounts = (0, utils_1.getSwapAmountsFromReceipt)({
|
|
399
|
-
receipt,
|
|
400
|
-
coinAddress: coinAddress,
|
|
401
|
-
chainId: Number(chainId),
|
|
402
|
-
});
|
|
403
|
-
const coinSymbol = await walletProvider.readContract({
|
|
404
|
-
address: coinAddress,
|
|
405
|
-
abi: constants_1.ERC20_ABI,
|
|
406
|
-
functionName: "symbol",
|
|
407
|
-
});
|
|
408
|
-
return `Bought ${(0, viem_1.formatEther)(swapAmounts.coinsBought)} $${coinSymbol} for ${(0, viem_1.formatEther)(swapAmounts.ethSold)} ETH\n
|
|
409
|
-
Tx hash: [${hash}](${network_1.NETWORK_ID_TO_VIEM_CHAIN[networkId].blockExplorers?.default.url}/tx/${hash})`;
|
|
410
|
-
}
|
|
411
|
-
catch (error) {
|
|
412
|
-
return `Error buying coin: ${error}`;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
342
|
}
|
|
416
343
|
exports.FlaunchActionProvider = FlaunchActionProvider;
|
|
417
344
|
__decorate([
|
|
@@ -423,16 +350,22 @@ This tool allows launching a new memecoin using the flaunch protocol.
|
|
|
423
350
|
It takes:
|
|
424
351
|
- name: The name of the token
|
|
425
352
|
- symbol: The symbol of the token
|
|
426
|
-
-
|
|
353
|
+
- image: Local image file path or URL to the token image
|
|
427
354
|
- description: Description of the token
|
|
428
|
-
|
|
429
|
-
-
|
|
430
|
-
-
|
|
431
|
-
-
|
|
432
|
-
-
|
|
355
|
+
- fairLaunchPercent: The percentage of tokens for fair launch (defaults to 60%)
|
|
356
|
+
- fairLaunchDuration: The duration of the fair launch in minutes (defaults to 30 minutes)
|
|
357
|
+
- initialMarketCapUSD: The initial market cap in USD (defaults to 10000 USD)
|
|
358
|
+
- preminePercent: The percentage of total supply to premine (defaults to 0%, max is equal to fairLaunchPercent)
|
|
359
|
+
- creatorFeeAllocationPercent: The percentage of fees allocated to creator and optional receivers (defaults to 80%)
|
|
360
|
+
- creatorSplitPercent: The percentage of fees allocated to the creator (defaults to 100%), remainder goes to fee split recipients
|
|
361
|
+
- splitReceivers: Array of fee split recipients with address and percentage (optional)
|
|
362
|
+
- websiteUrl: URL to the token website (optional)
|
|
363
|
+
- discordUrl: URL to the token Discord (optional)
|
|
364
|
+
- twitterUrl: URL to the token Twitter (optional)
|
|
365
|
+
- telegramUrl: URL to the token Telegram (optional)
|
|
433
366
|
|
|
434
367
|
Note:
|
|
435
|
-
-
|
|
368
|
+
- splitReceivers must add up to exactly 100% if provided.
|
|
436
369
|
`,
|
|
437
370
|
schema: schemas_1.FlaunchSchema,
|
|
438
371
|
}),
|
|
@@ -504,8 +437,7 @@ It takes:
|
|
|
504
437
|
/**
|
|
505
438
|
* Factory function to create a new FlaunchActionProvider instance.
|
|
506
439
|
*
|
|
507
|
-
* @param config - Configuration options for the FlaunchActionProvider
|
|
508
440
|
* @returns A new FlaunchActionProvider instance
|
|
509
441
|
*/
|
|
510
|
-
const flaunchActionProvider = (
|
|
442
|
+
const flaunchActionProvider = () => new FlaunchActionProvider();
|
|
511
443
|
exports.flaunchActionProvider = flaunchActionProvider;
|
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
const flaunchActionProvider_1 = require("./flaunchActionProvider");
|
|
4
37
|
const schemas_1 = require("./schemas");
|
|
5
38
|
const viem_1 = require("viem");
|
|
39
|
+
const swapUtils = __importStar(require("./swap_utils"));
|
|
6
40
|
// Mock the actual contract calls with Jest
|
|
7
41
|
jest.mock("viem", () => {
|
|
8
42
|
const originalModule = jest.requireActual("viem");
|
|
@@ -22,27 +56,54 @@ jest.mock("viem", () => {
|
|
|
22
56
|
};
|
|
23
57
|
}),
|
|
24
58
|
parseEther: jest.fn().mockReturnValue(BigInt(100000000000000000)),
|
|
59
|
+
parseUnits: jest.fn().mockReturnValue(BigInt(100000000000000000)),
|
|
60
|
+
encodeAbiParameters: jest.fn().mockReturnValue("0xencoded"),
|
|
61
|
+
encodeFunctionData: jest.fn().mockReturnValue("0xfunctiondata"),
|
|
25
62
|
zeroAddress: "0x0000000000000000000000000000000000000000",
|
|
63
|
+
zeroHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
26
64
|
};
|
|
27
65
|
});
|
|
28
|
-
// Mock the
|
|
29
|
-
jest.mock("./
|
|
66
|
+
// Mock the metadata_utils module
|
|
67
|
+
jest.mock("./metadata_utils", () => ({
|
|
30
68
|
generateTokenUri: jest.fn().mockResolvedValue("ipfs://test-uri"),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
69
|
+
}));
|
|
70
|
+
// Mock the client_utils module
|
|
71
|
+
jest.mock("./client_utils", () => ({
|
|
72
|
+
ethRequiredToFlaunch: jest.fn().mockResolvedValue(BigInt(100000000000000000)),
|
|
73
|
+
getMemecoinAddressFromReceipt: jest
|
|
74
|
+
.fn()
|
|
75
|
+
.mockReturnValue("0x1234567890123456789012345678901234567890"),
|
|
76
|
+
}));
|
|
77
|
+
// Mock the swap_utils module
|
|
78
|
+
jest.mock("./swap_utils", () => ({
|
|
79
|
+
getAmountWithSlippage: jest.fn().mockImplementation(amount => amount),
|
|
35
80
|
memecoinToEthWithPermit2: jest.fn().mockReturnValue({
|
|
36
81
|
commands: "0x02",
|
|
37
82
|
inputs: ["0x5678"],
|
|
38
83
|
}),
|
|
39
|
-
getAmountWithSlippage: jest.fn().mockImplementation(amount => amount),
|
|
40
84
|
getSwapAmountsFromReceipt: jest.fn().mockImplementation(() => ({
|
|
41
85
|
coinsBought: BigInt(1000000000000000000),
|
|
42
86
|
ethSold: BigInt(100000000000000000),
|
|
43
87
|
coinsSold: BigInt(1000000000000000000),
|
|
44
88
|
ethBought: BigInt(100000000000000000),
|
|
45
89
|
})),
|
|
90
|
+
buyFlaunchCoin: jest
|
|
91
|
+
.fn()
|
|
92
|
+
.mockImplementation(async (walletProvider, coinAddress, _swapType, _amount, _slippagePercent) => {
|
|
93
|
+
// Simulate the actual behavior by calling wallet provider methods
|
|
94
|
+
walletProvider.getNetwork();
|
|
95
|
+
const coinSymbol = await walletProvider.readContract({
|
|
96
|
+
address: coinAddress,
|
|
97
|
+
abi: [],
|
|
98
|
+
functionName: "symbol",
|
|
99
|
+
});
|
|
100
|
+
const hash = await walletProvider.sendTransaction({
|
|
101
|
+
to: coinAddress,
|
|
102
|
+
data: "0x",
|
|
103
|
+
});
|
|
104
|
+
await walletProvider.waitForTransactionReceipt(hash);
|
|
105
|
+
return `Bought ${(0, viem_1.formatEther)(BigInt(1000000000000000000))} $${coinSymbol} for ${(0, viem_1.formatEther)(BigInt(100000000000000000))} ETH`;
|
|
106
|
+
}),
|
|
46
107
|
}));
|
|
47
108
|
// Mock the constants used in the test
|
|
48
109
|
jest.mock("./constants", () => {
|
|
@@ -85,7 +146,7 @@ jest.mock("./constants", () => {
|
|
|
85
146
|
};
|
|
86
147
|
});
|
|
87
148
|
describe("FlaunchActionProvider", () => {
|
|
88
|
-
const provider = new flaunchActionProvider_1.FlaunchActionProvider(
|
|
149
|
+
const provider = new flaunchActionProvider_1.FlaunchActionProvider();
|
|
89
150
|
let mockWalletProvider;
|
|
90
151
|
beforeEach(() => {
|
|
91
152
|
mockWalletProvider = {
|
|
@@ -155,9 +216,10 @@ describe("FlaunchActionProvider", () => {
|
|
|
155
216
|
const validInput = {
|
|
156
217
|
name: "Test Token",
|
|
157
218
|
symbol: "TEST",
|
|
158
|
-
|
|
219
|
+
image: "https://example.com/image.png",
|
|
159
220
|
description: "A test token",
|
|
160
221
|
websiteUrl: "https://example.com",
|
|
222
|
+
premineAmount: 5,
|
|
161
223
|
};
|
|
162
224
|
const parseResult = schemas_1.FlaunchSchema.safeParse(validInput);
|
|
163
225
|
expect(parseResult.success).toBe(true);
|
|
@@ -166,8 +228,9 @@ describe("FlaunchActionProvider", () => {
|
|
|
166
228
|
const invalidInput = {
|
|
167
229
|
name: "",
|
|
168
230
|
symbol: "",
|
|
169
|
-
|
|
231
|
+
image: "not-a-url",
|
|
170
232
|
description: "",
|
|
233
|
+
premineAmount: 150, // Invalid: exceeds 100%
|
|
171
234
|
};
|
|
172
235
|
const parseResult = schemas_1.FlaunchSchema.safeParse(invalidInput);
|
|
173
236
|
expect(parseResult.success).toBe(false);
|
|
@@ -205,9 +268,21 @@ describe("FlaunchActionProvider", () => {
|
|
|
205
268
|
const args = {
|
|
206
269
|
name: "Test Token",
|
|
207
270
|
symbol: "TEST",
|
|
208
|
-
|
|
271
|
+
image: "https://example.com/image.png",
|
|
209
272
|
description: "A test token",
|
|
210
273
|
websiteUrl: "https://example.com",
|
|
274
|
+
fairLaunchPercent: 60,
|
|
275
|
+
fairLaunchDuration: 30,
|
|
276
|
+
initialMarketCapUSD: 10000,
|
|
277
|
+
creatorFeeAllocationPercent: 80,
|
|
278
|
+
creatorSplitPercent: 50,
|
|
279
|
+
splitReceivers: [
|
|
280
|
+
{
|
|
281
|
+
address: "0x1234567890123456789012345678901234567890",
|
|
282
|
+
percent: 100,
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
preminePercent: 5,
|
|
211
286
|
};
|
|
212
287
|
const result = await provider.flaunch(mockWalletProvider, args);
|
|
213
288
|
console.log("Test result:", result);
|
|
@@ -217,6 +292,24 @@ describe("FlaunchActionProvider", () => {
|
|
|
217
292
|
expect(mockWalletProvider.sendTransaction).toHaveBeenCalled();
|
|
218
293
|
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalled();
|
|
219
294
|
});
|
|
295
|
+
it("should reject premineAmount exceeding fairLaunchPercent", async () => {
|
|
296
|
+
const args = {
|
|
297
|
+
name: "Test Token",
|
|
298
|
+
symbol: "TEST",
|
|
299
|
+
image: "https://example.com/image.png",
|
|
300
|
+
description: "A test token",
|
|
301
|
+
websiteUrl: "https://example.com",
|
|
302
|
+
fairLaunchPercent: 60,
|
|
303
|
+
fairLaunchDuration: 30,
|
|
304
|
+
initialMarketCapUSD: 10000,
|
|
305
|
+
creatorFeeAllocationPercent: 80,
|
|
306
|
+
creatorSplitPercent: 50,
|
|
307
|
+
splitReceivers: [],
|
|
308
|
+
preminePercent: 70, // Invalid: exceeds fairLaunchPercent of 60%
|
|
309
|
+
};
|
|
310
|
+
const result = await provider.flaunch(mockWalletProvider, args);
|
|
311
|
+
expect(result).toContain("premineAmount (70%) cannot exceed fairLaunchPercent (60%)");
|
|
312
|
+
});
|
|
220
313
|
});
|
|
221
314
|
describe("buyCoinWithETHInput action", () => {
|
|
222
315
|
it("should execute buyCoinWithETHInput action with wallet provider", async () => {
|
|
@@ -235,7 +328,8 @@ describe("FlaunchActionProvider", () => {
|
|
|
235
328
|
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalled();
|
|
236
329
|
});
|
|
237
330
|
it("should handle errors in buyCoinWithETHInput", async () => {
|
|
238
|
-
|
|
331
|
+
// Mock buyFlaunchCoin to return an error string
|
|
332
|
+
swapUtils.buyFlaunchCoin.mockResolvedValueOnce("Error buying coin: Transaction failed");
|
|
239
333
|
const args = {
|
|
240
334
|
coinAddress: "0x1234567890123456789012345678901234567890",
|
|
241
335
|
amountIn: "0.1",
|
|
@@ -262,7 +356,8 @@ describe("FlaunchActionProvider", () => {
|
|
|
262
356
|
expect(mockWalletProvider.waitForTransactionReceipt).toHaveBeenCalled();
|
|
263
357
|
});
|
|
264
358
|
it("should handle errors in buyCoinWithCoinInput", async () => {
|
|
265
|
-
|
|
359
|
+
// Mock buyFlaunchCoin to return an error string
|
|
360
|
+
swapUtils.buyFlaunchCoin.mockResolvedValueOnce("Error buying coin: Transaction failed");
|
|
266
361
|
const args = {
|
|
267
362
|
coinAddress: "0x1234567890123456789012345678901234567890",
|
|
268
363
|
amountOut: "1000",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface TokenUriParams {
|
|
2
|
+
metadata: {
|
|
3
|
+
image: string;
|
|
4
|
+
description: string;
|
|
5
|
+
websiteUrl?: string;
|
|
6
|
+
discordUrl?: string;
|
|
7
|
+
twitterUrl?: string;
|
|
8
|
+
telegramUrl?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const generateTokenUri: (name: string, symbol: string, params: TokenUriParams) => Promise<string>;
|
|
12
|
+
export {};
|