four-flap-meme-sdk 1.5.54 → 1.5.55

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 (153) 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/index.d.ts +0 -1
  5. package/dist/index.js +1 -1
  6. package/dist/utils/constants.d.ts +3 -3
  7. package/dist/utils/constants.js +3 -3
  8. package/dist/xlayer/bundle.js +1 -1
  9. package/package.json +5 -44
  10. package/dist/sol/constants.d.ts +0 -150
  11. package/dist/sol/constants.js +0 -188
  12. package/dist/sol/dex/blockrazor/client.d.ts +0 -51
  13. package/dist/sol/dex/blockrazor/client.js +0 -96
  14. package/dist/sol/dex/blockrazor/constants.d.ts +0 -34
  15. package/dist/sol/dex/blockrazor/constants.js +0 -55
  16. package/dist/sol/dex/blockrazor/geyser.d.ts +0 -128
  17. package/dist/sol/dex/blockrazor/geyser.js +0 -530
  18. package/dist/sol/dex/blockrazor/index.d.ts +0 -18
  19. package/dist/sol/dex/blockrazor/index.js +0 -23
  20. package/dist/sol/dex/blockrazor/send.d.ts +0 -135
  21. package/dist/sol/dex/blockrazor/send.js +0 -254
  22. package/dist/sol/dex/blockrazor/types.d.ts +0 -191
  23. package/dist/sol/dex/blockrazor/types.js +0 -5
  24. package/dist/sol/dex/index.d.ts +0 -10
  25. package/dist/sol/dex/index.js +0 -16
  26. package/dist/sol/dex/jup/client.d.ts +0 -33
  27. package/dist/sol/dex/jup/client.js +0 -110
  28. package/dist/sol/dex/jup/index.d.ts +0 -16
  29. package/dist/sol/dex/jup/index.js +0 -148
  30. package/dist/sol/dex/jup/legacy.d.ts +0 -623
  31. package/dist/sol/dex/jup/legacy.js +0 -416
  32. package/dist/sol/dex/jup/lend.d.ts +0 -640
  33. package/dist/sol/dex/jup/lend.js +0 -603
  34. package/dist/sol/dex/jup/portfolio.d.ts +0 -362
  35. package/dist/sol/dex/jup/portfolio.js +0 -367
  36. package/dist/sol/dex/jup/price.d.ts +0 -173
  37. package/dist/sol/dex/jup/price.js +0 -220
  38. package/dist/sol/dex/jup/recurring.d.ts +0 -437
  39. package/dist/sol/dex/jup/recurring.js +0 -320
  40. package/dist/sol/dex/jup/send.d.ts +0 -282
  41. package/dist/sol/dex/jup/send.js +0 -295
  42. package/dist/sol/dex/jup/studio.d.ts +0 -457
  43. package/dist/sol/dex/jup/studio.js +0 -488
  44. package/dist/sol/dex/jup/tokens.d.ts +0 -767
  45. package/dist/sol/dex/jup/tokens.js +0 -697
  46. package/dist/sol/dex/jup/trigger.d.ts +0 -511
  47. package/dist/sol/dex/jup/trigger.js +0 -397
  48. package/dist/sol/dex/jup/types.d.ts +0 -433
  49. package/dist/sol/dex/jup/types.js +0 -5
  50. package/dist/sol/dex/jup/ultra.d.ts +0 -646
  51. package/dist/sol/dex/jup/ultra.js +0 -853
  52. package/dist/sol/dex/meteora/client.d.ts +0 -76
  53. package/dist/sol/dex/meteora/client.js +0 -219
  54. package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +0 -61
  55. package/dist/sol/dex/meteora/damm-v1-bundle.js +0 -112
  56. package/dist/sol/dex/meteora/damm-v1.d.ts +0 -118
  57. package/dist/sol/dex/meteora/damm-v1.js +0 -315
  58. package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +0 -82
  59. package/dist/sol/dex/meteora/damm-v2-bundle.js +0 -242
  60. package/dist/sol/dex/meteora/damm-v2.d.ts +0 -172
  61. package/dist/sol/dex/meteora/damm-v2.js +0 -632
  62. package/dist/sol/dex/meteora/dbc-bundle.d.ts +0 -123
  63. package/dist/sol/dex/meteora/dbc-bundle.js +0 -304
  64. package/dist/sol/dex/meteora/dbc.d.ts +0 -192
  65. package/dist/sol/dex/meteora/dbc.js +0 -619
  66. package/dist/sol/dex/meteora/dlmm-bundle.d.ts +0 -39
  67. package/dist/sol/dex/meteora/dlmm-bundle.js +0 -189
  68. package/dist/sol/dex/meteora/dlmm.d.ts +0 -157
  69. package/dist/sol/dex/meteora/dlmm.js +0 -671
  70. package/dist/sol/dex/meteora/index.d.ts +0 -25
  71. package/dist/sol/dex/meteora/index.js +0 -65
  72. package/dist/sol/dex/meteora/types.d.ts +0 -787
  73. package/dist/sol/dex/meteora/types.js +0 -110
  74. package/dist/sol/dex/orca/index.d.ts +0 -10
  75. package/dist/sol/dex/orca/index.js +0 -16
  76. package/dist/sol/dex/orca/orca-bundle.d.ts +0 -41
  77. package/dist/sol/dex/orca/orca-bundle.js +0 -173
  78. package/dist/sol/dex/orca/orca.d.ts +0 -65
  79. package/dist/sol/dex/orca/orca.js +0 -474
  80. package/dist/sol/dex/orca/types.d.ts +0 -263
  81. package/dist/sol/dex/orca/types.js +0 -38
  82. package/dist/sol/dex/orca/wavebreak-bundle.d.ts +0 -34
  83. package/dist/sol/dex/orca/wavebreak-bundle.js +0 -198
  84. package/dist/sol/dex/orca/wavebreak-types.d.ts +0 -227
  85. package/dist/sol/dex/orca/wavebreak-types.js +0 -23
  86. package/dist/sol/dex/orca/wavebreak.d.ts +0 -78
  87. package/dist/sol/dex/orca/wavebreak.js +0 -497
  88. package/dist/sol/dex/pump/index.d.ts +0 -9
  89. package/dist/sol/dex/pump/index.js +0 -14
  90. package/dist/sol/dex/pump/pump-bundle.d.ts +0 -92
  91. package/dist/sol/dex/pump/pump-bundle.js +0 -383
  92. package/dist/sol/dex/pump/pump-swap-bundle.d.ts +0 -103
  93. package/dist/sol/dex/pump/pump-swap-bundle.js +0 -380
  94. package/dist/sol/dex/pump/pump-swap.d.ts +0 -46
  95. package/dist/sol/dex/pump/pump-swap.js +0 -199
  96. package/dist/sol/dex/pump/pump.d.ts +0 -35
  97. package/dist/sol/dex/pump/pump.js +0 -352
  98. package/dist/sol/dex/pump/types.d.ts +0 -215
  99. package/dist/sol/dex/pump/types.js +0 -5
  100. package/dist/sol/dex/raydium/index.d.ts +0 -8
  101. package/dist/sol/dex/raydium/index.js +0 -12
  102. package/dist/sol/dex/raydium/launchlab.d.ts +0 -68
  103. package/dist/sol/dex/raydium/launchlab.js +0 -210
  104. package/dist/sol/dex/raydium/raydium-bundle.d.ts +0 -64
  105. package/dist/sol/dex/raydium/raydium-bundle.js +0 -324
  106. package/dist/sol/dex/raydium/raydium.d.ts +0 -40
  107. package/dist/sol/dex/raydium/raydium.js +0 -366
  108. package/dist/sol/dex/raydium/types.d.ts +0 -240
  109. package/dist/sol/dex/raydium/types.js +0 -5
  110. package/dist/sol/index.d.ts +0 -11
  111. package/dist/sol/index.js +0 -18
  112. package/dist/sol/jito/bundle.d.ts +0 -90
  113. package/dist/sol/jito/bundle.js +0 -263
  114. package/dist/sol/jito/index.d.ts +0 -7
  115. package/dist/sol/jito/index.js +0 -7
  116. package/dist/sol/jito/tip.d.ts +0 -51
  117. package/dist/sol/jito/tip.js +0 -83
  118. package/dist/sol/jito/types.d.ts +0 -100
  119. package/dist/sol/jito/types.js +0 -5
  120. package/dist/sol/nozomi/client.d.ts +0 -63
  121. package/dist/sol/nozomi/client.js +0 -222
  122. package/dist/sol/nozomi/index.d.ts +0 -8
  123. package/dist/sol/nozomi/index.js +0 -8
  124. package/dist/sol/nozomi/tip.d.ts +0 -50
  125. package/dist/sol/nozomi/tip.js +0 -80
  126. package/dist/sol/nozomi/types.d.ts +0 -96
  127. package/dist/sol/nozomi/types.js +0 -5
  128. package/dist/sol/token/create-complete.d.ts +0 -115
  129. package/dist/sol/token/create-complete.js +0 -235
  130. package/dist/sol/token/create-token.d.ts +0 -57
  131. package/dist/sol/token/create-token.js +0 -230
  132. package/dist/sol/token/index.d.ts +0 -9
  133. package/dist/sol/token/index.js +0 -14
  134. package/dist/sol/token/metadata-upload.d.ts +0 -86
  135. package/dist/sol/token/metadata-upload.js +0 -173
  136. package/dist/sol/token/metadata.d.ts +0 -92
  137. package/dist/sol/token/metadata.js +0 -274
  138. package/dist/sol/token/types.d.ts +0 -153
  139. package/dist/sol/token/types.js +0 -5
  140. package/dist/sol/types.d.ts +0 -176
  141. package/dist/sol/types.js +0 -7
  142. package/dist/sol/utils/balance.d.ts +0 -160
  143. package/dist/sol/utils/balance.js +0 -638
  144. package/dist/sol/utils/connection.d.ts +0 -78
  145. package/dist/sol/utils/connection.js +0 -168
  146. package/dist/sol/utils/index.d.ts +0 -9
  147. package/dist/sol/utils/index.js +0 -9
  148. package/dist/sol/utils/lp-inspect.d.ts +0 -129
  149. package/dist/sol/utils/lp-inspect.js +0 -900
  150. package/dist/sol/utils/transfer.d.ts +0 -196
  151. package/dist/sol/utils/transfer.js +0 -307
  152. package/dist/sol/utils/wallet.d.ts +0 -107
  153. package/dist/sol/utils/wallet.js +0 -210
@@ -1,632 +0,0 @@
1
- /**
2
- * Meteora DAMM v2 (CP-AMM) 集成
3
- *
4
- * 基于 https://github.com/MeteoraAg/cp-amm-sdk 源码分析
5
- * DAMM v2 是 DBC 迁移后的目标池之一,使用 NFT 代表仓位
6
- */
7
- import { PublicKey, Keypair, } from '@solana/web3.js';
8
- import BN from 'bn.js';
9
- import { getTokenProgram, derivePoolAddress, derivePositionAddress } from '@meteora-ag/cp-amm-sdk';
10
- import { getConnection, getCpAmmClient } from './client.js';
11
- // ============================================================================
12
- // 池信息查询
13
- // ============================================================================
14
- /**
15
- * 获取 DAMM v2 池信息
16
- * @param poolAddress 池地址
17
- * @param connection 可选连接
18
- */
19
- export async function getDammV2PoolInfo(poolAddress, connection) {
20
- const cpAmm = getCpAmmClient(connection);
21
- const poolState = await cpAmm.fetchPoolState(new PublicKey(poolAddress));
22
- return {
23
- poolAddress,
24
- tokenAMint: poolState.tokenAMint.toBase58(),
25
- tokenBMint: poolState.tokenBMint.toBase58(),
26
- currentPrice: 0,
27
- feeBps: poolState.poolFees?.baseFee?.cliffFeeNumerator?.toNumber() || 0,
28
- tokenAReserve: '0',
29
- tokenBReserve: '0',
30
- lpMint: '',
31
- lpSupply: '0',
32
- };
33
- }
34
- // ============================================================================
35
- // Swap
36
- // ============================================================================
37
- /**
38
- * 签名 DAMM v2 Swap 交易
39
- * @param params Swap 参数
40
- * @param wallet 钱包
41
- * @param connection 可选连接
42
- */
43
- export async function signDammV2Swap(params, wallet, connection) {
44
- const conn = getConnection(connection);
45
- const cpAmm = getCpAmmClient(connection);
46
- const poolPubkey = new PublicKey(params.poolAddress);
47
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
48
- const swapTx = await cpAmm.swap({
49
- payer: wallet.publicKey,
50
- pool: poolPubkey,
51
- inputTokenMint: new PublicKey(params.inputMint),
52
- outputTokenMint: new PublicKey(params.outputMint),
53
- amountIn: params.amountIn,
54
- minimumAmountOut: params.minAmountOut,
55
- tokenAMint: poolState.tokenAMint,
56
- tokenBMint: poolState.tokenBMint,
57
- tokenAVault: poolState.tokenAVault,
58
- tokenBVault: poolState.tokenBVault,
59
- tokenAProgram: getTokenProgram(poolState.tokenAFlag),
60
- tokenBProgram: getTokenProgram(poolState.tokenBFlag),
61
- referralTokenAccount: null,
62
- });
63
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
64
- swapTx.recentBlockhash = blockhash;
65
- swapTx.lastValidBlockHeight = lastValidBlockHeight;
66
- swapTx.feePayer = wallet.publicKey;
67
- swapTx.sign(wallet);
68
- return {
69
- signedTransaction: swapTx,
70
- type: 'damm_v2_swap',
71
- poolAddress: params.poolAddress,
72
- metadata: {
73
- amountIn: params.amountIn.toString(),
74
- minAmountOut: params.minAmountOut.toString(),
75
- inputMint: params.inputMint,
76
- outputMint: params.outputMint,
77
- },
78
- };
79
- }
80
- // ============================================================================
81
- // 添加流动性
82
- // ============================================================================
83
- /**
84
- * 签名 DAMM v2 添加流动性交易(创建新仓位)
85
- */
86
- export async function signDammV2AddLiquidity(params, wallet, positionNftKeypair, connection) {
87
- const conn = getConnection(connection);
88
- const cpAmm = getCpAmmClient(connection);
89
- const poolPubkey = new PublicKey(params.poolAddress);
90
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
91
- const liquidityDelta = cpAmm.getLiquidityDelta({
92
- maxAmountTokenA: params.amountA,
93
- maxAmountTokenB: params.amountB,
94
- sqrtPrice: poolState.sqrtPrice,
95
- sqrtMinPrice: poolState.sqrtMinPrice,
96
- sqrtMaxPrice: poolState.sqrtMaxPrice,
97
- });
98
- const positionNft = positionNftKeypair || Keypair.generate();
99
- const addLiquidityTx = await cpAmm.createPositionAndAddLiquidity({
100
- owner: wallet.publicKey,
101
- pool: poolPubkey,
102
- positionNft: positionNft.publicKey,
103
- tokenAMint: poolState.tokenAMint,
104
- tokenBMint: poolState.tokenBMint,
105
- maxAmountTokenA: params.amountA,
106
- maxAmountTokenB: params.amountB,
107
- liquidityDelta,
108
- tokenAAmountThreshold: new BN(0),
109
- tokenBAmountThreshold: new BN(0),
110
- tokenAProgram: getTokenProgram(poolState.tokenAFlag),
111
- tokenBProgram: getTokenProgram(poolState.tokenBFlag),
112
- });
113
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
114
- addLiquidityTx.recentBlockhash = blockhash;
115
- addLiquidityTx.lastValidBlockHeight = lastValidBlockHeight;
116
- addLiquidityTx.feePayer = wallet.publicKey;
117
- addLiquidityTx.sign(wallet, positionNft);
118
- return {
119
- signedTransaction: addLiquidityTx,
120
- type: 'damm_v2_add_liquidity',
121
- poolAddress: params.poolAddress,
122
- metadata: {
123
- amountA: params.amountA.toString(),
124
- amountB: params.amountB.toString(),
125
- positionNft: positionNft.publicKey.toBase58(),
126
- position: derivePositionAddress(positionNft.publicKey).toString(),
127
- },
128
- };
129
- }
130
- // ============================================================================
131
- // 移除流动性
132
- // ============================================================================
133
- /**
134
- * 签名 DAMM v2 移除流动性交易
135
- */
136
- export async function signDammV2RemoveLiquidity(params, positionAddress, positionNftAccount, wallet, connection) {
137
- const conn = getConnection(connection);
138
- const cpAmm = getCpAmmClient(connection);
139
- const poolPubkey = new PublicKey(params.poolAddress);
140
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
141
- const currentSlot = await conn.getSlot();
142
- const removeLiquidityTx = await cpAmm.removeLiquidity({
143
- owner: wallet.publicKey,
144
- position: new PublicKey(positionAddress),
145
- pool: poolPubkey,
146
- positionNftAccount: new PublicKey(positionNftAccount),
147
- tokenAMint: poolState.tokenAMint,
148
- tokenBMint: poolState.tokenBMint,
149
- tokenAVault: poolState.tokenAVault,
150
- tokenBVault: poolState.tokenBVault,
151
- liquidityDelta: params.lpAmount,
152
- tokenAAmountThreshold: params.minAmountA || new BN(0),
153
- tokenBAmountThreshold: params.minAmountB || new BN(0),
154
- tokenAProgram: getTokenProgram(poolState.tokenAFlag),
155
- tokenBProgram: getTokenProgram(poolState.tokenBFlag),
156
- vestings: [],
157
- currentPoint: new BN(currentSlot),
158
- });
159
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
160
- removeLiquidityTx.recentBlockhash = blockhash;
161
- removeLiquidityTx.lastValidBlockHeight = lastValidBlockHeight;
162
- removeLiquidityTx.feePayer = wallet.publicKey;
163
- removeLiquidityTx.sign(wallet);
164
- return {
165
- signedTransaction: removeLiquidityTx,
166
- type: 'damm_v2_remove_liquidity',
167
- poolAddress: params.poolAddress,
168
- metadata: {
169
- lpAmount: params.lpAmount.toString(),
170
- positionAddress,
171
- },
172
- };
173
- }
174
- // ============================================================================
175
- // 领取费用
176
- // ============================================================================
177
- /**
178
- * 签名领取 Position 费用交易
179
- */
180
- export async function signDammV2ClaimPositionFee(poolAddress, positionAddress, positionNftAccount, wallet, connection) {
181
- const conn = getConnection(connection);
182
- const cpAmm = getCpAmmClient(connection);
183
- const poolPubkey = new PublicKey(poolAddress);
184
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
185
- const claimFeeTx = await cpAmm.claimPositionFee({
186
- owner: wallet.publicKey,
187
- pool: poolPubkey,
188
- position: new PublicKey(positionAddress),
189
- positionNftAccount: new PublicKey(positionNftAccount),
190
- tokenAMint: poolState.tokenAMint,
191
- tokenBMint: poolState.tokenBMint,
192
- tokenAVault: poolState.tokenAVault,
193
- tokenBVault: poolState.tokenBVault,
194
- tokenAProgram: getTokenProgram(poolState.tokenAFlag),
195
- tokenBProgram: getTokenProgram(poolState.tokenBFlag),
196
- });
197
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
198
- claimFeeTx.recentBlockhash = blockhash;
199
- claimFeeTx.lastValidBlockHeight = lastValidBlockHeight;
200
- claimFeeTx.feePayer = wallet.publicKey;
201
- claimFeeTx.sign(wallet);
202
- return {
203
- signedTransaction: claimFeeTx,
204
- type: 'damm_v2_claim_fee',
205
- poolAddress,
206
- metadata: { positionAddress },
207
- };
208
- }
209
- // ============================================================================
210
- // 锁定流动性
211
- // ============================================================================
212
- /**
213
- * 签名永久锁定 Position 交易
214
- */
215
- export async function signDammV2PermanentLockPosition(poolAddress, positionAddress, positionNftAccount, unlockedLiquidity, wallet, connection) {
216
- const conn = getConnection(connection);
217
- const cpAmm = getCpAmmClient(connection);
218
- const poolPubkey = new PublicKey(poolAddress);
219
- const lockTx = await cpAmm.permanentLockPosition({
220
- owner: wallet.publicKey,
221
- pool: poolPubkey,
222
- position: new PublicKey(positionAddress),
223
- positionNftAccount: new PublicKey(positionNftAccount),
224
- unlockedLiquidity,
225
- });
226
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
227
- lockTx.recentBlockhash = blockhash;
228
- lockTx.lastValidBlockHeight = lastValidBlockHeight;
229
- lockTx.feePayer = wallet.publicKey;
230
- lockTx.sign(wallet);
231
- return {
232
- signedTransaction: lockTx,
233
- type: 'damm_v2_permanent_lock_position',
234
- poolAddress,
235
- metadata: {
236
- positionAddress,
237
- unlockedLiquidity: unlockedLiquidity.toString(),
238
- },
239
- };
240
- }
241
- // ============================================================================
242
- // 辅助函数
243
- // ============================================================================
244
- /**
245
- * 获取用户在池中的所有 Position
246
- */
247
- export async function getDammV2UserPositions(poolAddress, userAddress, connection) {
248
- const cpAmm = getCpAmmClient(connection);
249
- const positions = await cpAmm.getUserPositionByPool(new PublicKey(poolAddress), new PublicKey(userAddress));
250
- return positions.map((pos) => ({
251
- position: pos.position.toBase58(),
252
- positionNftAccount: pos.positionNftAccount.toBase58(),
253
- positionNftMint: pos.positionNftMint.toBase58(),
254
- liquidity: pos.liquidity?.toString() || '0',
255
- }));
256
- }
257
- /**
258
- * 派生池地址
259
- */
260
- export function deriveDammV2PoolAddress(config, tokenAMint, tokenBMint) {
261
- return derivePoolAddress(new PublicKey(config), new PublicKey(tokenAMint), new PublicKey(tokenBMint)).toString();
262
- }
263
- /**
264
- * 派生 Position 地址
265
- */
266
- export function deriveDammV2PositionAddress(positionNft) {
267
- return derivePositionAddress(new PublicKey(positionNft)).toString();
268
- }
269
- // ============================================================================
270
- // 创建池
271
- // ============================================================================
272
- /**
273
- * 签名创建 DAMM v2 池交易
274
- * @param params 创建池参数
275
- * @param positionNftKeypair Position NFT Keypair
276
- * @param wallet 钱包
277
- * @param connection 可选连接
278
- */
279
- export async function signDammV2CreatePool(params, positionNftKeypair, wallet, connection) {
280
- const conn = getConnection(connection);
281
- const cpAmm = getCpAmmClient(connection);
282
- const createPoolTxBuilder = await cpAmm.createPool({
283
- payer: wallet.publicKey,
284
- creator: wallet.publicKey,
285
- config: new PublicKey(params.configAddress),
286
- positionNft: positionNftKeypair.publicKey,
287
- tokenAMint: new PublicKey(params.tokenAMint),
288
- tokenBMint: new PublicKey(params.tokenBMint),
289
- activationPoint: params.activationPoint || null,
290
- tokenAAmount: params.tokenAAmount,
291
- tokenBAmount: params.tokenBAmount,
292
- initSqrtPrice: params.initSqrtPrice,
293
- liquidityDelta: params.liquidityDelta,
294
- tokenAProgram: (await import('@solana/spl-token')).TOKEN_PROGRAM_ID,
295
- tokenBProgram: (await import('@solana/spl-token')).TOKEN_PROGRAM_ID,
296
- });
297
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
298
- // TxBuilder 有 transaction() 方法,但 Transaction 没有,需要检查类型
299
- const tx = 'transaction' in createPoolTxBuilder
300
- ? await createPoolTxBuilder.transaction()
301
- : createPoolTxBuilder;
302
- tx.recentBlockhash = blockhash;
303
- tx.lastValidBlockHeight = lastValidBlockHeight;
304
- tx.feePayer = wallet.publicKey;
305
- tx.sign(wallet, positionNftKeypair);
306
- // 计算池地址
307
- const poolAddress = deriveDammV2PoolAddress(params.configAddress, params.tokenAMint, params.tokenBMint);
308
- return {
309
- signedTransaction: tx,
310
- type: 'damm_v2_create_pool',
311
- poolAddress,
312
- metadata: {
313
- tokenAMint: params.tokenAMint,
314
- tokenBMint: params.tokenBMint,
315
- positionNft: positionNftKeypair.publicKey.toBase58(),
316
- },
317
- };
318
- }
319
- /**
320
- * 签名创建 Position(空仓位)交易
321
- * @param poolAddress 池地址
322
- * @param positionNftKeypair Position NFT Keypair
323
- * @param wallet 钱包
324
- * @param connection 可选连接
325
- */
326
- export async function signDammV2CreatePosition(poolAddress, positionNftKeypair, wallet, connection) {
327
- const conn = getConnection(connection);
328
- const cpAmm = getCpAmmClient(connection);
329
- const poolPubkey = new PublicKey(poolAddress);
330
- // 根据文档: createPosition 参数为 owner, payer, pool, positionNft
331
- const createPositionTxBuilder = await cpAmm.createPosition({
332
- owner: wallet.publicKey,
333
- payer: wallet.publicKey,
334
- pool: poolPubkey,
335
- positionNft: positionNftKeypair.publicKey,
336
- });
337
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
338
- const tx = 'transaction' in createPositionTxBuilder
339
- ? await createPositionTxBuilder.transaction()
340
- : createPositionTxBuilder;
341
- tx.recentBlockhash = blockhash;
342
- tx.lastValidBlockHeight = lastValidBlockHeight;
343
- tx.feePayer = wallet.publicKey;
344
- tx.sign(wallet, positionNftKeypair);
345
- const positionAddress = deriveDammV2PositionAddress(positionNftKeypair.publicKey.toBase58());
346
- return {
347
- signedTransaction: tx,
348
- type: 'damm_v2_create_position',
349
- poolAddress,
350
- metadata: {
351
- positionNft: positionNftKeypair.publicKey.toBase58(),
352
- position: positionAddress,
353
- },
354
- };
355
- }
356
- // ============================================================================
357
- // 报价和计算
358
- // ============================================================================
359
- /**
360
- * 获取 DAMM v2 Swap 报价
361
- * @param poolAddress 池地址
362
- * @param inputMint 输入 Mint
363
- * @param amountIn 输入数量
364
- * @param slippage 滑点百分比 (例如 0.5 表示 0.5%)
365
- * @param tokenADecimal Token A 精度
366
- * @param tokenBDecimal Token B 精度
367
- * @param connection 可选连接
368
- */
369
- export async function getDammV2SwapQuote(poolAddress, inputMint, amountIn, slippage = 0.5, tokenADecimal = 9, tokenBDecimal = 9, connection) {
370
- const conn = getConnection(connection);
371
- const cpAmm = getCpAmmClient(connection);
372
- const poolPubkey = new PublicKey(poolAddress);
373
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
374
- // 获取当前 slot 和时间
375
- const currentSlot = await conn.getSlot();
376
- const blockTime = await conn.getBlockTime(currentSlot);
377
- // 根据文档调用 getQuote
378
- const quote = await cpAmm.getQuote({
379
- inAmount: amountIn,
380
- inputTokenMint: new PublicKey(inputMint),
381
- slippage,
382
- poolState,
383
- currentTime: blockTime || Math.floor(Date.now() / 1000),
384
- currentSlot,
385
- tokenADecimal,
386
- tokenBDecimal,
387
- hasReferral: false,
388
- });
389
- return {
390
- swapInAmount: quote.swapInAmount.toString(),
391
- consumedInAmount: quote.consumedInAmount.toString(),
392
- swapOutAmount: quote.swapOutAmount.toString(),
393
- minSwapOutAmount: quote.minSwapOutAmount.toString(),
394
- totalFee: quote.totalFee.toString(),
395
- priceImpact: typeof quote.priceImpact === 'number' ? quote.priceImpact : Number(quote.priceImpact),
396
- };
397
- }
398
- /**
399
- * 计算流动性增量
400
- * @param poolAddress 池地址
401
- * @param maxAmountA 最大 Token A 数量
402
- * @param maxAmountB 最大 Token B 数量
403
- * @param connection 可选连接
404
- */
405
- export async function getDammV2LiquidityDelta(poolAddress, maxAmountA, maxAmountB, connection) {
406
- const cpAmm = getCpAmmClient(connection);
407
- const poolPubkey = new PublicKey(poolAddress);
408
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
409
- const liquidityDelta = cpAmm.getLiquidityDelta({
410
- maxAmountTokenA: maxAmountA,
411
- maxAmountTokenB: maxAmountB,
412
- sqrtPrice: poolState.sqrtPrice,
413
- sqrtMinPrice: poolState.sqrtMinPrice,
414
- sqrtMaxPrice: poolState.sqrtMaxPrice,
415
- });
416
- // 返回计算的流动性增量和输入金额
417
- return {
418
- liquidityDelta: liquidityDelta.toString(),
419
- tokenAAmount: maxAmountA.toString(),
420
- tokenBAmount: maxAmountB.toString(),
421
- };
422
- }
423
- // ============================================================================
424
- // 仓位管理
425
- // ============================================================================
426
- /**
427
- * 签名关闭 Position 交易(需要先移除所有流动性)
428
- * @param poolAddress 池地址
429
- * @param positionAddress Position 地址
430
- * @param positionNftMint Position NFT Mint
431
- * @param positionNftAccount Position NFT 账户
432
- * @param wallet 钱包
433
- * @param connection 可选连接
434
- */
435
- export async function signDammV2ClosePosition(poolAddress, positionAddress, positionNftMint, positionNftAccount, wallet, connection) {
436
- const conn = getConnection(connection);
437
- const cpAmm = getCpAmmClient(connection);
438
- const poolPubkey = new PublicKey(poolAddress);
439
- // 根据文档: closePosition 参数为 owner, pool, position, positionNftMint, positionNftAccount
440
- const closeTxBuilder = await cpAmm.closePosition({
441
- owner: wallet.publicKey,
442
- pool: poolPubkey,
443
- position: new PublicKey(positionAddress),
444
- positionNftMint: new PublicKey(positionNftMint),
445
- positionNftAccount: new PublicKey(positionNftAccount),
446
- });
447
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
448
- const tx = 'transaction' in closeTxBuilder
449
- ? await closeTxBuilder.transaction()
450
- : closeTxBuilder;
451
- tx.recentBlockhash = blockhash;
452
- tx.lastValidBlockHeight = lastValidBlockHeight;
453
- tx.feePayer = wallet.publicKey;
454
- tx.sign(wallet);
455
- return {
456
- signedTransaction: tx,
457
- type: 'damm_v2_close_position',
458
- poolAddress,
459
- metadata: {
460
- positionAddress,
461
- },
462
- };
463
- }
464
- /**
465
- * 签名移除所有流动性交易
466
- * @param poolAddress 池地址
467
- * @param positionAddress Position 地址
468
- * @param positionNftAccount Position NFT 账户
469
- * @param liquidity 要移除的流动性数量
470
- * @param wallet 钱包
471
- * @param connection 可选连接
472
- */
473
- export async function signDammV2RemoveAllLiquidity(poolAddress, positionAddress, positionNftAccount, liquidity, wallet, connection) {
474
- const conn = getConnection(connection);
475
- const cpAmm = getCpAmmClient(connection);
476
- const poolPubkey = new PublicKey(poolAddress);
477
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
478
- const currentSlot = await conn.getSlot();
479
- const removeTx = await cpAmm.removeLiquidity({
480
- owner: wallet.publicKey,
481
- position: new PublicKey(positionAddress),
482
- pool: poolPubkey,
483
- positionNftAccount: new PublicKey(positionNftAccount),
484
- tokenAMint: poolState.tokenAMint,
485
- tokenBMint: poolState.tokenBMint,
486
- tokenAVault: poolState.tokenAVault,
487
- tokenBVault: poolState.tokenBVault,
488
- liquidityDelta: liquidity,
489
- tokenAAmountThreshold: new BN(0),
490
- tokenBAmountThreshold: new BN(0),
491
- tokenAProgram: getTokenProgram(poolState.tokenAFlag),
492
- tokenBProgram: getTokenProgram(poolState.tokenBFlag),
493
- vestings: [],
494
- currentPoint: new BN(currentSlot),
495
- });
496
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
497
- removeTx.recentBlockhash = blockhash;
498
- removeTx.lastValidBlockHeight = lastValidBlockHeight;
499
- removeTx.feePayer = wallet.publicKey;
500
- removeTx.sign(wallet);
501
- return {
502
- signedTransaction: removeTx,
503
- type: 'damm_v2_remove_all_liquidity',
504
- poolAddress,
505
- metadata: {
506
- positionAddress,
507
- liquidity: liquidity.toString(),
508
- },
509
- };
510
- }
511
- /**
512
- * 签名锁定 Position 交易(带 vesting)
513
- * @param poolAddress 池地址
514
- * @param positionAddress Position 地址
515
- * @param positionNftAccount Position NFT 账户
516
- * @param vestingParams Vesting 参数
517
- * @param vestingAccountKeypair Vesting 账户 Keypair
518
- * @param wallet 钱包
519
- * @param connection 可选连接
520
- */
521
- export async function signDammV2LockPosition(poolAddress, positionAddress, positionNftAccount, vestingParams, vestingAccountKeypair, wallet, connection) {
522
- const conn = getConnection(connection);
523
- const cpAmm = getCpAmmClient(connection);
524
- const poolPubkey = new PublicKey(poolAddress);
525
- // 根据文档: lockPosition 参数
526
- const lockTxBuilder = await cpAmm.lockPosition({
527
- owner: wallet.publicKey,
528
- pool: poolPubkey,
529
- payer: wallet.publicKey,
530
- vestingAccount: vestingAccountKeypair.publicKey,
531
- position: new PublicKey(positionAddress),
532
- positionNftAccount: new PublicKey(positionNftAccount),
533
- cliffPoint: vestingParams.cliffPoint,
534
- periodFrequency: vestingParams.periodFrequency,
535
- cliffUnlockLiquidity: vestingParams.cliffUnlockLiquidity,
536
- liquidityPerPeriod: vestingParams.liquidityPerPeriod,
537
- numberOfPeriod: vestingParams.numberOfPeriod,
538
- });
539
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
540
- const tx = 'transaction' in lockTxBuilder
541
- ? await lockTxBuilder.transaction()
542
- : lockTxBuilder;
543
- tx.recentBlockhash = blockhash;
544
- tx.lastValidBlockHeight = lastValidBlockHeight;
545
- tx.feePayer = wallet.publicKey;
546
- tx.sign(wallet, vestingAccountKeypair);
547
- return {
548
- signedTransaction: tx,
549
- type: 'damm_v2_lock_position',
550
- poolAddress,
551
- metadata: {
552
- positionAddress,
553
- vestingAccount: vestingAccountKeypair.publicKey.toBase58(),
554
- },
555
- };
556
- }
557
- /**
558
- * 签名领取奖励交易
559
- * @param poolAddress 池地址
560
- * @param positionAddress Position 地址
561
- * @param positionNftAccount Position NFT 账户
562
- * @param rewardIndex 奖励索引
563
- * @param wallet 钱包
564
- * @param connection 可选连接
565
- */
566
- export async function signDammV2ClaimReward(poolAddress, positionAddress, positionNftAccount, rewardIndex, wallet, connection) {
567
- const conn = getConnection(connection);
568
- const cpAmm = getCpAmmClient(connection);
569
- const poolPubkey = new PublicKey(poolAddress);
570
- const poolState = await cpAmm.fetchPoolState(poolPubkey);
571
- const positionState = await cpAmm.fetchPositionState(new PublicKey(positionAddress));
572
- // 根据文档: claimReward 参数
573
- const claimTxBuilder = await cpAmm.claimReward({
574
- user: wallet.publicKey,
575
- position: new PublicKey(positionAddress),
576
- poolState,
577
- positionState,
578
- positionNftAccount: new PublicKey(positionNftAccount),
579
- rewardIndex,
580
- isSkipReward: false,
581
- feePayer: wallet.publicKey,
582
- });
583
- const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
584
- const tx = 'transaction' in claimTxBuilder
585
- ? await claimTxBuilder.transaction()
586
- : claimTxBuilder;
587
- tx.recentBlockhash = blockhash;
588
- tx.lastValidBlockHeight = lastValidBlockHeight;
589
- tx.feePayer = wallet.publicKey;
590
- tx.sign(wallet);
591
- return {
592
- signedTransaction: tx,
593
- type: 'damm_v2_claim_reward',
594
- poolAddress,
595
- metadata: {
596
- positionAddress,
597
- rewardIndex,
598
- },
599
- };
600
- }
601
- // ============================================================================
602
- // 状态查询
603
- // ============================================================================
604
- /**
605
- * 获取 Position 详细信息
606
- * @param positionAddress Position 地址
607
- * @param connection 可选连接
608
- */
609
- export async function getDammV2PositionInfo(positionAddress, connection) {
610
- const cpAmm = getCpAmmClient(connection);
611
- const positionState = await cpAmm.fetchPositionState(new PublicKey(positionAddress));
612
- // 根据文档: PositionState 包含 unlockedLiquidity, vestedLiquidity, permanentLockedLiquidity
613
- return {
614
- unlockedLiquidity: positionState.unlockedLiquidity?.toString() || '0',
615
- vestedLiquidity: positionState.vestedLiquidity?.toString() || '0',
616
- permanentLockedLiquidity: positionState.permanentLockedLiquidity?.toString() || '0',
617
- pool: positionState.pool?.toBase58() || '',
618
- nftMint: positionState.nftMint?.toBase58() || '',
619
- feeAPending: positionState.feeAPending?.toString() || '0',
620
- feeBPending: positionState.feeBPending?.toString() || '0',
621
- };
622
- }
623
- /**
624
- * 获取池配置信息
625
- * @param configAddress 配置地址
626
- * @param connection 可选连接
627
- */
628
- export async function getDammV2ConfigInfo(configAddress, connection) {
629
- const cpAmm = getCpAmmClient(connection);
630
- const configState = await cpAmm.fetchConfigState(new PublicKey(configAddress));
631
- return configState;
632
- }