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,497 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Orca Wavebreak 核心功能
|
|
3
|
-
* Wavebreak 是 Orca 的代币发射平台(类似 Pump.fun)
|
|
4
|
-
*
|
|
5
|
-
* 由于 Wavebreak SDK 使用 @solana/kit(与 @solana/web3.js 类型不兼容),
|
|
6
|
-
* 我们使用 SDK 的编码器和数学函数,但手动构建 @solana/web3.js 的交易指令。
|
|
7
|
-
*/
|
|
8
|
-
import { PublicKey, Keypair, Transaction, TransactionInstruction, SystemProgram, ComputeBudgetProgram, } from '@solana/web3.js';
|
|
9
|
-
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, } from '@solana/spl-token';
|
|
10
|
-
import { WAVEBREAK_CONSTANTS } from './wavebreak-types.js';
|
|
11
|
-
// ============================================================================
|
|
12
|
-
// Wavebreak SDK 导入(动态导入以避免类型冲突)
|
|
13
|
-
// ============================================================================
|
|
14
|
-
let wavebreakSdk = null;
|
|
15
|
-
async function loadWavebreakSdk() {
|
|
16
|
-
if (!wavebreakSdk) {
|
|
17
|
-
wavebreakSdk = await import('@orca-so/wavebreak');
|
|
18
|
-
}
|
|
19
|
-
return wavebreakSdk;
|
|
20
|
-
}
|
|
21
|
-
// ============================================================================
|
|
22
|
-
// PDA 计算
|
|
23
|
-
// ============================================================================
|
|
24
|
-
/**
|
|
25
|
-
* 计算 Bonding Curve PDA 地址
|
|
26
|
-
*/
|
|
27
|
-
export async function getWavebreakBondingCurveAddress(baseMint) {
|
|
28
|
-
const sdk = await loadWavebreakSdk();
|
|
29
|
-
const mintStr = typeof baseMint === 'string' ? baseMint : baseMint.toBase58();
|
|
30
|
-
const [address] = await sdk.getBondingCurveAddress(mintStr);
|
|
31
|
-
return new PublicKey(address);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 同步计算 Bonding Curve PDA 地址(使用 @solana/web3.js)
|
|
35
|
-
*/
|
|
36
|
-
export function getWavebreakBondingCurveAddressSync(baseMint) {
|
|
37
|
-
const mintPubkey = typeof baseMint === 'string' ? new PublicKey(baseMint) : baseMint;
|
|
38
|
-
const [bondingCurve] = PublicKey.findProgramAddressSync([Buffer.from('bonding_curve'), mintPubkey.toBuffer()], new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID));
|
|
39
|
-
return bondingCurve;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 计算 Quote Vault PDA 地址
|
|
43
|
-
*/
|
|
44
|
-
export function getWavebreakQuoteVaultAddressSync(bondingCurve) {
|
|
45
|
-
const bcPubkey = typeof bondingCurve === 'string' ? new PublicKey(bondingCurve) : bondingCurve;
|
|
46
|
-
const [quoteVault] = PublicKey.findProgramAddressSync([Buffer.from('quote_vault'), bcPubkey.toBuffer()], new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID));
|
|
47
|
-
return quoteVault;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* 计算 LP Escrow PDA 地址
|
|
51
|
-
*/
|
|
52
|
-
export function getWavebreakLpEscrowAddressSync(bondingCurve) {
|
|
53
|
-
const bcPubkey = typeof bondingCurve === 'string' ? new PublicKey(bondingCurve) : bondingCurve;
|
|
54
|
-
const [lpEscrow] = PublicKey.findProgramAddressSync([Buffer.from('lp_escrow'), bcPubkey.toBuffer()], new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID));
|
|
55
|
-
return lpEscrow;
|
|
56
|
-
}
|
|
57
|
-
// ============================================================================
|
|
58
|
-
// 账户数据获取和解析
|
|
59
|
-
// ============================================================================
|
|
60
|
-
/**
|
|
61
|
-
* 获取 Wavebreak Bonding Curve 信息
|
|
62
|
-
*/
|
|
63
|
-
export async function getWavebreakBondingCurveInfo(bondingCurveOrMint, connection) {
|
|
64
|
-
if (!connection) {
|
|
65
|
-
throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
|
|
66
|
-
}
|
|
67
|
-
const conn = connection;
|
|
68
|
-
const sdk = await loadWavebreakSdk();
|
|
69
|
-
// 判断是 Bonding Curve 地址还是 Mint 地址
|
|
70
|
-
let bondingCurveAddress;
|
|
71
|
-
try {
|
|
72
|
-
const inputPubkey = new PublicKey(bondingCurveOrMint);
|
|
73
|
-
// 尝试作为 Mint 地址获取 Bonding Curve PDA
|
|
74
|
-
const calculatedBC = getWavebreakBondingCurveAddressSync(inputPubkey);
|
|
75
|
-
// 检查计算出的地址是否存在
|
|
76
|
-
const bcAccountInfo = await conn.getAccountInfo(calculatedBC);
|
|
77
|
-
if (bcAccountInfo) {
|
|
78
|
-
bondingCurveAddress = calculatedBC;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
// 假设输入的就是 Bonding Curve 地址
|
|
82
|
-
bondingCurveAddress = inputPubkey;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
const accountInfo = await conn.getAccountInfo(bondingCurveAddress);
|
|
90
|
-
if (!accountInfo)
|
|
91
|
-
return null;
|
|
92
|
-
// 检查账户 owner 是否是 Wavebreak 程序
|
|
93
|
-
if (accountInfo.owner.toBase58() !== WAVEBREAK_CONSTANTS.PROGRAM_ID) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
// 使用 SDK 的解码器解析账户数据
|
|
97
|
-
let data;
|
|
98
|
-
try {
|
|
99
|
-
const decoder = sdk.getBondingCurveDecoder();
|
|
100
|
-
data = decoder.decode(accountInfo.data);
|
|
101
|
-
}
|
|
102
|
-
catch (decodeError) {
|
|
103
|
-
// 解码失败,说明不是有效的 Wavebreak bonding curve 账户
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
// 构建价格曲线
|
|
107
|
-
const priceCurve = {
|
|
108
|
-
startPrice: data.startPrice,
|
|
109
|
-
endPrice: data.endPrice,
|
|
110
|
-
controlPoints: data.controlPoints,
|
|
111
|
-
};
|
|
112
|
-
// 计算当前价格
|
|
113
|
-
const currentPriceSqrt = sdk.tokenPrice(priceCurve, data.quoteAmount, data.graduationTarget);
|
|
114
|
-
const currentPrice = sdk.sqrtPriceToPrice(currentPriceSqrt, 9, 9);
|
|
115
|
-
// 计算进度
|
|
116
|
-
const progressPercent = Number(data.quoteAmount * BigInt(100) / data.graduationTarget);
|
|
117
|
-
const isGraduated = data.quoteAmount >= data.graduationTarget;
|
|
118
|
-
return {
|
|
119
|
-
bondingCurveAddress: bondingCurveAddress.toBase58(),
|
|
120
|
-
baseMint: data.baseMint,
|
|
121
|
-
quoteMint: data.quoteMint,
|
|
122
|
-
creator: data.creator,
|
|
123
|
-
quoteAmount: data.quoteAmount,
|
|
124
|
-
baseAmount: data.baseAmount,
|
|
125
|
-
startPrice: data.startPrice,
|
|
126
|
-
endPrice: data.endPrice,
|
|
127
|
-
graduationTarget: data.graduationTarget,
|
|
128
|
-
launchTime: data.launchTime,
|
|
129
|
-
graduationTime: data.graduationTime,
|
|
130
|
-
swapFeeBps: data.swapFeeBps,
|
|
131
|
-
isGraduated,
|
|
132
|
-
currentPrice,
|
|
133
|
-
progressPercent,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
console.error('获取 Bonding Curve 信息失败:', error);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
// ============================================================================
|
|
142
|
-
// 报价计算
|
|
143
|
-
// ============================================================================
|
|
144
|
-
/**
|
|
145
|
-
* 获取买入报价
|
|
146
|
-
*/
|
|
147
|
-
export async function getWavebreakBuyQuote(bondingCurveOrMint, amountIn, connection) {
|
|
148
|
-
const info = await getWavebreakBondingCurveInfo(bondingCurveOrMint, connection);
|
|
149
|
-
if (!info)
|
|
150
|
-
return null;
|
|
151
|
-
try {
|
|
152
|
-
const sdk = await loadWavebreakSdk();
|
|
153
|
-
const priceCurve = {
|
|
154
|
-
startPrice: info.startPrice,
|
|
155
|
-
endPrice: info.endPrice,
|
|
156
|
-
controlPoints: [3333, 3333, 6667, 6667], // 默认线性曲线
|
|
157
|
-
};
|
|
158
|
-
const quote = sdk.exactInBuyQuote(priceCurve, amountIn, info.swapFeeBps, info.quoteAmount, info.graduationTarget, BigInt('18446744073709551615') // max u64
|
|
159
|
-
);
|
|
160
|
-
// 计算价格影响
|
|
161
|
-
const priceImpact = amountIn > 0
|
|
162
|
-
? Number(quote.feeAmount) / Number(amountIn) * 100
|
|
163
|
-
: 0;
|
|
164
|
-
return {
|
|
165
|
-
amountIn: quote.amountIn,
|
|
166
|
-
amountOut: quote.amountOut,
|
|
167
|
-
feeAmount: quote.feeAmount,
|
|
168
|
-
priceImpact,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
catch (error) {
|
|
172
|
-
console.error('获取买入报价失败:', error);
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* 获取卖出报价
|
|
178
|
-
*/
|
|
179
|
-
export async function getWavebreakSellQuote(bondingCurveOrMint, amountIn, connection) {
|
|
180
|
-
const info = await getWavebreakBondingCurveInfo(bondingCurveOrMint, connection);
|
|
181
|
-
if (!info)
|
|
182
|
-
return null;
|
|
183
|
-
try {
|
|
184
|
-
const sdk = await loadWavebreakSdk();
|
|
185
|
-
const priceCurve = {
|
|
186
|
-
startPrice: info.startPrice,
|
|
187
|
-
endPrice: info.endPrice,
|
|
188
|
-
controlPoints: [3333, 3333, 6667, 6667],
|
|
189
|
-
};
|
|
190
|
-
const quote = sdk.exactInSellQuote(priceCurve, amountIn, info.swapFeeBps, info.quoteAmount, info.graduationTarget, BigInt('18446744073709551615'));
|
|
191
|
-
const priceImpact = amountIn > 0
|
|
192
|
-
? Number(quote.feeAmount) / Number(amountIn) * 100
|
|
193
|
-
: 0;
|
|
194
|
-
return {
|
|
195
|
-
amountIn: quote.amountIn,
|
|
196
|
-
amountOut: quote.amountOut,
|
|
197
|
-
feeAmount: quote.feeAmount,
|
|
198
|
-
priceImpact,
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
console.error('获取卖出报价失败:', error);
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
// ============================================================================
|
|
207
|
-
// 指令构建
|
|
208
|
-
// ============================================================================
|
|
209
|
-
/**
|
|
210
|
-
* 构建 Wavebreak 买入交易指令
|
|
211
|
-
*
|
|
212
|
-
* 使用 SDK 的编码器生成正确的指令数据
|
|
213
|
-
*/
|
|
214
|
-
export async function buildWavebreakBuyInstruction(params, buyer, connection) {
|
|
215
|
-
if (!connection) {
|
|
216
|
-
throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
|
|
217
|
-
}
|
|
218
|
-
const conn = connection;
|
|
219
|
-
const sdk = await loadWavebreakSdk();
|
|
220
|
-
const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
|
|
221
|
-
if (!info) {
|
|
222
|
-
throw new Error('Bonding Curve 不存在');
|
|
223
|
-
}
|
|
224
|
-
const baseMint = new PublicKey(info.baseMint);
|
|
225
|
-
const quoteMint = new PublicKey(info.quoteMint);
|
|
226
|
-
const bondingCurve = new PublicKey(info.bondingCurveAddress);
|
|
227
|
-
// 获取 ATA 地址
|
|
228
|
-
const baseAta = getAssociatedTokenAddressSync(baseMint, buyer, false, TOKEN_2022_PROGRAM_ID);
|
|
229
|
-
const quoteAta = getAssociatedTokenAddressSync(quoteMint, buyer, false, TOKEN_PROGRAM_ID);
|
|
230
|
-
// Quote Vault PDA
|
|
231
|
-
const quoteVault = getWavebreakQuoteVaultAddressSync(bondingCurve);
|
|
232
|
-
// 使用 SDK 编码器生成指令数据
|
|
233
|
-
const encoder = sdk.getTokenBuyExactInInstructionDataEncoder();
|
|
234
|
-
const encodedData = encoder.encode({
|
|
235
|
-
amountIn: params.amountIn,
|
|
236
|
-
allowPartialFill: params.allowPartialFill ?? true,
|
|
237
|
-
priceThreshold: null, // 不设置价格阈值
|
|
238
|
-
});
|
|
239
|
-
// 账户顺序(从 SDK 类型定义):
|
|
240
|
-
// 0: buyer (signer, writable)
|
|
241
|
-
// 1: bondingCurve (writable)
|
|
242
|
-
// 2: baseMint (writable)
|
|
243
|
-
// 3: baseAta (writable)
|
|
244
|
-
// 4: quoteMint (readonly)
|
|
245
|
-
// 5: quoteVault (writable)
|
|
246
|
-
// 6: quoteAta (writable)
|
|
247
|
-
// 7: systemProgram (readonly)
|
|
248
|
-
// 8: ataProgram (readonly)
|
|
249
|
-
// 9: baseTokenProgram (readonly)
|
|
250
|
-
// 10: quoteTokenProgram (readonly)
|
|
251
|
-
const keys = [
|
|
252
|
-
{ pubkey: buyer, isSigner: true, isWritable: true },
|
|
253
|
-
{ pubkey: bondingCurve, isSigner: false, isWritable: true },
|
|
254
|
-
{ pubkey: baseMint, isSigner: false, isWritable: true },
|
|
255
|
-
{ pubkey: baseAta, isSigner: false, isWritable: true },
|
|
256
|
-
{ pubkey: quoteMint, isSigner: false, isWritable: false },
|
|
257
|
-
{ pubkey: quoteVault, isSigner: false, isWritable: true },
|
|
258
|
-
{ pubkey: quoteAta, isSigner: false, isWritable: true },
|
|
259
|
-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
260
|
-
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
261
|
-
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
262
|
-
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
263
|
-
];
|
|
264
|
-
return new TransactionInstruction({
|
|
265
|
-
programId: new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID),
|
|
266
|
-
keys,
|
|
267
|
-
data: Buffer.from(encodedData),
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* 构建 Wavebreak 卖出交易指令
|
|
272
|
-
*/
|
|
273
|
-
export async function buildWavebreakSellInstruction(params, seller, connection) {
|
|
274
|
-
if (!connection) {
|
|
275
|
-
throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
|
|
276
|
-
}
|
|
277
|
-
const conn = connection;
|
|
278
|
-
const sdk = await loadWavebreakSdk();
|
|
279
|
-
const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
|
|
280
|
-
if (!info) {
|
|
281
|
-
throw new Error('Bonding Curve 不存在');
|
|
282
|
-
}
|
|
283
|
-
const baseMint = new PublicKey(info.baseMint);
|
|
284
|
-
const quoteMint = new PublicKey(info.quoteMint);
|
|
285
|
-
const bondingCurve = new PublicKey(info.bondingCurveAddress);
|
|
286
|
-
const baseAta = getAssociatedTokenAddressSync(baseMint, seller, false, TOKEN_2022_PROGRAM_ID);
|
|
287
|
-
const quoteAta = getAssociatedTokenAddressSync(quoteMint, seller, false, TOKEN_PROGRAM_ID);
|
|
288
|
-
const quoteVault = getWavebreakQuoteVaultAddressSync(bondingCurve);
|
|
289
|
-
// 使用 SDK 编码器
|
|
290
|
-
const encoder = sdk.getTokenSellExactInInstructionDataEncoder();
|
|
291
|
-
const encodedData = encoder.encode({
|
|
292
|
-
amountIn: params.amountIn,
|
|
293
|
-
allowPartialFill: params.allowPartialFill ?? true,
|
|
294
|
-
priceThreshold: null,
|
|
295
|
-
});
|
|
296
|
-
const keys = [
|
|
297
|
-
{ pubkey: seller, isSigner: true, isWritable: true },
|
|
298
|
-
{ pubkey: bondingCurve, isSigner: false, isWritable: true },
|
|
299
|
-
{ pubkey: baseMint, isSigner: false, isWritable: true },
|
|
300
|
-
{ pubkey: baseAta, isSigner: false, isWritable: true },
|
|
301
|
-
{ pubkey: quoteMint, isSigner: false, isWritable: false },
|
|
302
|
-
{ pubkey: quoteVault, isSigner: false, isWritable: true },
|
|
303
|
-
{ pubkey: quoteAta, isSigner: false, isWritable: true },
|
|
304
|
-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
305
|
-
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
306
|
-
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
307
|
-
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
308
|
-
];
|
|
309
|
-
return new TransactionInstruction({
|
|
310
|
-
programId: new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID),
|
|
311
|
-
keys,
|
|
312
|
-
data: Buffer.from(encodedData),
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* 构建 Wavebreak 创建代币发射指令
|
|
317
|
-
*/
|
|
318
|
-
export async function buildWavebreakCreateLaunchInstruction(params, creator, baseMintKeypair, connection) {
|
|
319
|
-
const sdk = await loadWavebreakSdk();
|
|
320
|
-
const baseMint = baseMintKeypair.publicKey;
|
|
321
|
-
const quoteMint = new PublicKey(params.quoteMint || WAVEBREAK_CONSTANTS.SOL_MINT);
|
|
322
|
-
// 计算 PDA
|
|
323
|
-
const bondingCurve = getWavebreakBondingCurveAddressSync(baseMint);
|
|
324
|
-
const quoteVault = getWavebreakQuoteVaultAddressSync(bondingCurve);
|
|
325
|
-
// Mint Config PDA
|
|
326
|
-
const [mintConfig] = PublicKey.findProgramAddressSync([Buffer.from('mint_config')], new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID));
|
|
327
|
-
// Metadata PDA
|
|
328
|
-
const [metadata] = PublicKey.findProgramAddressSync([
|
|
329
|
-
Buffer.from('metadata'),
|
|
330
|
-
new PublicKey(WAVEBREAK_CONSTANTS.METAPLEX_PROGRAM_ID).toBuffer(),
|
|
331
|
-
baseMint.toBuffer(),
|
|
332
|
-
], new PublicKey(WAVEBREAK_CONSTANTS.METAPLEX_PROGRAM_ID));
|
|
333
|
-
// 使用 SDK 编码器
|
|
334
|
-
const encoder = sdk.getCreateLaunchInstructionDataEncoder();
|
|
335
|
-
const encodedData = encoder.encode({
|
|
336
|
-
name: params.name,
|
|
337
|
-
symbol: params.symbol,
|
|
338
|
-
uri: params.uri,
|
|
339
|
-
startPrice: params.startPrice ?? null,
|
|
340
|
-
endPrice: params.endPrice ?? null,
|
|
341
|
-
controlPoints: null, // 使用默认曲线
|
|
342
|
-
graduationTarget: params.graduationTarget ?? null,
|
|
343
|
-
graduationMethods: null, // 使用默认
|
|
344
|
-
launchTime: params.launchTime ?? null,
|
|
345
|
-
graduationTime: params.graduationTime ?? null,
|
|
346
|
-
baseAllocationBps: params.baseAllocationBps ?? null,
|
|
347
|
-
});
|
|
348
|
-
// 账户顺序(从 SDK 类型定义):
|
|
349
|
-
// 0: creator (signer, writable)
|
|
350
|
-
// 1: bondingCurve (writable)
|
|
351
|
-
// 2: baseMint (signer, writable) - 新创建的 mint
|
|
352
|
-
// 3: quoteMint (readonly)
|
|
353
|
-
// 4: quoteVault (writable)
|
|
354
|
-
// 5: mintConfig (readonly)
|
|
355
|
-
// 6: metadata (writable)
|
|
356
|
-
// 7: systemProgram (readonly)
|
|
357
|
-
// 8: baseTokenProgram (readonly)
|
|
358
|
-
// 9: quoteTokenProgram (readonly)
|
|
359
|
-
// 10: ataProgram (readonly)
|
|
360
|
-
// 11: metaplexProgram (readonly)
|
|
361
|
-
const keys = [
|
|
362
|
-
{ pubkey: creator, isSigner: true, isWritable: true },
|
|
363
|
-
{ pubkey: bondingCurve, isSigner: false, isWritable: true },
|
|
364
|
-
{ pubkey: baseMint, isSigner: true, isWritable: true },
|
|
365
|
-
{ pubkey: quoteMint, isSigner: false, isWritable: false },
|
|
366
|
-
{ pubkey: quoteVault, isSigner: false, isWritable: true },
|
|
367
|
-
{ pubkey: mintConfig, isSigner: false, isWritable: false },
|
|
368
|
-
{ pubkey: metadata, isSigner: false, isWritable: true },
|
|
369
|
-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
370
|
-
{ pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
371
|
-
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
372
|
-
{ pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
373
|
-
{ pubkey: new PublicKey(WAVEBREAK_CONSTANTS.METAPLEX_PROGRAM_ID), isSigner: false, isWritable: false },
|
|
374
|
-
];
|
|
375
|
-
return new TransactionInstruction({
|
|
376
|
-
programId: new PublicKey(WAVEBREAK_CONSTANTS.PROGRAM_ID),
|
|
377
|
-
keys,
|
|
378
|
-
data: Buffer.from(encodedData),
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
// ============================================================================
|
|
382
|
-
// 交易签名
|
|
383
|
-
// ============================================================================
|
|
384
|
-
/**
|
|
385
|
-
* 签名 Wavebreak 买入交易
|
|
386
|
-
*/
|
|
387
|
-
export async function signWavebreakBuy(params, payer, connection) {
|
|
388
|
-
if (!connection) {
|
|
389
|
-
throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
|
|
390
|
-
}
|
|
391
|
-
const conn = connection;
|
|
392
|
-
const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
|
|
393
|
-
if (!info) {
|
|
394
|
-
throw new Error('Bonding Curve 不存在');
|
|
395
|
-
}
|
|
396
|
-
const quote = await getWavebreakBuyQuote(params.bondingCurveOrMint, params.amountIn, conn);
|
|
397
|
-
const tx = new Transaction();
|
|
398
|
-
tx.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 300000 }), ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 100000 }));
|
|
399
|
-
const buyIx = await buildWavebreakBuyInstruction(params, payer.publicKey, conn);
|
|
400
|
-
tx.add(buyIx);
|
|
401
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
402
|
-
tx.recentBlockhash = blockhash;
|
|
403
|
-
tx.lastValidBlockHeight = lastValidBlockHeight;
|
|
404
|
-
tx.feePayer = payer.publicKey;
|
|
405
|
-
tx.sign(payer);
|
|
406
|
-
return {
|
|
407
|
-
signedTransaction: tx,
|
|
408
|
-
type: 'buy',
|
|
409
|
-
bondingCurveAddress: info.bondingCurveAddress,
|
|
410
|
-
baseMint: info.baseMint,
|
|
411
|
-
metadata: {
|
|
412
|
-
estimatedAmountOut: quote?.amountOut.toString(),
|
|
413
|
-
feeAmount: quote?.feeAmount.toString(),
|
|
414
|
-
},
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* 签名 Wavebreak 卖出交易
|
|
419
|
-
*/
|
|
420
|
-
export async function signWavebreakSell(params, payer, connection) {
|
|
421
|
-
if (!connection) {
|
|
422
|
-
throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
|
|
423
|
-
}
|
|
424
|
-
const conn = connection;
|
|
425
|
-
const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
|
|
426
|
-
if (!info) {
|
|
427
|
-
throw new Error('Bonding Curve 不存在');
|
|
428
|
-
}
|
|
429
|
-
const quote = await getWavebreakSellQuote(params.bondingCurveOrMint, params.amountIn, conn);
|
|
430
|
-
const tx = new Transaction();
|
|
431
|
-
tx.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 300000 }), ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 100000 }));
|
|
432
|
-
const sellIx = await buildWavebreakSellInstruction(params, payer.publicKey, conn);
|
|
433
|
-
tx.add(sellIx);
|
|
434
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
435
|
-
tx.recentBlockhash = blockhash;
|
|
436
|
-
tx.lastValidBlockHeight = lastValidBlockHeight;
|
|
437
|
-
tx.feePayer = payer.publicKey;
|
|
438
|
-
tx.sign(payer);
|
|
439
|
-
return {
|
|
440
|
-
signedTransaction: tx,
|
|
441
|
-
type: 'sell',
|
|
442
|
-
bondingCurveAddress: info.bondingCurveAddress,
|
|
443
|
-
baseMint: info.baseMint,
|
|
444
|
-
metadata: {
|
|
445
|
-
estimatedAmountOut: quote?.amountOut.toString(),
|
|
446
|
-
feeAmount: quote?.feeAmount.toString(),
|
|
447
|
-
},
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
/**
|
|
451
|
-
* 签名 Wavebreak 创建代币发射交易
|
|
452
|
-
*/
|
|
453
|
-
export async function signWavebreakCreateLaunch(params, creator, connection) {
|
|
454
|
-
if (!connection) {
|
|
455
|
-
throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
|
|
456
|
-
}
|
|
457
|
-
const conn = connection;
|
|
458
|
-
const baseMintKeypair = Keypair.generate();
|
|
459
|
-
const bondingCurve = getWavebreakBondingCurveAddressSync(baseMintKeypair.publicKey);
|
|
460
|
-
const tx = new Transaction();
|
|
461
|
-
tx.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 500000 }), ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 100000 }));
|
|
462
|
-
const createIx = await buildWavebreakCreateLaunchInstruction(params, creator.publicKey, baseMintKeypair, conn);
|
|
463
|
-
tx.add(createIx);
|
|
464
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
465
|
-
tx.recentBlockhash = blockhash;
|
|
466
|
-
tx.lastValidBlockHeight = lastValidBlockHeight;
|
|
467
|
-
tx.feePayer = creator.publicKey;
|
|
468
|
-
tx.sign(creator, baseMintKeypair);
|
|
469
|
-
return {
|
|
470
|
-
signedTransaction: tx,
|
|
471
|
-
type: 'createLaunch',
|
|
472
|
-
bondingCurveAddress: bondingCurve.toBase58(),
|
|
473
|
-
baseMint: baseMintKeypair.publicKey.toBase58(),
|
|
474
|
-
baseMintKeypair,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
// ============================================================================
|
|
478
|
-
// API 转换
|
|
479
|
-
// ============================================================================
|
|
480
|
-
/**
|
|
481
|
-
* 将签名结果转换为后端 API 请求格式
|
|
482
|
-
*/
|
|
483
|
-
export function toWavebreakApiRequest(result) {
|
|
484
|
-
const tx = result.signedTransaction;
|
|
485
|
-
const serialized = tx instanceof Transaction
|
|
486
|
-
? tx.serialize()
|
|
487
|
-
: tx.serialize();
|
|
488
|
-
return {
|
|
489
|
-
transaction: Buffer.from(serialized).toString('base64'),
|
|
490
|
-
metadata: {
|
|
491
|
-
type: result.type,
|
|
492
|
-
bondingCurveAddress: result.bondingCurveAddress,
|
|
493
|
-
baseMint: result.baseMint,
|
|
494
|
-
...result.metadata,
|
|
495
|
-
},
|
|
496
|
-
};
|
|
497
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pump.fun 模块导出
|
|
3
|
-
* @module sol/dex/pump
|
|
4
|
-
*/
|
|
5
|
-
// 类型
|
|
6
|
-
export * from './types.js';
|
|
7
|
-
// Pump 核心功能(Bonding Curve 阶段)
|
|
8
|
-
export * from './pump.js';
|
|
9
|
-
// Pump Swap LP 管理(Pool 阶段)
|
|
10
|
-
export * from './pump-swap.js';
|
|
11
|
-
// Pump Bundle 批量签名(用于 Jito - Bonding Curve 阶段)
|
|
12
|
-
export * from './pump-bundle.js';
|
|
13
|
-
// Pump Swap Bundle 批量签名(用于 Jito - Pool 阶段)
|
|
14
|
-
export * from './pump-swap-bundle.js';
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pump.fun 批量签名(用于 Jito Bundle)
|
|
3
|
-
* 只构建指令和签名,不发送交易,提交到后端服务器通过 Jito 广播
|
|
4
|
-
* @module sol/dex/pump/pump-bundle
|
|
5
|
-
*/
|
|
6
|
-
import { Connection, Keypair } from '@solana/web3.js';
|
|
7
|
-
import type { SignedBundleData } from '../../jito/types.js';
|
|
8
|
-
/**
|
|
9
|
-
* 批量买入项
|
|
10
|
-
*/
|
|
11
|
-
export interface PumpBundleBuyItem {
|
|
12
|
-
wallet: Keypair;
|
|
13
|
-
solAmount: bigint;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* 批量卖出项
|
|
17
|
-
*/
|
|
18
|
-
export interface PumpBundleSellItem {
|
|
19
|
-
wallet: Keypair;
|
|
20
|
-
tokenAmount: bigint;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 批量签名结果
|
|
24
|
-
*/
|
|
25
|
-
export interface PumpBundleSignResult {
|
|
26
|
-
success: boolean;
|
|
27
|
-
/** 签名后的 Bundle 数据(用于提交后端) */
|
|
28
|
-
bundleData?: SignedBundleData;
|
|
29
|
-
/** 错误信息 */
|
|
30
|
-
error?: string;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 构建批量买入指令(用于 Jito Bundle)
|
|
34
|
-
* 每个钱包一笔交易,最后加 Tip 交易
|
|
35
|
-
*
|
|
36
|
-
* @param connection Solana 连接
|
|
37
|
-
* @param mint 代币 Mint 地址
|
|
38
|
-
* @param buyers 买入列表
|
|
39
|
-
* @param tipPayer Tip 支付者
|
|
40
|
-
* @param tipLamports Tip 金额
|
|
41
|
-
* @param slippageBps 滑点(基点)
|
|
42
|
-
*/
|
|
43
|
-
export declare function signPumpBundleBuy(connection: Connection, params: {
|
|
44
|
-
mint: string;
|
|
45
|
-
buyers: PumpBundleBuyItem[];
|
|
46
|
-
tipPayer: Keypair;
|
|
47
|
-
tipLamports?: bigint;
|
|
48
|
-
slippageBps?: number;
|
|
49
|
-
}): Promise<PumpBundleSignResult>;
|
|
50
|
-
/**
|
|
51
|
-
* 构建批量卖出指令(用于 Jito Bundle)
|
|
52
|
-
*/
|
|
53
|
-
export declare function signPumpBundleSell(connection: Connection, params: {
|
|
54
|
-
mint: string;
|
|
55
|
-
sellers: PumpBundleSellItem[];
|
|
56
|
-
tipPayer: Keypair;
|
|
57
|
-
tipLamports?: bigint;
|
|
58
|
-
slippageBps?: number;
|
|
59
|
-
}): Promise<PumpBundleSignResult>;
|
|
60
|
-
/**
|
|
61
|
-
* 构建创建代币 + 批量买入的 Bundle
|
|
62
|
-
* 第一笔:创建代币 + 创建者购买
|
|
63
|
-
* 后续:其他钱包购买
|
|
64
|
-
* 最后:Tip
|
|
65
|
-
*/
|
|
66
|
-
export declare function signPumpBundleCreateAndBuy(connection: Connection, params: {
|
|
67
|
-
name: string;
|
|
68
|
-
symbol: string;
|
|
69
|
-
uri: string;
|
|
70
|
-
creator: Keypair;
|
|
71
|
-
mintKeypair?: Keypair;
|
|
72
|
-
creatorBuyAmount?: bigint;
|
|
73
|
-
buyers: PumpBundleBuyItem[];
|
|
74
|
-
tipPayer: Keypair;
|
|
75
|
-
tipLamports?: bigint;
|
|
76
|
-
slippageBps?: number;
|
|
77
|
-
mayhemMode?: boolean;
|
|
78
|
-
}): Promise<PumpBundleSignResult & {
|
|
79
|
-
mintAddress?: string;
|
|
80
|
-
}>;
|
|
81
|
-
/**
|
|
82
|
-
* 将 Bundle 数据转换为后端 API 格式
|
|
83
|
-
*/
|
|
84
|
-
export declare function toBundleApiRequest(bundleData: SignedBundleData): {
|
|
85
|
-
transactions: string[];
|
|
86
|
-
signatures: string[];
|
|
87
|
-
tipAccount: string;
|
|
88
|
-
tipLamports: string;
|
|
89
|
-
recentBlockhash: string;
|
|
90
|
-
lastValidBlockHeight: number;
|
|
91
|
-
timestamp: number;
|
|
92
|
-
};
|