four-flap-meme-sdk 1.4.89 → 1.4.91
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.zh-CN.pdf +0 -0
- package/dist/flap/portal-bundle-merkle/create-to-dex.d.ts +1 -1
- package/dist/flap/portal-bundle-merkle/create-to-dex.js +51 -13
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +16 -0
- package/dist/flap/portal-bundle-merkle/encryption.js +146 -0
- package/dist/utils/holders-maker.d.ts +19 -0
- package/dist/utils/holders-maker.js +4 -1
- package/package.json +3 -38
- package/dist/sol/constants.d.ts +0 -126
- package/dist/sol/constants.js +0 -145
- package/dist/sol/dex/blockrazor/client.d.ts +0 -51
- package/dist/sol/dex/blockrazor/client.js +0 -96
- package/dist/sol/dex/blockrazor/constants.d.ts +0 -34
- package/dist/sol/dex/blockrazor/constants.js +0 -55
- package/dist/sol/dex/blockrazor/geyser.d.ts +0 -128
- package/dist/sol/dex/blockrazor/geyser.js +0 -530
- package/dist/sol/dex/blockrazor/index.d.ts +0 -18
- package/dist/sol/dex/blockrazor/index.js +0 -23
- package/dist/sol/dex/blockrazor/send.d.ts +0 -135
- package/dist/sol/dex/blockrazor/send.js +0 -254
- package/dist/sol/dex/blockrazor/types.d.ts +0 -191
- package/dist/sol/dex/blockrazor/types.js +0 -5
- package/dist/sol/dex/index.d.ts +0 -10
- package/dist/sol/dex/index.js +0 -16
- package/dist/sol/dex/jup/client.d.ts +0 -33
- package/dist/sol/dex/jup/client.js +0 -110
- package/dist/sol/dex/jup/index.d.ts +0 -16
- package/dist/sol/dex/jup/index.js +0 -148
- package/dist/sol/dex/jup/legacy.d.ts +0 -623
- package/dist/sol/dex/jup/legacy.js +0 -416
- package/dist/sol/dex/jup/lend.d.ts +0 -640
- package/dist/sol/dex/jup/lend.js +0 -603
- package/dist/sol/dex/jup/portfolio.d.ts +0 -362
- package/dist/sol/dex/jup/portfolio.js +0 -367
- package/dist/sol/dex/jup/price.d.ts +0 -173
- package/dist/sol/dex/jup/price.js +0 -220
- package/dist/sol/dex/jup/recurring.d.ts +0 -437
- package/dist/sol/dex/jup/recurring.js +0 -320
- package/dist/sol/dex/jup/send.d.ts +0 -282
- package/dist/sol/dex/jup/send.js +0 -295
- package/dist/sol/dex/jup/studio.d.ts +0 -457
- package/dist/sol/dex/jup/studio.js +0 -488
- package/dist/sol/dex/jup/tokens.d.ts +0 -767
- package/dist/sol/dex/jup/tokens.js +0 -697
- package/dist/sol/dex/jup/trigger.d.ts +0 -511
- package/dist/sol/dex/jup/trigger.js +0 -397
- package/dist/sol/dex/jup/types.d.ts +0 -433
- package/dist/sol/dex/jup/types.js +0 -5
- package/dist/sol/dex/jup/ultra.d.ts +0 -646
- package/dist/sol/dex/jup/ultra.js +0 -853
- package/dist/sol/dex/meteora/client.d.ts +0 -76
- package/dist/sol/dex/meteora/client.js +0 -219
- package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +0 -61
- package/dist/sol/dex/meteora/damm-v1-bundle.js +0 -112
- package/dist/sol/dex/meteora/damm-v1.d.ts +0 -118
- package/dist/sol/dex/meteora/damm-v1.js +0 -315
- package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +0 -82
- package/dist/sol/dex/meteora/damm-v2-bundle.js +0 -242
- package/dist/sol/dex/meteora/damm-v2.d.ts +0 -172
- package/dist/sol/dex/meteora/damm-v2.js +0 -632
- package/dist/sol/dex/meteora/dbc-bundle.d.ts +0 -123
- package/dist/sol/dex/meteora/dbc-bundle.js +0 -304
- package/dist/sol/dex/meteora/dbc.d.ts +0 -192
- package/dist/sol/dex/meteora/dbc.js +0 -619
- package/dist/sol/dex/meteora/dlmm-bundle.d.ts +0 -39
- package/dist/sol/dex/meteora/dlmm-bundle.js +0 -189
- package/dist/sol/dex/meteora/dlmm.d.ts +0 -157
- package/dist/sol/dex/meteora/dlmm.js +0 -671
- package/dist/sol/dex/meteora/index.d.ts +0 -25
- package/dist/sol/dex/meteora/index.js +0 -65
- package/dist/sol/dex/meteora/types.d.ts +0 -787
- package/dist/sol/dex/meteora/types.js +0 -110
- package/dist/sol/dex/orca/index.d.ts +0 -10
- package/dist/sol/dex/orca/index.js +0 -16
- package/dist/sol/dex/orca/orca-bundle.d.ts +0 -41
- package/dist/sol/dex/orca/orca-bundle.js +0 -173
- package/dist/sol/dex/orca/orca.d.ts +0 -65
- package/dist/sol/dex/orca/orca.js +0 -474
- package/dist/sol/dex/orca/types.d.ts +0 -263
- package/dist/sol/dex/orca/types.js +0 -38
- package/dist/sol/dex/orca/wavebreak-bundle.d.ts +0 -34
- package/dist/sol/dex/orca/wavebreak-bundle.js +0 -198
- package/dist/sol/dex/orca/wavebreak-types.d.ts +0 -227
- package/dist/sol/dex/orca/wavebreak-types.js +0 -23
- package/dist/sol/dex/orca/wavebreak.d.ts +0 -78
- package/dist/sol/dex/orca/wavebreak.js +0 -497
- package/dist/sol/dex/pump/index.d.ts +0 -9
- package/dist/sol/dex/pump/index.js +0 -14
- package/dist/sol/dex/pump/pump-bundle.d.ts +0 -92
- package/dist/sol/dex/pump/pump-bundle.js +0 -383
- package/dist/sol/dex/pump/pump-swap-bundle.d.ts +0 -103
- package/dist/sol/dex/pump/pump-swap-bundle.js +0 -380
- package/dist/sol/dex/pump/pump-swap.d.ts +0 -46
- package/dist/sol/dex/pump/pump-swap.js +0 -199
- package/dist/sol/dex/pump/pump.d.ts +0 -35
- package/dist/sol/dex/pump/pump.js +0 -352
- package/dist/sol/dex/pump/types.d.ts +0 -215
- package/dist/sol/dex/pump/types.js +0 -5
- package/dist/sol/dex/raydium/index.d.ts +0 -8
- package/dist/sol/dex/raydium/index.js +0 -12
- package/dist/sol/dex/raydium/launchlab.d.ts +0 -68
- package/dist/sol/dex/raydium/launchlab.js +0 -210
- package/dist/sol/dex/raydium/raydium-bundle.d.ts +0 -64
- package/dist/sol/dex/raydium/raydium-bundle.js +0 -324
- package/dist/sol/dex/raydium/raydium.d.ts +0 -40
- package/dist/sol/dex/raydium/raydium.js +0 -366
- package/dist/sol/dex/raydium/types.d.ts +0 -240
- package/dist/sol/dex/raydium/types.js +0 -5
- package/dist/sol/index.d.ts +0 -10
- package/dist/sol/index.js +0 -16
- package/dist/sol/jito/bundle.d.ts +0 -90
- package/dist/sol/jito/bundle.js +0 -263
- package/dist/sol/jito/index.d.ts +0 -7
- package/dist/sol/jito/index.js +0 -7
- package/dist/sol/jito/tip.d.ts +0 -51
- package/dist/sol/jito/tip.js +0 -83
- package/dist/sol/jito/types.d.ts +0 -100
- package/dist/sol/jito/types.js +0 -5
- package/dist/sol/token/create-complete.d.ts +0 -115
- package/dist/sol/token/create-complete.js +0 -235
- package/dist/sol/token/create-token.d.ts +0 -57
- package/dist/sol/token/create-token.js +0 -230
- package/dist/sol/token/index.d.ts +0 -9
- package/dist/sol/token/index.js +0 -14
- package/dist/sol/token/metadata-upload.d.ts +0 -86
- package/dist/sol/token/metadata-upload.js +0 -173
- package/dist/sol/token/metadata.d.ts +0 -92
- package/dist/sol/token/metadata.js +0 -274
- package/dist/sol/token/types.d.ts +0 -153
- package/dist/sol/token/types.js +0 -5
- package/dist/sol/types.d.ts +0 -176
- package/dist/sol/types.js +0 -7
- package/dist/sol/utils/balance.d.ts +0 -160
- package/dist/sol/utils/balance.js +0 -638
- package/dist/sol/utils/connection.d.ts +0 -78
- package/dist/sol/utils/connection.js +0 -168
- package/dist/sol/utils/index.d.ts +0 -9
- package/dist/sol/utils/index.js +0 -9
- package/dist/sol/utils/lp-inspect.d.ts +0 -129
- package/dist/sol/utils/lp-inspect.js +0 -900
- package/dist/sol/utils/transfer.d.ts +0 -125
- package/dist/sol/utils/transfer.js +0 -220
- package/dist/sol/utils/wallet.d.ts +0 -107
- package/dist/sol/utils/wallet.js +0 -210
package/README.zh-CN.pdf
ADDED
|
Binary file
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { type FlapSignConfig } from './config.js';
|
|
11
11
|
import type { MerkleSignedResult } from './types.js';
|
|
12
|
-
export type CreateToDexChain = 'bsc';
|
|
12
|
+
export type CreateToDexChain = 'bsc' | 'xlayer';
|
|
13
13
|
export type DexPoolType = 'v2' | 'v3';
|
|
14
14
|
/** 签名配置 */
|
|
15
15
|
export interface CreateToDexSignConfig extends FlapSignConfig {
|
|
@@ -26,9 +26,39 @@ const ERC20_ABI = [
|
|
|
26
26
|
}
|
|
27
27
|
];
|
|
28
28
|
// ==================== 链常量 ====================
|
|
29
|
+
// BSC
|
|
29
30
|
const BSC_PANCAKE_V2_ROUTER = ADDRESSES.BSC.PancakeV2Router;
|
|
30
31
|
const BSC_PANCAKE_V3_ROUTER = ADDRESSES.BSC.PancakeV3Router;
|
|
31
32
|
const BSC_WBNB = ADDRESSES.BSC.WBNB;
|
|
33
|
+
// XLAYER
|
|
34
|
+
const XLAYER_POTATOSWAP_V2_ROUTER = '0x881fb2f98c13d521009464e7d1cbf16e1b394e8e';
|
|
35
|
+
const XLAYER_POTATOSWAP_V3_ROUTER = '0xB45D0149249488333E3F3f9F359807F4b810C1FC';
|
|
36
|
+
const XLAYER_WOKB = '0xe538905cf8410324e03a5a23c1c177a474d59b2b';
|
|
37
|
+
// 链 ID 映射
|
|
38
|
+
const CHAIN_ID_MAP = {
|
|
39
|
+
bsc: 56,
|
|
40
|
+
xlayer: 196,
|
|
41
|
+
};
|
|
42
|
+
// 获取链配置
|
|
43
|
+
function getChainConfig(chain) {
|
|
44
|
+
if (chain === 'xlayer') {
|
|
45
|
+
return {
|
|
46
|
+
chainId: 196,
|
|
47
|
+
v2Router: XLAYER_POTATOSWAP_V2_ROUTER,
|
|
48
|
+
v3Router: XLAYER_POTATOSWAP_V3_ROUTER,
|
|
49
|
+
wrappedNative: XLAYER_WOKB,
|
|
50
|
+
nativeSymbol: 'OKB',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// 默认 BSC
|
|
54
|
+
return {
|
|
55
|
+
chainId: 56,
|
|
56
|
+
v2Router: BSC_PANCAKE_V2_ROUTER,
|
|
57
|
+
v3Router: BSC_PANCAKE_V3_ROUTER,
|
|
58
|
+
wrappedNative: BSC_WBNB,
|
|
59
|
+
nativeSymbol: 'BNB',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
32
62
|
// PancakeSwap Router ABI
|
|
33
63
|
const PANCAKE_V3_ROUTER_ABI = [
|
|
34
64
|
{
|
|
@@ -78,7 +108,8 @@ const USD1_V3_FEE = 100;
|
|
|
78
108
|
const DEFAULT_V3_FEE = 2500;
|
|
79
109
|
// ==================== 工具函数 ====================
|
|
80
110
|
/** 构建 ERC20 approve 交易 */
|
|
81
|
-
async function buildApproveTransaction(wallet, tokenAddress, spenderAddress, amount, nonce, gasPrice, txType
|
|
111
|
+
async function buildApproveTransaction(wallet, tokenAddress, spenderAddress, amount, nonce, gasPrice, txType, chainId = 56 // ✅ 添加 chainId 参数
|
|
112
|
+
) {
|
|
82
113
|
const erc20Interface = new ethers.Interface(ERC20_ABI);
|
|
83
114
|
const data = erc20Interface.encodeFunctionData('approve', [spenderAddress, amount]);
|
|
84
115
|
const tx = {
|
|
@@ -87,7 +118,7 @@ async function buildApproveTransaction(wallet, tokenAddress, spenderAddress, amo
|
|
|
87
118
|
from: wallet.address,
|
|
88
119
|
nonce,
|
|
89
120
|
gasLimit: BigInt(100000), // approve 交易 gas 较低
|
|
90
|
-
chainId
|
|
121
|
+
chainId,
|
|
91
122
|
type: txType
|
|
92
123
|
};
|
|
93
124
|
if (txType === 2) {
|
|
@@ -154,9 +185,12 @@ export async function flapBundleCreateToDex(params) {
|
|
|
154
185
|
// 判断是否使用原生代币
|
|
155
186
|
const useNativeToken = !quoteToken || quoteToken === ZERO_ADDRESS;
|
|
156
187
|
const inputToken = useNativeToken ? ZERO_ADDRESS : quoteToken;
|
|
188
|
+
// ✅ 获取链配置
|
|
189
|
+
const chainConfig = getChainConfig(chain);
|
|
190
|
+
const chainId = chainConfig.chainId;
|
|
157
191
|
// 创建 Provider
|
|
158
192
|
const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
|
|
159
|
-
chainId
|
|
193
|
+
chainId,
|
|
160
194
|
name: chain.toUpperCase()
|
|
161
195
|
});
|
|
162
196
|
const portalAddress = FLAP_PORTAL_ADDRESSES[chain.toUpperCase()];
|
|
@@ -228,7 +262,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
228
262
|
nonce: bribeNonce,
|
|
229
263
|
gasPrice,
|
|
230
264
|
gasLimit: 21000n,
|
|
231
|
-
chainId
|
|
265
|
+
chainId,
|
|
232
266
|
type: txType
|
|
233
267
|
});
|
|
234
268
|
allTransactions.push(bribeTx);
|
|
@@ -305,7 +339,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
305
339
|
from: devWallet.address,
|
|
306
340
|
nonce: devNonce,
|
|
307
341
|
gasLimit: finalGasLimit,
|
|
308
|
-
chainId
|
|
342
|
+
chainId,
|
|
309
343
|
type: txType
|
|
310
344
|
};
|
|
311
345
|
if (txType === 2) {
|
|
@@ -328,7 +362,8 @@ export async function flapBundleCreateToDex(params) {
|
|
|
328
362
|
if (!useNativeToken) {
|
|
329
363
|
const approveNonce = noncesMap.get(addr);
|
|
330
364
|
noncesMap.set(addr, approveNonce + 1);
|
|
331
|
-
const approveTx = await buildApproveTransaction(wallet, quoteToken, portalAddress, curveBuyAmounts[i], approveNonce, gasPrice, txType
|
|
365
|
+
const approveTx = await buildApproveTransaction(wallet, quoteToken, portalAddress, curveBuyAmounts[i], approveNonce, gasPrice, txType, chainId // ✅ 传递 chainId
|
|
366
|
+
);
|
|
332
367
|
signedTxs.push(approveTx);
|
|
333
368
|
}
|
|
334
369
|
// 构建买入交易
|
|
@@ -350,7 +385,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
350
385
|
from: wallet.address,
|
|
351
386
|
nonce: buyNonce,
|
|
352
387
|
gasLimit: buyGasLimit,
|
|
353
|
-
chainId
|
|
388
|
+
chainId,
|
|
354
389
|
type: txType,
|
|
355
390
|
value: useNativeToken ? curveBuyAmounts[i] : 0n
|
|
356
391
|
};
|
|
@@ -375,14 +410,17 @@ export async function flapBundleCreateToDex(params) {
|
|
|
375
410
|
const addr = wallet.address.toLowerCase();
|
|
376
411
|
const signedTxs = [];
|
|
377
412
|
const buyAmount = dexBuyAmounts[i];
|
|
378
|
-
|
|
413
|
+
// ✅ 使用动态 Router 地址
|
|
414
|
+
const smartRouter = dexPoolType === 'v3' ? chainConfig.v3Router : chainConfig.v2Router;
|
|
415
|
+
const wrappedNative = chainConfig.wrappedNative;
|
|
379
416
|
// ✅ 根据 quoteToken 选择 V3 费率
|
|
380
417
|
const actualV3Fee = v3Fee || (useNativeToken ? DEFAULT_V3_FEE : USD1_V3_FEE);
|
|
381
418
|
// ✅ ERC20: 先构建 approve 交易
|
|
382
419
|
if (!useNativeToken) {
|
|
383
420
|
const approveNonce = noncesMap.get(addr);
|
|
384
421
|
noncesMap.set(addr, approveNonce + 1);
|
|
385
|
-
const approveTx = await buildApproveTransaction(wallet, quoteToken, smartRouter, buyAmount, approveNonce, gasPrice, txType
|
|
422
|
+
const approveTx = await buildApproveTransaction(wallet, quoteToken, smartRouter, buyAmount, approveNonce, gasPrice, txType, chainId // ✅ 传递 chainId
|
|
423
|
+
);
|
|
386
424
|
signedTxs.push(approveTx);
|
|
387
425
|
}
|
|
388
426
|
// 构建买入交易
|
|
@@ -394,7 +432,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
394
432
|
if (dexPoolType === 'v3') {
|
|
395
433
|
// V3: exactInputSingle
|
|
396
434
|
const params = {
|
|
397
|
-
tokenIn: useNativeToken ?
|
|
435
|
+
tokenIn: useNativeToken ? wrappedNative : quoteToken,
|
|
398
436
|
tokenOut: tokenAddress,
|
|
399
437
|
fee: actualV3Fee,
|
|
400
438
|
recipient: wallet.address,
|
|
@@ -407,7 +445,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
407
445
|
}
|
|
408
446
|
else {
|
|
409
447
|
// V2: swapExactTokensForTokens
|
|
410
|
-
const path = useNativeToken ? [
|
|
448
|
+
const path = useNativeToken ? [wrappedNative, tokenAddress] : [quoteToken, tokenAddress];
|
|
411
449
|
const swapData = routerInterface.encodeFunctionData('swapExactTokensForTokens', [buyAmount, 0n, path, wallet.address]);
|
|
412
450
|
multicallData = [swapData];
|
|
413
451
|
value = useNativeToken ? buyAmount : 0n;
|
|
@@ -419,7 +457,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
419
457
|
from: wallet.address,
|
|
420
458
|
nonce: buyNonce,
|
|
421
459
|
gasLimit: BigInt(500000),
|
|
422
|
-
chainId
|
|
460
|
+
chainId,
|
|
423
461
|
type: txType,
|
|
424
462
|
value
|
|
425
463
|
};
|
|
@@ -450,7 +488,7 @@ export async function flapBundleCreateToDex(params) {
|
|
|
450
488
|
profitRecipient: getProfitRecipient(),
|
|
451
489
|
hopCount: PROFIT_HOP_COUNT,
|
|
452
490
|
gasPrice,
|
|
453
|
-
chainId
|
|
491
|
+
chainId,
|
|
454
492
|
txType,
|
|
455
493
|
startNonce: profitNonce
|
|
456
494
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECDH + AES-GCM 加密工具(浏览器兼容)
|
|
3
|
+
* 用于将签名交易用服务器公钥加密
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 用服务器公钥加密签名交易(ECDH + AES-GCM)
|
|
7
|
+
*
|
|
8
|
+
* @param signedTransactions 签名后的交易数组
|
|
9
|
+
* @param publicKeyBase64 服务器提供的公钥(Base64 格式)
|
|
10
|
+
* @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
|
|
11
|
+
*/
|
|
12
|
+
export declare function encryptWithPublicKey(signedTransactions: string[], publicKeyBase64: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* 验证公钥格式(Base64)
|
|
15
|
+
*/
|
|
16
|
+
export declare function validatePublicKey(publicKeyBase64: string): boolean;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECDH + AES-GCM 加密工具(浏览器兼容)
|
|
3
|
+
* 用于将签名交易用服务器公钥加密
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 获取全局 crypto 对象(最简单直接的方式)
|
|
7
|
+
*/
|
|
8
|
+
function getCryptoAPI() {
|
|
9
|
+
// 尝试所有可能的全局对象,优先浏览器环境
|
|
10
|
+
const cryptoObj = (typeof window !== 'undefined' && window.crypto) ||
|
|
11
|
+
(typeof self !== 'undefined' && self.crypto) ||
|
|
12
|
+
(typeof global !== 'undefined' && global.crypto) ||
|
|
13
|
+
(typeof globalThis !== 'undefined' && globalThis.crypto);
|
|
14
|
+
if (!cryptoObj) {
|
|
15
|
+
const env = typeof window !== 'undefined' ? 'Browser' : 'Node.js';
|
|
16
|
+
const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
|
|
17
|
+
throw new Error(`❌ Crypto API 不可用。环境: ${env}, 协议: ${protocol}. ` +
|
|
18
|
+
'请确保在 HTTPS 或 localhost 下运行');
|
|
19
|
+
}
|
|
20
|
+
return cryptoObj;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 获取 SubtleCrypto(用于加密操作)
|
|
24
|
+
*/
|
|
25
|
+
function getSubtleCrypto() {
|
|
26
|
+
const crypto = getCryptoAPI();
|
|
27
|
+
if (!crypto.subtle) {
|
|
28
|
+
const protocol = typeof location !== 'undefined' ? location.protocol : 'unknown';
|
|
29
|
+
const hostname = typeof location !== 'undefined' ? location.hostname : 'unknown';
|
|
30
|
+
throw new Error(`❌ SubtleCrypto API 不可用。协议: ${protocol}, 主机: ${hostname}. ` +
|
|
31
|
+
'请确保:1) 使用 HTTPS (或 localhost);2) 浏览器支持 Web Crypto API;' +
|
|
32
|
+
'3) 不在无痕/隐私浏览模式下');
|
|
33
|
+
}
|
|
34
|
+
return crypto.subtle;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Base64 转 ArrayBuffer(优先使用浏览器 API)
|
|
38
|
+
*/
|
|
39
|
+
function base64ToArrayBuffer(base64) {
|
|
40
|
+
// 浏览器环境(优先)
|
|
41
|
+
if (typeof atob !== 'undefined') {
|
|
42
|
+
const binaryString = atob(base64);
|
|
43
|
+
const bytes = new Uint8Array(binaryString.length);
|
|
44
|
+
for (let i = 0; i < binaryString.length; i++) {
|
|
45
|
+
bytes[i] = binaryString.charCodeAt(i);
|
|
46
|
+
}
|
|
47
|
+
return bytes.buffer;
|
|
48
|
+
}
|
|
49
|
+
// Node.js 环境(fallback)
|
|
50
|
+
if (typeof Buffer !== 'undefined') {
|
|
51
|
+
return Buffer.from(base64, 'base64').buffer;
|
|
52
|
+
}
|
|
53
|
+
throw new Error('❌ Base64 解码不可用');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* ArrayBuffer 转 Base64(优先使用浏览器 API)
|
|
57
|
+
*/
|
|
58
|
+
function arrayBufferToBase64(buffer) {
|
|
59
|
+
// 浏览器环境(优先)
|
|
60
|
+
if (typeof btoa !== 'undefined') {
|
|
61
|
+
const bytes = new Uint8Array(buffer);
|
|
62
|
+
let binary = '';
|
|
63
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
64
|
+
binary += String.fromCharCode(bytes[i]);
|
|
65
|
+
}
|
|
66
|
+
return btoa(binary);
|
|
67
|
+
}
|
|
68
|
+
// Node.js 环境(fallback)
|
|
69
|
+
if (typeof Buffer !== 'undefined') {
|
|
70
|
+
return Buffer.from(buffer).toString('base64');
|
|
71
|
+
}
|
|
72
|
+
throw new Error('❌ Base64 编码不可用');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* 生成随机 Hex 字符串
|
|
76
|
+
*/
|
|
77
|
+
function randomHex(length) {
|
|
78
|
+
const crypto = getCryptoAPI();
|
|
79
|
+
const array = new Uint8Array(length);
|
|
80
|
+
crypto.getRandomValues(array);
|
|
81
|
+
return Array.from(array)
|
|
82
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
83
|
+
.join('');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 用服务器公钥加密签名交易(ECDH + AES-GCM)
|
|
87
|
+
*
|
|
88
|
+
* @param signedTransactions 签名后的交易数组
|
|
89
|
+
* @param publicKeyBase64 服务器提供的公钥(Base64 格式)
|
|
90
|
+
* @returns JSON 字符串 {e: 临时公钥, i: IV, d: 密文}
|
|
91
|
+
*/
|
|
92
|
+
export async function encryptWithPublicKey(signedTransactions, publicKeyBase64) {
|
|
93
|
+
try {
|
|
94
|
+
// 0. 获取 SubtleCrypto 和 Crypto API
|
|
95
|
+
const subtle = getSubtleCrypto();
|
|
96
|
+
const crypto = getCryptoAPI();
|
|
97
|
+
// 1. 准备数据
|
|
98
|
+
const payload = {
|
|
99
|
+
signedTransactions,
|
|
100
|
+
timestamp: Date.now(),
|
|
101
|
+
nonce: randomHex(8)
|
|
102
|
+
};
|
|
103
|
+
const plaintext = JSON.stringify(payload);
|
|
104
|
+
// 2. 生成临时 ECDH 密钥对
|
|
105
|
+
const ephemeralKeyPair = await subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveKey']);
|
|
106
|
+
// 3. 导入服务器公钥
|
|
107
|
+
const publicKeyBuffer = base64ToArrayBuffer(publicKeyBase64);
|
|
108
|
+
const publicKey = await subtle.importKey('raw', publicKeyBuffer, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
|
|
109
|
+
// 4. 派生共享密钥(AES-256)
|
|
110
|
+
const sharedKey = await subtle.deriveKey({ name: 'ECDH', public: publicKey }, ephemeralKeyPair.privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt']);
|
|
111
|
+
// 5. AES-GCM 加密
|
|
112
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
113
|
+
const encrypted = await subtle.encrypt({ name: 'AES-GCM', iv }, sharedKey, new TextEncoder().encode(plaintext));
|
|
114
|
+
// 6. 导出临时公钥
|
|
115
|
+
const ephemeralPublicKeyRaw = await subtle.exportKey('raw', ephemeralKeyPair.publicKey);
|
|
116
|
+
// 7. 返回加密包(JSON 格式)
|
|
117
|
+
return JSON.stringify({
|
|
118
|
+
e: arrayBufferToBase64(ephemeralPublicKeyRaw), // 临时公钥
|
|
119
|
+
i: arrayBufferToBase64(iv.buffer), // IV
|
|
120
|
+
d: arrayBufferToBase64(encrypted) // 密文
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new Error(`加密失败: ${error?.message || String(error)}`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 验证公钥格式(Base64)
|
|
129
|
+
*/
|
|
130
|
+
export function validatePublicKey(publicKeyBase64) {
|
|
131
|
+
try {
|
|
132
|
+
if (!publicKeyBase64)
|
|
133
|
+
return false;
|
|
134
|
+
// Base64 字符集验证
|
|
135
|
+
if (!/^[A-Za-z0-9+/=]+$/.test(publicKeyBase64))
|
|
136
|
+
return false;
|
|
137
|
+
// ECDH P-256 公钥固定长度 65 字节(未压缩)
|
|
138
|
+
// Base64 编码后约 88 字符
|
|
139
|
+
if (publicKeyBase64.length < 80 || publicKeyBase64.length > 100)
|
|
140
|
+
return false;
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -66,6 +66,19 @@ export type HoldersMakerParams = {
|
|
|
66
66
|
/** 配置 */
|
|
67
67
|
config: HoldersMakerConfig;
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* ✅ 交易层级(用于按依赖顺序广播)
|
|
71
|
+
* 每层内的交易可以并行广播,层之间需要按顺序等待确认
|
|
72
|
+
*/
|
|
73
|
+
export type TransactionLayer = {
|
|
74
|
+
/** 层级名称 */
|
|
75
|
+
name: string;
|
|
76
|
+
/** 该层的交易索引范围 [startIndex, endIndex) */
|
|
77
|
+
startIndex: number;
|
|
78
|
+
endIndex: number;
|
|
79
|
+
/** 该层交易数量 */
|
|
80
|
+
count: number;
|
|
81
|
+
};
|
|
69
82
|
/** 批次结果 */
|
|
70
83
|
export type BatchResult = {
|
|
71
84
|
batchIndex: number;
|
|
@@ -74,6 +87,10 @@ export type BatchResult = {
|
|
|
74
87
|
txHashes?: string[];
|
|
75
88
|
error?: string;
|
|
76
89
|
walletCount: number;
|
|
90
|
+
/** ✅ 交易层级信息(用于非 Bundle 链按依赖顺序广播) */
|
|
91
|
+
transactionLayers?: TransactionLayer[];
|
|
92
|
+
/** ✅ 分发多跳数 */
|
|
93
|
+
disperseHopCount?: number;
|
|
77
94
|
};
|
|
78
95
|
/** 刷持有人结果 */
|
|
79
96
|
export type HoldersMakerResult = {
|
|
@@ -95,6 +112,8 @@ export type HoldersMakerResult = {
|
|
|
95
112
|
totalBatchCount: number;
|
|
96
113
|
/** 错误信息 */
|
|
97
114
|
error?: string;
|
|
115
|
+
/** ✅ 分发多跳数 */
|
|
116
|
+
disperseHopCount?: number;
|
|
98
117
|
};
|
|
99
118
|
/**
|
|
100
119
|
* 刷持有人(一个 bundle 完成分发+买入)
|
|
@@ -774,13 +774,16 @@ export async function holdersMaker(params) {
|
|
|
774
774
|
success: res.success,
|
|
775
775
|
signedTransactions: res.signedTransactions,
|
|
776
776
|
error: res.error,
|
|
777
|
-
walletCount: res.walletCount
|
|
777
|
+
walletCount: res.walletCount,
|
|
778
|
+
disperseHopCount: disperseHopCount // ✅ 添加分发多跳数
|
|
778
779
|
});
|
|
779
780
|
}
|
|
780
781
|
// ✅ 添加利润多跳钱包到结果
|
|
781
782
|
if (allProfitHopWallets.length > 0) {
|
|
782
783
|
result.profitHopWallets = allProfitHopWallets;
|
|
783
784
|
}
|
|
785
|
+
// ✅ 添加分发多跳数到结果
|
|
786
|
+
result.disperseHopCount = disperseHopCount;
|
|
784
787
|
result.success = result.successBatchCount > 0;
|
|
785
788
|
console.log(`[HoldersMaker] 完成: ${result.successBatchCount}/${result.totalBatchCount} 批成功`);
|
|
786
789
|
}
|
package/package.json
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "four-flap-meme-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.91",
|
|
4
4
|
"description": "SDK for Flap bonding curve and four.meme TokenManager",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
12
|
-
},
|
|
13
|
-
"./sol": {
|
|
14
|
-
"types": "./dist/sol/index.d.ts",
|
|
15
|
-
"import": "./dist/sol/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./sol/*": {
|
|
18
|
-
"types": "./dist/sol/*.d.ts",
|
|
19
|
-
"import": "./dist/sol/*.js"
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
8
|
"files": [
|
|
23
9
|
"dist",
|
|
24
10
|
"src/abis/*.json"
|
|
@@ -43,32 +29,11 @@
|
|
|
43
29
|
"node": ">=18"
|
|
44
30
|
},
|
|
45
31
|
"dependencies": {
|
|
46
|
-
"@metaplex-foundation/mpl-token-metadata": "^3.4.0",
|
|
47
|
-
"@metaplex-foundation/umi": "^1.4.1",
|
|
48
|
-
"@metaplex-foundation/umi-bundle-defaults": "^1.4.1",
|
|
49
|
-
"@metaplex-foundation/umi-web3js-adapters": "^1.4.1",
|
|
50
|
-
"@meteora-ag/cp-amm-sdk": "^1.2.6",
|
|
51
|
-
"@meteora-ag/dlmm": "^1.9.0",
|
|
52
|
-
"@meteora-ag/dynamic-amm-sdk": "^1.4.1",
|
|
53
|
-
"@meteora-ag/dynamic-bonding-curve-sdk": "^1.4.9",
|
|
54
|
-
"@orca-so/common-sdk": "^0.7.0",
|
|
55
|
-
"@orca-so/whirlpools-sdk": "^0.17.0",
|
|
56
|
-
"@pump-fun/pump-sdk": "^1.23.0",
|
|
57
|
-
"@pump-fun/pump-swap-sdk": "^1.11.0",
|
|
58
|
-
"@raydium-io/raydium-sdk-v2": "^0.2.30-alpha",
|
|
59
|
-
"@solana/spl-token": "^0.4.14",
|
|
60
|
-
"@solana/web3.js": "^1.98.4",
|
|
61
32
|
"axios": "^1.12.2",
|
|
62
33
|
"ethers": "^6.11.0",
|
|
63
|
-
"pinata": "^1.10.1"
|
|
64
|
-
"tweetnacl": "^1.0.3"
|
|
65
|
-
},
|
|
66
|
-
"optionalDependencies": {
|
|
67
|
-
"@orca-so/wavebreak": "^1.1.7"
|
|
34
|
+
"pinata": "^1.10.1"
|
|
68
35
|
},
|
|
69
36
|
"devDependencies": {
|
|
70
|
-
"@types/bn.js": "^5.2.0",
|
|
71
|
-
"@types/bs58": "^4.0.4",
|
|
72
37
|
"typescript": "^5.6.3"
|
|
73
38
|
}
|
|
74
|
-
}
|
|
39
|
+
}
|
package/dist/sol/constants.d.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Solana SDK 常量配置
|
|
3
|
-
* @module sol/constants
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Jito 配置
|
|
7
|
-
*
|
|
8
|
-
* 注意:BLOCK_ENGINE_URL 需要由前端传入,不在 SDK 中写死
|
|
9
|
-
*/
|
|
10
|
-
export declare const JITO_CONFIG: {
|
|
11
|
-
/** Tip 账户列表(随机选择一个)- 这些是 Jito 官方账户,固定不变 */
|
|
12
|
-
readonly TIP_ACCOUNTS: readonly ["96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5", "HFqU5x63VTqvQss8hp11i4bVmkzdNaVB6PYjYgNd4W5U", "Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY", "ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49", "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh", "ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt", "DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL", "3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT"];
|
|
13
|
-
/** 最小 Tip(lamports) */
|
|
14
|
-
readonly MIN_TIP_LAMPORTS: 1000;
|
|
15
|
-
/** 默认 Tip(lamports)- 0.00001 SOL */
|
|
16
|
-
readonly DEFAULT_TIP_LAMPORTS: 10000;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Solana 系统程序地址
|
|
20
|
-
*/
|
|
21
|
-
export declare const SYSTEM_PROGRAMS: {
|
|
22
|
-
/** Token Program */
|
|
23
|
-
readonly TOKEN_PROGRAM: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
24
|
-
/** Token-2022 Program */
|
|
25
|
-
readonly TOKEN_2022_PROGRAM: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";
|
|
26
|
-
/** Associated Token Account Program */
|
|
27
|
-
readonly ATA_PROGRAM: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
28
|
-
/** Metaplex Token Metadata Program */
|
|
29
|
-
readonly METADATA_PROGRAM: "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s";
|
|
30
|
-
/** System Program */
|
|
31
|
-
readonly SYSTEM_PROGRAM: "11111111111111111111111111111111";
|
|
32
|
-
/** Rent Sysvar */
|
|
33
|
-
readonly RENT_SYSVAR: "SysvarRent111111111111111111111111111111111";
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Pump.fun 程序地址
|
|
37
|
-
*/
|
|
38
|
-
export declare const PUMP_PROGRAMS: {
|
|
39
|
-
/** Pump Program ID */
|
|
40
|
-
readonly PUMP_PROGRAM: "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P";
|
|
41
|
-
/** Pump Swap Program ID */
|
|
42
|
-
readonly PUMP_SWAP_PROGRAM: "pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA";
|
|
43
|
-
/** Global Config */
|
|
44
|
-
readonly GLOBAL_CONFIG: "4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf";
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Raydium 程序地址
|
|
48
|
-
*/
|
|
49
|
-
export declare const RAYDIUM_PROGRAMS: {
|
|
50
|
-
/** AMM Program ID */
|
|
51
|
-
readonly AMM_PROGRAM: "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";
|
|
52
|
-
/** CLMM Program ID */
|
|
53
|
-
readonly CLMM_PROGRAM: "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK";
|
|
54
|
-
/** LaunchLab Program ID */
|
|
55
|
-
readonly LAUNCHLAB_PROGRAM: "LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj";
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Orca 程序地址
|
|
59
|
-
*/
|
|
60
|
-
export declare const ORCA_PROGRAMS: {
|
|
61
|
-
/** Whirlpool Program ID */
|
|
62
|
-
readonly WHIRLPOOL_PROGRAM: "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc";
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Meteora 程序地址
|
|
66
|
-
*/
|
|
67
|
-
export declare const METEORA_PROGRAMS: {
|
|
68
|
-
/** DLMM Program ID */
|
|
69
|
-
readonly DLMM_PROGRAM: "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo";
|
|
70
|
-
/** DAMM v2 Program ID */
|
|
71
|
-
readonly DAMM_V2_PROGRAM: "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG";
|
|
72
|
-
/** DBC Program ID */
|
|
73
|
-
readonly DBC_PROGRAM: "dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN";
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* 常用代币地址
|
|
77
|
-
*/
|
|
78
|
-
export declare const TOKENS: {
|
|
79
|
-
/** Wrapped SOL */
|
|
80
|
-
readonly SOL: "So11111111111111111111111111111111111111112";
|
|
81
|
-
/** USDC */
|
|
82
|
-
readonly USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
83
|
-
/** USDT */
|
|
84
|
-
readonly USDT: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB";
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* 交易默认配置
|
|
88
|
-
*/
|
|
89
|
-
export declare const TX_CONFIG: {
|
|
90
|
-
/** 默认滑点 1% */
|
|
91
|
-
readonly DEFAULT_SLIPPAGE: 1;
|
|
92
|
-
/** 最大滑点 50% */
|
|
93
|
-
readonly MAX_SLIPPAGE: 50;
|
|
94
|
-
/** 计算单元限制 */
|
|
95
|
-
readonly COMPUTE_UNIT_LIMIT: 200000;
|
|
96
|
-
/** 计算单元价格(microlamports) */
|
|
97
|
-
readonly COMPUTE_UNIT_PRICE: 50000;
|
|
98
|
-
/** 确认超时(毫秒) */
|
|
99
|
-
readonly CONFIRMATION_TIMEOUT: 60000;
|
|
100
|
-
/** 默认 commitment */
|
|
101
|
-
readonly DEFAULT_COMMITMENT: "confirmed";
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* 账户大小(用于计算租金)
|
|
105
|
-
*/
|
|
106
|
-
export declare const ACCOUNT_SIZE: {
|
|
107
|
-
/** Mint 账户大小 */
|
|
108
|
-
readonly MINT: 82;
|
|
109
|
-
/** Token 账户大小 */
|
|
110
|
-
readonly TOKEN_ACCOUNT: 165;
|
|
111
|
-
/** Metadata 账户大小(近似值) */
|
|
112
|
-
readonly METADATA: 679;
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* SOL 单位换算
|
|
116
|
-
*/
|
|
117
|
-
export declare const SOL_DECIMALS = 9;
|
|
118
|
-
export declare const LAMPORTS_PER_SOL = 1000000000;
|
|
119
|
-
/**
|
|
120
|
-
* 将 SOL 转换为 lamports
|
|
121
|
-
*/
|
|
122
|
-
export declare function solToLamports(sol: number): bigint;
|
|
123
|
-
/**
|
|
124
|
-
* 将 lamports 转换为 SOL
|
|
125
|
-
*/
|
|
126
|
-
export declare function lamportsToSol(lamports: bigint): number;
|