four-flap-meme-sdk 1.4.20 → 1.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +16 -0
- package/dist/flap/portal-bundle-merkle/encryption.js +146 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/package.json +3 -38
- package/dist/sol/constants.d.ts +0 -126
- package/dist/sol/constants.js +0 -145
- package/dist/sol/dex/index.d.ts +0 -8
- package/dist/sol/dex/index.js +0 -12
- package/dist/sol/dex/meteora/client.d.ts +0 -76
- package/dist/sol/dex/meteora/client.js +0 -219
- package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +0 -61
- package/dist/sol/dex/meteora/damm-v1-bundle.js +0 -112
- package/dist/sol/dex/meteora/damm-v1.d.ts +0 -118
- package/dist/sol/dex/meteora/damm-v1.js +0 -315
- package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +0 -82
- package/dist/sol/dex/meteora/damm-v2-bundle.js +0 -242
- package/dist/sol/dex/meteora/damm-v2.d.ts +0 -172
- package/dist/sol/dex/meteora/damm-v2.js +0 -632
- package/dist/sol/dex/meteora/dbc-bundle.d.ts +0 -123
- package/dist/sol/dex/meteora/dbc-bundle.js +0 -304
- package/dist/sol/dex/meteora/dbc.d.ts +0 -192
- package/dist/sol/dex/meteora/dbc.js +0 -619
- package/dist/sol/dex/meteora/dlmm-bundle.d.ts +0 -39
- package/dist/sol/dex/meteora/dlmm-bundle.js +0 -189
- package/dist/sol/dex/meteora/dlmm.d.ts +0 -157
- package/dist/sol/dex/meteora/dlmm.js +0 -671
- package/dist/sol/dex/meteora/index.d.ts +0 -25
- package/dist/sol/dex/meteora/index.js +0 -65
- package/dist/sol/dex/meteora/types.d.ts +0 -787
- package/dist/sol/dex/meteora/types.js +0 -110
- package/dist/sol/dex/orca/index.d.ts +0 -10
- package/dist/sol/dex/orca/index.js +0 -16
- package/dist/sol/dex/orca/orca-bundle.d.ts +0 -41
- package/dist/sol/dex/orca/orca-bundle.js +0 -173
- package/dist/sol/dex/orca/orca.d.ts +0 -65
- package/dist/sol/dex/orca/orca.js +0 -474
- package/dist/sol/dex/orca/types.d.ts +0 -263
- package/dist/sol/dex/orca/types.js +0 -38
- package/dist/sol/dex/orca/wavebreak-bundle.d.ts +0 -34
- package/dist/sol/dex/orca/wavebreak-bundle.js +0 -198
- package/dist/sol/dex/orca/wavebreak-types.d.ts +0 -227
- package/dist/sol/dex/orca/wavebreak-types.js +0 -23
- package/dist/sol/dex/orca/wavebreak.d.ts +0 -78
- package/dist/sol/dex/orca/wavebreak.js +0 -497
- package/dist/sol/dex/pump/index.d.ts +0 -9
- package/dist/sol/dex/pump/index.js +0 -14
- package/dist/sol/dex/pump/pump-bundle.d.ts +0 -92
- package/dist/sol/dex/pump/pump-bundle.js +0 -383
- package/dist/sol/dex/pump/pump-swap-bundle.d.ts +0 -103
- package/dist/sol/dex/pump/pump-swap-bundle.js +0 -380
- package/dist/sol/dex/pump/pump-swap.d.ts +0 -46
- package/dist/sol/dex/pump/pump-swap.js +0 -199
- package/dist/sol/dex/pump/pump.d.ts +0 -35
- package/dist/sol/dex/pump/pump.js +0 -352
- package/dist/sol/dex/pump/types.d.ts +0 -215
- package/dist/sol/dex/pump/types.js +0 -5
- package/dist/sol/dex/raydium/index.d.ts +0 -8
- package/dist/sol/dex/raydium/index.js +0 -12
- package/dist/sol/dex/raydium/launchlab.d.ts +0 -68
- package/dist/sol/dex/raydium/launchlab.js +0 -210
- package/dist/sol/dex/raydium/raydium-bundle.d.ts +0 -64
- package/dist/sol/dex/raydium/raydium-bundle.js +0 -324
- package/dist/sol/dex/raydium/raydium.d.ts +0 -40
- package/dist/sol/dex/raydium/raydium.js +0 -366
- package/dist/sol/dex/raydium/types.d.ts +0 -240
- package/dist/sol/dex/raydium/types.js +0 -5
- package/dist/sol/index.d.ts +0 -10
- package/dist/sol/index.js +0 -16
- package/dist/sol/jito/bundle.d.ts +0 -90
- package/dist/sol/jito/bundle.js +0 -263
- package/dist/sol/jito/index.d.ts +0 -7
- package/dist/sol/jito/index.js +0 -7
- package/dist/sol/jito/tip.d.ts +0 -51
- package/dist/sol/jito/tip.js +0 -83
- package/dist/sol/jito/types.d.ts +0 -100
- package/dist/sol/jito/types.js +0 -5
- package/dist/sol/token/create-complete.d.ts +0 -115
- package/dist/sol/token/create-complete.js +0 -235
- package/dist/sol/token/create-token.d.ts +0 -57
- package/dist/sol/token/create-token.js +0 -230
- package/dist/sol/token/index.d.ts +0 -9
- package/dist/sol/token/index.js +0 -14
- package/dist/sol/token/metadata-upload.d.ts +0 -86
- package/dist/sol/token/metadata-upload.js +0 -173
- package/dist/sol/token/metadata.d.ts +0 -92
- package/dist/sol/token/metadata.js +0 -274
- package/dist/sol/token/types.d.ts +0 -153
- package/dist/sol/token/types.js +0 -5
- package/dist/sol/types.d.ts +0 -176
- package/dist/sol/types.js +0 -7
- package/dist/sol/utils/balance.d.ts +0 -160
- package/dist/sol/utils/balance.js +0 -638
- package/dist/sol/utils/connection.d.ts +0 -78
- package/dist/sol/utils/connection.js +0 -168
- package/dist/sol/utils/index.d.ts +0 -9
- package/dist/sol/utils/index.js +0 -9
- package/dist/sol/utils/lp-inspect.d.ts +0 -129
- package/dist/sol/utils/lp-inspect.js +0 -900
- package/dist/sol/utils/transfer.d.ts +0 -125
- package/dist/sol/utils/transfer.js +0 -220
- package/dist/sol/utils/wallet.d.ts +0 -107
- package/dist/sol/utils/wallet.js +0 -210
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meteora DAMM v1 (Dynamic AMM) 集成
|
|
3
|
-
*
|
|
4
|
-
* 基于 https://github.com/MeteoraAg/dynamic-amm-sdk 源码分析
|
|
5
|
-
* DAMM v1 是 DBC 迁移后的目标池之一
|
|
6
|
-
*/
|
|
7
|
-
import { PublicKey, } from '@solana/web3.js';
|
|
8
|
-
import BN from 'bn.js';
|
|
9
|
-
import { getConnection, getDammV1Pool } from './client.js';
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// 池信息查询
|
|
12
|
-
// ============================================================================
|
|
13
|
-
/**
|
|
14
|
-
* 获取 DAMM v1 池信息
|
|
15
|
-
* @param poolAddress 池地址
|
|
16
|
-
* @param connection 可选连接
|
|
17
|
-
*/
|
|
18
|
-
export async function getDammV1PoolInfo(poolAddress, connection) {
|
|
19
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
20
|
-
const poolInfo = pool.poolInfo;
|
|
21
|
-
return {
|
|
22
|
-
poolAddress,
|
|
23
|
-
tokenAMint: pool.tokenAMint.address.toString(),
|
|
24
|
-
tokenBMint: pool.tokenBMint.address.toString(),
|
|
25
|
-
curveType: pool.isStablePool ? 'StableSwap' : 'ConstantProduct',
|
|
26
|
-
currentPrice: poolInfo.virtualPrice,
|
|
27
|
-
feeBps: pool.fees?.tradeFeeNumerator?.toNumber() || 0,
|
|
28
|
-
tokenAReserve: poolInfo.tokenAAmount.toString(),
|
|
29
|
-
tokenBReserve: poolInfo.tokenBAmount.toString(),
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
// ============================================================================
|
|
33
|
-
// Swap
|
|
34
|
-
// ============================================================================
|
|
35
|
-
/**
|
|
36
|
-
* 签名 DAMM v1 Swap 交易
|
|
37
|
-
* @param params Swap 参数
|
|
38
|
-
* @param wallet 钱包
|
|
39
|
-
* @param connection 可选连接
|
|
40
|
-
*/
|
|
41
|
-
export async function signDammV1Swap(params, wallet, connection) {
|
|
42
|
-
const conn = getConnection(connection);
|
|
43
|
-
const pool = await getDammV1Pool(params.poolAddress, connection);
|
|
44
|
-
const swapQuote = pool.getSwapQuote(new PublicKey(params.inputMint), params.amountIn, 100);
|
|
45
|
-
const minAmountOut = params.minAmountOut || swapQuote.minSwapOutAmount;
|
|
46
|
-
const swapTx = await pool.swap(wallet.publicKey, new PublicKey(params.inputMint), params.amountIn, minAmountOut);
|
|
47
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
48
|
-
swapTx.recentBlockhash = blockhash;
|
|
49
|
-
swapTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
50
|
-
swapTx.feePayer = wallet.publicKey;
|
|
51
|
-
swapTx.sign(wallet);
|
|
52
|
-
return {
|
|
53
|
-
signedTransaction: swapTx,
|
|
54
|
-
type: 'damm_v1_swap',
|
|
55
|
-
poolAddress: params.poolAddress,
|
|
56
|
-
metadata: {
|
|
57
|
-
amountIn: params.amountIn.toString(),
|
|
58
|
-
minAmountOut: minAmountOut.toString(),
|
|
59
|
-
inputMint: params.inputMint,
|
|
60
|
-
outputMint: params.outputMint,
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// 添加流动性
|
|
66
|
-
// ============================================================================
|
|
67
|
-
/**
|
|
68
|
-
* 签名 DAMM v1 添加流动性交易
|
|
69
|
-
*/
|
|
70
|
-
export async function signDammV1Deposit(poolAddress, amountA, amountB, wallet, connection) {
|
|
71
|
-
const conn = getConnection(connection);
|
|
72
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
73
|
-
const depositQuote = pool.getDepositQuote(amountA, amountB, true, 100);
|
|
74
|
-
const depositTx = await pool.deposit(wallet.publicKey, depositQuote.tokenAInAmount, depositQuote.tokenBInAmount, depositQuote.minPoolTokenAmountOut);
|
|
75
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
76
|
-
depositTx.recentBlockhash = blockhash;
|
|
77
|
-
depositTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
78
|
-
depositTx.feePayer = wallet.publicKey;
|
|
79
|
-
depositTx.sign(wallet);
|
|
80
|
-
return {
|
|
81
|
-
signedTransaction: depositTx,
|
|
82
|
-
type: 'damm_v1_deposit',
|
|
83
|
-
poolAddress,
|
|
84
|
-
metadata: {
|
|
85
|
-
amountA: amountA.toString(),
|
|
86
|
-
amountB: amountB.toString(),
|
|
87
|
-
minLpAmount: depositQuote.minPoolTokenAmountOut.toString(),
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// ============================================================================
|
|
92
|
-
// 移除流动性
|
|
93
|
-
// ============================================================================
|
|
94
|
-
/**
|
|
95
|
-
* 签名 DAMM v1 移除流动性交易
|
|
96
|
-
*/
|
|
97
|
-
export async function signDammV1Withdraw(poolAddress, lpAmount, wallet, connection) {
|
|
98
|
-
const conn = getConnection(connection);
|
|
99
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
100
|
-
const withdrawQuote = pool.getWithdrawQuote(lpAmount, 100);
|
|
101
|
-
const withdrawTx = await pool.withdraw(wallet.publicKey, lpAmount, withdrawQuote.minTokenAOutAmount, withdrawQuote.minTokenBOutAmount);
|
|
102
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
103
|
-
withdrawTx.recentBlockhash = blockhash;
|
|
104
|
-
withdrawTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
105
|
-
withdrawTx.feePayer = wallet.publicKey;
|
|
106
|
-
withdrawTx.sign(wallet);
|
|
107
|
-
return {
|
|
108
|
-
signedTransaction: withdrawTx,
|
|
109
|
-
type: 'damm_v1_withdraw',
|
|
110
|
-
poolAddress,
|
|
111
|
-
metadata: {
|
|
112
|
-
lpAmount: lpAmount.toString(),
|
|
113
|
-
minTokenAOut: withdrawQuote.minTokenAOutAmount.toString(),
|
|
114
|
-
minTokenBOut: withdrawQuote.minTokenBOutAmount.toString(),
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
// ============================================================================
|
|
119
|
-
// 锁定流动性
|
|
120
|
-
// ============================================================================
|
|
121
|
-
/**
|
|
122
|
-
* 签名锁定 LP 交易
|
|
123
|
-
*/
|
|
124
|
-
export async function signDammV1LockLiquidity(poolAddress, lpAmount, wallet, connection) {
|
|
125
|
-
const conn = getConnection(connection);
|
|
126
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
127
|
-
const lockTx = await pool.lock(wallet.publicKey, lpAmount);
|
|
128
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
129
|
-
lockTx.recentBlockhash = blockhash;
|
|
130
|
-
lockTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
131
|
-
lockTx.feePayer = wallet.publicKey;
|
|
132
|
-
lockTx.sign(wallet);
|
|
133
|
-
return {
|
|
134
|
-
signedTransaction: lockTx,
|
|
135
|
-
type: 'damm_v1_lock',
|
|
136
|
-
poolAddress,
|
|
137
|
-
metadata: { lpAmount: lpAmount.toString() },
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* 签名领取锁定 LP 费用交易
|
|
142
|
-
*/
|
|
143
|
-
export async function signDammV1ClaimLockFee(poolAddress, wallet, connection) {
|
|
144
|
-
const conn = getConnection(connection);
|
|
145
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
146
|
-
const claimTx = await pool.claimLockFee(wallet.publicKey);
|
|
147
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
148
|
-
claimTx.recentBlockhash = blockhash;
|
|
149
|
-
claimTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
150
|
-
claimTx.feePayer = wallet.publicKey;
|
|
151
|
-
claimTx.sign(wallet);
|
|
152
|
-
return {
|
|
153
|
-
signedTransaction: claimTx,
|
|
154
|
-
type: 'damm_v1_claim_lock_fee',
|
|
155
|
-
poolAddress,
|
|
156
|
-
metadata: {},
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
// ============================================================================
|
|
160
|
-
// 辅助函数
|
|
161
|
-
// ============================================================================
|
|
162
|
-
/**
|
|
163
|
-
* 获取 LP Token Mint 地址
|
|
164
|
-
*/
|
|
165
|
-
export async function getDammV1LpMint(poolAddress, connection) {
|
|
166
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
167
|
-
const lpMint = await pool.getPoolTokenMint();
|
|
168
|
-
return lpMint.toString();
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* 获取 LP 供应量
|
|
172
|
-
*/
|
|
173
|
-
export async function getDammV1LpSupply(poolAddress, connection) {
|
|
174
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
175
|
-
return pool.getLpSupply();
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* 获取锁定的 LP 数量
|
|
179
|
-
*/
|
|
180
|
-
export async function getDammV1LockedLpAmount(poolAddress, connection) {
|
|
181
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
182
|
-
return pool.getLockedLpAmount();
|
|
183
|
-
}
|
|
184
|
-
// ============================================================================
|
|
185
|
-
// 创建池
|
|
186
|
-
// ============================================================================
|
|
187
|
-
/**
|
|
188
|
-
* 签名创建 DAMM v1 池交易
|
|
189
|
-
* @param tokenAMint Token A Mint
|
|
190
|
-
* @param tokenBMint Token B Mint
|
|
191
|
-
* @param tokenAAmount 初始 Token A 数量
|
|
192
|
-
* @param tokenBAmount 初始 Token B 数量
|
|
193
|
-
* @param wallet 钱包
|
|
194
|
-
* @param connection 可选连接
|
|
195
|
-
*/
|
|
196
|
-
export async function signDammV1CreatePool(tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, wallet, connection) {
|
|
197
|
-
const conn = getConnection(connection);
|
|
198
|
-
// 需要使用 DynamicAmm 类的静态方法
|
|
199
|
-
const DynamicAmm = (await import('@meteora-ag/dynamic-amm-sdk')).default;
|
|
200
|
-
// 创建 Constant Product Pool
|
|
201
|
-
const createPoolTx = await DynamicAmm.createPermissionlessConstantProductPool(conn, wallet.publicKey, new PublicKey(tokenAMint), new PublicKey(tokenBMint), tokenAAmount, tokenBAmount, {
|
|
202
|
-
tradeFeeNumerator: new BN(25), // 0.25% 交易费
|
|
203
|
-
});
|
|
204
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
205
|
-
createPoolTx.recentBlockhash = blockhash;
|
|
206
|
-
createPoolTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
207
|
-
createPoolTx.feePayer = wallet.publicKey;
|
|
208
|
-
createPoolTx.sign(wallet);
|
|
209
|
-
return {
|
|
210
|
-
signedTransaction: createPoolTx,
|
|
211
|
-
type: 'damm_v1_create_pool',
|
|
212
|
-
poolAddress: '',
|
|
213
|
-
metadata: {
|
|
214
|
-
tokenAMint,
|
|
215
|
-
tokenBMint,
|
|
216
|
-
tokenAAmount: tokenAAmount.toString(),
|
|
217
|
-
tokenBAmount: tokenBAmount.toString(),
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
// ============================================================================
|
|
222
|
-
// 报价查询
|
|
223
|
-
// ============================================================================
|
|
224
|
-
/**
|
|
225
|
-
* 获取 DAMM v1 Swap 报价
|
|
226
|
-
* @param poolAddress 池地址
|
|
227
|
-
* @param inputMint 输入 Mint
|
|
228
|
-
* @param amountIn 输入数量
|
|
229
|
-
* @param slippageBps 滑点 (bps)
|
|
230
|
-
* @param connection 可选连接
|
|
231
|
-
*/
|
|
232
|
-
export async function getDammV1SwapQuote(poolAddress, inputMint, amountIn, slippageBps = 100, connection) {
|
|
233
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
234
|
-
const quote = pool.getSwapQuote(new PublicKey(inputMint), amountIn, slippageBps);
|
|
235
|
-
return {
|
|
236
|
-
swapInAmount: quote.swapInAmount.toString(),
|
|
237
|
-
swapOutAmount: quote.swapOutAmount.toString(),
|
|
238
|
-
minSwapOutAmount: quote.minSwapOutAmount.toString(),
|
|
239
|
-
priceImpact: quote.priceImpact?.toString() || '0',
|
|
240
|
-
fee: quote.fee?.toString() || '0',
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* 获取 DAMM v1 存款报价
|
|
245
|
-
* @param poolAddress 池地址
|
|
246
|
-
* @param tokenAAmount Token A 数量
|
|
247
|
-
* @param tokenBAmount Token B 数量
|
|
248
|
-
* @param slippageBps 滑点 (bps)
|
|
249
|
-
* @param connection 可选连接
|
|
250
|
-
*/
|
|
251
|
-
export async function getDammV1DepositQuote(poolAddress, tokenAAmount, tokenBAmount, slippageBps = 100, connection) {
|
|
252
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
253
|
-
const quote = pool.getDepositQuote(tokenAAmount, tokenBAmount, true, slippageBps);
|
|
254
|
-
return {
|
|
255
|
-
tokenAInAmount: quote.tokenAInAmount.toString(),
|
|
256
|
-
tokenBInAmount: quote.tokenBInAmount.toString(),
|
|
257
|
-
poolTokenAmountOut: quote.poolTokenAmountOut.toString(),
|
|
258
|
-
minPoolTokenAmountOut: quote.minPoolTokenAmountOut.toString(),
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* 获取 DAMM v1 提款报价
|
|
263
|
-
* @param poolAddress 池地址
|
|
264
|
-
* @param lpAmount LP 数量
|
|
265
|
-
* @param slippageBps 滑点 (bps)
|
|
266
|
-
* @param connection 可选连接
|
|
267
|
-
*/
|
|
268
|
-
export async function getDammV1WithdrawQuote(poolAddress, lpAmount, slippageBps = 100, connection) {
|
|
269
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
270
|
-
const quote = pool.getWithdrawQuote(lpAmount, slippageBps);
|
|
271
|
-
return {
|
|
272
|
-
tokenAOutAmount: quote.tokenAOutAmount.toString(),
|
|
273
|
-
tokenBOutAmount: quote.tokenBOutAmount.toString(),
|
|
274
|
-
minTokenAOutAmount: quote.minTokenAOutAmount.toString(),
|
|
275
|
-
minTokenBOutAmount: quote.minTokenBOutAmount.toString(),
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
// ============================================================================
|
|
279
|
-
// 用户信息
|
|
280
|
-
// ============================================================================
|
|
281
|
-
/**
|
|
282
|
-
* 获取用户的 LP 余额
|
|
283
|
-
* @param poolAddress 池地址
|
|
284
|
-
* @param userAddress 用户地址
|
|
285
|
-
* @param connection 可选连接
|
|
286
|
-
*/
|
|
287
|
-
export async function getDammV1UserLpBalance(poolAddress, userAddress, connection) {
|
|
288
|
-
const conn = getConnection(connection);
|
|
289
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
290
|
-
const lpMint = await pool.getPoolTokenMint();
|
|
291
|
-
const { getAssociatedTokenAddressSync } = await import('@solana/spl-token');
|
|
292
|
-
try {
|
|
293
|
-
const lpAta = getAssociatedTokenAddressSync(lpMint, new PublicKey(userAddress));
|
|
294
|
-
const lpAccount = await conn.getTokenAccountBalance(lpAta);
|
|
295
|
-
return {
|
|
296
|
-
balance: lpAccount.value.amount,
|
|
297
|
-
lockedBalance: '0', // 需要查询锁定账户
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
catch {
|
|
301
|
-
return {
|
|
302
|
-
balance: '0',
|
|
303
|
-
lockedBalance: '0',
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* 获取池的虚拟价格
|
|
309
|
-
* @param poolAddress 池地址
|
|
310
|
-
* @param connection 可选连接
|
|
311
|
-
*/
|
|
312
|
-
export async function getDammV1VirtualPrice(poolAddress, connection) {
|
|
313
|
-
const pool = await getDammV1Pool(poolAddress, connection);
|
|
314
|
-
return pool.poolInfo.virtualPrice;
|
|
315
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meteora DAMM v2 (CP-AMM) Bundle 批量交易
|
|
3
|
-
*
|
|
4
|
-
* 支持 Jito Bundle 的批量买卖
|
|
5
|
-
*/
|
|
6
|
-
import { Connection, Keypair } from '@solana/web3.js';
|
|
7
|
-
import BN from 'bn.js';
|
|
8
|
-
import type { MeteoraBundleSignedResult } from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* DAMM v2 Bundle Swap 参数
|
|
11
|
-
*/
|
|
12
|
-
export interface DammV2BundleSwapParams {
|
|
13
|
-
/** 池地址 */
|
|
14
|
-
poolAddress: string;
|
|
15
|
-
/** 输入代币地址 */
|
|
16
|
-
inputMint: string;
|
|
17
|
-
/** 输出代币地址 */
|
|
18
|
-
outputMint: string;
|
|
19
|
-
/** Token A 精度 */
|
|
20
|
-
tokenADecimal?: number;
|
|
21
|
-
/** Token B 精度 */
|
|
22
|
-
tokenBDecimal?: number;
|
|
23
|
-
/** 交易列表 */
|
|
24
|
-
trades: {
|
|
25
|
-
wallet: Keypair;
|
|
26
|
-
amountIn: BN;
|
|
27
|
-
minAmountOut?: BN;
|
|
28
|
-
}[];
|
|
29
|
-
/** 滑点百分比 (例如 0.5 表示 0.5%) */
|
|
30
|
-
slippagePercent?: number;
|
|
31
|
-
/** Jito 小费 */
|
|
32
|
-
jitoTipLamports?: number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 签名 DAMM v2 Bundle 批量买入交易
|
|
36
|
-
*
|
|
37
|
-
* @param params Bundle 参数
|
|
38
|
-
* @param connection 可选连接
|
|
39
|
-
*/
|
|
40
|
-
export declare function signDammV2BundleBuy(params: DammV2BundleSwapParams, connection?: Connection): Promise<MeteoraBundleSignedResult>;
|
|
41
|
-
/**
|
|
42
|
-
* 签名 DAMM v2 Bundle 批量卖出交易
|
|
43
|
-
*
|
|
44
|
-
* @param params Bundle 参数
|
|
45
|
-
* @param connection 可选连接
|
|
46
|
-
*/
|
|
47
|
-
export declare function signDammV2BundleSell(params: DammV2BundleSwapParams, connection?: Connection): Promise<MeteoraBundleSignedResult>;
|
|
48
|
-
/**
|
|
49
|
-
* 签名 DAMM v2 Bundle 通用 Swap 交易
|
|
50
|
-
*
|
|
51
|
-
* @param params Bundle 参数
|
|
52
|
-
* @param isBuy 是否买入 (true = 买入, false = 卖出)
|
|
53
|
-
* @param connection 可选连接
|
|
54
|
-
*/
|
|
55
|
-
export declare function signDammV2BundleSwap(params: DammV2BundleSwapParams, isBuy: boolean, connection?: Connection): Promise<MeteoraBundleSignedResult>;
|
|
56
|
-
/**
|
|
57
|
-
* 将 Bundle 结果转换为后端 API 请求格式
|
|
58
|
-
*/
|
|
59
|
-
export declare function toDammV2BundleApiRequest(result: MeteoraBundleSignedResult): {
|
|
60
|
-
transactions: string[];
|
|
61
|
-
type: string;
|
|
62
|
-
poolAddress: string;
|
|
63
|
-
tradeCount: number;
|
|
64
|
-
jitoTipLamports: number;
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* 批量获取 DAMM v2 Swap 报价
|
|
68
|
-
*
|
|
69
|
-
* @param poolAddress 池地址
|
|
70
|
-
* @param inputMint 输入代币地址
|
|
71
|
-
* @param amounts 输入金额列表
|
|
72
|
-
* @param tokenADecimal Token A 精度
|
|
73
|
-
* @param tokenBDecimal Token B 精度
|
|
74
|
-
* @param slippagePercent 滑点百分比
|
|
75
|
-
* @param connection 可选连接
|
|
76
|
-
*/
|
|
77
|
-
export declare function getDammV2BundleQuotes(poolAddress: string, inputMint: string, amounts: BN[], tokenADecimal?: number, tokenBDecimal?: number, slippagePercent?: number, connection?: Connection): Promise<{
|
|
78
|
-
swapOutAmount: string;
|
|
79
|
-
minSwapOutAmount: string;
|
|
80
|
-
totalFee: string;
|
|
81
|
-
priceImpact: number;
|
|
82
|
-
}[]>;
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Meteora DAMM v2 (CP-AMM) Bundle 批量交易
|
|
3
|
-
*
|
|
4
|
-
* 支持 Jito Bundle 的批量买卖
|
|
5
|
-
*/
|
|
6
|
-
import { PublicKey, } from '@solana/web3.js';
|
|
7
|
-
import { getTokenProgram } from '@meteora-ag/cp-amm-sdk';
|
|
8
|
-
import { getConnection, getCpAmmClient } from './client.js';
|
|
9
|
-
import { buildTipInstruction } from '../../jito/tip.js';
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// Bundle 批量买入
|
|
12
|
-
// ============================================================================
|
|
13
|
-
/**
|
|
14
|
-
* 签名 DAMM v2 Bundle 批量买入交易
|
|
15
|
-
*
|
|
16
|
-
* @param params Bundle 参数
|
|
17
|
-
* @param connection 可选连接
|
|
18
|
-
*/
|
|
19
|
-
export async function signDammV2BundleBuy(params, connection) {
|
|
20
|
-
const conn = getConnection(connection);
|
|
21
|
-
const cpAmm = getCpAmmClient(connection);
|
|
22
|
-
const poolPubkey = new PublicKey(params.poolAddress);
|
|
23
|
-
const poolState = await cpAmm.fetchPoolState(poolPubkey);
|
|
24
|
-
// 获取当前 slot 和时间用于报价
|
|
25
|
-
const currentSlot = await conn.getSlot();
|
|
26
|
-
const blockTime = await conn.getBlockTime(currentSlot);
|
|
27
|
-
const signedTransactions = [];
|
|
28
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
29
|
-
const tokenADecimal = params.tokenADecimal ?? 9;
|
|
30
|
-
const tokenBDecimal = params.tokenBDecimal ?? 9;
|
|
31
|
-
const slippage = params.slippagePercent ?? 0.5;
|
|
32
|
-
for (let i = 0; i < params.trades.length; i++) {
|
|
33
|
-
const trade = params.trades[i];
|
|
34
|
-
let minAmountOut = trade.minAmountOut;
|
|
35
|
-
// 如果没有指定 minAmountOut,使用 getQuote 获取准确报价
|
|
36
|
-
if (!minAmountOut) {
|
|
37
|
-
const quote = await cpAmm.getQuote({
|
|
38
|
-
inAmount: trade.amountIn,
|
|
39
|
-
inputTokenMint: new PublicKey(params.inputMint),
|
|
40
|
-
slippage,
|
|
41
|
-
poolState,
|
|
42
|
-
currentTime: blockTime || Math.floor(Date.now() / 1000),
|
|
43
|
-
currentSlot,
|
|
44
|
-
tokenADecimal,
|
|
45
|
-
tokenBDecimal,
|
|
46
|
-
hasReferral: false,
|
|
47
|
-
});
|
|
48
|
-
minAmountOut = quote.minSwapOutAmount;
|
|
49
|
-
}
|
|
50
|
-
// swap 返回 TxBuilder,需要调用 .transaction() 获取 Transaction
|
|
51
|
-
const swapTxBuilder = await cpAmm.swap({
|
|
52
|
-
payer: trade.wallet.publicKey,
|
|
53
|
-
pool: poolPubkey,
|
|
54
|
-
inputTokenMint: new PublicKey(params.inputMint),
|
|
55
|
-
outputTokenMint: new PublicKey(params.outputMint),
|
|
56
|
-
amountIn: trade.amountIn,
|
|
57
|
-
minimumAmountOut: minAmountOut,
|
|
58
|
-
tokenAMint: poolState.tokenAMint,
|
|
59
|
-
tokenBMint: poolState.tokenBMint,
|
|
60
|
-
tokenAVault: poolState.tokenAVault,
|
|
61
|
-
tokenBVault: poolState.tokenBVault,
|
|
62
|
-
tokenAProgram: getTokenProgram(poolState.tokenAFlag),
|
|
63
|
-
tokenBProgram: getTokenProgram(poolState.tokenBFlag),
|
|
64
|
-
referralTokenAccount: null,
|
|
65
|
-
});
|
|
66
|
-
// 处理 TxBuilder 或 Transaction 返回类型
|
|
67
|
-
const swapTx = 'transaction' in swapTxBuilder
|
|
68
|
-
? await swapTxBuilder.transaction()
|
|
69
|
-
: swapTxBuilder;
|
|
70
|
-
// 如果是最后一笔交易,添加 Jito tip
|
|
71
|
-
if (i === params.trades.length - 1 && params.jitoTipLamports) {
|
|
72
|
-
const tipIx = buildTipInstruction(trade.wallet.publicKey, BigInt(params.jitoTipLamports));
|
|
73
|
-
swapTx.add(tipIx);
|
|
74
|
-
}
|
|
75
|
-
swapTx.recentBlockhash = blockhash;
|
|
76
|
-
swapTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
77
|
-
swapTx.feePayer = trade.wallet.publicKey;
|
|
78
|
-
swapTx.sign(trade.wallet);
|
|
79
|
-
signedTransactions.push(swapTx);
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
signedTransactions,
|
|
83
|
-
type: 'damm_v2_bundle_buy',
|
|
84
|
-
poolAddress: params.poolAddress,
|
|
85
|
-
tradeCount: params.trades.length,
|
|
86
|
-
jitoTipLamports: params.jitoTipLamports || 0,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
// ============================================================================
|
|
90
|
-
// Bundle 批量卖出
|
|
91
|
-
// ============================================================================
|
|
92
|
-
/**
|
|
93
|
-
* 签名 DAMM v2 Bundle 批量卖出交易
|
|
94
|
-
*
|
|
95
|
-
* @param params Bundle 参数
|
|
96
|
-
* @param connection 可选连接
|
|
97
|
-
*/
|
|
98
|
-
export async function signDammV2BundleSell(params, connection) {
|
|
99
|
-
const conn = getConnection(connection);
|
|
100
|
-
const cpAmm = getCpAmmClient(connection);
|
|
101
|
-
const poolPubkey = new PublicKey(params.poolAddress);
|
|
102
|
-
const poolState = await cpAmm.fetchPoolState(poolPubkey);
|
|
103
|
-
// 获取当前 slot 和时间用于报价
|
|
104
|
-
const currentSlot = await conn.getSlot();
|
|
105
|
-
const blockTime = await conn.getBlockTime(currentSlot);
|
|
106
|
-
const signedTransactions = [];
|
|
107
|
-
const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
|
|
108
|
-
const tokenADecimal = params.tokenADecimal ?? 9;
|
|
109
|
-
const tokenBDecimal = params.tokenBDecimal ?? 9;
|
|
110
|
-
const slippage = params.slippagePercent ?? 0.5;
|
|
111
|
-
for (let i = 0; i < params.trades.length; i++) {
|
|
112
|
-
const trade = params.trades[i];
|
|
113
|
-
let minAmountOut = trade.minAmountOut;
|
|
114
|
-
// 如果没有指定 minAmountOut,使用 getQuote 获取准确报价
|
|
115
|
-
if (!minAmountOut) {
|
|
116
|
-
const quote = await cpAmm.getQuote({
|
|
117
|
-
inAmount: trade.amountIn,
|
|
118
|
-
inputTokenMint: new PublicKey(params.inputMint),
|
|
119
|
-
slippage,
|
|
120
|
-
poolState,
|
|
121
|
-
currentTime: blockTime || Math.floor(Date.now() / 1000),
|
|
122
|
-
currentSlot,
|
|
123
|
-
tokenADecimal,
|
|
124
|
-
tokenBDecimal,
|
|
125
|
-
hasReferral: false,
|
|
126
|
-
});
|
|
127
|
-
minAmountOut = quote.minSwapOutAmount;
|
|
128
|
-
}
|
|
129
|
-
// swap 返回 TxBuilder,需要调用 .transaction() 获取 Transaction
|
|
130
|
-
const swapTxBuilder = await cpAmm.swap({
|
|
131
|
-
payer: trade.wallet.publicKey,
|
|
132
|
-
pool: poolPubkey,
|
|
133
|
-
inputTokenMint: new PublicKey(params.inputMint),
|
|
134
|
-
outputTokenMint: new PublicKey(params.outputMint),
|
|
135
|
-
amountIn: trade.amountIn,
|
|
136
|
-
minimumAmountOut: minAmountOut,
|
|
137
|
-
tokenAMint: poolState.tokenAMint,
|
|
138
|
-
tokenBMint: poolState.tokenBMint,
|
|
139
|
-
tokenAVault: poolState.tokenAVault,
|
|
140
|
-
tokenBVault: poolState.tokenBVault,
|
|
141
|
-
tokenAProgram: getTokenProgram(poolState.tokenAFlag),
|
|
142
|
-
tokenBProgram: getTokenProgram(poolState.tokenBFlag),
|
|
143
|
-
referralTokenAccount: null,
|
|
144
|
-
});
|
|
145
|
-
// 处理 TxBuilder 或 Transaction 返回类型
|
|
146
|
-
const swapTx = 'transaction' in swapTxBuilder
|
|
147
|
-
? await swapTxBuilder.transaction()
|
|
148
|
-
: swapTxBuilder;
|
|
149
|
-
// 如果是最后一笔交易,添加 Jito tip
|
|
150
|
-
if (i === params.trades.length - 1 && params.jitoTipLamports) {
|
|
151
|
-
const tipIx = buildTipInstruction(trade.wallet.publicKey, BigInt(params.jitoTipLamports));
|
|
152
|
-
swapTx.add(tipIx);
|
|
153
|
-
}
|
|
154
|
-
swapTx.recentBlockhash = blockhash;
|
|
155
|
-
swapTx.lastValidBlockHeight = lastValidBlockHeight;
|
|
156
|
-
swapTx.feePayer = trade.wallet.publicKey;
|
|
157
|
-
swapTx.sign(trade.wallet);
|
|
158
|
-
signedTransactions.push(swapTx);
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
signedTransactions,
|
|
162
|
-
type: 'damm_v2_bundle_sell',
|
|
163
|
-
poolAddress: params.poolAddress,
|
|
164
|
-
tradeCount: params.trades.length,
|
|
165
|
-
jitoTipLamports: params.jitoTipLamports || 0,
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// ============================================================================
|
|
169
|
-
// Bundle 通用 Swap
|
|
170
|
-
// ============================================================================
|
|
171
|
-
/**
|
|
172
|
-
* 签名 DAMM v2 Bundle 通用 Swap 交易
|
|
173
|
-
*
|
|
174
|
-
* @param params Bundle 参数
|
|
175
|
-
* @param isBuy 是否买入 (true = 买入, false = 卖出)
|
|
176
|
-
* @param connection 可选连接
|
|
177
|
-
*/
|
|
178
|
-
export async function signDammV2BundleSwap(params, isBuy, connection) {
|
|
179
|
-
if (isBuy) {
|
|
180
|
-
return signDammV2BundleBuy(params, connection);
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return signDammV2BundleSell(params, connection);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* 将 Bundle 结果转换为后端 API 请求格式
|
|
188
|
-
*/
|
|
189
|
-
export function toDammV2BundleApiRequest(result) {
|
|
190
|
-
return {
|
|
191
|
-
transactions: result.signedTransactions.map((tx) => tx.serialize().toString('base64')),
|
|
192
|
-
type: result.type,
|
|
193
|
-
poolAddress: result.poolAddress,
|
|
194
|
-
tradeCount: result.tradeCount,
|
|
195
|
-
jitoTipLamports: result.jitoTipLamports,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
// ============================================================================
|
|
199
|
-
// 辅助函数:批量获取报价
|
|
200
|
-
// ============================================================================
|
|
201
|
-
/**
|
|
202
|
-
* 批量获取 DAMM v2 Swap 报价
|
|
203
|
-
*
|
|
204
|
-
* @param poolAddress 池地址
|
|
205
|
-
* @param inputMint 输入代币地址
|
|
206
|
-
* @param amounts 输入金额列表
|
|
207
|
-
* @param tokenADecimal Token A 精度
|
|
208
|
-
* @param tokenBDecimal Token B 精度
|
|
209
|
-
* @param slippagePercent 滑点百分比
|
|
210
|
-
* @param connection 可选连接
|
|
211
|
-
*/
|
|
212
|
-
export async function getDammV2BundleQuotes(poolAddress, inputMint, amounts, tokenADecimal = 9, tokenBDecimal = 9, slippagePercent = 0.5, connection) {
|
|
213
|
-
const conn = getConnection(connection);
|
|
214
|
-
const cpAmm = getCpAmmClient(connection);
|
|
215
|
-
const poolPubkey = new PublicKey(poolAddress);
|
|
216
|
-
const poolState = await cpAmm.fetchPoolState(poolPubkey);
|
|
217
|
-
const currentSlot = await conn.getSlot();
|
|
218
|
-
const blockTime = await conn.getBlockTime(currentSlot);
|
|
219
|
-
const quotes = [];
|
|
220
|
-
for (const amountIn of amounts) {
|
|
221
|
-
const quote = await cpAmm.getQuote({
|
|
222
|
-
inAmount: amountIn,
|
|
223
|
-
inputTokenMint: new PublicKey(inputMint),
|
|
224
|
-
slippage: slippagePercent,
|
|
225
|
-
poolState,
|
|
226
|
-
currentTime: blockTime || Math.floor(Date.now() / 1000),
|
|
227
|
-
currentSlot,
|
|
228
|
-
tokenADecimal,
|
|
229
|
-
tokenBDecimal,
|
|
230
|
-
hasReferral: false,
|
|
231
|
-
});
|
|
232
|
-
quotes.push({
|
|
233
|
-
swapOutAmount: quote.swapOutAmount.toString(),
|
|
234
|
-
minSwapOutAmount: quote.minSwapOutAmount.toString(),
|
|
235
|
-
totalFee: quote.totalFee.toString(),
|
|
236
|
-
priceImpact: typeof quote.priceImpact === 'number'
|
|
237
|
-
? quote.priceImpact
|
|
238
|
-
: Number(quote.priceImpact),
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return quotes;
|
|
242
|
-
}
|