four-flap-meme-sdk 1.4.20 → 1.4.21
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/flap/portal-bundle-merkle/encryption.d.ts +16 -0
- package/dist/flap/portal-bundle-merkle/encryption.js +146 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -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/index.d.ts +0 -8
- package/dist/sol/dex/index.js +0 -12
- 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
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Solana SOL 转账功能
|
|
3
|
-
* SDK 只负责构建和签名交易,提交到后端服务器广播
|
|
4
|
-
* @module sol/utils/transfer
|
|
5
|
-
*/
|
|
6
|
-
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
7
|
-
/**
|
|
8
|
-
* 转账项
|
|
9
|
-
*/
|
|
10
|
-
export interface TransferItem {
|
|
11
|
-
to: string;
|
|
12
|
-
amount: bigint;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 签名后的转账交易
|
|
16
|
-
*/
|
|
17
|
-
export interface SignedTransferTransaction {
|
|
18
|
-
/** Base64 编码的交易数据 */
|
|
19
|
-
data: string;
|
|
20
|
-
/** 交易签名 */
|
|
21
|
-
signature: string;
|
|
22
|
-
/** 转账详情 */
|
|
23
|
-
transfers: TransferItem[];
|
|
24
|
-
/** blockhash */
|
|
25
|
-
recentBlockhash: string;
|
|
26
|
-
/** 最后有效区块高度 */
|
|
27
|
-
lastValidBlockHeight: number;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 批量签名结果
|
|
31
|
-
*/
|
|
32
|
-
export interface BatchSignedTransfers {
|
|
33
|
-
/** 签名后的交易列表 */
|
|
34
|
-
transactions: SignedTransferTransaction[];
|
|
35
|
-
/** 总转账数 */
|
|
36
|
-
totalTransfers: number;
|
|
37
|
-
/** 总交易数 */
|
|
38
|
-
totalTransactions: number;
|
|
39
|
-
/** 创建时间 */
|
|
40
|
-
createdAt: number;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* 构建转账指令
|
|
44
|
-
* @param from 发送者公钥
|
|
45
|
-
* @param to 接收者地址
|
|
46
|
-
* @param amount lamports
|
|
47
|
-
*/
|
|
48
|
-
export declare function buildTransferInstruction(from: PublicKey, to: string, amount: bigint): TransactionInstruction;
|
|
49
|
-
/**
|
|
50
|
-
* 构建批量转账指令
|
|
51
|
-
* @param from 发送者公钥
|
|
52
|
-
* @param transfers 转账列表
|
|
53
|
-
*/
|
|
54
|
-
export declare function buildTransferInstructions(from: PublicKey, transfers: TransferItem[]): TransactionInstruction[];
|
|
55
|
-
/**
|
|
56
|
-
* 构建并签名单笔 SOL 转账
|
|
57
|
-
* @param connection Solana 连接
|
|
58
|
-
* @param from 发送者 Keypair
|
|
59
|
-
* @param to 接收者地址
|
|
60
|
-
* @param amount lamports
|
|
61
|
-
*/
|
|
62
|
-
export declare function signTransferSOL(connection: Connection, from: Keypair, to: string, amount: bigint): Promise<SignedTransferTransaction>;
|
|
63
|
-
/**
|
|
64
|
-
* 构建并签名单笔 SOL 转账(使用 SOL 数量)
|
|
65
|
-
*/
|
|
66
|
-
export declare function signTransferSOLAmount(connection: Connection, from: Keypair, to: string, solAmount: number): Promise<SignedTransferTransaction>;
|
|
67
|
-
/**
|
|
68
|
-
* 构建并签名批量转账(单笔交易,多个指令)
|
|
69
|
-
* 单笔交易最多约 20-30 个转账
|
|
70
|
-
* @param connection Solana 连接
|
|
71
|
-
* @param from 发送者 Keypair
|
|
72
|
-
* @param transfers 转账列表
|
|
73
|
-
*/
|
|
74
|
-
export declare function signBatchTransferSOL(connection: Connection, from: Keypair, transfers: TransferItem[]): Promise<SignedTransferTransaction>;
|
|
75
|
-
/**
|
|
76
|
-
* 构建并签名批量转账(多笔交易)
|
|
77
|
-
* 自动分批处理大量转账
|
|
78
|
-
* @param connection Solana 连接
|
|
79
|
-
* @param from 发送者 Keypair
|
|
80
|
-
* @param transfers 转账列表
|
|
81
|
-
* @param batchSize 每批大小(默认 20)
|
|
82
|
-
*/
|
|
83
|
-
export declare function signBatchTransferSOLMultiple(connection: Connection, from: Keypair, transfers: TransferItem[], batchSize?: number): Promise<BatchSignedTransfers>;
|
|
84
|
-
/**
|
|
85
|
-
* 多钱包转账项
|
|
86
|
-
*/
|
|
87
|
-
export interface MultiWalletTransferItem {
|
|
88
|
-
from: Keypair;
|
|
89
|
-
to: string;
|
|
90
|
-
amount: bigint;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 签名多钱包转账(每个钱包一笔交易)
|
|
94
|
-
* 用于归集或分发场景
|
|
95
|
-
* @param connection Solana 连接
|
|
96
|
-
* @param transfers 转账列表
|
|
97
|
-
*/
|
|
98
|
-
export declare function signMultiWalletTransfers(connection: Connection, transfers: MultiWalletTransferItem[]): Promise<BatchSignedTransfers>;
|
|
99
|
-
/**
|
|
100
|
-
* 归集 SOL(多个钱包转到一个地址)
|
|
101
|
-
* @param connection Solana 连接
|
|
102
|
-
* @param wallets 钱包列表
|
|
103
|
-
* @param toAddress 目标地址
|
|
104
|
-
* @param amounts 每个钱包转账金额(lamports),如果为空则转全部(保留 5000 lamports 作为手续费)
|
|
105
|
-
*/
|
|
106
|
-
export declare function signCollectSOL(connection: Connection, wallets: Keypair[], toAddress: string, amounts?: bigint[]): Promise<BatchSignedTransfers>;
|
|
107
|
-
/**
|
|
108
|
-
* 分发 SOL(一个钱包转到多个地址)
|
|
109
|
-
* @param connection Solana 连接
|
|
110
|
-
* @param from 发送者 Keypair
|
|
111
|
-
* @param distributions 分发列表
|
|
112
|
-
*/
|
|
113
|
-
export declare function signDistributeSOL(connection: Connection, from: Keypair, distributions: TransferItem[]): Promise<BatchSignedTransfers>;
|
|
114
|
-
/**
|
|
115
|
-
* 将签名结果转换为后端 API 格式
|
|
116
|
-
*/
|
|
117
|
-
export declare function toBackendFormat(result: BatchSignedTransfers): {
|
|
118
|
-
transactions: Array<{
|
|
119
|
-
data: string;
|
|
120
|
-
signature: string;
|
|
121
|
-
}>;
|
|
122
|
-
totalTransfers: number;
|
|
123
|
-
totalTransactions: number;
|
|
124
|
-
timestamp: number;
|
|
125
|
-
};
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Solana SOL 转账功能
|
|
3
|
-
* SDK 只负责构建和签名交易,提交到后端服务器广播
|
|
4
|
-
* @module sol/utils/transfer
|
|
5
|
-
*/
|
|
6
|
-
import { PublicKey, SystemProgram, Transaction, } from '@solana/web3.js';
|
|
7
|
-
import { solToLamports } from '../constants.js';
|
|
8
|
-
// ==================== 指令构建 ====================
|
|
9
|
-
/**
|
|
10
|
-
* 构建转账指令
|
|
11
|
-
* @param from 发送者公钥
|
|
12
|
-
* @param to 接收者地址
|
|
13
|
-
* @param amount lamports
|
|
14
|
-
*/
|
|
15
|
-
export function buildTransferInstruction(from, to, amount) {
|
|
16
|
-
return SystemProgram.transfer({
|
|
17
|
-
fromPubkey: from,
|
|
18
|
-
toPubkey: new PublicKey(to),
|
|
19
|
-
lamports: amount,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 构建批量转账指令
|
|
24
|
-
* @param from 发送者公钥
|
|
25
|
-
* @param transfers 转账列表
|
|
26
|
-
*/
|
|
27
|
-
export function buildTransferInstructions(from, transfers) {
|
|
28
|
-
return transfers.map(t => buildTransferInstruction(from, t.to, t.amount));
|
|
29
|
-
}
|
|
30
|
-
// ==================== 单笔转账签名 ====================
|
|
31
|
-
/**
|
|
32
|
-
* 构建并签名单笔 SOL 转账
|
|
33
|
-
* @param connection Solana 连接
|
|
34
|
-
* @param from 发送者 Keypair
|
|
35
|
-
* @param to 接收者地址
|
|
36
|
-
* @param amount lamports
|
|
37
|
-
*/
|
|
38
|
-
export async function signTransferSOL(connection, from, to, amount) {
|
|
39
|
-
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('finalized');
|
|
40
|
-
const transaction = new Transaction().add(buildTransferInstruction(from.publicKey, to, amount));
|
|
41
|
-
transaction.recentBlockhash = blockhash;
|
|
42
|
-
transaction.feePayer = from.publicKey;
|
|
43
|
-
transaction.sign(from);
|
|
44
|
-
const serialized = transaction.serialize();
|
|
45
|
-
return {
|
|
46
|
-
data: Buffer.from(serialized).toString('base64'),
|
|
47
|
-
signature: transaction.signature ? Buffer.from(transaction.signature).toString('base64') : '',
|
|
48
|
-
transfers: [{ to, amount }],
|
|
49
|
-
recentBlockhash: blockhash,
|
|
50
|
-
lastValidBlockHeight,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* 构建并签名单笔 SOL 转账(使用 SOL 数量)
|
|
55
|
-
*/
|
|
56
|
-
export async function signTransferSOLAmount(connection, from, to, solAmount) {
|
|
57
|
-
const lamports = solToLamports(solAmount);
|
|
58
|
-
return signTransferSOL(connection, from, to, lamports);
|
|
59
|
-
}
|
|
60
|
-
// ==================== 批量转账签名 ====================
|
|
61
|
-
/**
|
|
62
|
-
* 构建并签名批量转账(单笔交易,多个指令)
|
|
63
|
-
* 单笔交易最多约 20-30 个转账
|
|
64
|
-
* @param connection Solana 连接
|
|
65
|
-
* @param from 发送者 Keypair
|
|
66
|
-
* @param transfers 转账列表
|
|
67
|
-
*/
|
|
68
|
-
export async function signBatchTransferSOL(connection, from, transfers) {
|
|
69
|
-
if (transfers.length === 0) {
|
|
70
|
-
throw new Error('No transfers provided');
|
|
71
|
-
}
|
|
72
|
-
if (transfers.length > 20) {
|
|
73
|
-
throw new Error(`Too many transfers (${transfers.length}). Max 20 per transaction. Use signBatchTransferSOLMultiple instead.`);
|
|
74
|
-
}
|
|
75
|
-
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('finalized');
|
|
76
|
-
const transaction = new Transaction();
|
|
77
|
-
for (const transfer of transfers) {
|
|
78
|
-
transaction.add(buildTransferInstruction(from.publicKey, transfer.to, transfer.amount));
|
|
79
|
-
}
|
|
80
|
-
transaction.recentBlockhash = blockhash;
|
|
81
|
-
transaction.feePayer = from.publicKey;
|
|
82
|
-
transaction.sign(from);
|
|
83
|
-
const serialized = transaction.serialize();
|
|
84
|
-
return {
|
|
85
|
-
data: Buffer.from(serialized).toString('base64'),
|
|
86
|
-
signature: transaction.signature ? Buffer.from(transaction.signature).toString('base64') : '',
|
|
87
|
-
transfers,
|
|
88
|
-
recentBlockhash: blockhash,
|
|
89
|
-
lastValidBlockHeight,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 构建并签名批量转账(多笔交易)
|
|
94
|
-
* 自动分批处理大量转账
|
|
95
|
-
* @param connection Solana 连接
|
|
96
|
-
* @param from 发送者 Keypair
|
|
97
|
-
* @param transfers 转账列表
|
|
98
|
-
* @param batchSize 每批大小(默认 20)
|
|
99
|
-
*/
|
|
100
|
-
export async function signBatchTransferSOLMultiple(connection, from, transfers, batchSize = 20) {
|
|
101
|
-
if (transfers.length === 0) {
|
|
102
|
-
throw new Error('No transfers provided');
|
|
103
|
-
}
|
|
104
|
-
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('finalized');
|
|
105
|
-
const transactions = [];
|
|
106
|
-
// 分批处理
|
|
107
|
-
for (let i = 0; i < transfers.length; i += batchSize) {
|
|
108
|
-
const batch = transfers.slice(i, i + batchSize);
|
|
109
|
-
const transaction = new Transaction();
|
|
110
|
-
for (const transfer of batch) {
|
|
111
|
-
transaction.add(buildTransferInstruction(from.publicKey, transfer.to, transfer.amount));
|
|
112
|
-
}
|
|
113
|
-
transaction.recentBlockhash = blockhash;
|
|
114
|
-
transaction.feePayer = from.publicKey;
|
|
115
|
-
transaction.sign(from);
|
|
116
|
-
const serialized = transaction.serialize();
|
|
117
|
-
transactions.push({
|
|
118
|
-
data: Buffer.from(serialized).toString('base64'),
|
|
119
|
-
signature: transaction.signature ? Buffer.from(transaction.signature).toString('base64') : '',
|
|
120
|
-
transfers: batch,
|
|
121
|
-
recentBlockhash: blockhash,
|
|
122
|
-
lastValidBlockHeight,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
return {
|
|
126
|
-
transactions,
|
|
127
|
-
totalTransfers: transfers.length,
|
|
128
|
-
totalTransactions: transactions.length,
|
|
129
|
-
createdAt: Date.now(),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 签名多钱包转账(每个钱包一笔交易)
|
|
134
|
-
* 用于归集或分发场景
|
|
135
|
-
* @param connection Solana 连接
|
|
136
|
-
* @param transfers 转账列表
|
|
137
|
-
*/
|
|
138
|
-
export async function signMultiWalletTransfers(connection, transfers) {
|
|
139
|
-
if (transfers.length === 0) {
|
|
140
|
-
throw new Error('No transfers provided');
|
|
141
|
-
}
|
|
142
|
-
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('finalized');
|
|
143
|
-
const transactions = [];
|
|
144
|
-
for (const transfer of transfers) {
|
|
145
|
-
const transaction = new Transaction().add(buildTransferInstruction(transfer.from.publicKey, transfer.to, transfer.amount));
|
|
146
|
-
transaction.recentBlockhash = blockhash;
|
|
147
|
-
transaction.feePayer = transfer.from.publicKey;
|
|
148
|
-
transaction.sign(transfer.from);
|
|
149
|
-
const serialized = transaction.serialize();
|
|
150
|
-
transactions.push({
|
|
151
|
-
data: Buffer.from(serialized).toString('base64'),
|
|
152
|
-
signature: transaction.signature ? Buffer.from(transaction.signature).toString('base64') : '',
|
|
153
|
-
transfers: [{ to: transfer.to, amount: transfer.amount }],
|
|
154
|
-
recentBlockhash: blockhash,
|
|
155
|
-
lastValidBlockHeight,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
transactions,
|
|
160
|
-
totalTransfers: transfers.length,
|
|
161
|
-
totalTransactions: transactions.length,
|
|
162
|
-
createdAt: Date.now(),
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* 归集 SOL(多个钱包转到一个地址)
|
|
167
|
-
* @param connection Solana 连接
|
|
168
|
-
* @param wallets 钱包列表
|
|
169
|
-
* @param toAddress 目标地址
|
|
170
|
-
* @param amounts 每个钱包转账金额(lamports),如果为空则转全部(保留 5000 lamports 作为手续费)
|
|
171
|
-
*/
|
|
172
|
-
export async function signCollectSOL(connection, wallets, toAddress, amounts) {
|
|
173
|
-
const transfers = [];
|
|
174
|
-
for (let i = 0; i < wallets.length; i++) {
|
|
175
|
-
const wallet = wallets[i];
|
|
176
|
-
let amount;
|
|
177
|
-
if (amounts && amounts[i] !== undefined) {
|
|
178
|
-
amount = amounts[i];
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
// 查询余额,保留 5000 lamports 作为手续费
|
|
182
|
-
const balance = await connection.getBalance(wallet.publicKey);
|
|
183
|
-
const reserved = BigInt(5000);
|
|
184
|
-
amount = BigInt(balance) > reserved ? BigInt(balance) - reserved : BigInt(0);
|
|
185
|
-
}
|
|
186
|
-
if (amount > 0) {
|
|
187
|
-
transfers.push({
|
|
188
|
-
from: wallet,
|
|
189
|
-
to: toAddress,
|
|
190
|
-
amount,
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return signMultiWalletTransfers(connection, transfers);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* 分发 SOL(一个钱包转到多个地址)
|
|
198
|
-
* @param connection Solana 连接
|
|
199
|
-
* @param from 发送者 Keypair
|
|
200
|
-
* @param distributions 分发列表
|
|
201
|
-
*/
|
|
202
|
-
export async function signDistributeSOL(connection, from, distributions) {
|
|
203
|
-
// 使用批量转账
|
|
204
|
-
return signBatchTransferSOLMultiple(connection, from, distributions);
|
|
205
|
-
}
|
|
206
|
-
// ==================== 工具函数 ====================
|
|
207
|
-
/**
|
|
208
|
-
* 将签名结果转换为后端 API 格式
|
|
209
|
-
*/
|
|
210
|
-
export function toBackendFormat(result) {
|
|
211
|
-
return {
|
|
212
|
-
transactions: result.transactions.map(tx => ({
|
|
213
|
-
data: tx.data,
|
|
214
|
-
signature: tx.signature,
|
|
215
|
-
})),
|
|
216
|
-
totalTransfers: result.totalTransfers,
|
|
217
|
-
totalTransactions: result.totalTransactions,
|
|
218
|
-
timestamp: result.createdAt,
|
|
219
|
-
};
|
|
220
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Solana 钱包工具
|
|
3
|
-
* @module sol/utils/wallet
|
|
4
|
-
*/
|
|
5
|
-
import { Keypair, PublicKey } from '@solana/web3.js';
|
|
6
|
-
import type { WalletGenerateResult } from '../types.js';
|
|
7
|
-
/**
|
|
8
|
-
* 批量生成钱包的详细结果
|
|
9
|
-
*/
|
|
10
|
-
export interface BatchWalletGenerateResult {
|
|
11
|
-
wallets: WalletGenerateResult[];
|
|
12
|
-
count: number;
|
|
13
|
-
/** 所有地址列表(方便使用) */
|
|
14
|
-
addresses: string[];
|
|
15
|
-
/** 所有私钥列表(base58) */
|
|
16
|
-
secretKeys: string[];
|
|
17
|
-
/** Keypair 对象列表(方便直接使用) */
|
|
18
|
-
keypairs: Keypair[];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 生成新的 Solana 钱包
|
|
22
|
-
* @returns 钱包信息
|
|
23
|
-
*/
|
|
24
|
-
export declare function generateKeypair(): WalletGenerateResult;
|
|
25
|
-
/**
|
|
26
|
-
* 批量生成钱包
|
|
27
|
-
* @param count 数量
|
|
28
|
-
* @returns 钱包列表
|
|
29
|
-
*/
|
|
30
|
-
export declare function generateKeypairs(count: number): WalletGenerateResult[];
|
|
31
|
-
/**
|
|
32
|
-
* 批量生成钱包(增强版,返回更多信息)
|
|
33
|
-
* @param count 数量
|
|
34
|
-
* @returns 详细结果
|
|
35
|
-
*/
|
|
36
|
-
export declare function batchGenerateWallets(count: number): BatchWalletGenerateResult;
|
|
37
|
-
/**
|
|
38
|
-
* 从私钥列表批量导入钱包
|
|
39
|
-
* @param secretKeys 私钥列表(base58 字符串)
|
|
40
|
-
* @returns 导入结果
|
|
41
|
-
*/
|
|
42
|
-
export declare function batchImportWallets(secretKeys: string[]): {
|
|
43
|
-
keypairs: Keypair[];
|
|
44
|
-
addresses: string[];
|
|
45
|
-
failed: Array<{
|
|
46
|
-
index: number;
|
|
47
|
-
secretKey: string;
|
|
48
|
-
error: string;
|
|
49
|
-
}>;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* 从私钥导入钱包
|
|
53
|
-
* @param secretKey 私钥(Uint8Array 或 base58 字符串)
|
|
54
|
-
* @returns Keypair
|
|
55
|
-
*/
|
|
56
|
-
export declare function keypairFromSecretKey(secretKey: Uint8Array | string): Keypair;
|
|
57
|
-
/**
|
|
58
|
-
* 导出私钥为 base58 格式
|
|
59
|
-
* @param keypair Keypair
|
|
60
|
-
* @returns base58 编码的私钥
|
|
61
|
-
*/
|
|
62
|
-
export declare function exportSecretKey(keypair: Keypair): string;
|
|
63
|
-
/**
|
|
64
|
-
* 导出私钥为 Uint8Array
|
|
65
|
-
* @param keypair Keypair
|
|
66
|
-
* @returns Uint8Array 私钥
|
|
67
|
-
*/
|
|
68
|
-
export declare function exportSecretKeyArray(keypair: Keypair): Uint8Array;
|
|
69
|
-
/**
|
|
70
|
-
* 验证 Solana 地址格式
|
|
71
|
-
* @param address 地址字符串
|
|
72
|
-
* @returns 是否有效
|
|
73
|
-
*/
|
|
74
|
-
export declare function isValidAddress(address: string): boolean;
|
|
75
|
-
/**
|
|
76
|
-
* 验证私钥格式
|
|
77
|
-
* @param secretKey 私钥(base58 字符串)
|
|
78
|
-
* @returns 是否有效
|
|
79
|
-
*/
|
|
80
|
-
export declare function isValidSecretKey(secretKey: string): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* 从私钥获取公钥/地址
|
|
83
|
-
* @param secretKey 私钥(Uint8Array 或 base58 字符串)
|
|
84
|
-
* @returns 公钥地址
|
|
85
|
-
*/
|
|
86
|
-
export declare function getAddressFromSecretKey(secretKey: Uint8Array | string): string;
|
|
87
|
-
/**
|
|
88
|
-
* 创建 PublicKey 对象
|
|
89
|
-
* @param address 地址字符串
|
|
90
|
-
* @returns PublicKey
|
|
91
|
-
*/
|
|
92
|
-
export declare function toPublicKey(address: string): PublicKey;
|
|
93
|
-
/**
|
|
94
|
-
* 比较两个地址是否相同
|
|
95
|
-
* @param addr1 地址1
|
|
96
|
-
* @param addr2 地址2
|
|
97
|
-
* @returns 是否相同
|
|
98
|
-
*/
|
|
99
|
-
export declare function isSameAddress(addr1: string, addr2: string): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* 缩短地址显示
|
|
102
|
-
* @param address 完整地址
|
|
103
|
-
* @param prefixLength 前缀长度(默认4)
|
|
104
|
-
* @param suffixLength 后缀长度(默认4)
|
|
105
|
-
* @returns 缩短后的地址
|
|
106
|
-
*/
|
|
107
|
-
export declare function shortenAddress(address: string, prefixLength?: number, suffixLength?: number): string;
|
package/dist/sol/utils/wallet.js
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Solana 钱包工具
|
|
3
|
-
* @module sol/utils/wallet
|
|
4
|
-
*/
|
|
5
|
-
import { Keypair, PublicKey } from '@solana/web3.js';
|
|
6
|
-
import bs58 from 'bs58';
|
|
7
|
-
/**
|
|
8
|
-
* 生成新的 Solana 钱包
|
|
9
|
-
* @returns 钱包信息
|
|
10
|
-
*/
|
|
11
|
-
export function generateKeypair() {
|
|
12
|
-
const keypair = Keypair.generate();
|
|
13
|
-
return {
|
|
14
|
-
publicKey: keypair.publicKey.toBase58(),
|
|
15
|
-
secretKey: keypair.secretKey,
|
|
16
|
-
secretKeyBase58: bs58.encode(keypair.secretKey),
|
|
17
|
-
address: keypair.publicKey.toBase58(),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 批量生成钱包
|
|
22
|
-
* @param count 数量
|
|
23
|
-
* @returns 钱包列表
|
|
24
|
-
*/
|
|
25
|
-
export function generateKeypairs(count) {
|
|
26
|
-
const wallets = [];
|
|
27
|
-
for (let i = 0; i < count; i++) {
|
|
28
|
-
wallets.push(generateKeypair());
|
|
29
|
-
}
|
|
30
|
-
return wallets;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 批量生成钱包(增强版,返回更多信息)
|
|
34
|
-
* @param count 数量
|
|
35
|
-
* @returns 详细结果
|
|
36
|
-
*/
|
|
37
|
-
export function batchGenerateWallets(count) {
|
|
38
|
-
const wallets = [];
|
|
39
|
-
const addresses = [];
|
|
40
|
-
const secretKeys = [];
|
|
41
|
-
const keypairs = [];
|
|
42
|
-
for (let i = 0; i < count; i++) {
|
|
43
|
-
const keypair = Keypair.generate();
|
|
44
|
-
const address = keypair.publicKey.toBase58();
|
|
45
|
-
const secretKeyBase58 = bs58.encode(keypair.secretKey);
|
|
46
|
-
wallets.push({
|
|
47
|
-
publicKey: address,
|
|
48
|
-
secretKey: keypair.secretKey,
|
|
49
|
-
secretKeyBase58,
|
|
50
|
-
address,
|
|
51
|
-
});
|
|
52
|
-
addresses.push(address);
|
|
53
|
-
secretKeys.push(secretKeyBase58);
|
|
54
|
-
keypairs.push(keypair);
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
wallets,
|
|
58
|
-
count,
|
|
59
|
-
addresses,
|
|
60
|
-
secretKeys,
|
|
61
|
-
keypairs,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 从私钥列表批量导入钱包
|
|
66
|
-
* @param secretKeys 私钥列表(base58 字符串)
|
|
67
|
-
* @returns 导入结果
|
|
68
|
-
*/
|
|
69
|
-
export function batchImportWallets(secretKeys) {
|
|
70
|
-
const keypairs = [];
|
|
71
|
-
const addresses = [];
|
|
72
|
-
const failed = [];
|
|
73
|
-
for (let i = 0; i < secretKeys.length; i++) {
|
|
74
|
-
try {
|
|
75
|
-
const keypair = keypairFromSecretKey(secretKeys[i]);
|
|
76
|
-
keypairs.push(keypair);
|
|
77
|
-
addresses.push(keypair.publicKey.toBase58());
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
failed.push({
|
|
81
|
-
index: i,
|
|
82
|
-
secretKey: secretKeys[i].slice(0, 8) + '...', // 只显示前8位
|
|
83
|
-
error: error.message,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
keypairs,
|
|
89
|
-
addresses,
|
|
90
|
-
failed,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 从私钥导入钱包
|
|
95
|
-
* @param secretKey 私钥(Uint8Array 或 base58 字符串)
|
|
96
|
-
* @returns Keypair
|
|
97
|
-
*/
|
|
98
|
-
export function keypairFromSecretKey(secretKey) {
|
|
99
|
-
try {
|
|
100
|
-
let keyArray;
|
|
101
|
-
if (typeof secretKey === 'string') {
|
|
102
|
-
// base58 格式
|
|
103
|
-
keyArray = bs58.decode(secretKey);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
keyArray = secretKey;
|
|
107
|
-
}
|
|
108
|
-
// 验证私钥长度
|
|
109
|
-
if (keyArray.length !== 64) {
|
|
110
|
-
throw new Error(`Invalid secret key length: ${keyArray.length}, expected 64`);
|
|
111
|
-
}
|
|
112
|
-
return Keypair.fromSecretKey(keyArray);
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
throw new Error(`Failed to import keypair: ${error.message}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* 导出私钥为 base58 格式
|
|
120
|
-
* @param keypair Keypair
|
|
121
|
-
* @returns base58 编码的私钥
|
|
122
|
-
*/
|
|
123
|
-
export function exportSecretKey(keypair) {
|
|
124
|
-
return bs58.encode(keypair.secretKey);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* 导出私钥为 Uint8Array
|
|
128
|
-
* @param keypair Keypair
|
|
129
|
-
* @returns Uint8Array 私钥
|
|
130
|
-
*/
|
|
131
|
-
export function exportSecretKeyArray(keypair) {
|
|
132
|
-
return keypair.secretKey;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* 验证 Solana 地址格式
|
|
136
|
-
* @param address 地址字符串
|
|
137
|
-
* @returns 是否有效
|
|
138
|
-
*/
|
|
139
|
-
export function isValidAddress(address) {
|
|
140
|
-
try {
|
|
141
|
-
new PublicKey(address);
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
catch {
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* 验证私钥格式
|
|
150
|
-
* @param secretKey 私钥(base58 字符串)
|
|
151
|
-
* @returns 是否有效
|
|
152
|
-
*/
|
|
153
|
-
export function isValidSecretKey(secretKey) {
|
|
154
|
-
try {
|
|
155
|
-
const decoded = bs58.decode(secretKey);
|
|
156
|
-
return decoded.length === 64;
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* 从私钥获取公钥/地址
|
|
164
|
-
* @param secretKey 私钥(Uint8Array 或 base58 字符串)
|
|
165
|
-
* @returns 公钥地址
|
|
166
|
-
*/
|
|
167
|
-
export function getAddressFromSecretKey(secretKey) {
|
|
168
|
-
const keypair = keypairFromSecretKey(secretKey);
|
|
169
|
-
return keypair.publicKey.toBase58();
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* 创建 PublicKey 对象
|
|
173
|
-
* @param address 地址字符串
|
|
174
|
-
* @returns PublicKey
|
|
175
|
-
*/
|
|
176
|
-
export function toPublicKey(address) {
|
|
177
|
-
if (!isValidAddress(address)) {
|
|
178
|
-
throw new Error(`Invalid Solana address: ${address}`);
|
|
179
|
-
}
|
|
180
|
-
return new PublicKey(address);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* 比较两个地址是否相同
|
|
184
|
-
* @param addr1 地址1
|
|
185
|
-
* @param addr2 地址2
|
|
186
|
-
* @returns 是否相同
|
|
187
|
-
*/
|
|
188
|
-
export function isSameAddress(addr1, addr2) {
|
|
189
|
-
try {
|
|
190
|
-
const pk1 = new PublicKey(addr1);
|
|
191
|
-
const pk2 = new PublicKey(addr2);
|
|
192
|
-
return pk1.equals(pk2);
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* 缩短地址显示
|
|
200
|
-
* @param address 完整地址
|
|
201
|
-
* @param prefixLength 前缀长度(默认4)
|
|
202
|
-
* @param suffixLength 后缀长度(默认4)
|
|
203
|
-
* @returns 缩短后的地址
|
|
204
|
-
*/
|
|
205
|
-
export function shortenAddress(address, prefixLength = 4, suffixLength = 4) {
|
|
206
|
-
if (address.length <= prefixLength + suffixLength + 3) {
|
|
207
|
-
return address;
|
|
208
|
-
}
|
|
209
|
-
return `${address.slice(0, prefixLength)}...${address.slice(-suffixLength)}`;
|
|
210
|
-
}
|