four-flap-meme-sdk 1.3.87 → 1.3.89

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 (122) hide show
  1. package/dist/clients/blockrazor.js +0 -1
  2. package/dist/contracts/tm-bundle-merkle/core.js +6 -3
  3. package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +30 -38
  4. package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +0 -1
  5. package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +4 -3
  6. package/dist/contracts/tm-bundle-merkle/swap.d.ts +0 -3
  7. package/dist/contracts/tm-bundle-merkle/swap.js +2 -2
  8. package/dist/flap/portal-bundle-merkle/core.js +2 -6
  9. package/dist/flap/portal-bundle-merkle/encryption.d.ts +16 -0
  10. package/dist/flap/portal-bundle-merkle/encryption.js +146 -0
  11. package/dist/flap/portal-bundle-merkle/pancake-proxy.js +55 -35
  12. package/dist/flap/portal-bundle-merkle/swap-buy-first.d.ts +0 -2
  13. package/dist/flap/portal-bundle-merkle/swap-buy-first.js +6 -11
  14. package/dist/flap/portal-bundle-merkle/swap.d.ts +0 -2
  15. package/dist/flap/portal-bundle-merkle/swap.js +10 -22
  16. package/dist/index.d.ts +1 -2
  17. package/dist/index.js +0 -1
  18. package/dist/pancake/bundle-buy-first.d.ts +0 -1
  19. package/dist/pancake/bundle-buy-first.js +4 -9
  20. package/dist/pancake/bundle-swap.d.ts +0 -4
  21. package/dist/pancake/bundle-swap.js +7 -14
  22. package/dist/utils/erc20.d.ts +108 -2
  23. package/dist/utils/erc20.js +65 -17
  24. package/package.json +4 -39
  25. package/dist/sol/constants.d.ts +0 -136
  26. package/dist/sol/constants.js +0 -156
  27. package/dist/sol/dex/index.d.ts +0 -8
  28. package/dist/sol/dex/index.js +0 -12
  29. package/dist/sol/dex/meteora/client.d.ts +0 -75
  30. package/dist/sol/dex/meteora/client.js +0 -218
  31. package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +0 -61
  32. package/dist/sol/dex/meteora/damm-v1-bundle.js +0 -112
  33. package/dist/sol/dex/meteora/damm-v1.d.ts +0 -118
  34. package/dist/sol/dex/meteora/damm-v1.js +0 -315
  35. package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +0 -82
  36. package/dist/sol/dex/meteora/damm-v2-bundle.js +0 -242
  37. package/dist/sol/dex/meteora/damm-v2.d.ts +0 -172
  38. package/dist/sol/dex/meteora/damm-v2.js +0 -632
  39. package/dist/sol/dex/meteora/dbc-bundle.d.ts +0 -123
  40. package/dist/sol/dex/meteora/dbc-bundle.js +0 -304
  41. package/dist/sol/dex/meteora/dbc.d.ts +0 -192
  42. package/dist/sol/dex/meteora/dbc.js +0 -619
  43. package/dist/sol/dex/meteora/dlmm-bundle.d.ts +0 -39
  44. package/dist/sol/dex/meteora/dlmm-bundle.js +0 -189
  45. package/dist/sol/dex/meteora/dlmm.d.ts +0 -146
  46. package/dist/sol/dex/meteora/dlmm.js +0 -593
  47. package/dist/sol/dex/meteora/index.d.ts +0 -25
  48. package/dist/sol/dex/meteora/index.js +0 -65
  49. package/dist/sol/dex/meteora/types.d.ts +0 -787
  50. package/dist/sol/dex/meteora/types.js +0 -110
  51. package/dist/sol/dex/orca/index.d.ts +0 -10
  52. package/dist/sol/dex/orca/index.js +0 -16
  53. package/dist/sol/dex/orca/orca-bundle.d.ts +0 -41
  54. package/dist/sol/dex/orca/orca-bundle.js +0 -167
  55. package/dist/sol/dex/orca/orca.d.ts +0 -65
  56. package/dist/sol/dex/orca/orca.js +0 -454
  57. package/dist/sol/dex/orca/types.d.ts +0 -263
  58. package/dist/sol/dex/orca/types.js +0 -38
  59. package/dist/sol/dex/orca/wavebreak-bundle.d.ts +0 -34
  60. package/dist/sol/dex/orca/wavebreak-bundle.js +0 -189
  61. package/dist/sol/dex/orca/wavebreak-types.d.ts +0 -227
  62. package/dist/sol/dex/orca/wavebreak-types.js +0 -23
  63. package/dist/sol/dex/orca/wavebreak.d.ts +0 -78
  64. package/dist/sol/dex/orca/wavebreak.js +0 -469
  65. package/dist/sol/dex/pump/index.d.ts +0 -9
  66. package/dist/sol/dex/pump/index.js +0 -14
  67. package/dist/sol/dex/pump/pump-bundle.d.ts +0 -92
  68. package/dist/sol/dex/pump/pump-bundle.js +0 -383
  69. package/dist/sol/dex/pump/pump-swap-bundle.d.ts +0 -103
  70. package/dist/sol/dex/pump/pump-swap-bundle.js +0 -380
  71. package/dist/sol/dex/pump/pump-swap.d.ts +0 -46
  72. package/dist/sol/dex/pump/pump-swap.js +0 -199
  73. package/dist/sol/dex/pump/pump.d.ts +0 -35
  74. package/dist/sol/dex/pump/pump.js +0 -352
  75. package/dist/sol/dex/pump/types.d.ts +0 -215
  76. package/dist/sol/dex/pump/types.js +0 -5
  77. package/dist/sol/dex/raydium/index.d.ts +0 -8
  78. package/dist/sol/dex/raydium/index.js +0 -12
  79. package/dist/sol/dex/raydium/launchlab.d.ts +0 -68
  80. package/dist/sol/dex/raydium/launchlab.js +0 -210
  81. package/dist/sol/dex/raydium/raydium-bundle.d.ts +0 -64
  82. package/dist/sol/dex/raydium/raydium-bundle.js +0 -324
  83. package/dist/sol/dex/raydium/raydium.d.ts +0 -40
  84. package/dist/sol/dex/raydium/raydium.js +0 -366
  85. package/dist/sol/dex/raydium/types.d.ts +0 -240
  86. package/dist/sol/dex/raydium/types.js +0 -5
  87. package/dist/sol/index.d.ts +0 -10
  88. package/dist/sol/index.js +0 -16
  89. package/dist/sol/jito/bundle.d.ts +0 -90
  90. package/dist/sol/jito/bundle.js +0 -263
  91. package/dist/sol/jito/index.d.ts +0 -7
  92. package/dist/sol/jito/index.js +0 -7
  93. package/dist/sol/jito/tip.d.ts +0 -51
  94. package/dist/sol/jito/tip.js +0 -83
  95. package/dist/sol/jito/types.d.ts +0 -100
  96. package/dist/sol/jito/types.js +0 -5
  97. package/dist/sol/token/create-complete.d.ts +0 -115
  98. package/dist/sol/token/create-complete.js +0 -235
  99. package/dist/sol/token/create-token.d.ts +0 -57
  100. package/dist/sol/token/create-token.js +0 -230
  101. package/dist/sol/token/index.d.ts +0 -9
  102. package/dist/sol/token/index.js +0 -14
  103. package/dist/sol/token/metadata-upload.d.ts +0 -86
  104. package/dist/sol/token/metadata-upload.js +0 -173
  105. package/dist/sol/token/metadata.d.ts +0 -92
  106. package/dist/sol/token/metadata.js +0 -274
  107. package/dist/sol/token/types.d.ts +0 -153
  108. package/dist/sol/token/types.js +0 -5
  109. package/dist/sol/types.d.ts +0 -176
  110. package/dist/sol/types.js +0 -7
  111. package/dist/sol/utils/balance.d.ts +0 -160
  112. package/dist/sol/utils/balance.js +0 -638
  113. package/dist/sol/utils/connection.d.ts +0 -69
  114. package/dist/sol/utils/connection.js +0 -156
  115. package/dist/sol/utils/index.d.ts +0 -9
  116. package/dist/sol/utils/index.js +0 -9
  117. package/dist/sol/utils/lp-inspect.d.ts +0 -129
  118. package/dist/sol/utils/lp-inspect.js +0 -515
  119. package/dist/sol/utils/transfer.d.ts +0 -125
  120. package/dist/sol/utils/transfer.js +0 -220
  121. package/dist/sol/utils/wallet.d.ts +0 -107
  122. package/dist/sol/utils/wallet.js +0 -210
@@ -1,454 +0,0 @@
1
- /**
2
- * Orca Whirlpool 核心功能
3
- * 提供 Swap、LP 添加/移除等功能
4
- *
5
- * 基于 @orca-so/whirlpools-sdk (Legacy SDK)
6
- * 文档: https://dev.orca.so/SDKs/Overview
7
- */
8
- import { PublicKey, Transaction, } from '@solana/web3.js';
9
- import { WhirlpoolContext, buildWhirlpoolClient, ORCA_WHIRLPOOL_PROGRAM_ID, PDAUtil, TickUtil, PriceMath, PoolUtil, TokenExtensionUtil, } from '@orca-so/whirlpools-sdk';
10
- import { Percentage, AddressUtil, DecimalUtil } from '@orca-so/common-sdk';
11
- import { createConnection } from '../../utils/connection.js';
12
- import { ORCA_WHIRLPOOL_CONFIG } from './types.js';
13
- /**
14
- * 从 Keypair 创建 Wallet 适配器(兼容浏览器环境)
15
- */
16
- function createWalletFromKeypair(keypair) {
17
- return {
18
- publicKey: keypair.publicKey,
19
- signTransaction: async (tx) => {
20
- if (tx instanceof Transaction) {
21
- tx.partialSign(keypair);
22
- }
23
- else {
24
- // VersionedTransaction
25
- tx.sign([keypair]);
26
- }
27
- return tx;
28
- },
29
- signAllTransactions: async (txs) => {
30
- for (const tx of txs) {
31
- if (tx instanceof Transaction) {
32
- tx.partialSign(keypair);
33
- }
34
- else {
35
- tx.sign([keypair]);
36
- }
37
- }
38
- return txs;
39
- },
40
- };
41
- }
42
- /**
43
- * 创建 Orca Whirlpool Context
44
- */
45
- export async function createOrcaContext(connection, wallet) {
46
- const conn = connection || createConnection();
47
- // 创建 Wallet 适配器(不依赖 @coral-xyz/anchor 的 Wallet 类)
48
- const anchorWallet = wallet
49
- ? createWalletFromKeypair(wallet)
50
- : {
51
- publicKey: PublicKey.default,
52
- signTransaction: async (tx) => tx,
53
- signAllTransactions: async (txs) => txs,
54
- };
55
- // WhirlpoolContext.from 只需要 connection 和 wallet
56
- const ctx = WhirlpoolContext.from(conn, anchorWallet);
57
- return ctx;
58
- }
59
- /**
60
- * 创建 Orca Whirlpool Client
61
- */
62
- export async function createOrcaClient(connection, wallet) {
63
- const ctx = await createOrcaContext(connection, wallet);
64
- return buildWhirlpoolClient(ctx);
65
- }
66
- /**
67
- * 获取 Orca Whirlpool 池信息
68
- */
69
- export async function getOrcaPoolInfo(poolAddress, connection) {
70
- const client = await createOrcaClient(connection);
71
- const pool = await client.getPool(poolAddress);
72
- const data = pool.getData();
73
- const tokenInfoA = pool.getTokenAInfo();
74
- const tokenInfoB = pool.getTokenBInfo();
75
- const vaultInfoA = pool.getTokenVaultAInfo();
76
- const vaultInfoB = pool.getTokenVaultBInfo();
77
- const rewardInfos = pool.getRewardInfos();
78
- // 计算当前价格
79
- const price = PriceMath.sqrtPriceX64ToPrice(data.sqrtPrice, tokenInfoA.decimals, tokenInfoB.decimals);
80
- return {
81
- poolAddress,
82
- tokenMintA: tokenInfoA.mint.toBase58(),
83
- tokenMintB: tokenInfoB.mint.toBase58(),
84
- tokenDecimalsA: tokenInfoA.decimals,
85
- tokenDecimalsB: tokenInfoB.decimals,
86
- tokenVaultA: vaultInfoA.address.toBase58(),
87
- tokenVaultB: vaultInfoB.address.toBase58(),
88
- price: price.toNumber(),
89
- sqrtPrice: data.sqrtPrice.toString(),
90
- currentTick: data.tickCurrentIndex,
91
- tickSpacing: data.tickSpacing,
92
- feeRate: data.feeRate,
93
- protocolFeeRate: data.protocolFeeRate,
94
- liquidity: data.liquidity.toString(),
95
- feeGrowthGlobalA: data.feeGrowthGlobalA.toString(),
96
- feeGrowthGlobalB: data.feeGrowthGlobalB.toString(),
97
- rewardInfos: rewardInfos.map(info => ({
98
- mint: info.mint.toBase58(),
99
- vault: info.vault.toBase58(),
100
- emissionsPerSecond: info.emissionsPerSecondX64.toString(),
101
- growthGlobal: info.growthGlobalX64.toString(),
102
- })),
103
- };
104
- }
105
- /**
106
- * 查找 Orca Whirlpool 池
107
- */
108
- export async function findOrcaPool(tokenMintA, tokenMintB, tickSpacing = 64, connection) {
109
- const conn = connection || createConnection();
110
- // 确保代币顺序正确 (按地址排序)
111
- const [mintAAddr, mintBAddr] = PoolUtil.orderMints(new PublicKey(tokenMintA), new PublicKey(tokenMintB));
112
- // 转换为 PublicKey
113
- const mintA = AddressUtil.toPubKey(mintAAddr);
114
- const mintB = AddressUtil.toPubKey(mintBAddr);
115
- // 计算池 PDA
116
- const poolPda = PDAUtil.getWhirlpool(ORCA_WHIRLPOOL_PROGRAM_ID, new PublicKey(ORCA_WHIRLPOOL_CONFIG.MAINNET), mintA, mintB, tickSpacing);
117
- // 检查池是否存在
118
- const accountInfo = await conn.getAccountInfo(poolPda.publicKey);
119
- return accountInfo ? poolPda.publicKey.toBase58() : null;
120
- }
121
- /**
122
- * 签名 Orca Swap 交易
123
- * 使用 Whirlpool 的高级 swap 接口
124
- */
125
- export async function signOrcaSwap(params, payer, connection) {
126
- const conn = connection || createConnection();
127
- const client = await createOrcaClient(conn, payer);
128
- const pool = await client.getPool(params.poolAddress);
129
- const ctx = await createOrcaContext(conn, payer);
130
- const inputMint = new PublicKey(params.inputMint);
131
- const slippage = Percentage.fromFraction(params.slippageBps || 100, 10000);
132
- // 获取 token extension context
133
- const tokenInfoA = pool.getTokenAInfo();
134
- const tokenInfoB = pool.getTokenBInfo();
135
- const tokenExtensionCtx = await TokenExtensionUtil.buildTokenExtensionContextForPool(ctx.fetcher, tokenInfoA.mint, tokenInfoB.mint);
136
- // 使用 SDK 的 swapQuoteByInputToken
137
- const { swapQuoteByInputToken } = await import('@orca-so/whirlpools-sdk');
138
- const quote = await swapQuoteByInputToken(pool, inputMint, params.amountIn, slippage, ORCA_WHIRLPOOL_PROGRAM_ID, ctx.fetcher);
139
- // 构建 swap 交易
140
- const txBuilder = await pool.swap(quote, payer.publicKey);
141
- // 获取最新区块哈希
142
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
143
- // 构建交易
144
- const tx = await txBuilder.build();
145
- // 如果是 Transaction 类型
146
- if ('recentBlockhash' in tx.transaction) {
147
- const transaction = tx.transaction;
148
- transaction.recentBlockhash = blockhash;
149
- transaction.lastValidBlockHeight = lastValidBlockHeight;
150
- transaction.feePayer = payer.publicKey;
151
- // 签名
152
- transaction.sign(payer, ...tx.signers);
153
- return {
154
- signedTransaction: transaction,
155
- type: 'swap',
156
- poolAddress: params.poolAddress,
157
- metadata: {
158
- estimatedAmountOut: quote.estimatedAmountOut.toString(),
159
- },
160
- };
161
- }
162
- // VersionedTransaction 类型
163
- const versionedTx = tx.transaction;
164
- versionedTx.sign([payer, ...tx.signers]);
165
- return {
166
- signedTransaction: versionedTx,
167
- type: 'swap',
168
- poolAddress: params.poolAddress,
169
- metadata: {
170
- estimatedAmountOut: quote.estimatedAmountOut.toString(),
171
- },
172
- };
173
- }
174
- /**
175
- * 签名 Orca 添加流动性交易
176
- */
177
- export async function signOrcaAddLiquidity(params, payer, connection) {
178
- const conn = connection || createConnection();
179
- const client = await createOrcaClient(conn, payer);
180
- const pool = await client.getPool(params.poolAddress);
181
- const ctx = await createOrcaContext(conn, payer);
182
- const tokenInfoA = pool.getTokenAInfo();
183
- const tokenInfoB = pool.getTokenBInfo();
184
- const slippage = Percentage.fromFraction(params.slippageBps || 100, 10000);
185
- // 获取 token extension context
186
- const tokenExtensionCtx = await TokenExtensionUtil.buildTokenExtensionContextForPool(ctx.fetcher, tokenInfoA.mint, tokenInfoB.mint);
187
- // 计算流动性报价
188
- const { increaseLiquidityQuoteByInputToken } = await import('@orca-so/whirlpools-sdk');
189
- // 使用 DecimalUtil 创建 Decimal 值 (从 BN 转换,不带小数位移位)
190
- const inputAmount = DecimalUtil.fromBN(params.tokenAmountA, 0);
191
- const quote = increaseLiquidityQuoteByInputToken(tokenInfoA.mint, inputAmount, params.tickLower, params.tickUpper, slippage, pool, tokenExtensionCtx);
192
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
193
- if (params.createNewPosition !== false) {
194
- // 创建新的 position
195
- const { positionMint, tx: txBuilder } = await pool.openPosition(params.tickLower, params.tickUpper, quote);
196
- const tx = await txBuilder.build();
197
- if ('recentBlockhash' in tx.transaction) {
198
- const transaction = tx.transaction;
199
- transaction.recentBlockhash = blockhash;
200
- transaction.lastValidBlockHeight = lastValidBlockHeight;
201
- transaction.feePayer = payer.publicKey;
202
- transaction.sign(payer, ...tx.signers);
203
- return {
204
- signedTransaction: transaction,
205
- type: 'addLiquidity',
206
- poolAddress: params.poolAddress,
207
- metadata: {
208
- positionMint: positionMint.toBase58(),
209
- liquidityAmount: quote.liquidityAmount.toString(),
210
- },
211
- };
212
- }
213
- const versionedTx = tx.transaction;
214
- versionedTx.sign([payer, ...tx.signers]);
215
- return {
216
- signedTransaction: versionedTx,
217
- type: 'addLiquidity',
218
- poolAddress: params.poolAddress,
219
- metadata: {
220
- positionMint: positionMint.toBase58(),
221
- liquidityAmount: quote.liquidityAmount.toString(),
222
- },
223
- };
224
- }
225
- else {
226
- // 增加已有 position 的流动性
227
- if (!params.positionAddress) {
228
- throw new Error('positionAddress is required when createNewPosition is false');
229
- }
230
- const position = await client.getPosition(params.positionAddress);
231
- const txBuilder = await position.increaseLiquidity(quote);
232
- const tx = await txBuilder.build();
233
- if ('recentBlockhash' in tx.transaction) {
234
- const transaction = tx.transaction;
235
- transaction.recentBlockhash = blockhash;
236
- transaction.lastValidBlockHeight = lastValidBlockHeight;
237
- transaction.feePayer = payer.publicKey;
238
- transaction.sign(payer, ...tx.signers);
239
- return {
240
- signedTransaction: transaction,
241
- type: 'addLiquidity',
242
- poolAddress: params.poolAddress,
243
- metadata: {
244
- positionAddress: params.positionAddress,
245
- liquidityAmount: quote.liquidityAmount.toString(),
246
- },
247
- };
248
- }
249
- const versionedTx = tx.transaction;
250
- versionedTx.sign([payer, ...tx.signers]);
251
- return {
252
- signedTransaction: versionedTx,
253
- type: 'addLiquidity',
254
- poolAddress: params.poolAddress,
255
- metadata: {
256
- positionAddress: params.positionAddress,
257
- liquidityAmount: quote.liquidityAmount.toString(),
258
- },
259
- };
260
- }
261
- }
262
- /**
263
- * 签名 Orca 移除流动性交易
264
- */
265
- export async function signOrcaRemoveLiquidity(params, payer, connection) {
266
- const conn = connection || createConnection();
267
- const client = await createOrcaClient(conn, payer);
268
- const ctx = await createOrcaContext(conn, payer);
269
- const position = await client.getPosition(params.positionAddress);
270
- const positionData = position.getData();
271
- const whirlpoolData = position.getWhirlpoolData();
272
- const pool = await client.getPool(positionData.whirlpool);
273
- const tokenInfoA = pool.getTokenAInfo();
274
- const tokenInfoB = pool.getTokenBInfo();
275
- const slippage = Percentage.fromFraction(params.slippageBps || 100, 10000);
276
- // 获取 token extension context
277
- const tokenExtensionCtx = await TokenExtensionUtil.buildTokenExtensionContextForPool(ctx.fetcher, tokenInfoA.mint, tokenInfoB.mint);
278
- // 确定要移除的流动性数量
279
- const liquidityToRemove = params.liquidityAmount || positionData.liquidity;
280
- // 计算移除流动性报价
281
- const { decreaseLiquidityQuoteByLiquidity } = await import('@orca-so/whirlpools-sdk');
282
- const quote = decreaseLiquidityQuoteByLiquidity(liquidityToRemove, slippage, position, pool, tokenExtensionCtx);
283
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
284
- if (params.closePosition) {
285
- // 关闭 position (移除全部流动性并关闭)
286
- const txBuilders = await pool.closePosition(params.positionAddress, slippage);
287
- const signedTxs = [];
288
- for (const txBuilder of txBuilders) {
289
- const tx = await txBuilder.build();
290
- if ('recentBlockhash' in tx.transaction) {
291
- const transaction = tx.transaction;
292
- transaction.recentBlockhash = blockhash;
293
- transaction.lastValidBlockHeight = lastValidBlockHeight;
294
- transaction.feePayer = payer.publicKey;
295
- transaction.sign(payer, ...tx.signers);
296
- signedTxs.push(transaction);
297
- }
298
- else {
299
- const versionedTx = tx.transaction;
300
- versionedTx.sign([payer, ...tx.signers]);
301
- signedTxs.push(versionedTx);
302
- }
303
- }
304
- // 返回第一个交易 (通常只有一个)
305
- return {
306
- signedTransaction: signedTxs[0],
307
- type: 'removeLiquidity',
308
- poolAddress: positionData.whirlpool.toBase58(),
309
- metadata: {
310
- positionAddress: params.positionAddress,
311
- liquidityAmount: liquidityToRemove.toString(),
312
- },
313
- };
314
- }
315
- else {
316
- // 只移除部分流动性
317
- const txBuilder = await position.decreaseLiquidity(quote);
318
- const tx = await txBuilder.build();
319
- if ('recentBlockhash' in tx.transaction) {
320
- const transaction = tx.transaction;
321
- transaction.recentBlockhash = blockhash;
322
- transaction.lastValidBlockHeight = lastValidBlockHeight;
323
- transaction.feePayer = payer.publicKey;
324
- transaction.sign(payer, ...tx.signers);
325
- return {
326
- signedTransaction: transaction,
327
- type: 'removeLiquidity',
328
- poolAddress: positionData.whirlpool.toBase58(),
329
- metadata: {
330
- positionAddress: params.positionAddress,
331
- liquidityAmount: liquidityToRemove.toString(),
332
- },
333
- };
334
- }
335
- const versionedTx = tx.transaction;
336
- versionedTx.sign([payer, ...tx.signers]);
337
- return {
338
- signedTransaction: versionedTx,
339
- type: 'removeLiquidity',
340
- poolAddress: positionData.whirlpool.toBase58(),
341
- metadata: {
342
- positionAddress: params.positionAddress,
343
- liquidityAmount: liquidityToRemove.toString(),
344
- },
345
- };
346
- }
347
- }
348
- /**
349
- * 签名创建 Orca Whirlpool 池交易
350
- */
351
- export async function signOrcaCreatePool(params, payer, connection) {
352
- const conn = connection || createConnection();
353
- const client = await createOrcaClient(conn, payer);
354
- const initialPrice = DecimalUtil.fromNumber(params.initialPrice);
355
- // 创建 Splash Pool (简化的全范围流动性池)
356
- const { poolKey, tx: txBuilder } = await client.createSplashPool(params.whirlpoolsConfig || ORCA_WHIRLPOOL_CONFIG.MAINNET, params.tokenMintA, params.tokenMintB, initialPrice, payer.publicKey.toBase58());
357
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
358
- const tx = await txBuilder.build();
359
- if ('recentBlockhash' in tx.transaction) {
360
- const transaction = tx.transaction;
361
- transaction.recentBlockhash = blockhash;
362
- transaction.lastValidBlockHeight = lastValidBlockHeight;
363
- transaction.feePayer = payer.publicKey;
364
- transaction.sign(payer, ...tx.signers);
365
- return {
366
- signedTransaction: transaction,
367
- type: 'createPool',
368
- poolAddress: poolKey.toBase58(),
369
- };
370
- }
371
- const versionedTx = tx.transaction;
372
- versionedTx.sign([payer, ...tx.signers]);
373
- return {
374
- signedTransaction: versionedTx,
375
- type: 'createPool',
376
- poolAddress: poolKey.toBase58(),
377
- };
378
- }
379
- /**
380
- * 签名收集费用交易
381
- */
382
- export async function signOrcaCollectFees(positionAddress, payer, connection) {
383
- const conn = connection || createConnection();
384
- const client = await createOrcaClient(conn, payer);
385
- const position = await client.getPosition(positionAddress);
386
- const positionData = position.getData();
387
- const txBuilder = await position.collectFees();
388
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
389
- const tx = await txBuilder.build();
390
- if ('recentBlockhash' in tx.transaction) {
391
- const transaction = tx.transaction;
392
- transaction.recentBlockhash = blockhash;
393
- transaction.lastValidBlockHeight = lastValidBlockHeight;
394
- transaction.feePayer = payer.publicKey;
395
- transaction.sign(payer, ...tx.signers);
396
- return {
397
- signedTransaction: transaction,
398
- type: 'collectFees',
399
- poolAddress: positionData.whirlpool.toBase58(),
400
- metadata: {
401
- positionAddress,
402
- },
403
- };
404
- }
405
- const versionedTx = tx.transaction;
406
- versionedTx.sign([payer, ...tx.signers]);
407
- return {
408
- signedTransaction: versionedTx,
409
- type: 'collectFees',
410
- poolAddress: positionData.whirlpool.toBase58(),
411
- metadata: {
412
- positionAddress,
413
- },
414
- };
415
- }
416
- /**
417
- * 获取 Position 信息
418
- */
419
- export async function getOrcaPositionInfo(positionAddress, connection) {
420
- const client = await createOrcaClient(connection);
421
- const position = await client.getPosition(positionAddress);
422
- const data = position.getData();
423
- return {
424
- positionAddress,
425
- positionMint: data.positionMint.toBase58(),
426
- poolAddress: data.whirlpool.toBase58(),
427
- tickLower: data.tickLowerIndex,
428
- tickUpper: data.tickUpperIndex,
429
- liquidity: data.liquidity.toString(),
430
- feeOwedA: data.feeOwedA.toString(),
431
- feeOwedB: data.feeOwedB.toString(),
432
- rewardOwed: data.rewardInfos.map(info => info.amountOwed.toString()),
433
- };
434
- }
435
- /**
436
- * 计算全范围流动性的 tick 范围
437
- */
438
- export function getFullRangeTickIndices(tickSpacing) {
439
- const [tickLower, tickUpper] = TickUtil.getFullRangeTickIndex(tickSpacing);
440
- return { tickLower, tickUpper };
441
- }
442
- /**
443
- * 根据价格范围计算 tick 范围
444
- */
445
- export function getTickIndicesFromPriceRange(priceLower, priceUpper, decimalsA, decimalsB, tickSpacing) {
446
- const sqrtPriceLower = PriceMath.priceToSqrtPriceX64(DecimalUtil.fromNumber(priceLower), decimalsA, decimalsB);
447
- const sqrtPriceUpper = PriceMath.priceToSqrtPriceX64(DecimalUtil.fromNumber(priceUpper), decimalsA, decimalsB);
448
- let tickLower = PriceMath.sqrtPriceX64ToTickIndex(sqrtPriceLower);
449
- let tickUpper = PriceMath.sqrtPriceX64ToTickIndex(sqrtPriceUpper);
450
- // 对齐到 tickSpacing
451
- tickLower = TickUtil.getInitializableTickIndex(tickLower, tickSpacing);
452
- tickUpper = TickUtil.getInitializableTickIndex(tickUpper, tickSpacing);
453
- return { tickLower, tickUpper };
454
- }