four-flap-meme-sdk 1.2.40 → 1.2.41

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.
@@ -32,6 +32,14 @@ export interface SubmitBundleResult {
32
32
  totalTransactions: number;
33
33
  /** 固定利润点(单位:bps,千分比) */
34
34
  profitRateBps: number;
35
+ /** 交易总流水(Wei字符串) */
36
+ totalFlowWei: string;
37
+ /** 交易总流水(格式化成 Ether/BNB 字符串) */
38
+ totalFlow: string;
39
+ /** 实际利润(Wei字符串) */
40
+ profitWei: string;
41
+ /** 实际利润(格式化成 Ether/BNB 字符串) */
42
+ profitAmount: string;
35
43
  /** Bundle哈希(成功时返回) */
36
44
  bundleHash?: string;
37
45
  /** 交易哈希列表(成功时返回) */
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { MerkleClient } from '../../clients/merkle.js';
7
7
  import { PROFIT_CONFIG } from '../../utils/constants.js';
8
+ import { Transaction, formatEther } from 'ethers';
8
9
  /**
9
10
  * 提交已签名的交易到Merkle(服务器端使用)
10
11
  *
@@ -35,20 +36,30 @@ import { PROFIT_CONFIG } from '../../utils/constants.js';
35
36
  */
36
37
  export async function submitBundleToMerkle(signedTransactions, config) {
37
38
  try {
39
+ const metrics = calculateBundleMetrics(signedTransactions);
40
+ const totalTransactions = signedTransactions?.length ?? 0;
38
41
  // 验证输入
39
42
  if (!signedTransactions || signedTransactions.length === 0) {
40
43
  return {
41
44
  code: false,
42
- totalTransactions: signedTransactions?.length ?? 0,
45
+ totalTransactions,
43
46
  profitRateBps: PROFIT_CONFIG.RATE_BPS,
47
+ totalFlowWei: metrics.totalFlowWei,
48
+ totalFlow: metrics.totalFlow,
49
+ profitWei: metrics.profitWei,
50
+ profitAmount: metrics.profitAmount,
44
51
  error: 'signedTransactions cannot be empty'
45
52
  };
46
53
  }
47
54
  if (!config.apiKey) {
48
55
  return {
49
56
  code: false,
50
- totalTransactions: signedTransactions.length,
57
+ totalTransactions,
51
58
  profitRateBps: PROFIT_CONFIG.RATE_BPS,
59
+ totalFlowWei: metrics.totalFlowWei,
60
+ totalFlow: metrics.totalFlow,
61
+ profitWei: metrics.profitWei,
62
+ profitAmount: metrics.profitAmount,
52
63
  error: 'apiKey is required in config'
53
64
  };
54
65
  }
@@ -69,8 +80,12 @@ export async function submitBundleToMerkle(signedTransactions, config) {
69
80
  // ✅ 提交成功
70
81
  return {
71
82
  code: true,
72
- totalTransactions: signedTransactions.length,
83
+ totalTransactions,
73
84
  profitRateBps: PROFIT_CONFIG.RATE_BPS,
85
+ totalFlowWei: metrics.totalFlowWei,
86
+ totalFlow: metrics.totalFlow,
87
+ profitWei: metrics.profitWei,
88
+ profitAmount: metrics.profitAmount,
74
89
  bundleHash: bundleResult.bundleHash,
75
90
  txHashes: bundleResult.txHashes,
76
91
  targetBlock: bundleResult.targetBlock,
@@ -79,10 +94,15 @@ export async function submitBundleToMerkle(signedTransactions, config) {
79
94
  }
80
95
  catch (error) {
81
96
  // ❌ 提交失败
97
+ const metrics = calculateBundleMetrics(signedTransactions);
82
98
  return {
83
99
  code: false,
84
100
  totalTransactions: signedTransactions?.length ?? 0,
85
101
  profitRateBps: PROFIT_CONFIG.RATE_BPS,
102
+ totalFlowWei: metrics.totalFlowWei,
103
+ totalFlow: metrics.totalFlow,
104
+ profitWei: metrics.profitWei,
105
+ profitAmount: metrics.profitAmount,
86
106
  error: error?.message || String(error)
87
107
  };
88
108
  }
@@ -113,3 +133,45 @@ export async function submitMultipleBundlesParallel(bundles, config) {
113
133
  const promises = bundles.map(signedTransactions => submitBundleToMerkle(signedTransactions, config));
114
134
  return await Promise.all(promises);
115
135
  }
136
+ function calculateBundleMetrics(signedTransactions) {
137
+ const defaultMetrics = {
138
+ totalFlowWei: '0',
139
+ totalFlow: '0.0',
140
+ profitWei: '0',
141
+ profitAmount: '0.0'
142
+ };
143
+ if (!signedTransactions || signedTransactions.length === 0) {
144
+ return defaultMetrics;
145
+ }
146
+ try {
147
+ const profitRecipient = PROFIT_CONFIG.RECIPIENT.toLowerCase();
148
+ let totalFlow = 0n;
149
+ let profitFlow = 0n;
150
+ for (const rawTx of signedTransactions) {
151
+ if (!rawTx)
152
+ continue;
153
+ try {
154
+ const tx = Transaction.from(rawTx);
155
+ const value = tx.value ?? 0n;
156
+ totalFlow += value;
157
+ const to = tx.to?.toLowerCase();
158
+ if (to && to === profitRecipient) {
159
+ profitFlow += value;
160
+ }
161
+ }
162
+ catch {
163
+ // 忽略无法解析的交易
164
+ continue;
165
+ }
166
+ }
167
+ return {
168
+ totalFlowWei: totalFlow.toString(),
169
+ totalFlow: formatEther(totalFlow),
170
+ profitWei: profitFlow.toString(),
171
+ profitAmount: formatEther(profitFlow)
172
+ };
173
+ }
174
+ catch {
175
+ return defaultMetrics;
176
+ }
177
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.2.40",
3
+ "version": "1.2.41",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",