four-flap-meme-sdk 4.4.3 → 4.5.1

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 (57) hide show
  1. package/README.md +16 -22
  2. package/dist/bundle/four-meme/types/buy-first.d.ts +2 -1
  3. package/dist/bundle/four-meme/types/config.d.ts +2 -1
  4. package/dist/bundle/four-meme/types/swap-types.d.ts +2 -1
  5. package/dist/bundle/four-meme/utils-sweep/erc20-no-hop.js +16 -8
  6. package/dist/bundle/four-meme/utils-sweep/main.js +15 -1
  7. package/dist/bundle/four-meme/utils-sweep/native-no-hop.js +17 -9
  8. package/dist/bundle/index.d.ts +1 -1
  9. package/dist/bundle/index.js +1 -1
  10. package/dist/bundle/internal.d.ts +2 -0
  11. package/dist/bundle/internal.js +7 -3
  12. package/dist/bundle/submit/index.d.ts +1 -3
  13. package/dist/bundle/submit/index.js +1 -3
  14. package/dist/chains/bsc/index.d.ts +1 -1
  15. package/dist/chains/bsc/index.js +1 -1
  16. package/dist/chains/bsc/pancake/bundle-buy-first-types.d.ts +2 -1
  17. package/dist/chains/bsc/pancake/bundle-swap-types.d.ts +2 -1
  18. package/dist/chains/bsc/platforms/four/index.d.ts +1 -1
  19. package/dist/chains/bsc/platforms/four/index.js +1 -1
  20. package/dist/core/clients/blockrazor.js +8 -6
  21. package/dist/core/clients/blockrazor.test.d.ts +1 -0
  22. package/dist/core/clients/blockrazor.test.js +23 -0
  23. package/dist/core/clients/index.d.ts +0 -1
  24. package/dist/core/clients/index.js +0 -1
  25. package/dist/core/clients/merkle.js +12 -7
  26. package/dist/core/clients/merkle.test.d.ts +1 -0
  27. package/dist/core/clients/merkle.test.js +8 -0
  28. package/dist/core/nonce/nonce-manager.d.ts +2 -0
  29. package/dist/core/nonce/nonce-manager.js +21 -1
  30. package/dist/core/tx/wallet-sign-patch.js +22 -11
  31. package/dist/core/tx/wallet-sign-patch.test.d.ts +1 -0
  32. package/dist/core/tx/wallet-sign-patch.test.js +21 -0
  33. package/dist/domains/dex/direct-router-approvals.d.ts +28 -0
  34. package/dist/domains/dex/direct-router-approvals.js +45 -0
  35. package/dist/domains/dex/direct-router-helpers.d.ts +1 -0
  36. package/dist/domains/dex/direct-router-helpers.js +1 -0
  37. package/dist/domains/dex/direct-router-v2-buy.js +13 -0
  38. package/dist/domains/dex/direct-router-v3.js +43 -4
  39. package/dist/domains/flap/portal-bundle-merkle/private/buy.js +3 -3
  40. package/dist/domains/flap/portal-bundle-merkle/private/helpers.d.ts +1 -1
  41. package/dist/domains/flap/portal-bundle-merkle/private/helpers.js +4 -8
  42. package/dist/domains/flap/portal-bundle-merkle/private/sell.js +3 -3
  43. package/dist/domains/flap/portal-bundle-merkle/swap-buy-first-types.d.ts +2 -1
  44. package/dist/domains/flap/portal-bundle-merkle/swap-helpers.d.ts +2 -1
  45. package/dist/domains/flap/portal-bundle-merkle/swap-planning.js +5 -2
  46. package/dist/domains/flap/portal-bundle-merkle/swap-planning.test.d.ts +1 -0
  47. package/dist/domains/flap/portal-bundle-merkle/swap-planning.test.js +16 -0
  48. package/dist/domains/flap/portal-bundle-merkle/types-config.d.ts +2 -1
  49. package/dist/domains/merkle/index.d.ts +1 -1
  50. package/dist/domains/merkle/index.js +1 -1
  51. package/dist/exports/root-bundle-and-tooling.d.ts +1 -1
  52. package/dist/exports/root-bundle-and-tooling.js +1 -1
  53. package/dist/exports/root-foundations.d.ts +0 -1
  54. package/dist/exports/root-foundations.js +0 -1
  55. package/dist/utils/swap-helpers.d.ts +1 -15
  56. package/dist/utils/swap-helpers.js +0 -80
  57. package/package.json +1 -1
@@ -2,88 +2,8 @@
2
2
  * 换手交易通用工具函数
3
3
  */
4
4
  import { ethers, Contract, Interface } from 'ethers';
5
- import { batchCheckAllowances } from '../core/erc20/index.js';
6
5
  import { ERC20_ABI, MULTICALL3_ABI } from '../abis/common.js';
7
6
  import { getMulticall3Address } from '../core/constants/index.js';
8
- import { NonceManager, getOptimizedGasPrice } from './bundle-helpers.js';
9
- const APPROVAL_THRESHOLD = ethers.MaxUint256 / 2n;
10
- /**
11
- * 获取 Gas Limit(授权专用)
12
- * 优先使用 config.gasLimit,否则使用默认值 * multiplier
13
- *
14
- * ✅ ethers v6 最佳实践:直接使用 bigint 类型
15
- */
16
- function getApprovalGasLimit(config, defaultGas = 80000) {
17
- // 优先使用前端传入的 gasLimit
18
- if (config.gasLimit !== undefined) {
19
- // 如果已经是 bigint,直接返回;否则转换
20
- return typeof config.gasLimit === 'bigint' ? config.gasLimit : BigInt(config.gasLimit);
21
- }
22
- // 使用默认值 * multiplier
23
- const multiplier = config.gasLimitMultiplier ?? 1.0;
24
- const calculatedGas = Math.ceil(defaultGas * multiplier);
25
- // JavaScript 原生 BigInt 转换(ethers v6 兼容)
26
- return BigInt(calculatedGas);
27
- }
28
- /**
29
- * 检查并执行代币授权(如果需要)
30
- * ✅ 与 pancake-proxy.ts 的授权逻辑一致
31
- */
32
- export async function ensureTokenApproval(provider, merkle, wallet, tokenAddress, spenderAddress, config) {
33
- // 使用Multicall3批量检查(虽然只有一个地址,但保持接口一致)
34
- const allowances = await batchCheckAllowances(provider, tokenAddress, [wallet.address], spenderAddress);
35
- const currentAllowance = allowances[0];
36
- if (currentAllowance >= APPROVAL_THRESHOLD) {
37
- return;
38
- }
39
- // ✅ 使用 NonceManager(与 pancake-proxy.ts 一致)
40
- const nonceManager = new NonceManager(provider);
41
- // 构建授权交易
42
- const tokenContract = new Contract(tokenAddress, ERC20_ABI, wallet);
43
- const approveUnsigned = await tokenContract.approve.populateTransaction(spenderAddress, ethers.MaxUint256);
44
- // ✅ 使用 getApprovalGasLimit 函数处理 Gas Limit(与 pancake-proxy.ts 一致)
45
- const approveGasLimit = getApprovalGasLimit(config, 80000);
46
- // ✅ 使用 getOptimizedGasPrice 处理 Gas Price(与 pancake-proxy.ts 一致)
47
- const gasPriceConfig = {};
48
- if (config.minGasPriceGwei !== undefined) {
49
- gasPriceConfig.baseGasPrice = ethers.parseUnits(String(config.minGasPriceGwei), 'gwei');
50
- gasPriceConfig.multiplierPercent = 0;
51
- }
52
- if (config.maxGasPriceGwei !== undefined) {
53
- gasPriceConfig.maxGasPrice = ethers.parseUnits(String(config.maxGasPriceGwei), 'gwei');
54
- }
55
- const gasPrice = await getOptimizedGasPrice(provider, gasPriceConfig);
56
- // ✅ 使用 NonceManager 获取 nonce
57
- const nonce = await nonceManager.getNextNonce(wallet);
58
- // ✅ 获取 chainId(不硬编码)
59
- const network = await provider.getNetwork();
60
- const chainId = Number(network.chainId);
61
- // 签名
62
- const signedTx = await wallet.signTransaction({
63
- ...approveUnsigned,
64
- from: wallet.address,
65
- nonce,
66
- gasLimit: approveGasLimit,
67
- gasPrice,
68
- chainId,
69
- type: config.txType ?? 0,
70
- });
71
- // 清理临时 nonce 缓存
72
- nonceManager.clearTemp();
73
- // ✅ 提交 Bundle(使用 blockOffset)
74
- const blockOffset = config.bundleBlockOffset ?? 5;
75
- const bundleResult = await merkle.sendBundle({
76
- transactions: [signedTx],
77
- blockOffset,
78
- minTimestamp: 0,
79
- maxTimestamp: 0,
80
- });
81
- // 等待确认
82
- const results = await merkle.waitForBundleConfirmation(bundleResult.txHashes, 1, config.waitTimeoutMs ?? 120000);
83
- if (!results[0]?.success) {
84
- throw new Error(`授权失败: ${results[0]?.error || '未知错误'}`);
85
- }
86
- }
87
7
  async function readDecimalsAndBalance(provider, tokenAddress, walletAddress) {
88
8
  try {
89
9
  const chainId = Number((await provider.getNetwork()).chainId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "4.4.3",
3
+ "version": "4.5.1",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",