four-flap-meme-sdk 1.4.89 → 1.4.90

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.
Files changed (142) hide show
  1. package/README.zh-CN.pdf +0 -0
  2. package/dist/flap/portal-bundle-merkle/encryption.d.ts +16 -0
  3. package/dist/flap/portal-bundle-merkle/encryption.js +146 -0
  4. package/dist/utils/holders-maker.d.ts +19 -0
  5. package/dist/utils/holders-maker.js +4 -1
  6. package/package.json +3 -38
  7. package/dist/sol/constants.d.ts +0 -126
  8. package/dist/sol/constants.js +0 -145
  9. package/dist/sol/dex/blockrazor/client.d.ts +0 -51
  10. package/dist/sol/dex/blockrazor/client.js +0 -96
  11. package/dist/sol/dex/blockrazor/constants.d.ts +0 -34
  12. package/dist/sol/dex/blockrazor/constants.js +0 -55
  13. package/dist/sol/dex/blockrazor/geyser.d.ts +0 -128
  14. package/dist/sol/dex/blockrazor/geyser.js +0 -530
  15. package/dist/sol/dex/blockrazor/index.d.ts +0 -18
  16. package/dist/sol/dex/blockrazor/index.js +0 -23
  17. package/dist/sol/dex/blockrazor/send.d.ts +0 -135
  18. package/dist/sol/dex/blockrazor/send.js +0 -254
  19. package/dist/sol/dex/blockrazor/types.d.ts +0 -191
  20. package/dist/sol/dex/blockrazor/types.js +0 -5
  21. package/dist/sol/dex/index.d.ts +0 -10
  22. package/dist/sol/dex/index.js +0 -16
  23. package/dist/sol/dex/jup/client.d.ts +0 -33
  24. package/dist/sol/dex/jup/client.js +0 -110
  25. package/dist/sol/dex/jup/index.d.ts +0 -16
  26. package/dist/sol/dex/jup/index.js +0 -148
  27. package/dist/sol/dex/jup/legacy.d.ts +0 -623
  28. package/dist/sol/dex/jup/legacy.js +0 -416
  29. package/dist/sol/dex/jup/lend.d.ts +0 -640
  30. package/dist/sol/dex/jup/lend.js +0 -603
  31. package/dist/sol/dex/jup/portfolio.d.ts +0 -362
  32. package/dist/sol/dex/jup/portfolio.js +0 -367
  33. package/dist/sol/dex/jup/price.d.ts +0 -173
  34. package/dist/sol/dex/jup/price.js +0 -220
  35. package/dist/sol/dex/jup/recurring.d.ts +0 -437
  36. package/dist/sol/dex/jup/recurring.js +0 -320
  37. package/dist/sol/dex/jup/send.d.ts +0 -282
  38. package/dist/sol/dex/jup/send.js +0 -295
  39. package/dist/sol/dex/jup/studio.d.ts +0 -457
  40. package/dist/sol/dex/jup/studio.js +0 -488
  41. package/dist/sol/dex/jup/tokens.d.ts +0 -767
  42. package/dist/sol/dex/jup/tokens.js +0 -697
  43. package/dist/sol/dex/jup/trigger.d.ts +0 -511
  44. package/dist/sol/dex/jup/trigger.js +0 -397
  45. package/dist/sol/dex/jup/types.d.ts +0 -433
  46. package/dist/sol/dex/jup/types.js +0 -5
  47. package/dist/sol/dex/jup/ultra.d.ts +0 -646
  48. package/dist/sol/dex/jup/ultra.js +0 -853
  49. package/dist/sol/dex/meteora/client.d.ts +0 -76
  50. package/dist/sol/dex/meteora/client.js +0 -219
  51. package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +0 -61
  52. package/dist/sol/dex/meteora/damm-v1-bundle.js +0 -112
  53. package/dist/sol/dex/meteora/damm-v1.d.ts +0 -118
  54. package/dist/sol/dex/meteora/damm-v1.js +0 -315
  55. package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +0 -82
  56. package/dist/sol/dex/meteora/damm-v2-bundle.js +0 -242
  57. package/dist/sol/dex/meteora/damm-v2.d.ts +0 -172
  58. package/dist/sol/dex/meteora/damm-v2.js +0 -632
  59. package/dist/sol/dex/meteora/dbc-bundle.d.ts +0 -123
  60. package/dist/sol/dex/meteora/dbc-bundle.js +0 -304
  61. package/dist/sol/dex/meteora/dbc.d.ts +0 -192
  62. package/dist/sol/dex/meteora/dbc.js +0 -619
  63. package/dist/sol/dex/meteora/dlmm-bundle.d.ts +0 -39
  64. package/dist/sol/dex/meteora/dlmm-bundle.js +0 -189
  65. package/dist/sol/dex/meteora/dlmm.d.ts +0 -157
  66. package/dist/sol/dex/meteora/dlmm.js +0 -671
  67. package/dist/sol/dex/meteora/index.d.ts +0 -25
  68. package/dist/sol/dex/meteora/index.js +0 -65
  69. package/dist/sol/dex/meteora/types.d.ts +0 -787
  70. package/dist/sol/dex/meteora/types.js +0 -110
  71. package/dist/sol/dex/orca/index.d.ts +0 -10
  72. package/dist/sol/dex/orca/index.js +0 -16
  73. package/dist/sol/dex/orca/orca-bundle.d.ts +0 -41
  74. package/dist/sol/dex/orca/orca-bundle.js +0 -173
  75. package/dist/sol/dex/orca/orca.d.ts +0 -65
  76. package/dist/sol/dex/orca/orca.js +0 -474
  77. package/dist/sol/dex/orca/types.d.ts +0 -263
  78. package/dist/sol/dex/orca/types.js +0 -38
  79. package/dist/sol/dex/orca/wavebreak-bundle.d.ts +0 -34
  80. package/dist/sol/dex/orca/wavebreak-bundle.js +0 -198
  81. package/dist/sol/dex/orca/wavebreak-types.d.ts +0 -227
  82. package/dist/sol/dex/orca/wavebreak-types.js +0 -23
  83. package/dist/sol/dex/orca/wavebreak.d.ts +0 -78
  84. package/dist/sol/dex/orca/wavebreak.js +0 -497
  85. package/dist/sol/dex/pump/index.d.ts +0 -9
  86. package/dist/sol/dex/pump/index.js +0 -14
  87. package/dist/sol/dex/pump/pump-bundle.d.ts +0 -92
  88. package/dist/sol/dex/pump/pump-bundle.js +0 -383
  89. package/dist/sol/dex/pump/pump-swap-bundle.d.ts +0 -103
  90. package/dist/sol/dex/pump/pump-swap-bundle.js +0 -380
  91. package/dist/sol/dex/pump/pump-swap.d.ts +0 -46
  92. package/dist/sol/dex/pump/pump-swap.js +0 -199
  93. package/dist/sol/dex/pump/pump.d.ts +0 -35
  94. package/dist/sol/dex/pump/pump.js +0 -352
  95. package/dist/sol/dex/pump/types.d.ts +0 -215
  96. package/dist/sol/dex/pump/types.js +0 -5
  97. package/dist/sol/dex/raydium/index.d.ts +0 -8
  98. package/dist/sol/dex/raydium/index.js +0 -12
  99. package/dist/sol/dex/raydium/launchlab.d.ts +0 -68
  100. package/dist/sol/dex/raydium/launchlab.js +0 -210
  101. package/dist/sol/dex/raydium/raydium-bundle.d.ts +0 -64
  102. package/dist/sol/dex/raydium/raydium-bundle.js +0 -324
  103. package/dist/sol/dex/raydium/raydium.d.ts +0 -40
  104. package/dist/sol/dex/raydium/raydium.js +0 -366
  105. package/dist/sol/dex/raydium/types.d.ts +0 -240
  106. package/dist/sol/dex/raydium/types.js +0 -5
  107. package/dist/sol/index.d.ts +0 -10
  108. package/dist/sol/index.js +0 -16
  109. package/dist/sol/jito/bundle.d.ts +0 -90
  110. package/dist/sol/jito/bundle.js +0 -263
  111. package/dist/sol/jito/index.d.ts +0 -7
  112. package/dist/sol/jito/index.js +0 -7
  113. package/dist/sol/jito/tip.d.ts +0 -51
  114. package/dist/sol/jito/tip.js +0 -83
  115. package/dist/sol/jito/types.d.ts +0 -100
  116. package/dist/sol/jito/types.js +0 -5
  117. package/dist/sol/token/create-complete.d.ts +0 -115
  118. package/dist/sol/token/create-complete.js +0 -235
  119. package/dist/sol/token/create-token.d.ts +0 -57
  120. package/dist/sol/token/create-token.js +0 -230
  121. package/dist/sol/token/index.d.ts +0 -9
  122. package/dist/sol/token/index.js +0 -14
  123. package/dist/sol/token/metadata-upload.d.ts +0 -86
  124. package/dist/sol/token/metadata-upload.js +0 -173
  125. package/dist/sol/token/metadata.d.ts +0 -92
  126. package/dist/sol/token/metadata.js +0 -274
  127. package/dist/sol/token/types.d.ts +0 -153
  128. package/dist/sol/token/types.js +0 -5
  129. package/dist/sol/types.d.ts +0 -176
  130. package/dist/sol/types.js +0 -7
  131. package/dist/sol/utils/balance.d.ts +0 -160
  132. package/dist/sol/utils/balance.js +0 -638
  133. package/dist/sol/utils/connection.d.ts +0 -78
  134. package/dist/sol/utils/connection.js +0 -168
  135. package/dist/sol/utils/index.d.ts +0 -9
  136. package/dist/sol/utils/index.js +0 -9
  137. package/dist/sol/utils/lp-inspect.d.ts +0 -129
  138. package/dist/sol/utils/lp-inspect.js +0 -900
  139. package/dist/sol/utils/transfer.d.ts +0 -125
  140. package/dist/sol/utils/transfer.js +0 -220
  141. package/dist/sol/utils/wallet.d.ts +0 -107
  142. package/dist/sol/utils/wallet.js +0 -210
@@ -1,671 +0,0 @@
1
- /**
2
- * Meteora DLMM (Dynamic Liquidity Market Maker) 集成
3
- *
4
- * 基于 https://github.com/MeteoraAg/dlmm-sdk 源码分析
5
- * DLMM 是 Meteora 的集中流动性池,类似于 Uniswap V3
6
- */
7
- import { PublicKey, Keypair, Transaction, } from '@solana/web3.js';
8
- import BN from 'bn.js';
9
- import { StrategyType, ActivationType } from '@meteora-ag/dlmm';
10
- import { getConnection, getDlmmPool } from './client.js';
11
- // ============================================================================
12
- // 池信息查询
13
- // ============================================================================
14
- /**
15
- * 获取 DLMM 池信息
16
- * @param poolAddress 池地址
17
- * @param connection 可选连接
18
- */
19
- export async function getDlmmPoolInfo(poolAddress, connection) {
20
- const dlmmPool = await getDlmmPool(poolAddress, connection);
21
- // 获取活跃 bin 信息
22
- const activeBin = await dlmmPool.getActiveBin();
23
- return {
24
- poolAddress,
25
- tokenXMint: dlmmPool.tokenX.publicKey.toBase58(),
26
- tokenYMint: dlmmPool.tokenY.publicKey.toBase58(),
27
- tokenXReserve: dlmmPool.tokenX.amount.toString(),
28
- tokenYReserve: dlmmPool.tokenY.amount.toString(),
29
- activeId: dlmmPool.lbPair.activeId,
30
- binStep: dlmmPool.lbPair.binStep,
31
- currentPrice: Number(activeBin.price),
32
- feeBps: dlmmPool.lbPair.parameters.baseFactor,
33
- };
34
- }
35
- /**
36
- * 通过 Token Mint 查找 DLMM 池
37
- * 优化: 使用 Meteora API 替代全量链上查询
38
- * @param tokenXMint Token X Mint 地址
39
- * @param tokenYMint Token Y Mint 地址
40
- * @param connection 可选连接(备用)
41
- */
42
- export async function findDlmmPool(tokenXMint, tokenYMint, _connection) {
43
- try {
44
- // 方法1: 使用 Meteora API 查询 (推荐,速度快)
45
- const apiResult = await findDlmmPoolByApi(tokenXMint, tokenYMint);
46
- if (apiResult) {
47
- return apiResult;
48
- }
49
- // 方法2: 如果 API 失败,尝试计算 PDA(某些池子可能有固定 PDA)
50
- // 注意:DLMM 池子使用 seeds = [tokenX, tokenY, binStep] 计算 PDA
51
- // 但 binStep 不确定,所以这里不做 PDA 计算
52
- return null;
53
- }
54
- catch (e) {
55
- console.error('查找 DLMM 池失败:', e);
56
- return null;
57
- }
58
- }
59
- /**
60
- * 通过 Meteora API 查找 DLMM 池
61
- * API 文档: https://dlmm-api.meteora.ag/swagger-ui/
62
- */
63
- async function findDlmmPoolByApi(tokenXMint, tokenYMint) {
64
- try {
65
- // 使用 Meteora 官方 API 查询池子
66
- const response = await fetch(`https://dlmm-api.meteora.ag/pair/all_by_groups?include_token_mints=${tokenXMint},${tokenYMint}`, {
67
- headers: {
68
- 'Content-Type': 'application/json',
69
- },
70
- });
71
- if (!response.ok) {
72
- console.warn('[Meteora API] Request failed:', response.status);
73
- return null;
74
- }
75
- const data = await response.json();
76
- // 查找匹配的池子
77
- if (data?.groups) {
78
- for (const group of data.groups) {
79
- if (group.pairs) {
80
- for (const pair of group.pairs) {
81
- const mintX = pair.mint_x;
82
- const mintY = pair.mint_y;
83
- if ((mintX === tokenXMint && mintY === tokenYMint) ||
84
- (mintX === tokenYMint && mintY === tokenXMint)) {
85
- return pair.address;
86
- }
87
- }
88
- }
89
- }
90
- }
91
- return null;
92
- }
93
- catch (e) {
94
- console.warn('[Meteora API] 查询失败:', e);
95
- return null;
96
- }
97
- }
98
- /**
99
- * 通过代币地址获取所有相关的 DLMM 池子
100
- * 使用 Meteora API,不再全量查询链上数据
101
- */
102
- export async function findDlmmPoolsByToken(tokenMint) {
103
- try {
104
- const response = await fetch(`https://dlmm-api.meteora.ag/pair/all_by_groups?include_token_mints=${tokenMint}`, {
105
- headers: {
106
- 'Content-Type': 'application/json',
107
- },
108
- });
109
- if (!response.ok) {
110
- return [];
111
- }
112
- const data = await response.json();
113
- const pools = [];
114
- if (data?.groups) {
115
- for (const group of data.groups) {
116
- if (group.pairs) {
117
- for (const pair of group.pairs) {
118
- if (pair.mint_x === tokenMint || pair.mint_y === tokenMint) {
119
- pools.push({
120
- address: pair.address,
121
- tokenX: pair.mint_x,
122
- tokenY: pair.mint_y,
123
- binStep: pair.bin_step || 0,
124
- });
125
- }
126
- }
127
- }
128
- }
129
- }
130
- return pools;
131
- }
132
- catch (e) {
133
- console.warn('[Meteora API] 查询池子列表失败:', e);
134
- return [];
135
- }
136
- }
137
- // ============================================================================
138
- // Swap
139
- // ============================================================================
140
- /**
141
- * 签名 DLMM Swap 交易
142
- * @param params Swap 参数
143
- * @param wallet 钱包
144
- * @param connection 可选连接
145
- */
146
- export async function signDlmmSwap(params, wallet, connection) {
147
- const conn = getConnection(connection);
148
- const dlmmPool = await getDlmmPool(params.poolAddress, connection);
149
- // 确定交易方向
150
- const swapYtoX = params.inputMint === dlmmPool.tokenY.publicKey.toBase58();
151
- // 获取 bin arrays
152
- const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);
153
- // 获取报价
154
- const swapQuote = dlmmPool.swapQuote(params.amountIn, swapYtoX, new BN(params.slippageBps || 100), binArrays);
155
- const minAmountOut = params.minAmountOut || swapQuote.minOutAmount;
156
- // 确定输入输出 token
157
- const [inToken, outToken] = swapYtoX
158
- ? [dlmmPool.tokenY.publicKey, dlmmPool.tokenX.publicKey]
159
- : [dlmmPool.tokenX.publicKey, dlmmPool.tokenY.publicKey];
160
- // 构建 Swap 交易
161
- const swapTx = await dlmmPool.swap({
162
- inToken,
163
- binArraysPubkey: swapQuote.binArraysPubkey,
164
- inAmount: params.amountIn,
165
- lbPair: dlmmPool.pubkey,
166
- user: wallet.publicKey,
167
- minOutAmount: minAmountOut,
168
- outToken,
169
- });
170
- // 设置 blockhash
171
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
172
- swapTx.recentBlockhash = blockhash;
173
- swapTx.lastValidBlockHeight = lastValidBlockHeight;
174
- swapTx.feePayer = wallet.publicKey;
175
- // 签名
176
- swapTx.sign(wallet);
177
- return {
178
- signedTransaction: swapTx,
179
- type: swapYtoX ? 'dlmm_buy' : 'dlmm_sell',
180
- poolAddress: params.poolAddress,
181
- metadata: {
182
- amountIn: params.amountIn.toString(),
183
- minAmountOut: minAmountOut.toString(),
184
- inputMint: params.inputMint,
185
- outputMint: params.outputMint,
186
- },
187
- };
188
- }
189
- // ============================================================================
190
- // 添加流动性
191
- // ============================================================================
192
- /**
193
- * 签名 DLMM 添加流动性交易
194
- * @param params 添加流动性参数
195
- * @param wallet 钱包
196
- * @param positionKeypair 仓位 Keypair(如果创建新仓位)
197
- * @param connection 可选连接
198
- */
199
- export async function signDlmmAddLiquidity(params, wallet, positionKeypair, connection) {
200
- const conn = getConnection(connection);
201
- const dlmmPool = await getDlmmPool(params.poolAddress, connection);
202
- // 获取活跃 bin
203
- const activeBin = await dlmmPool.getActiveBin();
204
- // 计算 bin 范围
205
- const minBinId = params.minBinId ?? activeBin.binId - 10;
206
- const maxBinId = params.maxBinId ?? activeBin.binId + 10;
207
- let tx;
208
- if (params.positionAddress) {
209
- // 添加到现有仓位
210
- tx = await dlmmPool.addLiquidityByStrategy({
211
- positionPubKey: new PublicKey(params.positionAddress),
212
- user: wallet.publicKey,
213
- totalXAmount: params.amountX,
214
- totalYAmount: params.amountY,
215
- strategy: {
216
- maxBinId,
217
- minBinId,
218
- strategyType: StrategyType.Spot,
219
- },
220
- });
221
- }
222
- else {
223
- // 创建新仓位并添加流动性
224
- const newPosition = positionKeypair || Keypair.generate();
225
- tx = await dlmmPool.initializePositionAndAddLiquidityByStrategy({
226
- positionPubKey: newPosition.publicKey,
227
- user: wallet.publicKey,
228
- totalXAmount: params.amountX,
229
- totalYAmount: params.amountY,
230
- strategy: {
231
- maxBinId,
232
- minBinId,
233
- strategyType: StrategyType.Spot,
234
- },
235
- });
236
- // 设置 blockhash
237
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
238
- tx.recentBlockhash = blockhash;
239
- tx.lastValidBlockHeight = lastValidBlockHeight;
240
- tx.feePayer = wallet.publicKey;
241
- // 签名 - 包括 position keypair
242
- tx.sign(wallet, newPosition);
243
- return {
244
- signedTransaction: tx,
245
- type: 'dlmm_add_liquidity',
246
- poolAddress: params.poolAddress,
247
- metadata: {
248
- amountX: params.amountX.toString(),
249
- amountY: params.amountY.toString(),
250
- minBinId,
251
- maxBinId,
252
- newPosition: newPosition.publicKey.toBase58(),
253
- },
254
- };
255
- }
256
- // 设置 blockhash
257
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
258
- tx.recentBlockhash = blockhash;
259
- tx.lastValidBlockHeight = lastValidBlockHeight;
260
- tx.feePayer = wallet.publicKey;
261
- // 签名
262
- tx.sign(wallet);
263
- return {
264
- signedTransaction: tx,
265
- type: 'dlmm_add_liquidity',
266
- poolAddress: params.poolAddress,
267
- metadata: {
268
- amountX: params.amountX.toString(),
269
- amountY: params.amountY.toString(),
270
- minBinId,
271
- maxBinId,
272
- positionAddress: params.positionAddress,
273
- },
274
- };
275
- }
276
- // ============================================================================
277
- // 移除流动性
278
- // ============================================================================
279
- /**
280
- * 签名 DLMM 移除流动性交易
281
- * @param params 移除流动性参数
282
- * @param wallet 钱包
283
- * @param connection 可选连接
284
- */
285
- export async function signDlmmRemoveLiquidity(params, wallet, connection) {
286
- const conn = getConnection(connection);
287
- const dlmmPool = await getDlmmPool(params.poolAddress, connection);
288
- // 获取用户仓位
289
- const positionsState = await dlmmPool.getPositionsByUserAndLbPair(wallet.publicKey);
290
- const position = positionsState.userPositions.find((p) => p.publicKey.toBase58() === params.positionAddress);
291
- if (!position) {
292
- throw new Error(`Position not found: ${params.positionAddress}`);
293
- }
294
- // 获取仓位的 bin IDs
295
- const binIds = position.positionData.positionBinData.map((bin) => bin.binId);
296
- const fromBinId = binIds[0];
297
- const toBinId = binIds[binIds.length - 1];
298
- // 移除流动性 - 返回 Transaction[]
299
- const removeLiquidityTxs = await dlmmPool.removeLiquidity({
300
- position: new PublicKey(params.positionAddress),
301
- user: wallet.publicKey,
302
- fromBinId,
303
- toBinId,
304
- bps: params.bps,
305
- shouldClaimAndClose: params.shouldClaimAndClose ?? false,
306
- });
307
- // 处理返回的交易数组
308
- const signedTransactions = [];
309
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
310
- for (const tx of removeLiquidityTxs) {
311
- tx.recentBlockhash = blockhash;
312
- tx.lastValidBlockHeight = lastValidBlockHeight;
313
- tx.feePayer = wallet.publicKey;
314
- tx.sign(wallet);
315
- signedTransactions.push(tx);
316
- }
317
- return {
318
- signedTransaction: signedTransactions[0],
319
- signedTransactions,
320
- type: 'dlmm_remove_liquidity',
321
- poolAddress: params.poolAddress,
322
- metadata: {
323
- positionAddress: params.positionAddress,
324
- bps: params.bps.toString(),
325
- shouldClaimAndClose: params.shouldClaimAndClose ?? false,
326
- transactionCount: signedTransactions.length,
327
- },
328
- };
329
- }
330
- // ============================================================================
331
- // 创建池
332
- // ============================================================================
333
- /**
334
- * 签名创建 DLMM 池交易
335
- * @param tokenXMint Token X Mint 地址
336
- * @param tokenYMint Token Y Mint 地址
337
- * @param binStep Bin Step
338
- * @param activeId 初始活跃 Bin ID
339
- * @param feeBps 费率 (bps)
340
- * @param wallet 钱包
341
- * @param connection 可选连接
342
- */
343
- export async function signDlmmCreatePool(tokenXMint, tokenYMint, binStep, activeId, feeBps, wallet, connection) {
344
- const conn = getConnection(connection);
345
- // 需要直接使用 DLMM 类的静态方法
346
- const DLMMModule = (await import('@meteora-ag/dlmm')).default;
347
- // 创建自定义 permissionless 池
348
- const createPoolTx = await DLMMModule.createCustomizablePermissionlessLbPair(conn, new BN(binStep), new PublicKey(tokenXMint), new PublicKey(tokenYMint), new BN(activeId), new BN(feeBps), ActivationType.Timestamp, false, wallet.publicKey);
349
- // 设置 blockhash
350
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
351
- createPoolTx.recentBlockhash = blockhash;
352
- createPoolTx.lastValidBlockHeight = lastValidBlockHeight;
353
- createPoolTx.feePayer = wallet.publicKey;
354
- // 签名
355
- createPoolTx.sign(wallet);
356
- return {
357
- signedTransaction: createPoolTx,
358
- type: 'dlmm_create_pool',
359
- poolAddress: '',
360
- metadata: {
361
- tokenXMint,
362
- tokenYMint,
363
- binStep,
364
- activeId,
365
- feeBps,
366
- },
367
- };
368
- }
369
- // ============================================================================
370
- // 领取费用
371
- // ============================================================================
372
- /**
373
- * 签名领取 DLMM 手续费交易
374
- * @param poolAddress 池地址
375
- * @param positionAddress 仓位地址
376
- * @param wallet 钱包
377
- * @param connection 可选连接
378
- */
379
- export async function signDlmmClaimFees(poolAddress, positionAddress, wallet, connection) {
380
- const conn = getConnection(connection);
381
- const dlmmPool = await getDlmmPool(poolAddress, connection);
382
- // 领取费用
383
- const claimFeeTx = await dlmmPool.claimSwapFee({
384
- owner: wallet.publicKey,
385
- position: new PublicKey(positionAddress),
386
- });
387
- // 设置 blockhash
388
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
389
- claimFeeTx.recentBlockhash = blockhash;
390
- claimFeeTx.lastValidBlockHeight = lastValidBlockHeight;
391
- claimFeeTx.feePayer = wallet.publicKey;
392
- // 签名
393
- claimFeeTx.sign(wallet);
394
- return {
395
- signedTransaction: claimFeeTx,
396
- type: 'dlmm_claim_fees',
397
- poolAddress,
398
- metadata: {
399
- positionAddress,
400
- },
401
- };
402
- }
403
- // ============================================================================
404
- // 辅助函数
405
- // ============================================================================
406
- /**
407
- * 获取用户在池中的所有仓位
408
- * @param poolAddress 池地址
409
- * @param userAddress 用户地址
410
- * @param connection 可选连接
411
- */
412
- export async function getDlmmUserPositions(poolAddress, userAddress, connection) {
413
- const dlmmPool = await getDlmmPool(poolAddress, connection);
414
- const positionsState = await dlmmPool.getPositionsByUserAndLbPair(new PublicKey(userAddress));
415
- return positionsState.userPositions.map((position) => ({
416
- publicKey: position.publicKey.toBase58(),
417
- positionData: {
418
- lowerBinId: position.positionData.lowerBinId,
419
- upperBinId: position.positionData.upperBinId,
420
- totalXAmount: position.positionData.totalXAmount?.toString() || '0',
421
- totalYAmount: position.positionData.totalYAmount?.toString() || '0',
422
- feeX: position.positionData.feeX?.toString() || '0',
423
- feeY: position.positionData.feeY?.toString() || '0',
424
- },
425
- }));
426
- }
427
- // ============================================================================
428
- // 报价查询
429
- // ============================================================================
430
- /**
431
- * 获取 DLMM Swap 报价
432
- * @param poolAddress 池地址
433
- * @param amountIn 输入金额
434
- * @param swapYtoX 是否从 Y 交换到 X
435
- * @param slippageBps 滑点 (bps)
436
- * @param connection 可选连接
437
- */
438
- export async function getDlmmSwapQuote(poolAddress, amountIn, swapYtoX, slippageBps = 100, connection) {
439
- const dlmmPool = await getDlmmPool(poolAddress, connection);
440
- // 获取 bin arrays
441
- const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);
442
- // 获取报价
443
- const quote = dlmmPool.swapQuote(amountIn, swapYtoX, new BN(slippageBps), binArrays);
444
- return {
445
- consumedInAmount: quote.consumedInAmount.toString(),
446
- outAmount: quote.outAmount.toString(),
447
- minOutAmount: quote.minOutAmount.toString(),
448
- fee: quote.fee.toString(),
449
- priceImpact: quote.priceImpact ? quote.priceImpact.toString() : '0',
450
- };
451
- }
452
- /**
453
- * 签名 DLMM Swap Exact Out 交易 (指定输出金额)
454
- * @param poolAddress 池地址
455
- * @param amountOut 期望输出金额
456
- * @param inputMint 输入代币 Mint
457
- * @param maxAmountIn 最大输入金额
458
- * @param wallet 钱包
459
- * @param connection 可选连接
460
- */
461
- export async function signDlmmSwapExactOut(poolAddress, amountOut, inputMint, maxAmountIn, wallet, connection) {
462
- const conn = getConnection(connection);
463
- const dlmmPool = await getDlmmPool(poolAddress, connection);
464
- // 确定交易方向
465
- const swapYtoX = inputMint === dlmmPool.tokenY.publicKey.toBase58();
466
- // 获取 bin arrays
467
- const binArrays = await dlmmPool.getBinArrayForSwap(swapYtoX);
468
- // 获取 exact out 报价
469
- const swapQuote = dlmmPool.swapQuoteExactOut(amountOut, swapYtoX, new BN(100), // slippage
470
- binArrays);
471
- // 确定输入输出 token
472
- const [inToken, outToken] = swapYtoX
473
- ? [dlmmPool.tokenY.publicKey, dlmmPool.tokenX.publicKey]
474
- : [dlmmPool.tokenX.publicKey, dlmmPool.tokenY.publicKey];
475
- // 构建 Swap 交易 - 使用 maxAmountIn 作为输入
476
- const swapTx = await dlmmPool.swap({
477
- inToken,
478
- binArraysPubkey: swapQuote.binArraysPubkey,
479
- inAmount: maxAmountIn.lt(swapQuote.maxInAmount) ? maxAmountIn : swapQuote.maxInAmount,
480
- lbPair: dlmmPool.pubkey,
481
- user: wallet.publicKey,
482
- minOutAmount: amountOut,
483
- outToken,
484
- });
485
- // 设置 blockhash
486
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
487
- swapTx.recentBlockhash = blockhash;
488
- swapTx.lastValidBlockHeight = lastValidBlockHeight;
489
- swapTx.feePayer = wallet.publicKey;
490
- // 签名
491
- swapTx.sign(wallet);
492
- return {
493
- signedTransaction: swapTx,
494
- type: swapYtoX ? 'dlmm_buy_exact_out' : 'dlmm_sell_exact_out',
495
- poolAddress,
496
- metadata: {
497
- amountOut: amountOut.toString(),
498
- maxAmountIn: maxAmountIn.toString(),
499
- inputMint,
500
- },
501
- };
502
- }
503
- // ============================================================================
504
- // 奖励领取
505
- // ============================================================================
506
- /**
507
- * 签名领取 DLMM 所有奖励交易
508
- * @param poolAddress 池地址
509
- * @param positionAddresses 仓位地址列表
510
- * @param wallet 钱包
511
- * @param connection 可选连接
512
- */
513
- export async function signDlmmClaimAllRewards(poolAddress, positionAddresses, wallet, connection) {
514
- const conn = getConnection(connection);
515
- const dlmmPool = await getDlmmPool(poolAddress, connection);
516
- // 领取所有奖励(包括交易费和农场奖励)
517
- const claimTxs = await dlmmPool.claimAllRewards({
518
- owner: wallet.publicKey,
519
- positions: positionAddresses.map((addr) => new PublicKey(addr)),
520
- });
521
- // 合并所有交易
522
- const combinedTx = new Transaction();
523
- for (const tx of claimTxs) {
524
- combinedTx.add(...tx.instructions);
525
- }
526
- // 设置 blockhash
527
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
528
- combinedTx.recentBlockhash = blockhash;
529
- combinedTx.lastValidBlockHeight = lastValidBlockHeight;
530
- combinedTx.feePayer = wallet.publicKey;
531
- // 签名
532
- combinedTx.sign(wallet);
533
- return {
534
- signedTransaction: combinedTx,
535
- type: 'dlmm_claim_all_rewards',
536
- poolAddress,
537
- metadata: {
538
- positionCount: positionAddresses.length,
539
- },
540
- };
541
- }
542
- // ============================================================================
543
- // 仓位管理
544
- // ============================================================================
545
- /**
546
- * 签名关闭 DLMM 仓位交易
547
- * @param poolAddress 池地址
548
- * @param positionAddress 仓位地址
549
- * @param wallet 钱包
550
- * @param connection 可选连接
551
- */
552
- export async function signDlmmClosePosition(poolAddress, positionAddress, wallet, connection) {
553
- const conn = getConnection(connection);
554
- const dlmmPool = await getDlmmPool(poolAddress, connection);
555
- // 关闭仓位
556
- const closeTx = await dlmmPool.closePosition({
557
- owner: wallet.publicKey,
558
- position: new PublicKey(positionAddress),
559
- });
560
- // 设置 blockhash
561
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
562
- closeTx.recentBlockhash = blockhash;
563
- closeTx.lastValidBlockHeight = lastValidBlockHeight;
564
- closeTx.feePayer = wallet.publicKey;
565
- // 签名
566
- closeTx.sign(wallet);
567
- return {
568
- signedTransaction: closeTx,
569
- type: 'dlmm_close_position',
570
- poolAddress,
571
- metadata: {
572
- positionAddress,
573
- },
574
- };
575
- }
576
- /**
577
- * 签名创建空的 DLMM 仓位交易
578
- * @param poolAddress 池地址
579
- * @param wallet 钱包
580
- * @param positionKeypair 仓位 Keypair
581
- * @param connection 可选连接
582
- */
583
- export async function signDlmmCreateEmptyPosition(poolAddress, wallet, positionKeypair, connection) {
584
- const conn = getConnection(connection);
585
- const dlmmPool = await getDlmmPool(poolAddress, connection);
586
- // 创建空仓位
587
- const createPositionTx = await dlmmPool.initializePosition({
588
- positionPubKey: positionKeypair.publicKey,
589
- owner: wallet.publicKey,
590
- });
591
- // 设置 blockhash
592
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
593
- createPositionTx.recentBlockhash = blockhash;
594
- createPositionTx.lastValidBlockHeight = lastValidBlockHeight;
595
- createPositionTx.feePayer = wallet.publicKey;
596
- // 签名 - 包括 position keypair
597
- createPositionTx.sign(wallet, positionKeypair);
598
- return {
599
- signedTransaction: createPositionTx,
600
- type: 'dlmm_create_empty_position',
601
- poolAddress,
602
- metadata: {
603
- positionAddress: positionKeypair.publicKey.toBase58(),
604
- },
605
- };
606
- }
607
- /**
608
- * 获取用户在所有 DLMM 池中的仓位
609
- * @param userAddress 用户地址
610
- * @param connection 可选连接
611
- */
612
- export async function getAllDlmmUserPositions(userAddress, connection) {
613
- const conn = getConnection(connection);
614
- const DLMMModule = (await import('@meteora-ag/dlmm')).default;
615
- // 获取用户的所有 DLMM 仓位
616
- const allPositions = await DLMMModule.getAllLbPairPositionsByUser(conn, new PublicKey(userAddress));
617
- const result = [];
618
- for (const [poolKey, poolPositions] of allPositions.entries()) {
619
- const positions = poolPositions.map((position) => ({
620
- publicKey: position.publicKey.toBase58(),
621
- positionData: {
622
- lowerBinId: position.positionData.lowerBinId,
623
- upperBinId: position.positionData.upperBinId,
624
- totalXAmount: position.positionData.totalXAmount?.toString() || '0',
625
- totalYAmount: position.positionData.totalYAmount?.toString() || '0',
626
- feeX: position.positionData.feeX?.toString() || '0',
627
- feeY: position.positionData.feeY?.toString() || '0',
628
- },
629
- }));
630
- result.push({
631
- poolAddress: poolKey.toString(),
632
- positions,
633
- });
634
- }
635
- return result;
636
- }
637
- // ============================================================================
638
- // 价格计算
639
- // ============================================================================
640
- /**
641
- * 计算 Bin ID 对应的价格
642
- * @param binId Bin ID
643
- * @param binStep Bin Step
644
- * @param tokenXDecimals Token X 精度
645
- * @param tokenYDecimals Token Y 精度
646
- */
647
- export function calculatePriceFromBinId(binId, binStep, tokenXDecimals, tokenYDecimals) {
648
- // 价格公式: price = (1 + binStep / 10000) ^ (binId - 8388608)
649
- const base = 1 + binStep / 10000;
650
- const exponent = binId - 8388608;
651
- const price = Math.pow(base, exponent);
652
- // 调整精度
653
- const decimalAdjustment = Math.pow(10, tokenYDecimals - tokenXDecimals);
654
- return price * decimalAdjustment;
655
- }
656
- /**
657
- * 计算价格对应的 Bin ID
658
- * @param price 价格
659
- * @param binStep Bin Step
660
- * @param tokenXDecimals Token X 精度
661
- * @param tokenYDecimals Token Y 精度
662
- */
663
- export function calculateBinIdFromPrice(price, binStep, tokenXDecimals, tokenYDecimals) {
664
- // 调整精度
665
- const decimalAdjustment = Math.pow(10, tokenYDecimals - tokenXDecimals);
666
- const adjustedPrice = price / decimalAdjustment;
667
- // binId 公式: binId = log(price) / log(1 + binStep / 10000) + 8388608
668
- const base = 1 + binStep / 10000;
669
- const exponent = Math.log(adjustedPrice) / Math.log(base);
670
- return Math.round(exponent + 8388608);
671
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * Meteora DEX 集成模块
3
- *
4
- * 包含:
5
- * - DLMM: 集中流动性池 (类似 Uniswap V3)
6
- * - DBC: Dynamic Bonding Curve (代币发射平台)
7
- * - DAMM v1: 动态 AMM (DBC 毕业后迁移目标)
8
- * - DAMM v2: 恒定乘积 AMM (DBC 毕业后迁移目标,新版)
9
- *
10
- * SDK 源码参考:
11
- * - DLMM: sol文档/dlmm-sdk/
12
- * - DBC: sol文档/dynamic-bonding-curve-sdk/
13
- * - DAMM v1: sol文档/damm-v1-sdk/
14
- * - DAMM v2: sol文档/damm-v2-sdk/
15
- */
16
- export * from './types.js';
17
- export { getConnection, setDefaultConnection, resetDefaultConnection, getDlmmPool, getAllDlmmPools, clearDlmmCache, getDbcClient, resetDbcClient, getDammV1Pool, clearDammV1Cache, getCpAmmClient, resetCpAmmClient, clearAllMeteoraCache, setCacheTtl, getCacheTtl, } from './client.js';
18
- export { getDlmmPoolInfo, findDlmmPool, signDlmmSwap, signDlmmAddLiquidity, signDlmmRemoveLiquidity, signDlmmCreatePool, signDlmmClaimFees, getDlmmUserPositions, getDlmmSwapQuote, signDlmmSwapExactOut, signDlmmClaimAllRewards, signDlmmClosePosition, signDlmmCreateEmptyPosition, getAllDlmmUserPositions, calculatePriceFromBinId, calculateBinIdFromPrice, } from './dlmm.js';
19
- export { signDlmmBundleBuy, signDlmmBundleSell, signDlmmBundleSwap, toDlmmBundleApiRequest, } from './dlmm-bundle.js';
20
- export { getDbcPoolInfo, findDbcPoolByBaseMint, getDbcSwapQuote, signDbcSwap, signDbcMigrateToDammV1, signDbcMigrateToDammV2, signDbcClaimCreatorFee, signDbcClaimPartnerFee, signDbcCreateLocker, calculateLockedVestingParams, signDbcCreateConfig, signDbcCreatePool, signDbcCreatePoolWithFirstBuy, signDbcPartnerWithdrawMigrationFee, signDbcPartnerWithdrawSurplus, signDbcCreatorWithdrawMigrationFee, signDbcCreatorWithdrawSurplus, signDbcClaimDammV1LpToken, getDbcConfigInfo, getAllDbcPools, getDbcUserBalance, } from './dbc.js';
21
- export { signDbcBundleBuy, signDbcBundleSell, signDbcBundleSwap, signDbcCreatePoolAndBundleBuy, signDbcCreatePoolBundleBuyWithConfig, toDbcBundleApiRequest, type DbcCreatePoolAndBundleBuyParams, type DbcCreatePoolBundleResult, } from './dbc-bundle.js';
22
- export { getDammV1PoolInfo, signDammV1Swap, signDammV1Deposit, signDammV1Withdraw, signDammV1LockLiquidity, signDammV1ClaimLockFee, getDammV1LpMint, getDammV1LpSupply, getDammV1LockedLpAmount, signDammV1CreatePool, getDammV1SwapQuote, getDammV1DepositQuote, getDammV1WithdrawQuote, getDammV1UserLpBalance, getDammV1VirtualPrice, } from './damm-v1.js';
23
- export { signDammV1BundleBuy, signDammV1BundleSell, signDammV1BundleSwap, toDammV1BundleApiRequest, type DammV1BundleSwapParams, } from './damm-v1-bundle.js';
24
- export { getDammV2PoolInfo, signDammV2Swap, signDammV2AddLiquidity, signDammV2RemoveLiquidity, signDammV2ClaimPositionFee, signDammV2PermanentLockPosition, getDammV2UserPositions, deriveDammV2PoolAddress, deriveDammV2PositionAddress, signDammV2CreatePool, signDammV2CreatePosition, getDammV2SwapQuote, getDammV2LiquidityDelta, signDammV2ClosePosition, signDammV2RemoveAllLiquidity, signDammV2LockPosition, signDammV2ClaimReward, getDammV2PositionInfo, getDammV2ConfigInfo, } from './damm-v2.js';
25
- export { signDammV2BundleBuy, signDammV2BundleSell, signDammV2BundleSwap, toDammV2BundleApiRequest, getDammV2BundleQuotes, type DammV2BundleSwapParams, } from './damm-v2-bundle.js';