four-flap-meme-sdk 1.3.92 → 1.3.93

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