four-flap-meme-sdk 1.4.95 → 1.4.96
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/dist/contracts/tm-bundle-merkle/config.d.ts +0 -1
- package/dist/contracts/tm-bundle-merkle/config.js +0 -1
- package/dist/contracts/tm-bundle-merkle/core.js +13 -9
- package/dist/flap/portal-bundle-merkle/config.d.ts +0 -1
- package/dist/flap/portal-bundle-merkle/config.js +0 -1
- package/package.json +2 -2
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +0 -16
- package/dist/flap/portal-bundle-merkle/encryption.js +0 -146
|
@@ -45,7 +45,6 @@ export declare function shouldExtractProfit(config?: FourAnyConfig): boolean;
|
|
|
45
45
|
export declare function getProfitRateBps(config?: FourAnyConfig): number;
|
|
46
46
|
/**
|
|
47
47
|
* 获取利润接收地址
|
|
48
|
-
* ✅ 硬编码:0xe8D0334fAf713884133640CAEe4ECdd2106AF103
|
|
49
48
|
*/
|
|
50
49
|
export declare function getProfitRecipient(config?: FourAnyConfig): string;
|
|
51
50
|
/**
|
|
@@ -54,6 +54,9 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
54
54
|
}
|
|
55
55
|
const accessToken = await loginFourClient(devWallet, fourClient);
|
|
56
56
|
const imgUrl = await resolveTokenImage(fourClient, tokenInfo, accessToken);
|
|
57
|
+
// ✅ 兼容:历史调用可能把 Dev 首买金额塞在 buyAmounts[0],而不是 tokenInfo.preSale
|
|
58
|
+
// Four 官方 API/链上 createArg 使用 preSale 表达“创建者预购金额”
|
|
59
|
+
const effectivePreSaleStr = (tokenInfo.preSale && String(tokenInfo.preSale).trim().length > 0 ? String(tokenInfo.preSale) : String(buyAmounts[0] ?? '0'));
|
|
57
60
|
const createResp = await fourClient.createToken(accessToken, {
|
|
58
61
|
name: tokenInfo.name,
|
|
59
62
|
shortName: tokenInfo.symbol,
|
|
@@ -64,7 +67,7 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
64
67
|
webUrl: tokenInfo.webUrl,
|
|
65
68
|
twitterUrl: tokenInfo.twitterUrl,
|
|
66
69
|
telegramUrl: tokenInfo.telegramUrl,
|
|
67
|
-
preSale:
|
|
70
|
+
preSale: effectivePreSaleStr || '0',
|
|
68
71
|
onlyMPC: false,
|
|
69
72
|
lpTradingFee: 0.0025,
|
|
70
73
|
symbol: 'BNB',
|
|
@@ -83,7 +86,8 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
83
86
|
// ✅ 单笔交易: 和 Four.meme 官网一样
|
|
84
87
|
// 计算利润
|
|
85
88
|
const extractProfit = shouldExtractProfit(config);
|
|
86
|
-
|
|
89
|
+
// ✅ 对 create 流程来说,“买入金额”就是 preSale(创建者预购)
|
|
90
|
+
const originalBuyAmount = ethers.parseEther(effectivePreSaleStr || '0');
|
|
87
91
|
let actualBuyFunds;
|
|
88
92
|
let profitAmount;
|
|
89
93
|
if (extractProfit) {
|
|
@@ -99,13 +103,13 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
99
103
|
const bribeAmount = getBribeAmount(config);
|
|
100
104
|
const needBribeTx = bribeAmount > 0n;
|
|
101
105
|
const b0AmountWei = ethers.parseEther(params.b0Amount ?? '0');
|
|
102
|
-
const preSaleWei =
|
|
103
|
-
// ✅
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
+
const preSaleWei = effectivePreSaleStr ? ethers.parseEther(effectivePreSaleStr) : 0n;
|
|
107
|
+
// ✅ 关键修复:
|
|
108
|
+
// createToken 的预购金额由 createArg.preSale 决定;因此这里只需要支付:创建费 + b0Amount + preSale
|
|
109
|
+
// 不要把“其它买入金额”额外塞进 msg.value,否则会被合约退回,造成“看起来没买到”的误解。
|
|
110
|
+
const valueWei = PLATFORM_CREATE_FEE + b0AmountWei + preSaleWei;
|
|
106
111
|
const tmCreate = new ethers.Contract(tmCreateAddr, TM2_ABI, devWallet);
|
|
107
|
-
const createTxUnsigned = await tmCreate.createToken.populateTransaction(createResp.createArg, createResp.signature, { value: valueWei }
|
|
108
|
-
);
|
|
112
|
+
const createTxUnsigned = await tmCreate.createToken.populateTransaction(createResp.createArg, createResp.signature, { value: valueWei });
|
|
109
113
|
// ✅ 贿赂交易放在首位(由 devWallet 发送)
|
|
110
114
|
let bribeNonce;
|
|
111
115
|
if (needBribeTx) {
|
|
@@ -125,7 +129,7 @@ export async function createTokenWithBundleBuyMerkle(params) {
|
|
|
125
129
|
...createTxUnsigned,
|
|
126
130
|
from: devWallet.address,
|
|
127
131
|
nonce: await nonceManager.getNextNonce(devWallet),
|
|
128
|
-
gasLimit: getGasLimit(config, 1500000),
|
|
132
|
+
gasLimit: getGasLimit(config, 1500000),
|
|
129
133
|
gasPrice,
|
|
130
134
|
chainId,
|
|
131
135
|
type: getTxType(config),
|
|
@@ -46,7 +46,6 @@ export declare function shouldExtractProfit(config?: FlapAnyConfig): boolean;
|
|
|
46
46
|
export declare function getProfitRateBps(config?: FlapAnyConfig): number;
|
|
47
47
|
/**
|
|
48
48
|
* 获取利润接收地址
|
|
49
|
-
* ✅ 硬编码:0xe8D0334fAf713884133640CAEe4ECdd2106AF103
|
|
50
49
|
*/
|
|
51
50
|
export declare function getProfitRecipient(config?: FlapAnyConfig): string;
|
|
52
51
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "four-flap-meme-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.96",
|
|
4
4
|
"description": "SDK for Flap bonding curve and four.meme TokenManager",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.6.3"
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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;
|
|
@@ -1,146 +0,0 @@
|
|
|
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
|
-
}
|