four-flap-meme-sdk 1.4.59 → 1.4.62

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 (130) hide show
  1. package/dist/contracts/tm-bundle-merkle/core.js +13 -5
  2. package/dist/contracts/tm-bundle-merkle/internal.d.ts +5 -1
  3. package/dist/contracts/tm-bundle-merkle/internal.js +8 -1
  4. package/dist/contracts/tm-bundle-merkle/pancake-proxy.js +8 -2
  5. package/dist/contracts/tm-bundle-merkle/private.js +16 -4
  6. package/dist/contracts/tm-bundle-merkle/swap-buy-first.d.ts +2 -0
  7. package/dist/contracts/tm-bundle-merkle/swap-buy-first.js +3 -0
  8. package/dist/contracts/tm-bundle-merkle/types.d.ts +5 -2
  9. package/dist/contracts/tm-bundle-merkle/types.js +0 -3
  10. package/dist/contracts/tm-bundle-merkle/utils.js +14 -2
  11. package/dist/contracts/tm-bundle.d.ts +4 -0
  12. package/dist/contracts/tm-bundle.js +10 -3
  13. package/dist/dex/direct-router.d.ts +2 -0
  14. package/dist/dex/direct-router.js +22 -7
  15. package/dist/flap/portal-bundle-merkle/core.js +10 -1
  16. package/dist/flap/portal-bundle-merkle/pancake-proxy.js +8 -2
  17. package/dist/flap/portal-bundle-merkle/private.js +17 -7
  18. package/dist/flap/portal-bundle-merkle/swap-buy-first.d.ts +2 -0
  19. package/dist/flap/portal-bundle-merkle/swap-buy-first.js +8 -4
  20. package/dist/flap/portal-bundle-merkle/types.d.ts +3 -0
  21. package/dist/flap/portal-bundle-merkle/types.js +0 -3
  22. package/dist/flap/portal-bundle-merkle/utils.d.ts +5 -2
  23. package/dist/flap/portal-bundle-merkle/utils.js +22 -3
  24. package/dist/index.d.ts +1 -0
  25. package/dist/index.js +1 -0
  26. package/dist/pancake/bundle-buy-first.d.ts +2 -0
  27. package/dist/pancake/bundle-buy-first.js +8 -4
  28. package/dist/sol/constants.d.ts +126 -0
  29. package/dist/sol/constants.js +145 -0
  30. package/dist/sol/dex/index.d.ts +8 -0
  31. package/dist/sol/dex/index.js +12 -0
  32. package/dist/sol/dex/meteora/client.d.ts +76 -0
  33. package/dist/sol/dex/meteora/client.js +219 -0
  34. package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +61 -0
  35. package/dist/sol/dex/meteora/damm-v1-bundle.js +112 -0
  36. package/dist/sol/dex/meteora/damm-v1.d.ts +118 -0
  37. package/dist/sol/dex/meteora/damm-v1.js +315 -0
  38. package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +82 -0
  39. package/dist/sol/dex/meteora/damm-v2-bundle.js +242 -0
  40. package/dist/sol/dex/meteora/damm-v2.d.ts +172 -0
  41. package/dist/sol/dex/meteora/damm-v2.js +632 -0
  42. package/dist/sol/dex/meteora/dbc-bundle.d.ts +123 -0
  43. package/dist/sol/dex/meteora/dbc-bundle.js +304 -0
  44. package/dist/sol/dex/meteora/dbc.d.ts +192 -0
  45. package/dist/sol/dex/meteora/dbc.js +619 -0
  46. package/dist/sol/dex/meteora/dlmm-bundle.d.ts +39 -0
  47. package/dist/sol/dex/meteora/dlmm-bundle.js +189 -0
  48. package/dist/sol/dex/meteora/dlmm.d.ts +157 -0
  49. package/dist/sol/dex/meteora/dlmm.js +671 -0
  50. package/dist/sol/dex/meteora/index.d.ts +25 -0
  51. package/dist/sol/dex/meteora/index.js +65 -0
  52. package/dist/sol/dex/meteora/types.d.ts +787 -0
  53. package/dist/sol/dex/meteora/types.js +110 -0
  54. package/dist/sol/dex/orca/index.d.ts +10 -0
  55. package/dist/sol/dex/orca/index.js +16 -0
  56. package/dist/sol/dex/orca/orca-bundle.d.ts +41 -0
  57. package/dist/sol/dex/orca/orca-bundle.js +173 -0
  58. package/dist/sol/dex/orca/orca.d.ts +65 -0
  59. package/dist/sol/dex/orca/orca.js +474 -0
  60. package/dist/sol/dex/orca/types.d.ts +263 -0
  61. package/dist/sol/dex/orca/types.js +38 -0
  62. package/dist/sol/dex/orca/wavebreak-bundle.d.ts +34 -0
  63. package/dist/sol/dex/orca/wavebreak-bundle.js +198 -0
  64. package/dist/sol/dex/orca/wavebreak-types.d.ts +227 -0
  65. package/dist/sol/dex/orca/wavebreak-types.js +23 -0
  66. package/dist/sol/dex/orca/wavebreak.d.ts +78 -0
  67. package/dist/sol/dex/orca/wavebreak.js +497 -0
  68. package/dist/sol/dex/pump/index.d.ts +9 -0
  69. package/dist/sol/dex/pump/index.js +14 -0
  70. package/dist/sol/dex/pump/pump-bundle.d.ts +92 -0
  71. package/dist/sol/dex/pump/pump-bundle.js +383 -0
  72. package/dist/sol/dex/pump/pump-swap-bundle.d.ts +103 -0
  73. package/dist/sol/dex/pump/pump-swap-bundle.js +380 -0
  74. package/dist/sol/dex/pump/pump-swap.d.ts +46 -0
  75. package/dist/sol/dex/pump/pump-swap.js +199 -0
  76. package/dist/sol/dex/pump/pump.d.ts +35 -0
  77. package/dist/sol/dex/pump/pump.js +352 -0
  78. package/dist/sol/dex/pump/types.d.ts +215 -0
  79. package/dist/sol/dex/pump/types.js +5 -0
  80. package/dist/sol/dex/raydium/index.d.ts +8 -0
  81. package/dist/sol/dex/raydium/index.js +12 -0
  82. package/dist/sol/dex/raydium/launchlab.d.ts +68 -0
  83. package/dist/sol/dex/raydium/launchlab.js +210 -0
  84. package/dist/sol/dex/raydium/raydium-bundle.d.ts +64 -0
  85. package/dist/sol/dex/raydium/raydium-bundle.js +324 -0
  86. package/dist/sol/dex/raydium/raydium.d.ts +40 -0
  87. package/dist/sol/dex/raydium/raydium.js +366 -0
  88. package/dist/sol/dex/raydium/types.d.ts +240 -0
  89. package/dist/sol/dex/raydium/types.js +5 -0
  90. package/dist/sol/index.d.ts +10 -0
  91. package/dist/sol/index.js +16 -0
  92. package/dist/sol/jito/bundle.d.ts +90 -0
  93. package/dist/sol/jito/bundle.js +263 -0
  94. package/dist/sol/jito/index.d.ts +7 -0
  95. package/dist/sol/jito/index.js +7 -0
  96. package/dist/sol/jito/tip.d.ts +51 -0
  97. package/dist/sol/jito/tip.js +83 -0
  98. package/dist/sol/jito/types.d.ts +100 -0
  99. package/dist/sol/jito/types.js +5 -0
  100. package/dist/sol/token/create-complete.d.ts +115 -0
  101. package/dist/sol/token/create-complete.js +235 -0
  102. package/dist/sol/token/create-token.d.ts +57 -0
  103. package/dist/sol/token/create-token.js +230 -0
  104. package/dist/sol/token/index.d.ts +9 -0
  105. package/dist/sol/token/index.js +14 -0
  106. package/dist/sol/token/metadata-upload.d.ts +86 -0
  107. package/dist/sol/token/metadata-upload.js +173 -0
  108. package/dist/sol/token/metadata.d.ts +92 -0
  109. package/dist/sol/token/metadata.js +274 -0
  110. package/dist/sol/token/types.d.ts +153 -0
  111. package/dist/sol/token/types.js +5 -0
  112. package/dist/sol/types.d.ts +176 -0
  113. package/dist/sol/types.js +7 -0
  114. package/dist/sol/utils/balance.d.ts +160 -0
  115. package/dist/sol/utils/balance.js +638 -0
  116. package/dist/sol/utils/connection.d.ts +78 -0
  117. package/dist/sol/utils/connection.js +168 -0
  118. package/dist/sol/utils/index.d.ts +9 -0
  119. package/dist/sol/utils/index.js +9 -0
  120. package/dist/sol/utils/lp-inspect.d.ts +129 -0
  121. package/dist/sol/utils/lp-inspect.js +900 -0
  122. package/dist/sol/utils/transfer.d.ts +125 -0
  123. package/dist/sol/utils/transfer.js +220 -0
  124. package/dist/sol/utils/wallet.d.ts +107 -0
  125. package/dist/sol/utils/wallet.js +210 -0
  126. package/dist/utils/private-sale.d.ts +3 -0
  127. package/dist/utils/private-sale.js +3 -0
  128. package/package.json +38 -3
  129. package/dist/flap/portal-bundle-merkle/encryption.d.ts +0 -16
  130. package/dist/flap/portal-bundle-merkle/encryption.js +0 -146
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Solana SDK 常量配置
3
+ * @module sol/constants
4
+ */
5
+ // ==================== Jito Bundle 配置 ====================
6
+ /**
7
+ * Jito 配置
8
+ *
9
+ * 注意:BLOCK_ENGINE_URL 需要由前端传入,不在 SDK 中写死
10
+ */
11
+ export const JITO_CONFIG = {
12
+ /** Tip 账户列表(随机选择一个)- 这些是 Jito 官方账户,固定不变 */
13
+ TIP_ACCOUNTS: [
14
+ '96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5',
15
+ 'HFqU5x63VTqvQss8hp11i4bVmkzdNaVB6PYjYgNd4W5U',
16
+ 'Cw8CFyM9FkoMi7K7Crf6HNQqf4uEMzpKw6QNghXLvLkY',
17
+ 'ADaUMid9yfUytqMBgopwjb2DTLSokTSzL1zt6iGPaS49',
18
+ 'DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh',
19
+ 'ADuUkR4vqLUMWXxW9gh6D6L8pMSawimctcNZ5pGwDcEt',
20
+ 'DttWaMuVvTiduZRnguLF7jNxTgiMBZ1hyAumKUiL2KRL',
21
+ '3AVi9Tg9Uo68tJfuvoKvqKNWKkC5wPdSSdeBnizKZ6jT',
22
+ ],
23
+ /** 最小 Tip(lamports) */
24
+ MIN_TIP_LAMPORTS: 1000,
25
+ /** 默认 Tip(lamports)- 0.00001 SOL */
26
+ DEFAULT_TIP_LAMPORTS: 10000,
27
+ };
28
+ // ==================== 程序地址 ====================
29
+ /**
30
+ * Solana 系统程序地址
31
+ */
32
+ export const SYSTEM_PROGRAMS = {
33
+ /** Token Program */
34
+ TOKEN_PROGRAM: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
35
+ /** Token-2022 Program */
36
+ TOKEN_2022_PROGRAM: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
37
+ /** Associated Token Account Program */
38
+ ATA_PROGRAM: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
39
+ /** Metaplex Token Metadata Program */
40
+ METADATA_PROGRAM: 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s',
41
+ /** System Program */
42
+ SYSTEM_PROGRAM: '11111111111111111111111111111111',
43
+ /** Rent Sysvar */
44
+ RENT_SYSVAR: 'SysvarRent111111111111111111111111111111111',
45
+ };
46
+ /**
47
+ * Pump.fun 程序地址
48
+ */
49
+ export const PUMP_PROGRAMS = {
50
+ /** Pump Program ID */
51
+ PUMP_PROGRAM: '6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P',
52
+ /** Pump Swap Program ID */
53
+ PUMP_SWAP_PROGRAM: 'pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA',
54
+ /** Global Config */
55
+ GLOBAL_CONFIG: '4wTV1YmiEkRvAtNtsSGPtUrqRYQMe5SKy2uB4Jjaxnjf',
56
+ };
57
+ /**
58
+ * Raydium 程序地址
59
+ */
60
+ export const RAYDIUM_PROGRAMS = {
61
+ /** AMM Program ID */
62
+ AMM_PROGRAM: '675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8',
63
+ /** CLMM Program ID */
64
+ CLMM_PROGRAM: 'CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK',
65
+ /** LaunchLab Program ID */
66
+ LAUNCHLAB_PROGRAM: 'LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj',
67
+ };
68
+ /**
69
+ * Orca 程序地址
70
+ */
71
+ export const ORCA_PROGRAMS = {
72
+ /** Whirlpool Program ID */
73
+ WHIRLPOOL_PROGRAM: 'whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc',
74
+ };
75
+ /**
76
+ * Meteora 程序地址
77
+ */
78
+ export const METEORA_PROGRAMS = {
79
+ /** DLMM Program ID */
80
+ DLMM_PROGRAM: 'LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo',
81
+ /** DAMM v2 Program ID */
82
+ DAMM_V2_PROGRAM: 'cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG',
83
+ /** DBC Program ID */
84
+ DBC_PROGRAM: 'dbcij3LWUppWqq96dh6gJWwBifmcGfLSB5D4DuSMaqN',
85
+ };
86
+ // ==================== 常用代币地址 ====================
87
+ /**
88
+ * 常用代币地址
89
+ */
90
+ export const TOKENS = {
91
+ /** Wrapped SOL */
92
+ SOL: 'So11111111111111111111111111111111111111112',
93
+ /** USDC */
94
+ USDC: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
95
+ /** USDT */
96
+ USDT: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',
97
+ };
98
+ // ==================== 交易配置 ====================
99
+ /**
100
+ * 交易默认配置
101
+ */
102
+ export const TX_CONFIG = {
103
+ /** 默认滑点 1% */
104
+ DEFAULT_SLIPPAGE: 1,
105
+ /** 最大滑点 50% */
106
+ MAX_SLIPPAGE: 50,
107
+ /** 计算单元限制 */
108
+ COMPUTE_UNIT_LIMIT: 200000,
109
+ /** 计算单元价格(microlamports) */
110
+ COMPUTE_UNIT_PRICE: 50000,
111
+ /** 确认超时(毫秒) */
112
+ CONFIRMATION_TIMEOUT: 60000,
113
+ /** 默认 commitment */
114
+ DEFAULT_COMMITMENT: 'confirmed',
115
+ };
116
+ // ==================== 账户大小 ====================
117
+ /**
118
+ * 账户大小(用于计算租金)
119
+ */
120
+ export const ACCOUNT_SIZE = {
121
+ /** Mint 账户大小 */
122
+ MINT: 82,
123
+ /** Token 账户大小 */
124
+ TOKEN_ACCOUNT: 165,
125
+ /** Metadata 账户大小(近似值) */
126
+ METADATA: 679,
127
+ };
128
+ // ==================== 单位换算 ====================
129
+ /**
130
+ * SOL 单位换算
131
+ */
132
+ export const SOL_DECIMALS = 9;
133
+ export const LAMPORTS_PER_SOL = 1000000000;
134
+ /**
135
+ * 将 SOL 转换为 lamports
136
+ */
137
+ export function solToLamports(sol) {
138
+ return BigInt(Math.floor(sol * LAMPORTS_PER_SOL));
139
+ }
140
+ /**
141
+ * 将 lamports 转换为 SOL
142
+ */
143
+ export function lamportsToSol(lamports) {
144
+ return Number(lamports) / LAMPORTS_PER_SOL;
145
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * DEX 模块导出
3
+ * @module sol/dex
4
+ */
5
+ export * from './pump/index.js';
6
+ export * from './raydium/index.js';
7
+ export * from './orca/index.js';
8
+ export * from './meteora/index.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * DEX 模块导出
3
+ * @module sol/dex
4
+ */
5
+ // Pump.fun
6
+ export * from './pump/index.js';
7
+ // Raydium
8
+ export * from './raydium/index.js';
9
+ // Orca
10
+ export * from './orca/index.js';
11
+ // Meteora
12
+ export * from './meteora/index.js';
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Meteora SDK 客户端管理器
3
+ *
4
+ * 统一管理 RPC 连接和 SDK 实例,避免重复实例化
5
+ */
6
+ import { Connection } from '@solana/web3.js';
7
+ import { CpAmm } from '@meteora-ag/cp-amm-sdk';
8
+ import { DynamicBondingCurveClient } from '@meteora-ag/dynamic-bonding-curve-sdk';
9
+ /**
10
+ * 获取连接
11
+ * @param connection 可选的自定义连接
12
+ * @throws Error 如果没有传入连接且未设置默认连接
13
+ */
14
+ export declare function getConnection(connection?: Connection): Connection;
15
+ /**
16
+ * 设置默认连接
17
+ * @param connection 新的连接实例
18
+ */
19
+ export declare function setDefaultConnection(connection: Connection): void;
20
+ /**
21
+ * 重置默认连接
22
+ */
23
+ export declare function resetDefaultConnection(): void;
24
+ /**
25
+ * 获取或创建 DLMM 池实例
26
+ * @param poolAddress 池地址
27
+ * @param connection 可选连接
28
+ * @param forceRefresh 强制刷新缓存
29
+ */
30
+ export declare function getDlmmPool(poolAddress: string, connection?: Connection, forceRefresh?: boolean): Promise<any>;
31
+ /**
32
+ * 获取所有 DLMM 池列表
33
+ * @param connection 可选连接
34
+ */
35
+ export declare function getAllDlmmPools(connection?: Connection): Promise<any[]>;
36
+ /**
37
+ * 清除 DLMM 池缓存
38
+ * @param poolAddress 可选,指定池地址;不传则清除全部
39
+ */
40
+ export declare function clearDlmmCache(poolAddress?: string): void;
41
+ /**
42
+ * 获取或创建 DBC 客户端
43
+ * @param connection 可选连接
44
+ */
45
+ export declare function getDbcClient(connection?: Connection): DynamicBondingCurveClient;
46
+ /**
47
+ * 重置 DBC 客户端
48
+ */
49
+ export declare function resetDbcClient(): void;
50
+ /**
51
+ * 获取或创建 DAMM v1 池实例
52
+ * @param poolAddress 池地址
53
+ * @param connection 可选连接
54
+ * @param forceRefresh 强制刷新缓存
55
+ */
56
+ export declare function getDammV1Pool(poolAddress: string, connection?: Connection, forceRefresh?: boolean): Promise<any>;
57
+ /**
58
+ * 清除 DAMM v1 池缓存
59
+ * @param poolAddress 可选,指定池地址;不传则清除全部
60
+ */
61
+ export declare function clearDammV1Cache(poolAddress?: string): void;
62
+ /**
63
+ * 获取或创建 DAMM v2 (CpAmm) 客户端
64
+ * @param connection 可选连接
65
+ */
66
+ export declare function getCpAmmClient(connection?: Connection): CpAmm;
67
+ /**
68
+ * 重置 DAMM v2 客户端
69
+ */
70
+ export declare function resetCpAmmClient(): void;
71
+ /**
72
+ * 清除所有 Meteora 缓存
73
+ */
74
+ export declare function clearAllMeteoraCache(): void;
75
+ export declare function setCacheTtl(ttlMs: number): void;
76
+ export declare function getCacheTtl(): number;
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Meteora SDK 客户端管理器
3
+ *
4
+ * 统一管理 RPC 连接和 SDK 实例,避免重复实例化
5
+ */
6
+ import { PublicKey } from '@solana/web3.js';
7
+ // 不再导入 createConnection,强制使用者传入连接
8
+ // SDK 导入 - 使用类型断言绕过 TypeScript 类型检查
9
+ import DLMMModule from '@meteora-ag/dlmm';
10
+ import AmmImplModule from '@meteora-ag/dynamic-amm-sdk';
11
+ import { CpAmm } from '@meteora-ag/cp-amm-sdk';
12
+ import { DynamicBondingCurveClient } from '@meteora-ag/dynamic-bonding-curve-sdk';
13
+ const DLMM = DLMMModule;
14
+ const AmmImpl = AmmImplModule;
15
+ // ============================================================================
16
+ // 连接管理
17
+ // ============================================================================
18
+ /** 默认连接实例(必须通过 setDefaultConnection 设置) */
19
+ let defaultConnection = null;
20
+ /**
21
+ * 获取连接
22
+ * @param connection 可选的自定义连接
23
+ * @throws Error 如果没有传入连接且未设置默认连接
24
+ */
25
+ export function getConnection(connection) {
26
+ if (connection) {
27
+ return connection;
28
+ }
29
+ if (!defaultConnection) {
30
+ throw new Error('Connection is required. Either pass a connection parameter or call setDefaultConnection() first with user-configured RPC.');
31
+ }
32
+ return defaultConnection;
33
+ }
34
+ /**
35
+ * 设置默认连接
36
+ * @param connection 新的连接实例
37
+ */
38
+ export function setDefaultConnection(connection) {
39
+ defaultConnection = connection;
40
+ }
41
+ /**
42
+ * 重置默认连接
43
+ */
44
+ export function resetDefaultConnection() {
45
+ defaultConnection = null;
46
+ }
47
+ // ============================================================================
48
+ // DLMM 实例缓存
49
+ // ============================================================================
50
+ /** DLMM 池实例缓存 */
51
+ const dlmmPoolCache = new Map();
52
+ /** 缓存过期时间 (毫秒) - 默认 30 秒 */
53
+ const CACHE_TTL = 30 * 1000;
54
+ /**
55
+ * 获取或创建 DLMM 池实例
56
+ * @param poolAddress 池地址
57
+ * @param connection 可选连接
58
+ * @param forceRefresh 强制刷新缓存
59
+ */
60
+ export async function getDlmmPool(poolAddress, connection, forceRefresh = false) {
61
+ const conn = getConnection(connection);
62
+ const cacheKey = poolAddress;
63
+ // 检查缓存
64
+ if (!forceRefresh) {
65
+ const cached = dlmmPoolCache.get(cacheKey);
66
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
67
+ return cached.instance;
68
+ }
69
+ }
70
+ // 创建新实例
71
+ const instance = await DLMM.create(conn, new PublicKey(poolAddress));
72
+ // 存入缓存
73
+ dlmmPoolCache.set(cacheKey, {
74
+ instance,
75
+ timestamp: Date.now(),
76
+ });
77
+ return instance;
78
+ }
79
+ /**
80
+ * 获取所有 DLMM 池列表
81
+ * @param connection 可选连接
82
+ */
83
+ export async function getAllDlmmPools(connection) {
84
+ const conn = getConnection(connection);
85
+ return DLMM.getLbPairs(conn);
86
+ }
87
+ /**
88
+ * 清除 DLMM 池缓存
89
+ * @param poolAddress 可选,指定池地址;不传则清除全部
90
+ */
91
+ export function clearDlmmCache(poolAddress) {
92
+ if (poolAddress) {
93
+ dlmmPoolCache.delete(poolAddress);
94
+ }
95
+ else {
96
+ dlmmPoolCache.clear();
97
+ }
98
+ }
99
+ // ============================================================================
100
+ // DBC 客户端管理
101
+ // ============================================================================
102
+ /** DBC 客户端实例缓存 */
103
+ let dbcClient = null;
104
+ let dbcClientConnection = null;
105
+ /**
106
+ * 获取或创建 DBC 客户端
107
+ * @param connection 可选连接
108
+ */
109
+ export function getDbcClient(connection) {
110
+ const conn = getConnection(connection);
111
+ // 如果连接相同,复用现有客户端
112
+ if (dbcClient && dbcClientConnection === conn) {
113
+ return dbcClient;
114
+ }
115
+ // 创建新客户端
116
+ dbcClient = DynamicBondingCurveClient.create(conn, 'confirmed');
117
+ dbcClientConnection = conn;
118
+ return dbcClient;
119
+ }
120
+ /**
121
+ * 重置 DBC 客户端
122
+ */
123
+ export function resetDbcClient() {
124
+ dbcClient = null;
125
+ dbcClientConnection = null;
126
+ }
127
+ // ============================================================================
128
+ // DAMM v1 实例缓存
129
+ // ============================================================================
130
+ /** DAMM v1 池实例缓存 */
131
+ const dammV1PoolCache = new Map();
132
+ /**
133
+ * 获取或创建 DAMM v1 池实例
134
+ * @param poolAddress 池地址
135
+ * @param connection 可选连接
136
+ * @param forceRefresh 强制刷新缓存
137
+ */
138
+ export async function getDammV1Pool(poolAddress, connection, forceRefresh = false) {
139
+ const conn = getConnection(connection);
140
+ const cacheKey = poolAddress;
141
+ // 检查缓存
142
+ if (!forceRefresh) {
143
+ const cached = dammV1PoolCache.get(cacheKey);
144
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL) {
145
+ return cached.instance;
146
+ }
147
+ }
148
+ // 创建新实例
149
+ const instance = await AmmImpl.create(conn, new PublicKey(poolAddress));
150
+ // 存入缓存
151
+ dammV1PoolCache.set(cacheKey, {
152
+ instance,
153
+ timestamp: Date.now(),
154
+ });
155
+ return instance;
156
+ }
157
+ /**
158
+ * 清除 DAMM v1 池缓存
159
+ * @param poolAddress 可选,指定池地址;不传则清除全部
160
+ */
161
+ export function clearDammV1Cache(poolAddress) {
162
+ if (poolAddress) {
163
+ dammV1PoolCache.delete(poolAddress);
164
+ }
165
+ else {
166
+ dammV1PoolCache.clear();
167
+ }
168
+ }
169
+ // ============================================================================
170
+ // DAMM v2 客户端管理
171
+ // ============================================================================
172
+ /** DAMM v2 客户端实例缓存 */
173
+ let cpAmmClient = null;
174
+ let cpAmmClientConnection = null;
175
+ /**
176
+ * 获取或创建 DAMM v2 (CpAmm) 客户端
177
+ * @param connection 可选连接
178
+ */
179
+ export function getCpAmmClient(connection) {
180
+ const conn = getConnection(connection);
181
+ // 如果连接相同,复用现有客户端
182
+ if (cpAmmClient && cpAmmClientConnection === conn) {
183
+ return cpAmmClient;
184
+ }
185
+ // 创建新客户端
186
+ cpAmmClient = new CpAmm(conn);
187
+ cpAmmClientConnection = conn;
188
+ return cpAmmClient;
189
+ }
190
+ /**
191
+ * 重置 DAMM v2 客户端
192
+ */
193
+ export function resetCpAmmClient() {
194
+ cpAmmClient = null;
195
+ cpAmmClientConnection = null;
196
+ }
197
+ // ============================================================================
198
+ // 全局缓存管理
199
+ // ============================================================================
200
+ /**
201
+ * 清除所有 Meteora 缓存
202
+ */
203
+ export function clearAllMeteoraCache() {
204
+ clearDlmmCache();
205
+ clearDammV1Cache();
206
+ resetDbcClient();
207
+ resetCpAmmClient();
208
+ }
209
+ /**
210
+ * 设置缓存 TTL (毫秒)
211
+ * 注意: 这会影响新创建的缓存项,不会影响已存在的
212
+ */
213
+ let cacheTtl = CACHE_TTL;
214
+ export function setCacheTtl(ttlMs) {
215
+ cacheTtl = ttlMs;
216
+ }
217
+ export function getCacheTtl() {
218
+ return cacheTtl;
219
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Meteora DAMM v1 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 v1 Bundle Swap 参数
11
+ */
12
+ export interface DammV1BundleSwapParams {
13
+ /** 池地址 */
14
+ poolAddress: string;
15
+ /** 输入代币地址 */
16
+ inputMint: string;
17
+ /** 输出代币地址 */
18
+ outputMint: string;
19
+ /** 交易列表 */
20
+ trades: {
21
+ wallet: Keypair;
22
+ amountIn: BN;
23
+ minAmountOut?: BN;
24
+ }[];
25
+ /** 滑点 (bps) */
26
+ slippageBps?: number;
27
+ /** Jito 小费 */
28
+ jitoTipLamports?: number;
29
+ }
30
+ /**
31
+ * 签名 DAMM v1 Bundle 批量买入交易
32
+ *
33
+ * @param params Bundle 参数
34
+ * @param connection 可选连接
35
+ */
36
+ export declare function signDammV1BundleBuy(params: DammV1BundleSwapParams, connection?: Connection): Promise<MeteoraBundleSignedResult>;
37
+ /**
38
+ * 签名 DAMM v1 Bundle 批量卖出交易
39
+ *
40
+ * @param params Bundle 参数
41
+ * @param connection 可选连接
42
+ */
43
+ export declare function signDammV1BundleSell(params: DammV1BundleSwapParams, connection?: Connection): Promise<MeteoraBundleSignedResult>;
44
+ /**
45
+ * 签名 DAMM v1 Bundle 通用 Swap 交易
46
+ *
47
+ * @param params Bundle 参数
48
+ * @param isBuy 是否买入 (true = 买入, false = 卖出)
49
+ * @param connection 可选连接
50
+ */
51
+ export declare function signDammV1BundleSwap(params: DammV1BundleSwapParams, isBuy: boolean, connection?: Connection): Promise<MeteoraBundleSignedResult>;
52
+ /**
53
+ * 将 Bundle 结果转换为后端 API 请求格式
54
+ */
55
+ export declare function toDammV1BundleApiRequest(result: MeteoraBundleSignedResult): {
56
+ transactions: string[];
57
+ type: string;
58
+ poolAddress: string;
59
+ tradeCount: number;
60
+ jitoTipLamports: number;
61
+ };
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Meteora DAMM v1 Bundle 批量交易
3
+ *
4
+ * 支持 Jito Bundle 的批量买卖
5
+ */
6
+ import { PublicKey, } from '@solana/web3.js';
7
+ import { getConnection, getDammV1Pool } from './client.js';
8
+ import { buildTipInstruction } from '../../jito/tip.js';
9
+ // ============================================================================
10
+ // Bundle 批量买入
11
+ // ============================================================================
12
+ /**
13
+ * 签名 DAMM v1 Bundle 批量买入交易
14
+ *
15
+ * @param params Bundle 参数
16
+ * @param connection 可选连接
17
+ */
18
+ export async function signDammV1BundleBuy(params, connection) {
19
+ const conn = getConnection(connection);
20
+ const pool = await getDammV1Pool(params.poolAddress, connection);
21
+ const signedTransactions = [];
22
+ for (let i = 0; i < params.trades.length; i++) {
23
+ const trade = params.trades[i];
24
+ const swapQuote = pool.getSwapQuote(new PublicKey(params.inputMint), trade.amountIn, params.slippageBps || 100);
25
+ const minAmountOut = trade.minAmountOut || swapQuote.minSwapOutAmount;
26
+ const swapTx = await pool.swap(trade.wallet.publicKey, new PublicKey(params.inputMint), trade.amountIn, minAmountOut);
27
+ if (i === params.trades.length - 1 && params.jitoTipLamports) {
28
+ const tipIx = buildTipInstruction(trade.wallet.publicKey, BigInt(params.jitoTipLamports));
29
+ swapTx.add(tipIx);
30
+ }
31
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
32
+ swapTx.recentBlockhash = blockhash;
33
+ swapTx.lastValidBlockHeight = lastValidBlockHeight;
34
+ swapTx.feePayer = trade.wallet.publicKey;
35
+ swapTx.sign(trade.wallet);
36
+ signedTransactions.push(swapTx);
37
+ }
38
+ return {
39
+ signedTransactions,
40
+ type: 'damm_v1_bundle_buy',
41
+ poolAddress: params.poolAddress,
42
+ tradeCount: params.trades.length,
43
+ jitoTipLamports: params.jitoTipLamports || 0,
44
+ };
45
+ }
46
+ // ============================================================================
47
+ // Bundle 批量卖出
48
+ // ============================================================================
49
+ /**
50
+ * 签名 DAMM v1 Bundle 批量卖出交易
51
+ *
52
+ * @param params Bundle 参数
53
+ * @param connection 可选连接
54
+ */
55
+ export async function signDammV1BundleSell(params, connection) {
56
+ const conn = getConnection(connection);
57
+ const pool = await getDammV1Pool(params.poolAddress, connection);
58
+ const signedTransactions = [];
59
+ for (let i = 0; i < params.trades.length; i++) {
60
+ const trade = params.trades[i];
61
+ const swapQuote = pool.getSwapQuote(new PublicKey(params.inputMint), trade.amountIn, params.slippageBps || 100);
62
+ const minAmountOut = trade.minAmountOut || swapQuote.minSwapOutAmount;
63
+ const swapTx = await pool.swap(trade.wallet.publicKey, new PublicKey(params.inputMint), trade.amountIn, minAmountOut);
64
+ if (i === params.trades.length - 1 && params.jitoTipLamports) {
65
+ const tipIx = buildTipInstruction(trade.wallet.publicKey, BigInt(params.jitoTipLamports));
66
+ swapTx.add(tipIx);
67
+ }
68
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash();
69
+ swapTx.recentBlockhash = blockhash;
70
+ swapTx.lastValidBlockHeight = lastValidBlockHeight;
71
+ swapTx.feePayer = trade.wallet.publicKey;
72
+ swapTx.sign(trade.wallet);
73
+ signedTransactions.push(swapTx);
74
+ }
75
+ return {
76
+ signedTransactions,
77
+ type: 'damm_v1_bundle_sell',
78
+ poolAddress: params.poolAddress,
79
+ tradeCount: params.trades.length,
80
+ jitoTipLamports: params.jitoTipLamports || 0,
81
+ };
82
+ }
83
+ // ============================================================================
84
+ // Bundle 通用 Swap
85
+ // ============================================================================
86
+ /**
87
+ * 签名 DAMM v1 Bundle 通用 Swap 交易
88
+ *
89
+ * @param params Bundle 参数
90
+ * @param isBuy 是否买入 (true = 买入, false = 卖出)
91
+ * @param connection 可选连接
92
+ */
93
+ export async function signDammV1BundleSwap(params, isBuy, connection) {
94
+ if (isBuy) {
95
+ return signDammV1BundleBuy(params, connection);
96
+ }
97
+ else {
98
+ return signDammV1BundleSell(params, connection);
99
+ }
100
+ }
101
+ /**
102
+ * 将 Bundle 结果转换为后端 API 请求格式
103
+ */
104
+ export function toDammV1BundleApiRequest(result) {
105
+ return {
106
+ transactions: result.signedTransactions.map((tx) => tx.serialize().toString('base64')),
107
+ type: result.type,
108
+ poolAddress: result.poolAddress,
109
+ tradeCount: result.tradeCount,
110
+ jitoTipLamports: result.jitoTipLamports,
111
+ };
112
+ }