four-flap-meme-sdk 2.0.0 → 2.1.0

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 (205) hide show
  1. package/dist/__tests__/subpath-exports.test.js +34 -0
  2. package/dist/chains/index.d.ts +13 -0
  3. package/dist/chains/index.js +13 -0
  4. package/dist/chains/xlayer/eip7702/index.d.ts +2 -0
  5. package/dist/flap/index.d.ts +10 -0
  6. package/dist/flap/index.js +8 -0
  7. package/dist/shared/constants/index.d.ts +2 -0
  8. package/dist/shared/index.d.ts +2 -0
  9. package/package.json +66 -1
  10. package/dist/chains/bsc/four/disperse.d.ts +0 -12
  11. package/dist/chains/bsc/four/disperse.js +0 -470
  12. package/dist/chains/bsc/four/pairwise.d.ts +0 -7
  13. package/dist/chains/bsc/four/pairwise.js +0 -308
  14. package/dist/chains/bsc/four/submit/blockrazor.d.ts +0 -18
  15. package/dist/chains/bsc/four/submit/blockrazor.js +0 -86
  16. package/dist/chains/bsc/four/submit/direct.d.ts +0 -66
  17. package/dist/chains/bsc/four/submit/direct.js +0 -452
  18. package/dist/chains/bsc/four/submit/helpers.d.ts +0 -18
  19. package/dist/chains/bsc/four/submit/helpers.js +0 -57
  20. package/dist/chains/bsc/four/submit/index.d.ts +0 -12
  21. package/dist/chains/bsc/four/submit/index.js +0 -11
  22. package/dist/chains/bsc/four/submit/merkle.d.ts +0 -18
  23. package/dist/chains/bsc/four/submit/merkle.js +0 -74
  24. package/dist/chains/bsc/four/submit/types.d.ts +0 -143
  25. package/dist/chains/bsc/four/swap/index.d.ts +0 -32
  26. package/dist/chains/bsc/four/swap/index.js +0 -829
  27. package/dist/chains/bsc/four/swap/types.d.ts +0 -70
  28. package/dist/chains/bsc/four/swap/types.js +0 -1
  29. package/dist/chains/bsc/four/sweep.d.ts +0 -13
  30. package/dist/chains/bsc/four/sweep.js +0 -788
  31. package/dist/chains/bsc/four/utils/index.d.ts +0 -20
  32. package/dist/chains/bsc/four/utils/index.js +0 -1558
  33. package/dist/chains/bsc/four/utils/types.d.ts +0 -1
  34. package/dist/chains/bsc/four/utils/types.js +0 -1
  35. package/dist/chains/bsc/pancake/bundle-buy-first/index.d.ts +0 -8
  36. package/dist/chains/bsc/pancake/bundle-buy-first/index.js +0 -907
  37. package/dist/chains/bsc/pancake/bundle-buy-first/types.d.ts +0 -73
  38. package/dist/chains/bsc/pancake/bundle-buy-first/types.js +0 -1
  39. package/dist/chains/bsc/pancake/bundle-swap/helpers.d.ts +0 -102
  40. package/dist/chains/bsc/pancake/bundle-swap/helpers.js +0 -572
  41. package/dist/chains/bsc/pancake/bundle-swap/index.d.ts +0 -50
  42. package/dist/chains/bsc/pancake/bundle-swap/index.js +0 -1066
  43. package/dist/chains/bsc/pancake/bundle-swap/types.d.ts +0 -202
  44. package/dist/chains/bsc/pancake/bundle-swap/types.js +0 -3
  45. package/dist/chains/xlayer/eip7702/bundle-swap/index.d.ts +0 -72
  46. package/dist/chains/xlayer/eip7702/bundle-swap/index.js +0 -921
  47. package/dist/chains/xlayer/eip7702/bundle-swap/types.d.ts +0 -65
  48. package/dist/chains/xlayer/eip7702/bundle-swap/types.js +0 -1
  49. package/dist/chains/xlayer/eip7702/multi-hop-transfer/index.d.ts +0 -128
  50. package/dist/chains/xlayer/eip7702/multi-hop-transfer/index.js +0 -857
  51. package/dist/chains/xlayer/eip7702/multi-hop-transfer/types.d.ts +0 -85
  52. package/dist/chains/xlayer/eip7702/multi-hop-transfer/types.js +0 -1
  53. package/dist/chains/xlayer/eip7702/volume/index.d.ts +0 -96
  54. package/dist/chains/xlayer/eip7702/volume/index.js +0 -793
  55. package/dist/chains/xlayer/eip7702/volume/types.d.ts +0 -124
  56. package/dist/chains/xlayer/eip7702/volume/types.js +0 -1
  57. package/dist/chains/xlayer/eoa/types-core.d.ts +0 -363
  58. package/dist/chains/xlayer/eoa/types-core.js +0 -53
  59. package/dist/chains/xlayer/eoa/types-create.d.ts +0 -413
  60. package/dist/chains/xlayer/eoa/types-create.js +0 -9
  61. package/dist/chains/xlayer/eoa/types-volume.d.ts +0 -209
  62. package/dist/chains/xlayer/eoa/types-volume.js +0 -13
  63. package/dist/dex/direct-router/index.d.ts +0 -70
  64. package/dist/dex/direct-router/index.js +0 -1410
  65. package/dist/dex/direct-router/types.d.ts +0 -81
  66. package/dist/dex/direct-router/types.js +0 -1
  67. package/dist/shared/abis/TaxToken.json +0 -969
  68. package/dist/shared/abis/TokenManager.json +0 -836
  69. package/dist/shared/abis/TokenManager2.json +0 -136
  70. package/dist/shared/abis/TokenManagerHelper3.json +0 -993
  71. package/dist/shared/abis 2/TaxToken.json +0 -105
  72. package/dist/shared/abis 2/TokenManager.json +0 -836
  73. package/dist/shared/abis 2/TokenManager2.json +0 -60
  74. package/dist/shared/abis 2/TokenManagerHelper3.json +0 -993
  75. package/dist/shared/abis 2/common.d.ts +0 -85
  76. package/dist/shared/abis 2/common.js +0 -254
  77. package/dist/shared/abis 2/index.d.ts +0 -8
  78. package/dist/shared/abis 2/index.js +0 -8
  79. package/dist/shared/clients 2/blockrazor.d.ts +0 -314
  80. package/dist/shared/clients 2/blockrazor.js +0 -596
  81. package/dist/shared/clients 2/club48.d.ts +0 -154
  82. package/dist/shared/clients 2/club48.js +0 -331
  83. package/dist/shared/clients 2/emitservice.d.ts +0 -47
  84. package/dist/shared/clients 2/emitservice.js +0 -44
  85. package/dist/shared/clients 2/four.d.ts +0 -132
  86. package/dist/shared/clients 2/four.js +0 -281
  87. package/dist/shared/clients 2/merkle.d.ts +0 -210
  88. package/dist/shared/clients 2/merkle.js +0 -400
  89. package/dist/shared/flap/__tests__/curve.test.d.ts +0 -1
  90. package/dist/shared/flap/__tests__/curve.test.js +0 -85
  91. package/dist/shared/flap/portal/index.d.ts +0 -12
  92. package/dist/shared/flap/portal/index.js +0 -11
  93. package/dist/shared/flap/portal/portal.d.ts +0 -47
  94. package/dist/shared/flap/portal/portal.js +0 -218
  95. package/dist/shared/flap/portal/types.d.ts +0 -227
  96. package/dist/shared/flap/portal/types.js +0 -80
  97. package/dist/shared/flap/portal/writer.d.ts +0 -121
  98. package/dist/shared/flap/portal/writer.js +0 -265
  99. package/dist/shared/flap/portal-bundle-merkle/core/index.d.ts +0 -18
  100. package/dist/shared/flap/portal-bundle-merkle/core/index.js +0 -938
  101. package/dist/shared/flap/portal-bundle-merkle/core/types.d.ts +0 -1
  102. package/dist/shared/flap/portal-bundle-merkle/core/types.js +0 -1
  103. package/dist/shared/flap/portal-bundle-merkle/swap/index.d.ts +0 -42
  104. package/dist/shared/flap/portal-bundle-merkle/swap/index.js +0 -1448
  105. package/dist/shared/flap/portal-bundle-merkle/swap/types.d.ts +0 -84
  106. package/dist/shared/flap/portal-bundle-merkle/swap/types.js +0 -1
  107. package/dist/shared/flap/portal-bundle-merkle/utils/index.d.ts +0 -17
  108. package/dist/shared/flap/portal-bundle-merkle/utils/index.js +0 -1024
  109. package/dist/shared/flap/portal-bundle-merkle/utils/types.d.ts +0 -16
  110. package/dist/shared/flap/portal-bundle-merkle/utils/types.js +0 -1
  111. package/dist/shared/flap/portal-bundle-merkle/utils-helpers.d.ts +0 -100
  112. package/dist/shared/flap/portal-bundle-merkle/utils-helpers.js +0 -133
  113. package/dist/shared/flap 2/__tests__/curve.test.d.ts +0 -1
  114. package/dist/shared/flap 2/__tests__/curve.test.js +0 -85
  115. package/dist/shared/flap 2/abi.d.ts +0 -4
  116. package/dist/shared/flap 2/abi.js +0 -4
  117. package/dist/shared/flap 2/constants.d.ts +0 -128
  118. package/dist/shared/flap 2/constants.js +0 -143
  119. package/dist/shared/flap 2/curve.d.ts +0 -33
  120. package/dist/shared/flap 2/curve.js +0 -84
  121. package/dist/shared/flap 2/errors.d.ts +0 -37
  122. package/dist/shared/flap 2/errors.js +0 -114
  123. package/dist/shared/flap 2/index.d.ts +0 -22
  124. package/dist/shared/flap 2/index.js +0 -33
  125. package/dist/shared/flap 2/ipfs.d.ts +0 -21
  126. package/dist/shared/flap 2/ipfs.js +0 -38
  127. package/dist/shared/flap 2/meta.d.ts +0 -30
  128. package/dist/shared/flap 2/meta.js +0 -195
  129. package/dist/shared/flap 2/permit.d.ts +0 -16
  130. package/dist/shared/flap 2/permit.js +0 -67
  131. package/dist/shared/flap 2/pinata.d.ts +0 -40
  132. package/dist/shared/flap 2/pinata.js +0 -106
  133. package/dist/shared/flap 2/portal-bundle-merkle/config.d.ts +0 -79
  134. package/dist/shared/flap 2/portal-bundle-merkle/config.js +0 -133
  135. package/dist/shared/flap 2/portal-bundle-merkle/core.d.ts +0 -18
  136. package/dist/shared/flap 2/portal-bundle-merkle/core.js +0 -938
  137. package/dist/shared/flap 2/portal-bundle-merkle/create-to-dex.d.ts +0 -125
  138. package/dist/shared/flap 2/portal-bundle-merkle/create-to-dex.js +0 -665
  139. package/dist/shared/flap 2/portal-bundle-merkle/curve-to-dex.d.ts +0 -88
  140. package/dist/shared/flap 2/portal-bundle-merkle/curve-to-dex.js +0 -446
  141. package/dist/shared/flap 2/portal-bundle-merkle/index.d.ts +0 -14
  142. package/dist/shared/flap 2/portal-bundle-merkle/index.js +0 -26
  143. package/dist/shared/flap 2/portal-bundle-merkle/pancake-proxy.d.ts +0 -28
  144. package/dist/shared/flap 2/portal-bundle-merkle/pancake-proxy.js +0 -701
  145. package/dist/shared/flap 2/portal-bundle-merkle/private.d.ts +0 -17
  146. package/dist/shared/flap 2/portal-bundle-merkle/private.js +0 -549
  147. package/dist/shared/flap 2/portal-bundle-merkle/swap-buy-first.d.ts +0 -65
  148. package/dist/shared/flap 2/portal-bundle-merkle/swap-buy-first.js +0 -831
  149. package/dist/shared/flap 2/portal-bundle-merkle/swap.d.ts +0 -201
  150. package/dist/shared/flap 2/portal-bundle-merkle/swap.js +0 -1359
  151. package/dist/shared/flap 2/portal-bundle-merkle/types.d.ts +0 -358
  152. package/dist/shared/flap 2/portal-bundle-merkle/types.js +0 -1
  153. package/dist/shared/flap 2/portal-bundle-merkle/utils.d.ts +0 -89
  154. package/dist/shared/flap 2/portal-bundle-merkle/utils.js +0 -963
  155. package/dist/shared/flap 2/portal-bundle.d.ts +0 -119
  156. package/dist/shared/flap 2/portal-bundle.js +0 -584
  157. package/dist/shared/flap 2/portal.d.ts +0 -392
  158. package/dist/shared/flap 2/portal.js +0 -559
  159. package/dist/shared/flap 2/vanity.d.ts +0 -48
  160. package/dist/shared/flap 2/vanity.js +0 -110
  161. package/dist/shared/flap 2/vault.d.ts +0 -240
  162. package/dist/shared/flap 2/vault.js +0 -366
  163. package/dist/shared/four 2/index.d.ts +0 -7
  164. package/dist/shared/four 2/index.js +0 -22
  165. package/dist/shared/four 2/tax-token.d.ts +0 -176
  166. package/dist/shared/four 2/tax-token.js +0 -302
  167. package/dist/shared/index 2.js +0 -10
  168. package/dist/shared/index.d 2.ts +0 -10
  169. package/dist/types/distribute.d.ts +0 -72
  170. package/dist/types/distribute.js +0 -1
  171. package/dist/types 2/errors.d.ts +0 -27
  172. package/dist/types 2/errors.js +0 -34
  173. package/dist/utils/__tests__/errors.test.d.ts +0 -1
  174. package/dist/utils/__tests__/errors.test.js +0 -76
  175. package/dist/utils/airdrop-sweep-types.d.ts +0 -1
  176. package/dist/utils/airdrop-sweep-types.js +0 -1
  177. package/dist/utils/erc20/index.d.ts +0 -242
  178. package/dist/utils/erc20/index.js +0 -645
  179. package/dist/utils/erc20/types.d.ts +0 -77
  180. package/dist/utils/erc20/types.js +0 -1
  181. package/dist/utils/erc20-types.d.ts +0 -1
  182. package/dist/utils/erc20-types.js +0 -1
  183. package/dist/utils/holders-maker/helpers.d.ts +0 -43
  184. package/dist/utils/holders-maker/helpers.js +0 -371
  185. package/dist/utils/holders-maker/index.d.ts +0 -26
  186. package/dist/utils/holders-maker/index.js +0 -218
  187. package/dist/utils/holders-maker/types.d.ts +0 -72
  188. package/dist/utils/holders-maker/types.js +0 -4
  189. package/dist/utils/holders-maker-types.d.ts +0 -1
  190. package/dist/utils/holders-maker-types.js +0 -1
  191. package/dist/utils/lp-inspect/index.d.ts +0 -44
  192. package/dist/utils/lp-inspect/index.js +0 -937
  193. package/dist/utils/lp-inspect/types.d.ts +0 -100
  194. package/dist/utils/lp-inspect/types.js +0 -1
  195. package/dist/utils/lp-inspect-types.d.ts +0 -1
  196. package/dist/utils/lp-inspect-types.js +0 -1
  197. package/dist/utils/private-sale-types.d.ts +0 -1
  198. package/dist/utils/private-sale-types.js +0 -1
  199. package/dist/utils/quote-helpers/index.d.ts +0 -107
  200. package/dist/utils/quote-helpers/index.js +0 -346
  201. package/dist/utils/quote-helpers/types.d.ts +0 -16
  202. package/dist/utils/quote-helpers/types.js +0 -1
  203. package/dist/utils/quote-helpers-types.d.ts +0 -1
  204. package/dist/utils/quote-helpers-types.js +0 -1
  205. /package/dist/{chains/bsc/four/submit/types.js → __tests__/subpath-exports.test.d.ts} +0 -0
@@ -1,452 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { CHAINS } from '../../../../shared/constants/index.js';
3
- import { recoverTxHashIfAlreadySeen } from './helpers.js';
4
- export async function submitDirectToRpc(signedTransactions, config) {
5
- const totalTransactions = signedTransactions?.length ?? 0;
6
- // 验证输入
7
- if (!signedTransactions || signedTransactions.length === 0) {
8
- return {
9
- code: false,
10
- totalTransactions: 0,
11
- bundleHash: 'direct',
12
- txHashes: [],
13
- txCount: 0,
14
- error: 'signedTransactions cannot be empty'
15
- };
16
- }
17
- if (!config.rpcUrl) {
18
- return {
19
- code: false,
20
- totalTransactions,
21
- bundleHash: 'direct',
22
- txHashes: [],
23
- txCount: totalTransactions,
24
- error: 'rpcUrl is required in config'
25
- };
26
- }
27
- const chainId = config.chainId ?? 143;
28
- const chainName = config.chainName ?? 'MONAD';
29
- // 创建 Provider
30
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
31
- chainId,
32
- name: chainName
33
- });
34
- // ✅ 并行广播所有交易
35
- const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
36
- try {
37
- const txResponse = await provider.broadcastTransaction(signedTx);
38
- // 如果需要等待确认
39
- if (config.waitForConfirmation) {
40
- try {
41
- const receipt = await provider.waitForTransaction(txResponse.hash, 1, config.confirmationTimeout ?? 30000);
42
- if (receipt && receipt.status === 0) {
43
- console.warn(`⚠️ [${chainName}] 交易 ${txResponse.hash} 执行失败(已上链但状态为0)`);
44
- }
45
- }
46
- catch (waitError) {
47
- console.warn(`⚠️ [${chainName}] 等待交易确认超时: ${txResponse.hash}`);
48
- }
49
- }
50
- return {
51
- index: i,
52
- success: true,
53
- txHash: txResponse.hash
54
- };
55
- }
56
- catch (error) {
57
- const errorMessage = error?.message || String(error);
58
- console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
59
- // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
60
- const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
61
- if (recovered) {
62
- if (config.waitForConfirmation) {
63
- try {
64
- await provider.waitForTransaction(recovered, 1, config.confirmationTimeout ?? 30000);
65
- }
66
- catch { }
67
- }
68
- return { index: i, success: true, txHash: recovered, error: errorMessage };
69
- }
70
- return {
71
- index: i,
72
- success: false,
73
- error: errorMessage
74
- };
75
- }
76
- });
77
- const results = await Promise.all(broadcastPromises);
78
- // 按索引排序结果
79
- results.sort((a, b) => a.index - b.index);
80
- const txHashes = results.filter(r => r.success && r.txHash).map(r => r.txHash);
81
- const errors = results.filter(r => !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
82
- return {
83
- code: txHashes.length > 0,
84
- totalTransactions,
85
- bundleHash: 'direct',
86
- txHashes,
87
- txCount: totalTransactions,
88
- error: errors.length > 0 ? errors.join('; ') : undefined
89
- };
90
- }
91
- /**
92
- * ✅ 顺序广播并等待确认(用于多跳交易等需要顺序执行的场景)
93
- *
94
- * 每笔交易广播后会等待上链确认,确保后续交易能正确执行
95
- *
96
- * ⚠️ 多跳场景:如果某笔交易失败,会立即停止(因为后续交易肯定也会失败)
97
- *
98
- * @param signedTransactions 签名后的交易数组
99
- * @param config 直接广播配置
100
- * @returns 广播结果
101
- */
102
- export async function submitDirectToRpcSequential(signedTransactions, config) {
103
- const totalTransactions = signedTransactions?.length ?? 0;
104
- if (!signedTransactions || signedTransactions.length === 0) {
105
- return {
106
- code: false,
107
- totalTransactions: 0,
108
- bundleHash: 'direct',
109
- txHashes: [],
110
- txCount: 0,
111
- error: 'signedTransactions cannot be empty'
112
- };
113
- }
114
- if (!config.rpcUrl) {
115
- return {
116
- code: false,
117
- totalTransactions,
118
- bundleHash: 'direct',
119
- txHashes: [],
120
- txCount: totalTransactions,
121
- error: 'rpcUrl is required in config'
122
- };
123
- }
124
- const chainId = config.chainId ?? CHAINS.MONAD.chainId;
125
- const chainName = config.chainName ?? 'MONAD';
126
- // ✅ XLayer 链默认 120 秒超时(网络可能较慢)
127
- const confirmationTimeout = config.confirmationTimeout ?? (chainId === CHAINS.XLAYER.chainId ? CHAINS.XLAYER.confirmationTimeout : CHAINS.BSC.confirmationTimeout);
128
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
129
- chainId,
130
- name: chainName
131
- });
132
- const results = [];
133
- const txHashes = [];
134
- const errors = [];
135
- console.log(`📤 [${chainName}] 开始顺序广播 ${totalTransactions} 笔交易(等待每笔确认)`);
136
- // 顺序广播并等待确认
137
- for (let i = 0; i < signedTransactions.length; i++) {
138
- const signedTx = signedTransactions[i];
139
- try {
140
- // 广播交易
141
- const txResponse = await provider.broadcastTransaction(signedTx);
142
- console.log(`📡 [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播成功: ${txResponse.hash},等待确认...`);
143
- // ✅ 等待交易确认
144
- const receipt = await provider.waitForTransaction(txResponse.hash, 1, // 等待1个确认
145
- confirmationTimeout);
146
- if (receipt && receipt.status === 1) {
147
- console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 已确认: ${txResponse.hash}`);
148
- results.push({
149
- index: i,
150
- success: true,
151
- txHash: txResponse.hash
152
- });
153
- txHashes.push(txResponse.hash);
154
- }
155
- else {
156
- const errorMsg = `交易执行失败(status=${receipt?.status})`;
157
- console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 上链失败: ${errorMsg}`);
158
- results.push({
159
- index: i,
160
- success: false,
161
- txHash: txResponse.hash,
162
- error: errorMsg
163
- });
164
- errors.push(`交易 ${i + 1}: ${errorMsg}`);
165
- // ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
166
- console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
167
- break;
168
- }
169
- }
170
- catch (error) {
171
- const errorMessage = error?.message || String(error);
172
- console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播/确认失败:`, errorMessage);
173
- // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
174
- const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
175
- if (recovered) {
176
- console.log(`🔄 [${chainName}] 交易 ${i + 1} 可能已广播,尝试等待确认: ${recovered}`);
177
- // 顺序模式依赖确认:尽量等待一下
178
- try {
179
- const receipt = await provider.waitForTransaction(recovered, 1, confirmationTimeout);
180
- if (receipt && receipt.status === 1) {
181
- console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 恢复成功: ${recovered}`);
182
- results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
183
- txHashes.push(recovered);
184
- continue;
185
- }
186
- const errorMsg = `交易执行失败(status=${receipt?.status})`;
187
- console.error(`❌ [${chainName}] 交易 ${i + 1} 恢复失败: ${errorMsg}`);
188
- results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | ${errorMsg}` });
189
- errors.push(`交易 ${i + 1}: ${errorMessage} | ${errorMsg}`);
190
- // ✅ 多跳场景:失败则停止
191
- console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
192
- break;
193
- }
194
- catch (waitError) {
195
- // 等待超时:对于多跳场景,不能假设成功,需要停止
196
- const waitErrorMsg = waitError?.message || String(waitError);
197
- console.error(`⏱️ [${chainName}] 交易 ${i + 1} 等待确认超时: ${waitErrorMsg}`);
198
- results.push({ index: i, success: false, txHash: recovered, error: `${errorMessage} | 等待确认超时: ${waitErrorMsg}` });
199
- errors.push(`交易 ${i + 1}: ${errorMessage} | 等待确认超时`);
200
- // ✅ 多跳场景:超时也停止
201
- console.warn(`⚠️ [${chainName}] 多跳模式检测到超时,停止后续 ${totalTransactions - i - 1} 笔交易`);
202
- break;
203
- }
204
- }
205
- results.push({
206
- index: i,
207
- success: false,
208
- error: errorMessage
209
- });
210
- errors.push(`交易 ${i + 1}: ${errorMessage}`);
211
- // ✅ 多跳场景:如果某笔失败,后续交易肯定也会失败,立即停止
212
- console.warn(`⚠️ [${chainName}] 多跳模式检测到失败,停止后续 ${totalTransactions - i - 1} 笔交易`);
213
- break;
214
- }
215
- }
216
- console.log(`📊 [${chainName}] 顺序广播完成: 成功 ${txHashes.length}/${totalTransactions}`);
217
- return {
218
- code: txHashes.length > 0,
219
- totalTransactions,
220
- bundleHash: 'direct',
221
- txHashes,
222
- txCount: totalTransactions,
223
- error: errors.length > 0 ? errors.join('; ') : undefined
224
- };
225
- }
226
- /**
227
- * ✅ 顺序广播但不等待确认(用于 AA handleOps + tail 等 nonce 连续的场景)
228
- *
229
- * 按顺序逐笔发送交易,每笔只等待广播成功(RPC 返回 txHash),不等待链上确认。
230
- * 这样可以保证交易按顺序进入 mempool,同时避免等待确认超时。
231
- *
232
- * @param signedTransactions 签名后的交易数组
233
- * @param config 直接广播配置
234
- * @returns 广播结果
235
- */
236
- export async function submitDirectToRpcSequentialNoWait(signedTransactions, config) {
237
- const totalTransactions = signedTransactions?.length ?? 0;
238
- if (!signedTransactions || signedTransactions.length === 0) {
239
- return {
240
- code: false,
241
- totalTransactions: 0,
242
- bundleHash: 'direct',
243
- txHashes: [],
244
- txCount: 0,
245
- error: 'signedTransactions cannot be empty'
246
- };
247
- }
248
- if (!config.rpcUrl) {
249
- return {
250
- code: false,
251
- totalTransactions,
252
- bundleHash: 'direct',
253
- txHashes: [],
254
- txCount: totalTransactions,
255
- error: 'rpcUrl is required in config'
256
- };
257
- }
258
- const chainId = config.chainId ?? 143;
259
- const chainName = config.chainName ?? 'MONAD';
260
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
261
- chainId,
262
- name: chainName
263
- });
264
- const results = [];
265
- const txHashes = [];
266
- const errors = [];
267
- // ✅ 顺序广播,每笔只等待广播成功(不等待链上确认)
268
- for (let i = 0; i < signedTransactions.length; i++) {
269
- const signedTx = signedTransactions[i];
270
- try {
271
- // 广播交易,等待 RPC 返回 txHash
272
- const txResponse = await provider.broadcastTransaction(signedTx);
273
- results.push({
274
- index: i,
275
- success: true,
276
- txHash: txResponse.hash
277
- });
278
- txHashes.push(txResponse.hash);
279
- console.log(`✅ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播成功: ${txResponse.hash}`);
280
- }
281
- catch (error) {
282
- const errorMessage = error?.message || String(error);
283
- console.error(`❌ [${chainName}] 交易 ${i + 1}/${totalTransactions} 广播失败:`, errorMessage);
284
- // ✅ 兼容:nonce too low / already known 等情况下,交易可能已经被接收
285
- const recovered = await recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage);
286
- if (recovered) {
287
- results.push({ index: i, success: true, txHash: recovered, error: errorMessage });
288
- txHashes.push(recovered);
289
- continue;
290
- }
291
- results.push({
292
- index: i,
293
- success: false,
294
- error: errorMessage
295
- });
296
- errors.push(`交易 ${i + 1}: ${errorMessage}`);
297
- // ✅ 如果某笔失败,继续尝试后续交易(可能是 nonce 问题可以自动恢复)
298
- }
299
- }
300
- return {
301
- code: txHashes.length > 0,
302
- totalTransactions,
303
- bundleHash: 'direct',
304
- txHashes,
305
- txCount: totalTransactions,
306
- error: errors.length > 0 ? errors.join('; ') : undefined
307
- };
308
- }
309
- /**
310
- * 并行逐笔广播到 RPC(速度更快,但可能有 nonce 冲突)
311
- *
312
- * ⚠️ 注意:仅适用于不同钱包的交易,同一钱包的多笔交易应使用顺序广播
313
- *
314
- * @param signedTransactions 签名后的交易数组
315
- * @param config 直接广播配置
316
- * @returns 广播结果
317
- */
318
- export async function submitDirectToRpcParallel(signedTransactions, config) {
319
- const totalTransactions = signedTransactions?.length ?? 0;
320
- if (!signedTransactions || signedTransactions.length === 0) {
321
- return {
322
- code: false,
323
- totalTransactions: 0,
324
- bundleHash: 'direct',
325
- txHashes: [],
326
- txCount: 0,
327
- error: 'signedTransactions cannot be empty'
328
- };
329
- }
330
- if (!config.rpcUrl) {
331
- return {
332
- code: false,
333
- totalTransactions,
334
- bundleHash: 'direct',
335
- txHashes: [],
336
- txCount: totalTransactions,
337
- error: 'rpcUrl is required in config'
338
- };
339
- }
340
- const chainId = config.chainId ?? 143;
341
- const chainName = config.chainName ?? 'MONAD';
342
- const provider = new ethers.JsonRpcProvider(config.rpcUrl, {
343
- chainId,
344
- name: chainName
345
- });
346
- // 并行广播
347
- const broadcastPromises = signedTransactions.map(async (signedTx, i) => {
348
- try {
349
- const txResponse = await provider.broadcastTransaction(signedTx);
350
- return {
351
- index: i,
352
- success: true,
353
- txHash: txResponse.hash
354
- };
355
- }
356
- catch (error) {
357
- return {
358
- index: i,
359
- success: false,
360
- error: error?.message || String(error)
361
- };
362
- }
363
- });
364
- const results = await Promise.all(broadcastPromises);
365
- const txHashes = results.filter(r => r.success && r.txHash).map(r => r.txHash);
366
- const errors = results.filter(r => !r.success).map(r => `交易 ${r.index + 1}: ${r.error}`);
367
- return {
368
- code: txHashes.length > 0,
369
- totalTransactions,
370
- bundleHash: 'direct',
371
- txHashes,
372
- txCount: totalTransactions,
373
- error: errors.length > 0 ? errors.join('; ') : undefined
374
- };
375
- }
376
- /**
377
- * ✅ 智能广播到 RPC(自动选择并行或顺序)
378
- *
379
- * 根据交易的发送者地址自动决定广播策略:
380
- * - 如果所有交易来自不同钱包:使用并行广播(速度快)
381
- * - 如果存在同一钱包的多笔交易:使用顺序广播(确保 nonce 顺序)
382
- *
383
- * @param signedTransactions 签名后的交易数组
384
- * @param config 直接广播配置
385
- * @param options 额外选项
386
- * @returns 广播结果(包含使用的模式)
387
- *
388
- * @example
389
- * ```typescript
390
- * import { submitDirectToRpcSmart } from 'four-flap-meme-sdk';
391
- *
392
- * const result = await submitDirectToRpcSmart(signedTransactions, {
393
- * rpcUrl: 'https://xlayerrpc.okx.com',
394
- * chainId: 196,
395
- * chainName: 'XLAYER'
396
- * });
397
- *
398
- * console.log('使用模式:', result.mode); // 'parallel' 或 'sequential'
399
- * ```
400
- */
401
- export async function submitDirectToRpcSmart(signedTransactions, config, options) {
402
- const totalTransactions = signedTransactions?.length ?? 0;
403
- if (!signedTransactions || signedTransactions.length === 0) {
404
- return {
405
- code: false,
406
- totalTransactions: 0,
407
- bundleHash: 'direct',
408
- txHashes: [],
409
- txCount: 0,
410
- error: 'signedTransactions cannot be empty',
411
- mode: 'parallel'
412
- };
413
- }
414
- // 检测是否有同一钱包的多笔交易
415
- const hasMultipleFromSameWallet = (() => {
416
- if (signedTransactions.length < 2)
417
- return false;
418
- const seen = new Set();
419
- for (const raw of signedTransactions) {
420
- if (!raw)
421
- continue;
422
- try {
423
- const tx = ethers.Transaction.from(raw);
424
- const from = (tx.from || '').toLowerCase();
425
- if (!from)
426
- continue;
427
- if (seen.has(from))
428
- return true;
429
- seen.add(from);
430
- }
431
- catch {
432
- // ignore parse errors
433
- }
434
- }
435
- return false;
436
- })();
437
- const chainName = config.chainName ?? 'UNKNOWN';
438
- if (hasMultipleFromSameWallet) {
439
- console.log(`🔄 [${chainName}] 检测到同一钱包多笔交易,使用顺序广播`);
440
- // 使用顺序广播
441
- const result = options?.waitConfirmation
442
- ? await submitDirectToRpcSequential(signedTransactions, config)
443
- : await submitDirectToRpcSequentialNoWait(signedTransactions, config);
444
- return { ...result, mode: 'sequential' };
445
- }
446
- else {
447
- console.log(`⚡ [${chainName}] 所有交易来自不同钱包,使用并行广播`);
448
- // 使用并行广播
449
- const result = await submitDirectToRpcParallel(signedTransactions, config);
450
- return { ...result, mode: 'parallel' };
451
- }
452
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * 独立的Bundle提交方法
3
- *
4
- * 用于服务器端接收前端构建的签名交易后,提交到Merkle或BlockRazor
5
- * 以及 Monad 等不支持 Bundle 的链的逐笔广播
6
- */
7
- import { MerkleClient } from '../../../../shared/clients/merkle.js';
8
- import { ethers } from 'ethers';
9
- import type { MerkleSubmitConfig } from './types.js';
10
- /**
11
- * 获取或创建 MerkleClient(带缓存)
12
- */
13
- export declare function getMerkleClient(config: MerkleSubmitConfig): MerkleClient;
14
- /**
15
- * 精简的Merkle提交配置(只包含提交需要的字段)
16
- */
17
- export declare function shouldTreatBroadcastErrorAsMaybeSent(msg: string): boolean;
18
- export declare function recoverTxHashIfAlreadySeen(provider: ethers.JsonRpcProvider, signedTx: string, errorMessage: string): Promise<string | undefined>;
@@ -1,57 +0,0 @@
1
- /**
2
- * 独立的Bundle提交方法
3
- *
4
- * 用于服务器端接收前端构建的签名交易后,提交到Merkle或BlockRazor
5
- * 以及 Monad 等不支持 Bundle 的链的逐笔广播
6
- */
7
- import { MerkleClient } from '../../../../shared/clients/merkle.js';
8
- import { ethers } from 'ethers';
9
- // ✅ MerkleClient 缓存(复用连接,减少初始化开销)
10
- const merkleClientCache = new Map();
11
- const CLIENT_CACHE_TTL_MS = 60 * 1000; // 60秒缓存
12
- /**
13
- * 获取或创建 MerkleClient(带缓存)
14
- */
15
- export function getMerkleClient(config) {
16
- const cacheKey = `${config.apiKey}-${config.chainId ?? 56}-${config.customRpcUrl || ''}`;
17
- const now = Date.now();
18
- const cached = merkleClientCache.get(cacheKey);
19
- if (cached && cached.expireAt > now) {
20
- return cached.client;
21
- }
22
- // 创建新客户端并缓存
23
- const client = new MerkleClient({
24
- apiKey: config.apiKey,
25
- chainId: config.chainId ?? 56,
26
- customRpcUrl: config.customRpcUrl
27
- });
28
- merkleClientCache.set(cacheKey, { client, expireAt: now + CLIENT_CACHE_TTL_MS });
29
- return client;
30
- }
31
- /**
32
- * 精简的Merkle提交配置(只包含提交需要的字段)
33
- */
34
- export function shouldTreatBroadcastErrorAsMaybeSent(msg) {
35
- const m = String(msg || '').toLowerCase();
36
- return (m.includes('already known') ||
37
- m.includes('known transaction') ||
38
- m.includes('already exists') ||
39
- m.includes('nonce too low') ||
40
- m.includes('nonce has already been used') ||
41
- m.includes('nonce expired') ||
42
- m.includes('replacement transaction underpriced'));
43
- }
44
- export async function recoverTxHashIfAlreadySeen(provider, signedTx, errorMessage) {
45
- if (!shouldTreatBroadcastErrorAsMaybeSent(errorMessage))
46
- return undefined;
47
- try {
48
- const hash = ethers.keccak256(signedTx);
49
- if (!hash)
50
- return undefined;
51
- const tx = await provider.getTransaction(hash);
52
- return tx ? hash : undefined;
53
- }
54
- catch {
55
- return undefined;
56
- }
57
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Bundle 提交方法
3
- *
4
- * 拆分自 submit.ts。包括:
5
- * - Merkle 提交
6
- * - BlockRazor 提交
7
- * - 直接 RPC 广播
8
- */
9
- export type { MerkleSubmitConfig, SubmitBundleResult, BlockRazorSubmitConfig, BlockRazorSubmitResult, DirectSubmitConfig, DirectTxResult, DirectSubmitResult, } from './types.js';
10
- export { submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, } from './merkle.js';
11
- export { submitBundleToBlockRazor, submitMultipleBundlesToBlockRazor, submitMultipleBundlesToBlockRazorParallel, } from './blockrazor.js';
12
- export { submitDirectToRpc, submitDirectToRpcSequential, submitDirectToRpcSequentialNoWait, submitDirectToRpcParallel, submitDirectToRpcSmart, } from './direct.js';
@@ -1,11 +0,0 @@
1
- /**
2
- * Bundle 提交方法
3
- *
4
- * 拆分自 submit.ts。包括:
5
- * - Merkle 提交
6
- * - BlockRazor 提交
7
- * - 直接 RPC 广播
8
- */
9
- export { submitBundleToMerkle, submitMultipleBundles, submitMultipleBundlesParallel, } from './merkle.js';
10
- export { submitBundleToBlockRazor, submitMultipleBundlesToBlockRazor, submitMultipleBundlesToBlockRazorParallel, } from './blockrazor.js';
11
- export { submitDirectToRpc, submitDirectToRpcSequential, submitDirectToRpcSequentialNoWait, submitDirectToRpcParallel, submitDirectToRpcSmart, } from './direct.js';
@@ -1,18 +0,0 @@
1
- import type { MerkleSubmitConfig, SubmitBundleResult } from './types.js';
2
- export declare function submitBundleToMerkle(signedTransactions: string[], config: MerkleSubmitConfig): Promise<SubmitBundleResult>;
3
- /**
4
- * 批量提交多个Bundle到Merkle(顺序执行)
5
- *
6
- * @param bundles 多个Bundle的签名交易数组
7
- * @param config Merkle提交配置
8
- * @returns Bundle提交结果数组
9
- */
10
- export declare function submitMultipleBundles(bundles: string[][], config: MerkleSubmitConfig): Promise<SubmitBundleResult[]>;
11
- /**
12
- * 并行提交多个Bundle到Merkle(适用于独立的Bundle)
13
- *
14
- * @param bundles 多个Bundle的签名交易数组
15
- * @param config Merkle提交配置
16
- * @returns Bundle提交结果数组
17
- */
18
- export declare function submitMultipleBundlesParallel(bundles: string[][], config: MerkleSubmitConfig): Promise<SubmitBundleResult[]>;
@@ -1,74 +0,0 @@
1
- import { getMerkleClient } from './helpers.js';
2
- export async function submitBundleToMerkle(signedTransactions, config) {
3
- try {
4
- const totalTransactions = signedTransactions?.length ?? 0;
5
- // 验证输入
6
- if (!signedTransactions || signedTransactions.length === 0) {
7
- return {
8
- code: false,
9
- totalTransactions,
10
- error: 'signedTransactions cannot be empty'
11
- };
12
- }
13
- if (!config.apiKey) {
14
- return {
15
- code: false,
16
- totalTransactions,
17
- error: 'apiKey is required in config'
18
- };
19
- }
20
- // ✅ 使用缓存的 MerkleClient(复用连接 + 区块号缓存)
21
- const merkle = getMerkleClient(config);
22
- // 提交Bundle
23
- const bundleResult = await merkle.sendBundle({
24
- transactions: signedTransactions,
25
- blockOffset: config.bundleBlockOffset ?? 3,
26
- minBlockOffset: config.minBlockOffset ?? 3,
27
- autoRetry: config.autoRetryBundle ?? false,
28
- maxRetries: config.maxBundleRetries ?? 2
29
- });
30
- // ✅ 提交成功
31
- return {
32
- code: true,
33
- totalTransactions,
34
- bundleHash: bundleResult.bundleHash,
35
- txHashes: bundleResult.txHashes,
36
- targetBlock: bundleResult.targetBlock,
37
- txCount: bundleResult.txCount
38
- };
39
- }
40
- catch (error) {
41
- // ❌ 提交失败
42
- return {
43
- code: false,
44
- totalTransactions: signedTransactions?.length ?? 0,
45
- error: error?.message || String(error)
46
- };
47
- }
48
- }
49
- /**
50
- * 批量提交多个Bundle到Merkle(顺序执行)
51
- *
52
- * @param bundles 多个Bundle的签名交易数组
53
- * @param config Merkle提交配置
54
- * @returns Bundle提交结果数组
55
- */
56
- export async function submitMultipleBundles(bundles, config) {
57
- const results = [];
58
- for (const signedTransactions of bundles) {
59
- const result = await submitBundleToMerkle(signedTransactions, config);
60
- results.push(result);
61
- }
62
- return results;
63
- }
64
- /**
65
- * 并行提交多个Bundle到Merkle(适用于独立的Bundle)
66
- *
67
- * @param bundles 多个Bundle的签名交易数组
68
- * @param config Merkle提交配置
69
- * @returns Bundle提交结果数组
70
- */
71
- export async function submitMultipleBundlesParallel(bundles, config) {
72
- const promises = bundles.map(signedTransactions => submitBundleToMerkle(signedTransactions, config));
73
- return await Promise.all(promises);
74
- }