four-flap-meme-sdk 1.3.87 → 1.3.88

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.
@@ -3,22 +3,12 @@
3
3
  * @module sol/constants
4
4
  */
5
5
  /**
6
- * RPC 节点配置
7
- * 使用 Helius 主网(开发和生产都用主网)
8
- */
9
- export declare const SOLANA_RPC: {
10
- /** Helius 主网 RPC(需要替换 API Key) */
11
- readonly MAINNET: "https://mainnet.helius-rpc.com/?api-key=YOUR_HELIUS_KEY";
12
- /** 公共主网 RPC(备用,有限速) */
13
- readonly MAINNET_PUBLIC: "https://api.mainnet-beta.solana.com";
14
- };
15
- /**
16
- * Jito Block Engine 配置
6
+ * Jito 配置
7
+ *
8
+ * 注意:BLOCK_ENGINE_URL 需要由前端传入,不在 SDK 中写死
17
9
  */
18
10
  export declare const JITO_CONFIG: {
19
- /** Block Engine URL */
20
- readonly BLOCK_ENGINE_URL: "https://mainnet.block-engine.jito.wtf";
21
- /** Tip 账户列表(随机选择一个) */
11
+ /** Tip 账户列表(随机选择一个)- 这些是 Jito 官方账户,固定不变 */
22
12
  readonly TIP_ACCOUNTS: readonly ["96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5", "HFqU5x63VTqvQss8hp11i4bVmkzdNaVB6PYjYgNd4W5U", "Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY", "ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49", "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh", "ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt", "DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL", "3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT"];
23
13
  /** 最小 Tip(lamports) */
24
14
  readonly MIN_TIP_LAMPORTS: 1000;
@@ -2,25 +2,14 @@
2
2
  * Solana SDK 常量配置
3
3
  * @module sol/constants
4
4
  */
5
- // ==================== RPC 配置 ====================
6
- /**
7
- * RPC 节点配置
8
- * 使用 Helius 主网(开发和生产都用主网)
9
- */
10
- export const SOLANA_RPC = {
11
- /** Helius 主网 RPC(需要替换 API Key) */
12
- MAINNET: 'https://mainnet.helius-rpc.com/?api-key=YOUR_HELIUS_KEY',
13
- /** 公共主网 RPC(备用,有限速) */
14
- MAINNET_PUBLIC: 'https://api.mainnet-beta.solana.com',
15
- };
16
5
  // ==================== Jito Bundle 配置 ====================
17
6
  /**
18
- * Jito Block Engine 配置
7
+ * Jito 配置
8
+ *
9
+ * 注意:BLOCK_ENGINE_URL 需要由前端传入,不在 SDK 中写死
19
10
  */
20
11
  export const JITO_CONFIG = {
21
- /** Block Engine URL */
22
- BLOCK_ENGINE_URL: 'https://mainnet.block-engine.jito.wtf',
23
- /** Tip 账户列表(随机选择一个) */
12
+ /** Tip 账户列表(随机选择一个)- 这些是 Jito 官方账户,固定不变 */
24
13
  TIP_ACCOUNTS: [
25
14
  '96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5',
26
15
  'HFqU5x63VTqvQss8hp11i4bVmkzdNaVB6PYjYgNd4W5U',
@@ -7,8 +7,9 @@ import { Connection } from '@solana/web3.js';
7
7
  import { CpAmm } from '@meteora-ag/cp-amm-sdk';
8
8
  import { DynamicBondingCurveClient } from '@meteora-ag/dynamic-bonding-curve-sdk';
9
9
  /**
10
- * 获取或创建默认连接
10
+ * 获取连接
11
11
  * @param connection 可选的自定义连接
12
+ * @throws Error 如果没有传入连接且未设置默认连接
12
13
  */
13
14
  export declare function getConnection(connection?: Connection): Connection;
14
15
  /**
@@ -4,7 +4,7 @@
4
4
  * 统一管理 RPC 连接和 SDK 实例,避免重复实例化
5
5
  */
6
6
  import { PublicKey } from '@solana/web3.js';
7
- import { createConnection } from '../../utils/connection.js';
7
+ // 不再导入 createConnection,强制使用者传入连接
8
8
  // SDK 导入 - 使用类型断言绕过 TypeScript 类型检查
9
9
  import DLMMModule from '@meteora-ag/dlmm';
10
10
  import AmmImplModule from '@meteora-ag/dynamic-amm-sdk';
@@ -15,18 +15,19 @@ const AmmImpl = AmmImplModule;
15
15
  // ============================================================================
16
16
  // 连接管理
17
17
  // ============================================================================
18
- /** 默认连接实例 */
18
+ /** 默认连接实例(必须通过 setDefaultConnection 设置) */
19
19
  let defaultConnection = null;
20
20
  /**
21
- * 获取或创建默认连接
21
+ * 获取连接
22
22
  * @param connection 可选的自定义连接
23
+ * @throws Error 如果没有传入连接且未设置默认连接
23
24
  */
24
25
  export function getConnection(connection) {
25
26
  if (connection) {
26
27
  return connection;
27
28
  }
28
29
  if (!defaultConnection) {
29
- defaultConnection = createConnection();
30
+ throw new Error('Connection is required. Either pass a connection parameter or call setDefaultConnection() first with user-configured RPC.');
30
31
  }
31
32
  return defaultConnection;
32
33
  }
@@ -33,7 +33,7 @@ function createWalletFromKeypair(keypair) {
33
33
  },
34
34
  };
35
35
  }
36
- import { createConnection } from '../../utils/connection.js';
36
+ // 不再导入 createConnection,强制使用者传入连接
37
37
  import { buildTipInstruction, getRandomTipAccount } from '../../jito/tip.js';
38
38
  /**
39
39
  * 默认 Jito 小费 (0.001 SOL)
@@ -58,7 +58,10 @@ export async function signOrcaBundleSell(params, connection) {
58
58
  * 支持买入和卖出
59
59
  */
60
60
  export async function signOrcaBundleSwap(params, connection) {
61
- const conn = connection || createConnection();
61
+ if (!connection) {
62
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
63
+ }
64
+ const conn = connection;
62
65
  const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
63
66
  const signedTransactions = [];
64
67
  const jitoTipLamports = params.jitoTipLamports || DEFAULT_JITO_TIP_LAMPORTS;
@@ -144,7 +147,10 @@ export function toOrcaBundleApiRequest(result) {
144
147
  * 批量获取多个池的信息
145
148
  */
146
149
  export async function batchGetOrcaPoolInfo(poolAddresses, connection) {
147
- const conn = connection || createConnection();
150
+ if (!connection) {
151
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
152
+ }
153
+ const conn = connection;
148
154
  const result = new Map();
149
155
  // 创建一个临时钱包用于查询
150
156
  const tempWallet = Keypair.generate();
@@ -8,7 +8,6 @@
8
8
  import { PublicKey, Transaction, } from '@solana/web3.js';
9
9
  import { WhirlpoolContext, buildWhirlpoolClient, ORCA_WHIRLPOOL_PROGRAM_ID, PDAUtil, TickUtil, PriceMath, PoolUtil, TokenExtensionUtil, } from '@orca-so/whirlpools-sdk';
10
10
  import { Percentage, AddressUtil, DecimalUtil } from '@orca-so/common-sdk';
11
- import { createConnection } from '../../utils/connection.js';
12
11
  import { ORCA_WHIRLPOOL_CONFIG } from './types.js';
13
12
  /**
14
13
  * 从 Keypair 创建 Wallet 适配器(兼容浏览器环境)
@@ -43,7 +42,10 @@ function createWalletFromKeypair(keypair) {
43
42
  * 创建 Orca Whirlpool Context
44
43
  */
45
44
  export async function createOrcaContext(connection, wallet) {
46
- const conn = connection || createConnection();
45
+ if (!connection) {
46
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
47
+ }
48
+ const conn = connection;
47
49
  // 创建 Wallet 适配器(不依赖 @coral-xyz/anchor 的 Wallet 类)
48
50
  const anchorWallet = wallet
49
51
  ? createWalletFromKeypair(wallet)
@@ -106,7 +108,10 @@ export async function getOrcaPoolInfo(poolAddress, connection) {
106
108
  * 查找 Orca Whirlpool 池
107
109
  */
108
110
  export async function findOrcaPool(tokenMintA, tokenMintB, tickSpacing = 64, connection) {
109
- const conn = connection || createConnection();
111
+ if (!connection) {
112
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
113
+ }
114
+ const conn = connection;
110
115
  // 确保代币顺序正确 (按地址排序)
111
116
  const [mintAAddr, mintBAddr] = PoolUtil.orderMints(new PublicKey(tokenMintA), new PublicKey(tokenMintB));
112
117
  // 转换为 PublicKey
@@ -123,7 +128,10 @@ export async function findOrcaPool(tokenMintA, tokenMintB, tickSpacing = 64, con
123
128
  * 使用 Whirlpool 的高级 swap 接口
124
129
  */
125
130
  export async function signOrcaSwap(params, payer, connection) {
126
- const conn = connection || createConnection();
131
+ if (!connection) {
132
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
133
+ }
134
+ const conn = connection;
127
135
  const client = await createOrcaClient(conn, payer);
128
136
  const pool = await client.getPool(params.poolAddress);
129
137
  const ctx = await createOrcaContext(conn, payer);
@@ -175,7 +183,10 @@ export async function signOrcaSwap(params, payer, connection) {
175
183
  * 签名 Orca 添加流动性交易
176
184
  */
177
185
  export async function signOrcaAddLiquidity(params, payer, connection) {
178
- const conn = connection || createConnection();
186
+ if (!connection) {
187
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
188
+ }
189
+ const conn = connection;
179
190
  const client = await createOrcaClient(conn, payer);
180
191
  const pool = await client.getPool(params.poolAddress);
181
192
  const ctx = await createOrcaContext(conn, payer);
@@ -263,7 +274,10 @@ export async function signOrcaAddLiquidity(params, payer, connection) {
263
274
  * 签名 Orca 移除流动性交易
264
275
  */
265
276
  export async function signOrcaRemoveLiquidity(params, payer, connection) {
266
- const conn = connection || createConnection();
277
+ if (!connection) {
278
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
279
+ }
280
+ const conn = connection;
267
281
  const client = await createOrcaClient(conn, payer);
268
282
  const ctx = await createOrcaContext(conn, payer);
269
283
  const position = await client.getPosition(params.positionAddress);
@@ -349,7 +363,10 @@ export async function signOrcaRemoveLiquidity(params, payer, connection) {
349
363
  * 签名创建 Orca Whirlpool 池交易
350
364
  */
351
365
  export async function signOrcaCreatePool(params, payer, connection) {
352
- const conn = connection || createConnection();
366
+ if (!connection) {
367
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
368
+ }
369
+ const conn = connection;
353
370
  const client = await createOrcaClient(conn, payer);
354
371
  const initialPrice = DecimalUtil.fromNumber(params.initialPrice);
355
372
  // 创建 Splash Pool (简化的全范围流动性池)
@@ -380,7 +397,10 @@ export async function signOrcaCreatePool(params, payer, connection) {
380
397
  * 签名收集费用交易
381
398
  */
382
399
  export async function signOrcaCollectFees(positionAddress, payer, connection) {
383
- const conn = connection || createConnection();
400
+ if (!connection) {
401
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
402
+ }
403
+ const conn = connection;
384
404
  const client = await createOrcaClient(conn, payer);
385
405
  const position = await client.getPosition(positionAddress);
386
406
  const positionData = position.getData();
@@ -3,7 +3,7 @@
3
3
  * 支持批量买卖的原子性交易
4
4
  */
5
5
  import { PublicKey, Keypair, Transaction, ComputeBudgetProgram, } from '@solana/web3.js';
6
- import { createConnection } from '../../utils/connection.js';
6
+ // 不再导入 createConnection,强制使用者传入连接
7
7
  import { buildTipInstruction, getRandomTipAccount } from '../../jito/tip.js';
8
8
  import { buildWavebreakBuyInstruction, buildWavebreakSellInstruction, buildWavebreakCreateLaunchInstruction, getWavebreakBondingCurveInfo, } from './wavebreak.js';
9
9
  import { WAVEBREAK_CONSTANTS } from './wavebreak-types.js';
@@ -15,7 +15,10 @@ const DEFAULT_JITO_TIP_LAMPORTS = 1000000;
15
15
  * 签名 Wavebreak Bundle 批量买入交易
16
16
  */
17
17
  export async function signWavebreakBundleBuy(params, connection) {
18
- const conn = connection || createConnection();
18
+ if (!connection) {
19
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
20
+ }
21
+ const conn = connection;
19
22
  const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
20
23
  // 获取 Bonding Curve 信息
21
24
  const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
@@ -66,7 +69,10 @@ export async function signWavebreakBundleBuy(params, connection) {
66
69
  * 签名 Wavebreak Bundle 批量卖出交易
67
70
  */
68
71
  export async function signWavebreakBundleSell(params, connection) {
69
- const conn = connection || createConnection();
72
+ if (!connection) {
73
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
74
+ }
75
+ const conn = connection;
70
76
  const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
71
77
  const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
72
78
  if (!info) {
@@ -112,7 +118,10 @@ export async function signWavebreakBundleSell(params, connection) {
112
118
  * 第一笔交易创建代币,后续交易批量买入
113
119
  */
114
120
  export async function signWavebreakBundleCreateAndBuy(params, connection) {
115
- const conn = connection || createConnection();
121
+ if (!connection) {
122
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
123
+ }
124
+ const conn = connection;
116
125
  const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
117
126
  const signedTransactions = [];
118
127
  const jitoTipLamports = params.jitoTipLamports || DEFAULT_JITO_TIP_LAMPORTS;
@@ -7,7 +7,6 @@
7
7
  */
8
8
  import { PublicKey, Keypair, Transaction, TransactionInstruction, SystemProgram, ComputeBudgetProgram, } from '@solana/web3.js';
9
9
  import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, } from '@solana/spl-token';
10
- import { createConnection } from '../../utils/connection.js';
11
10
  import { WAVEBREAK_CONSTANTS } from './wavebreak-types.js';
12
11
  // ============================================================================
13
12
  // Wavebreak SDK 导入(动态导入以避免类型冲突)
@@ -62,7 +61,10 @@ export function getWavebreakLpEscrowAddressSync(bondingCurve) {
62
61
  * 获取 Wavebreak Bonding Curve 信息
63
62
  */
64
63
  export async function getWavebreakBondingCurveInfo(bondingCurveOrMint, connection) {
65
- const conn = connection || createConnection();
64
+ if (!connection) {
65
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
66
+ }
67
+ const conn = connection;
66
68
  const sdk = await loadWavebreakSdk();
67
69
  // 判断是 Bonding Curve 地址还是 Mint 地址
68
70
  let bondingCurveAddress;
@@ -199,7 +201,10 @@ export async function getWavebreakSellQuote(bondingCurveOrMint, amountIn, connec
199
201
  * 使用 SDK 的编码器生成正确的指令数据
200
202
  */
201
203
  export async function buildWavebreakBuyInstruction(params, buyer, connection) {
202
- const conn = connection || createConnection();
204
+ if (!connection) {
205
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
206
+ }
207
+ const conn = connection;
203
208
  const sdk = await loadWavebreakSdk();
204
209
  const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
205
210
  if (!info) {
@@ -255,7 +260,10 @@ export async function buildWavebreakBuyInstruction(params, buyer, connection) {
255
260
  * 构建 Wavebreak 卖出交易指令
256
261
  */
257
262
  export async function buildWavebreakSellInstruction(params, seller, connection) {
258
- const conn = connection || createConnection();
263
+ if (!connection) {
264
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
265
+ }
266
+ const conn = connection;
259
267
  const sdk = await loadWavebreakSdk();
260
268
  const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
261
269
  if (!info) {
@@ -366,7 +374,10 @@ export async function buildWavebreakCreateLaunchInstruction(params, creator, bas
366
374
  * 签名 Wavebreak 买入交易
367
375
  */
368
376
  export async function signWavebreakBuy(params, payer, connection) {
369
- const conn = connection || createConnection();
377
+ if (!connection) {
378
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
379
+ }
380
+ const conn = connection;
370
381
  const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
371
382
  if (!info) {
372
383
  throw new Error('Bonding Curve 不存在');
@@ -396,7 +407,10 @@ export async function signWavebreakBuy(params, payer, connection) {
396
407
  * 签名 Wavebreak 卖出交易
397
408
  */
398
409
  export async function signWavebreakSell(params, payer, connection) {
399
- const conn = connection || createConnection();
410
+ if (!connection) {
411
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
412
+ }
413
+ const conn = connection;
400
414
  const info = await getWavebreakBondingCurveInfo(params.bondingCurveOrMint, conn);
401
415
  if (!info) {
402
416
  throw new Error('Bonding Curve 不存在');
@@ -426,7 +440,10 @@ export async function signWavebreakSell(params, payer, connection) {
426
440
  * 签名 Wavebreak 创建代币发射交易
427
441
  */
428
442
  export async function signWavebreakCreateLaunch(params, creator, connection) {
429
- const conn = connection || createConnection();
443
+ if (!connection) {
444
+ throw new Error('Connection is required. Please pass a connection created with user-configured RPC.');
445
+ }
446
+ const conn = connection;
430
447
  const baseMintKeypair = Keypair.generate();
431
448
  const bondingCurve = getWavebreakBondingCurveAddressSync(baseMintKeypair.publicKey);
432
449
  const tx = new Transaction();
@@ -5,10 +5,19 @@
5
5
  import { Connection, Commitment } from '@solana/web3.js';
6
6
  /**
7
7
  * 创建 Solana 连接
8
- * @param rpcUrl RPC URL(可选,默认使用 Helius 主网)
8
+ *
9
+ * 重要:必须传入用户选择的 RPC URL,SDK 不提供默认 RPC
10
+ * 前端应从 RPC 设置中获取用户配置的节点
11
+ *
12
+ * @param rpcUrl RPC URL(必填)
9
13
  * @param commitment Commitment 级别(可选,默认 confirmed)
14
+ *
15
+ * @example
16
+ * const connection = createConnection('https://user-selected-rpc.com')
17
+ *
18
+ * @throws Error 如果没有传入 rpcUrl
10
19
  */
11
- export declare function createConnection(rpcUrl?: string, commitment?: Commitment): Connection;
20
+ export declare function createConnection(rpcUrl: string, commitment?: Commitment): Connection;
12
21
  /**
13
22
  * 获取账户 SOL 余额
14
23
  * @param connection Solana 连接
@@ -3,13 +3,25 @@
3
3
  * @module sol/utils/connection
4
4
  */
5
5
  import { Connection, PublicKey } from '@solana/web3.js';
6
- import { SOLANA_RPC, TX_CONFIG, lamportsToSol } from '../constants.js';
6
+ import { TX_CONFIG, lamportsToSol } from '../constants.js';
7
7
  /**
8
8
  * 创建 Solana 连接
9
- * @param rpcUrl RPC URL(可选,默认使用 Helius 主网)
9
+ *
10
+ * 重要:必须传入用户选择的 RPC URL,SDK 不提供默认 RPC
11
+ * 前端应从 RPC 设置中获取用户配置的节点
12
+ *
13
+ * @param rpcUrl RPC URL(必填)
10
14
  * @param commitment Commitment 级别(可选,默认 confirmed)
15
+ *
16
+ * @example
17
+ * const connection = createConnection('https://user-selected-rpc.com')
18
+ *
19
+ * @throws Error 如果没有传入 rpcUrl
11
20
  */
12
- export function createConnection(rpcUrl = SOLANA_RPC.MAINNET, commitment = TX_CONFIG.DEFAULT_COMMITMENT) {
21
+ export function createConnection(rpcUrl, commitment = TX_CONFIG.DEFAULT_COMMITMENT) {
22
+ if (!rpcUrl) {
23
+ throw new Error('RPC URL is required. Please pass the user-configured RPC URL from frontend settings.');
24
+ }
13
25
  return new Connection(rpcUrl, {
14
26
  commitment,
15
27
  confirmTransactionInitialTimeout: TX_CONFIG.CONFIRMATION_TIMEOUT,
@@ -371,6 +371,9 @@ async function detectRaydiumPools(mint, connection, debug) {
371
371
  */
372
372
  export async function inspectSolanaTokenLP(mint, options = {}) {
373
373
  const startTime = Date.now();
374
+ if (!options.connection && !options.rpcUrl) {
375
+ throw new Error('Either connection or rpcUrl is required in options');
376
+ }
374
377
  const connection = options.connection || createConnection(options.rpcUrl);
375
378
  const debug = options.debug;
376
379
  // 初始化结果
@@ -479,6 +482,9 @@ export async function inspectSolanaTokenLP(mint, options = {}) {
479
482
  * @returns 如果在内盘返回内盘信息,否则返回 null
480
483
  */
481
484
  export async function detectBondingCurve(mint, options = {}) {
485
+ if (!options.connection && !options.rpcUrl) {
486
+ throw new Error('Either connection or rpcUrl is required in options');
487
+ }
482
488
  const connection = options.connection || createConnection(options.rpcUrl);
483
489
  const debug = options.debug;
484
490
  // 并行检测所有内盘
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.3.87",
3
+ "version": "1.3.88",
4
4
  "description": "SDK for Flap bonding curve, four.meme TokenManager, and Solana DEX",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",