@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.
- package/README.md +30 -0
- package/dist/action-providers/flaunch/constants.d.ts +1078 -0
- package/dist/action-providers/flaunch/constants.js +709 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.d.ts +102 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.js +519 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.d.ts +1 -0
- package/dist/action-providers/flaunch/flaunchActionProvider.test.js +307 -0
- package/dist/action-providers/flaunch/index.d.ts +7 -0
- package/dist/action-providers/flaunch/index.js +23 -0
- package/dist/action-providers/flaunch/schemas.d.ts +77 -0
- package/dist/action-providers/flaunch/schemas.js +71 -0
- package/dist/action-providers/flaunch/types.d.ts +64 -0
- package/dist/action-providers/flaunch/types.js +2 -0
- package/dist/action-providers/flaunch/utils.d.ts +60 -0
- package/dist/action-providers/flaunch/utils.js +507 -0
- package/dist/action-providers/index.d.ts +2 -0
- package/dist/action-providers/index.js +2 -0
- package/dist/action-providers/onramp/index.d.ts +7 -0
- package/dist/action-providers/onramp/index.js +23 -0
- package/dist/action-providers/onramp/onrampActionProvider.d.ts +56 -0
- package/dist/action-providers/onramp/onrampActionProvider.js +109 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.d.ts +1 -0
- package/dist/action-providers/onramp/onrampActionProvider.test.js +97 -0
- package/dist/action-providers/onramp/schemas.d.ts +12 -0
- package/dist/action-providers/onramp/schemas.js +15 -0
- package/dist/action-providers/onramp/types.d.ts +107 -0
- package/dist/action-providers/onramp/types.js +2 -0
- package/dist/action-providers/onramp/utils.d.ts +16 -0
- package/dist/action-providers/onramp/utils.js +56 -0
- package/dist/action-providers/onramp/version.d.ts +2 -0
- package/dist/action-providers/onramp/version.js +5 -0
- package/dist/wallet-providers/cdpWalletProvider.js +20 -10
- package/dist/wallet-providers/cdpWalletProvider.test.js +37 -3
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.test.js +1 -0
- package/dist/wallet-providers/privyShared.d.ts +3 -5
- package/dist/wallet-providers/privySvmWalletProvider.d.ts +2 -0
- package/dist/wallet-providers/privySvmWalletProvider.js +4 -1
- package/dist/wallet-providers/privySvmWalletProvider.test.js +1 -0
- package/dist/wallet-providers/privyWalletProvider.d.ts +6 -5
- package/dist/wallet-providers/privyWalletProvider.test.js +30 -0
- package/package.json +4 -2
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSwapAmountsFromReceipt = exports.getSwapAmountsFromLog = exports.memecoinToEthWithPermit2 = exports.ethToMemecoin = exports.getAmountWithSlippage = exports.generateTokenUri = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
/**
|
|
7
|
+
* Uploads a base64 image to IPFS using Pinata
|
|
8
|
+
*
|
|
9
|
+
* @param params - Configuration and base64 image data
|
|
10
|
+
* @param params.pinataConfig - Pinata configuration including JWT
|
|
11
|
+
* @param params.base64Image - Base64 encoded image data
|
|
12
|
+
* @param params.name - Optional name for the uploaded file
|
|
13
|
+
* @param params.metadata - Optional metadata key-value pairs
|
|
14
|
+
* @returns Upload response with CID and other details
|
|
15
|
+
*/
|
|
16
|
+
const uploadImageToIPFS = async (params) => {
|
|
17
|
+
try {
|
|
18
|
+
const formData = new FormData();
|
|
19
|
+
// Convert base64 to Blob and then to File
|
|
20
|
+
// Remove data URL prefix if present (e.g., "data:image/jpeg;base64,")
|
|
21
|
+
const base64Data = params.base64Image.split(",")[1] || params.base64Image;
|
|
22
|
+
const byteCharacters = atob(base64Data);
|
|
23
|
+
const byteArrays = [];
|
|
24
|
+
for (let offset = 0; offset < byteCharacters.length; offset += 1024) {
|
|
25
|
+
const slice = byteCharacters.slice(offset, offset + 1024);
|
|
26
|
+
const byteNumbers = new Array(slice.length);
|
|
27
|
+
for (let i = 0; i < slice.length; i++) {
|
|
28
|
+
byteNumbers[i] = slice.charCodeAt(i);
|
|
29
|
+
}
|
|
30
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
31
|
+
byteArrays.push(byteArray);
|
|
32
|
+
}
|
|
33
|
+
// Detect mime type from base64 string
|
|
34
|
+
let mimeType = "image/png"; // default
|
|
35
|
+
if (params.base64Image.startsWith("data:")) {
|
|
36
|
+
mimeType = params.base64Image.split(";")[0].split(":")[1];
|
|
37
|
+
}
|
|
38
|
+
const blob = new Blob(byteArrays, { type: mimeType });
|
|
39
|
+
const fileName = params.name || `image.${mimeType.split("/")[1]}`;
|
|
40
|
+
const file = new File([blob], fileName, { type: mimeType });
|
|
41
|
+
formData.append("file", file);
|
|
42
|
+
const pinataMetadata = {
|
|
43
|
+
name: params.name || null,
|
|
44
|
+
keyvalues: params.metadata || {},
|
|
45
|
+
};
|
|
46
|
+
formData.append("pinataMetadata", JSON.stringify(pinataMetadata));
|
|
47
|
+
const pinataOptions = {
|
|
48
|
+
cidVersion: 1,
|
|
49
|
+
};
|
|
50
|
+
formData.append("pinataOptions", JSON.stringify(pinataOptions));
|
|
51
|
+
const response = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: {
|
|
54
|
+
Authorization: `Bearer ${params.pinataConfig.jwt}`,
|
|
55
|
+
},
|
|
56
|
+
body: formData,
|
|
57
|
+
});
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
const error = await response.json();
|
|
60
|
+
throw new Error(`Failed to upload image to IPFS: ${error.message || response.statusText}`);
|
|
61
|
+
}
|
|
62
|
+
const data = await response.json();
|
|
63
|
+
return {
|
|
64
|
+
IpfsHash: data.IpfsHash,
|
|
65
|
+
PinSize: data.PinSize,
|
|
66
|
+
Timestamp: data.Timestamp,
|
|
67
|
+
isDuplicate: data.isDuplicate || false,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
throw new Error(`Failed to upload image to IPFS: ${error.message}`);
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Uploads JSON data to IPFS using Pinata
|
|
79
|
+
*
|
|
80
|
+
* @param params - Configuration and JSON data
|
|
81
|
+
* @param params.pinataConfig - Pinata configuration including JWT
|
|
82
|
+
* @param params.json - JSON data to upload
|
|
83
|
+
* @param params.name - Optional name for the uploaded file
|
|
84
|
+
* @param params.metadata - Optional metadata key-value pairs
|
|
85
|
+
* @returns Upload response with CID and other details
|
|
86
|
+
*/
|
|
87
|
+
const uploadJsonToIPFS = async (params) => {
|
|
88
|
+
try {
|
|
89
|
+
const requestBody = {
|
|
90
|
+
pinataOptions: {
|
|
91
|
+
cidVersion: 1,
|
|
92
|
+
},
|
|
93
|
+
pinataMetadata: {
|
|
94
|
+
name: params.name || null,
|
|
95
|
+
keyvalues: params.metadata || {},
|
|
96
|
+
},
|
|
97
|
+
pinataContent: params.json,
|
|
98
|
+
};
|
|
99
|
+
const response = await fetch("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: {
|
|
102
|
+
Authorization: `Bearer ${params.pinataConfig.jwt}`,
|
|
103
|
+
"Content-Type": "application/json",
|
|
104
|
+
},
|
|
105
|
+
body: JSON.stringify(requestBody),
|
|
106
|
+
});
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
const error = await response.json();
|
|
109
|
+
throw new Error(`Failed to upload JSON to IPFS: ${error.message || response.statusText}`);
|
|
110
|
+
}
|
|
111
|
+
const data = await response.json();
|
|
112
|
+
return {
|
|
113
|
+
IpfsHash: data.IpfsHash,
|
|
114
|
+
PinSize: data.PinSize,
|
|
115
|
+
Timestamp: data.Timestamp,
|
|
116
|
+
isDuplicate: data.isDuplicate || false,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error instanceof Error) {
|
|
121
|
+
throw new Error(`Failed to upload JSON to IPFS: ${error.message}`);
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const generateTokenUriBase64Image = async (name, params) => {
|
|
127
|
+
// 1. upload image to IPFS
|
|
128
|
+
const imageRes = await uploadImageToIPFS({
|
|
129
|
+
pinataConfig: params.pinataConfig,
|
|
130
|
+
base64Image: params.metadata.base64Image,
|
|
131
|
+
});
|
|
132
|
+
// 2. upload metadata to IPFS
|
|
133
|
+
const coinMetadata = {
|
|
134
|
+
name,
|
|
135
|
+
description: params.metadata.description,
|
|
136
|
+
image: `ipfs://${imageRes.IpfsHash}`,
|
|
137
|
+
external_link: params.metadata.websiteUrl || "",
|
|
138
|
+
collaborators: [],
|
|
139
|
+
discordUrl: params.metadata.discordUrl || "",
|
|
140
|
+
twitterUrl: params.metadata.twitterUrl || "",
|
|
141
|
+
telegramUrl: params.metadata.telegramUrl || "",
|
|
142
|
+
};
|
|
143
|
+
const metadataRes = await uploadJsonToIPFS({
|
|
144
|
+
pinataConfig: params.pinataConfig,
|
|
145
|
+
json: coinMetadata,
|
|
146
|
+
});
|
|
147
|
+
return `ipfs://${metadataRes.IpfsHash}`;
|
|
148
|
+
};
|
|
149
|
+
const generateTokenUri = async (name, params) => {
|
|
150
|
+
// 1. get base64Image from imageUrl
|
|
151
|
+
const response = await fetch(params.metadata.imageUrl);
|
|
152
|
+
if (!response.ok) {
|
|
153
|
+
throw new Error(`Failed to fetch image: ${response.statusText}`);
|
|
154
|
+
}
|
|
155
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
156
|
+
const base64Image = Buffer.from(arrayBuffer).toString("base64");
|
|
157
|
+
// 2. generate token uri
|
|
158
|
+
const tokenUri = await generateTokenUriBase64Image(name, {
|
|
159
|
+
pinataConfig: params.pinataConfig,
|
|
160
|
+
metadata: {
|
|
161
|
+
base64Image,
|
|
162
|
+
description: params.metadata.description,
|
|
163
|
+
websiteUrl: params.metadata.websiteUrl,
|
|
164
|
+
discordUrl: params.metadata.discordUrl,
|
|
165
|
+
twitterUrl: params.metadata.twitterUrl,
|
|
166
|
+
telegramUrl: params.metadata.telegramUrl,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
return tokenUri;
|
|
170
|
+
};
|
|
171
|
+
exports.generateTokenUri = generateTokenUri;
|
|
172
|
+
const getAmountWithSlippage = (amount, slippage, swapType) => {
|
|
173
|
+
if (amount == null) {
|
|
174
|
+
return 0n;
|
|
175
|
+
}
|
|
176
|
+
const absAmount = amount < 0n ? -amount : amount;
|
|
177
|
+
const slippageMultiplier = swapType === "EXACT_IN"
|
|
178
|
+
? BigInt(1e18) - (0, viem_1.parseEther)(slippage)
|
|
179
|
+
: BigInt(1e18) + (0, viem_1.parseEther)(slippage);
|
|
180
|
+
return (absAmount * slippageMultiplier) / BigInt(1e18);
|
|
181
|
+
};
|
|
182
|
+
exports.getAmountWithSlippage = getAmountWithSlippage;
|
|
183
|
+
const ETH = viem_1.zeroAddress;
|
|
184
|
+
const ethToMemecoin = (params) => {
|
|
185
|
+
const flETH = constants_1.FLETHAddress[params.chainId];
|
|
186
|
+
const flETHHooks = constants_1.FLETHHooksAddress[params.chainId];
|
|
187
|
+
const flaunchHooks = constants_1.FlaunchPositionManagerAddress[params.chainId];
|
|
188
|
+
// Determine actions based on swapType
|
|
189
|
+
const v4Actions = ("0x" +
|
|
190
|
+
(params.swapType === "EXACT_IN" ? constants_1.V4Actions.SWAP_EXACT_IN : constants_1.V4Actions.SWAP_EXACT_OUT) +
|
|
191
|
+
constants_1.V4Actions.SETTLE_ALL +
|
|
192
|
+
constants_1.V4Actions.TAKE_ALL);
|
|
193
|
+
// Initialize variables for path and v4Params
|
|
194
|
+
let path;
|
|
195
|
+
let v4Params;
|
|
196
|
+
// Configure path and parameters based on swapType
|
|
197
|
+
if (params.swapType === "EXACT_IN") {
|
|
198
|
+
if (params.amountIn == null || params.amountOutMin == null) {
|
|
199
|
+
throw new Error("amountIn and amountOutMin are required for EXACT_IN swap");
|
|
200
|
+
}
|
|
201
|
+
// Path for 'EXACT_IN' swap
|
|
202
|
+
path = [
|
|
203
|
+
{
|
|
204
|
+
intermediateCurrency: flETH,
|
|
205
|
+
fee: 0,
|
|
206
|
+
tickSpacing: 60,
|
|
207
|
+
hooks: flETHHooks,
|
|
208
|
+
hookData: "0x",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
intermediateCurrency: params.memecoin,
|
|
212
|
+
fee: 0,
|
|
213
|
+
tickSpacing: 60,
|
|
214
|
+
hooks: flaunchHooks,
|
|
215
|
+
hookData: (0, viem_1.encodeAbiParameters)([{ type: "address", name: "referrer" }], [params.referrer ?? viem_1.zeroAddress]),
|
|
216
|
+
},
|
|
217
|
+
];
|
|
218
|
+
// Parameters for 'EXACT_IN' swap
|
|
219
|
+
v4Params = (0, viem_1.encodeAbiParameters)(constants_1.IV4RouterAbiExactInput, [
|
|
220
|
+
{
|
|
221
|
+
currencyIn: ETH,
|
|
222
|
+
path: path,
|
|
223
|
+
amountIn: params.amountIn,
|
|
224
|
+
amountOutMinimum: params.amountOutMin,
|
|
225
|
+
},
|
|
226
|
+
]);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
if (params.amountOut == null || params.amountInMax == null) {
|
|
230
|
+
throw new Error("amountOut and amountInMax are required for EXACT_OUT swap");
|
|
231
|
+
}
|
|
232
|
+
// Path for 'EXACT_OUT' swap
|
|
233
|
+
path = [
|
|
234
|
+
{
|
|
235
|
+
fee: 0,
|
|
236
|
+
tickSpacing: 60,
|
|
237
|
+
hookData: "0x",
|
|
238
|
+
hooks: flETHHooks,
|
|
239
|
+
intermediateCurrency: ETH,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
fee: 0,
|
|
243
|
+
tickSpacing: 60,
|
|
244
|
+
hooks: flaunchHooks,
|
|
245
|
+
intermediateCurrency: flETH,
|
|
246
|
+
hookData: (0, viem_1.encodeAbiParameters)([{ type: "address", name: "referrer" }], [params.referrer ?? viem_1.zeroAddress]),
|
|
247
|
+
},
|
|
248
|
+
];
|
|
249
|
+
// Parameters for 'EXACT_OUT' swap
|
|
250
|
+
v4Params = (0, viem_1.encodeAbiParameters)(constants_1.IV4RouterAbiExactOutput, [
|
|
251
|
+
{
|
|
252
|
+
currencyOut: params.memecoin,
|
|
253
|
+
path: path,
|
|
254
|
+
amountOut: params.amountOut,
|
|
255
|
+
amountInMaximum: params.amountInMax,
|
|
256
|
+
},
|
|
257
|
+
]);
|
|
258
|
+
}
|
|
259
|
+
// Common parameters for both swap types
|
|
260
|
+
const settleParams = (0, viem_1.encodeAbiParameters)([
|
|
261
|
+
{
|
|
262
|
+
type: "address",
|
|
263
|
+
name: "currency",
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
type: "uint256",
|
|
267
|
+
name: "maxAmount",
|
|
268
|
+
},
|
|
269
|
+
], [
|
|
270
|
+
ETH,
|
|
271
|
+
params.swapType === "EXACT_IN"
|
|
272
|
+
? (params.amountIn ?? viem_1.maxUint256)
|
|
273
|
+
: (params.amountInMax ?? viem_1.maxUint256),
|
|
274
|
+
]);
|
|
275
|
+
const takeParams = (0, viem_1.encodeAbiParameters)([
|
|
276
|
+
{
|
|
277
|
+
type: "address",
|
|
278
|
+
name: "currency",
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: "uint256",
|
|
282
|
+
name: "minAmount",
|
|
283
|
+
},
|
|
284
|
+
], [
|
|
285
|
+
params.memecoin,
|
|
286
|
+
params.swapType === "EXACT_IN"
|
|
287
|
+
? (params.amountOutMin ?? viem_1.maxUint256)
|
|
288
|
+
: (params.amountOut ?? viem_1.maxUint256),
|
|
289
|
+
]);
|
|
290
|
+
// Encode router data
|
|
291
|
+
const v4RouterData = (0, viem_1.encodeAbiParameters)([
|
|
292
|
+
{ type: "bytes", name: "actions" },
|
|
293
|
+
{ type: "bytes[]", name: "params" },
|
|
294
|
+
], [v4Actions, [v4Params, settleParams, takeParams]]);
|
|
295
|
+
// Commands for Universal Router
|
|
296
|
+
const urCommands = ("0x" + constants_1.URCommands.V4_SWAP + constants_1.URCommands.SWEEP);
|
|
297
|
+
const sweepInput = (0, viem_1.encodeAbiParameters)([
|
|
298
|
+
{ type: "address", name: "token" },
|
|
299
|
+
{ type: "address", name: "recipient" },
|
|
300
|
+
{ type: "uint160", name: "amountIn" },
|
|
301
|
+
], [ETH, params.sender, 0n]);
|
|
302
|
+
// Encode calldata for Universal Router
|
|
303
|
+
const inputs = [v4RouterData, sweepInput];
|
|
304
|
+
const urExecuteCalldata = (0, viem_1.encodeFunctionData)({
|
|
305
|
+
abi: constants_1.UNIVERSAL_ROUTER_ABI,
|
|
306
|
+
functionName: "execute",
|
|
307
|
+
args: [urCommands, inputs],
|
|
308
|
+
});
|
|
309
|
+
return {
|
|
310
|
+
calldata: urExecuteCalldata,
|
|
311
|
+
commands: urCommands,
|
|
312
|
+
inputs,
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
exports.ethToMemecoin = ethToMemecoin;
|
|
316
|
+
// @notice Beofre calling the UniversalRouter the user must have:
|
|
317
|
+
// 1. Given the Permit2 contract allowance to spend the memecoin
|
|
318
|
+
const memecoinToEthWithPermit2 = (params) => {
|
|
319
|
+
const flETH = constants_1.FLETHAddress[params.chainId];
|
|
320
|
+
const flETHHooks = constants_1.FLETHHooksAddress[params.chainId];
|
|
321
|
+
const flaunchHooks = constants_1.FlaunchPositionManagerAddress[params.chainId];
|
|
322
|
+
const v4Actions = ("0x" +
|
|
323
|
+
constants_1.V4Actions.SWAP_EXACT_IN +
|
|
324
|
+
constants_1.V4Actions.SETTLE_ALL +
|
|
325
|
+
constants_1.V4Actions.TAKE_ALL);
|
|
326
|
+
const v4ExactInputParams = (0, viem_1.encodeAbiParameters)(constants_1.IV4RouterAbiExactInput, [
|
|
327
|
+
{
|
|
328
|
+
currencyIn: params.memecoin,
|
|
329
|
+
path: [
|
|
330
|
+
{
|
|
331
|
+
intermediateCurrency: flETH,
|
|
332
|
+
fee: 0,
|
|
333
|
+
tickSpacing: 60,
|
|
334
|
+
hooks: flaunchHooks,
|
|
335
|
+
hookData: (0, viem_1.encodeAbiParameters)([
|
|
336
|
+
{
|
|
337
|
+
type: "address",
|
|
338
|
+
name: "referrer",
|
|
339
|
+
},
|
|
340
|
+
], [params.referrer ?? viem_1.zeroAddress]),
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
intermediateCurrency: ETH,
|
|
344
|
+
fee: 0,
|
|
345
|
+
tickSpacing: 60,
|
|
346
|
+
hooks: flETHHooks,
|
|
347
|
+
hookData: "0x",
|
|
348
|
+
},
|
|
349
|
+
],
|
|
350
|
+
amountIn: params.amountIn,
|
|
351
|
+
amountOutMinimum: params.ethOutMin,
|
|
352
|
+
},
|
|
353
|
+
]);
|
|
354
|
+
const settleParams = (0, viem_1.encodeAbiParameters)([
|
|
355
|
+
{
|
|
356
|
+
type: "address",
|
|
357
|
+
name: "currency",
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
type: "uint256",
|
|
361
|
+
name: "maxAmount",
|
|
362
|
+
},
|
|
363
|
+
], [params.memecoin, params.amountIn]);
|
|
364
|
+
const takeParams = (0, viem_1.encodeAbiParameters)([
|
|
365
|
+
{
|
|
366
|
+
type: "address",
|
|
367
|
+
name: "currency",
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
type: "uint256",
|
|
371
|
+
name: "minAmount",
|
|
372
|
+
},
|
|
373
|
+
], [ETH, params.ethOutMin]);
|
|
374
|
+
const v4RouterData = (0, viem_1.encodeAbiParameters)([
|
|
375
|
+
{ type: "bytes", name: "actions" },
|
|
376
|
+
{ type: "bytes[]", name: "params" },
|
|
377
|
+
], [v4Actions, [v4ExactInputParams, settleParams, takeParams]]);
|
|
378
|
+
if (params.signature && params.permitSingle) {
|
|
379
|
+
const urCommands = ("0x" + constants_1.URCommands.PERMIT2_PERMIT + constants_1.URCommands.V4_SWAP);
|
|
380
|
+
const permit2PermitInput = (0, viem_1.encodeAbiParameters)([
|
|
381
|
+
{
|
|
382
|
+
type: "tuple",
|
|
383
|
+
components: [
|
|
384
|
+
{
|
|
385
|
+
type: "tuple",
|
|
386
|
+
components: [
|
|
387
|
+
{ type: "address", name: "token" },
|
|
388
|
+
{ type: "uint160", name: "amount" },
|
|
389
|
+
{ type: "uint48", name: "expiration" },
|
|
390
|
+
{ type: "uint48", name: "nonce" },
|
|
391
|
+
],
|
|
392
|
+
name: "details",
|
|
393
|
+
},
|
|
394
|
+
{ type: "address", name: "spender" },
|
|
395
|
+
{ type: "uint256", name: "sigDeadline" },
|
|
396
|
+
],
|
|
397
|
+
name: "PermitSingle",
|
|
398
|
+
},
|
|
399
|
+
{ type: "bytes", name: "signature" },
|
|
400
|
+
], [params.permitSingle, params.signature]);
|
|
401
|
+
const inputs = [permit2PermitInput, v4RouterData];
|
|
402
|
+
const urExecuteCalldata = (0, viem_1.encodeFunctionData)({
|
|
403
|
+
abi: constants_1.UNIVERSAL_ROUTER_ABI,
|
|
404
|
+
functionName: "execute",
|
|
405
|
+
args: [urCommands, inputs],
|
|
406
|
+
});
|
|
407
|
+
return {
|
|
408
|
+
calldata: urExecuteCalldata,
|
|
409
|
+
commands: urCommands,
|
|
410
|
+
inputs,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
const urCommands = ("0x" + constants_1.URCommands.V4_SWAP);
|
|
415
|
+
const inputs = [v4RouterData];
|
|
416
|
+
const urExecuteCalldata = (0, viem_1.encodeFunctionData)({
|
|
417
|
+
abi: constants_1.UNIVERSAL_ROUTER_ABI,
|
|
418
|
+
functionName: "execute",
|
|
419
|
+
args: [urCommands, inputs],
|
|
420
|
+
});
|
|
421
|
+
return {
|
|
422
|
+
calldata: urExecuteCalldata,
|
|
423
|
+
commands: urCommands,
|
|
424
|
+
inputs,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
exports.memecoinToEthWithPermit2 = memecoinToEthWithPermit2;
|
|
429
|
+
const getSwapAmountsFromLog = ({ filteredPoolSwapEvent, coinAddress, chainId, }) => {
|
|
430
|
+
const { flAmount0, flAmount1, flFee0, flFee1, ispAmount0, ispAmount1, ispFee0, ispFee1, uniAmount0, uniAmount1, uniFee0, uniFee1, } = filteredPoolSwapEvent;
|
|
431
|
+
const currency0Delta = flAmount0 + ispAmount0 + uniAmount0;
|
|
432
|
+
const currency1Delta = flAmount1 + ispAmount1 + uniAmount1;
|
|
433
|
+
const currency0Fees = flFee0 + ispFee0 + uniFee0;
|
|
434
|
+
const currency1Fees = flFee1 + ispFee1 + uniFee1;
|
|
435
|
+
let feesIsInFLETH;
|
|
436
|
+
let swapType;
|
|
437
|
+
const flETHIsCurrencyZero = coinAddress > constants_1.FLETHAddress[chainId];
|
|
438
|
+
if (flETHIsCurrencyZero) {
|
|
439
|
+
swapType = currency0Delta < 0 ? "BUY" : "SELL";
|
|
440
|
+
feesIsInFLETH = currency0Fees < 0;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
swapType = currency1Delta < 0 ? "BUY" : "SELL";
|
|
444
|
+
feesIsInFLETH = currency1Fees < 0;
|
|
445
|
+
}
|
|
446
|
+
const absCurrency0Delta = currency0Delta < 0 ? -currency0Delta : currency0Delta;
|
|
447
|
+
const absCurrency1Delta = currency1Delta < 0 ? -currency1Delta : currency1Delta;
|
|
448
|
+
const absCurrency0Fees = currency0Fees < 0 ? -currency0Fees : currency0Fees;
|
|
449
|
+
const absCurrency1Fees = currency1Fees < 0 ? -currency1Fees : currency1Fees;
|
|
450
|
+
const fees = {
|
|
451
|
+
isInFLETH: feesIsInFLETH,
|
|
452
|
+
amount: flETHIsCurrencyZero
|
|
453
|
+
? feesIsInFLETH
|
|
454
|
+
? absCurrency0Fees
|
|
455
|
+
: absCurrency1Fees
|
|
456
|
+
: feesIsInFLETH
|
|
457
|
+
? absCurrency1Fees
|
|
458
|
+
: absCurrency0Fees,
|
|
459
|
+
};
|
|
460
|
+
if (swapType === "BUY") {
|
|
461
|
+
return {
|
|
462
|
+
coinsBought: flETHIsCurrencyZero
|
|
463
|
+
? absCurrency1Delta - (!fees.isInFLETH ? fees.amount : 0n)
|
|
464
|
+
: absCurrency0Delta - (!fees.isInFLETH ? fees.amount : 0n),
|
|
465
|
+
ethSold: flETHIsCurrencyZero
|
|
466
|
+
? absCurrency0Delta - (fees.isInFLETH ? fees.amount : 0n)
|
|
467
|
+
: absCurrency1Delta - (fees.isInFLETH ? fees.amount : 0n),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
return {
|
|
472
|
+
coinsSold: flETHIsCurrencyZero
|
|
473
|
+
? absCurrency1Delta - (!fees.isInFLETH ? fees.amount : 0n)
|
|
474
|
+
: absCurrency0Delta - (!fees.isInFLETH ? fees.amount : 0n),
|
|
475
|
+
ethBought: flETHIsCurrencyZero
|
|
476
|
+
? absCurrency0Delta - (fees.isInFLETH ? fees.amount : 0n)
|
|
477
|
+
: absCurrency1Delta - (fees.isInFLETH ? fees.amount : 0n),
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
exports.getSwapAmountsFromLog = getSwapAmountsFromLog;
|
|
482
|
+
const getSwapAmountsFromReceipt = ({ receipt, coinAddress, chainId, }) => {
|
|
483
|
+
const filteredPoolSwapEvent = receipt.logs
|
|
484
|
+
.map(log => {
|
|
485
|
+
try {
|
|
486
|
+
if (log.address.toLowerCase() !== constants_1.FlaunchPositionManagerAddress[chainId].toLowerCase()) {
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
const event = (0, viem_1.decodeEventLog)({
|
|
490
|
+
abi: constants_1.POSITION_MANAGER_ABI,
|
|
491
|
+
data: log.data,
|
|
492
|
+
topics: log.topics,
|
|
493
|
+
});
|
|
494
|
+
return event.eventName === "PoolSwap" ? event.args : null;
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
})
|
|
500
|
+
.filter((event) => event !== null)[0];
|
|
501
|
+
return (0, exports.getSwapAmountsFromLog)({
|
|
502
|
+
filteredPoolSwapEvent,
|
|
503
|
+
coinAddress,
|
|
504
|
+
chainId,
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
exports.getSwapAmountsFromReceipt = getSwapAmountsFromReceipt;
|
|
@@ -38,3 +38,5 @@ __exportStar(require("./wallet"), exports);
|
|
|
38
38
|
__exportStar(require("./weth"), exports);
|
|
39
39
|
__exportStar(require("./wow"), exports);
|
|
40
40
|
__exportStar(require("./allora"), exports);
|
|
41
|
+
__exportStar(require("./flaunch"), exports);
|
|
42
|
+
__exportStar(require("./onramp"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Exports for onramp action provider
|
|
4
|
+
*
|
|
5
|
+
* @module onramp
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
__exportStar(require("./onrampActionProvider"), exports);
|
|
23
|
+
__exportStar(require("./schemas"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Onramp Action Provider
|
|
3
|
+
*
|
|
4
|
+
* This file contains the implementation of the OnrampActionProvider,
|
|
5
|
+
* which provides actions for onramp operations.
|
|
6
|
+
*
|
|
7
|
+
* @module onramp
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { ActionProvider } from "../actionProvider";
|
|
11
|
+
import { Network } from "../../network";
|
|
12
|
+
import { EvmWalletProvider } from "../../wallet-providers";
|
|
13
|
+
import { GetOnrampBuyUrlActionSchema } from "./schemas";
|
|
14
|
+
type OnrampActionProviderProps = {
|
|
15
|
+
projectId: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* OnrampActionProvider provides actions for onramp operations.
|
|
19
|
+
*
|
|
20
|
+
* @description
|
|
21
|
+
* This provider is designed to work with EvmWalletProvider for blockchain interactions.
|
|
22
|
+
* It supports all evm networks.
|
|
23
|
+
*/
|
|
24
|
+
export declare class OnrampActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
25
|
+
private projectId;
|
|
26
|
+
/**
|
|
27
|
+
* Constructor for the OnrampActionProvider.
|
|
28
|
+
*
|
|
29
|
+
* @param props - The props for the OnrampActionProvider
|
|
30
|
+
* @param props.projectId - The project ID for the OnrampActionProvider
|
|
31
|
+
*/
|
|
32
|
+
constructor(props: OnrampActionProviderProps);
|
|
33
|
+
/**
|
|
34
|
+
* This action provides a link to buy more cryptocurrency (ETH, USDC, or BTC) using fiat currency (regular money like USD).
|
|
35
|
+
*
|
|
36
|
+
* @param walletProvider - The wallet provider instance for blockchain interactions
|
|
37
|
+
* @param _ - The arguments for the action (not used)
|
|
38
|
+
* @returns A promise that resolves to a string describing the action result
|
|
39
|
+
*/
|
|
40
|
+
getOnrampBuyUrl(walletProvider: EvmWalletProvider, _?: z.infer<typeof GetOnrampBuyUrlActionSchema>): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if this provider supports the given network.
|
|
43
|
+
*
|
|
44
|
+
* @param network - The network to check support for
|
|
45
|
+
* @returns True if the network is supported
|
|
46
|
+
*/
|
|
47
|
+
supportsNetwork(network: Network): boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Factory function to create a new OnrampActionProvider instance.
|
|
51
|
+
*
|
|
52
|
+
* @param props - The props for the OnrampActionProvider
|
|
53
|
+
* @returns A new OnrampActionProvider instance
|
|
54
|
+
*/
|
|
55
|
+
export declare const onrampActionProvider: (props: OnrampActionProviderProps) => OnrampActionProvider;
|
|
56
|
+
export {};
|