four-flap-meme-sdk 1.5.12 → 1.5.13

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.
@@ -98,6 +98,7 @@ export const ADDRESSES = {
98
98
  USDT: '0x1e4a5963abfd975d8c9021ce480b42188849d41d', // 6位精度(不一定被 Flap 内盘支持)
99
99
  USDC: '0x74b7f16337b8972027f6196a17a631ac6de26d22', // 6位精度(不一定被 Flap 内盘支持)
100
100
  USDT0: '0x779ded0c9e1022225f8e0630b35a9b54be713736', // 6位精度(USD₮0)
101
+ // ✅ USD₮0(Tether USD0)
101
102
  },
102
103
  MORPH: {
103
104
  // Flap Portal
@@ -2,6 +2,11 @@ import { Contract, Wallet, JsonRpcProvider, Interface, parseUnits } from 'ethers
2
2
  import { ADDRESSES, ZERO_ADDRESS } from './constants.js';
3
3
  import { NonceManager } from './bundle-helpers.js';
4
4
  import { ERC20_ABI, MULTICALL3_ABI } from '../abis/common.js';
5
+ // ============================================================================
6
+ // ✅ Max approval(与 BSC 策略一致:阈值判断,避免频繁重复授权)
7
+ // ============================================================================
8
+ const MAX_UINT256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
9
+ const MAX_APPROVAL_THRESHOLD = MAX_UINT256 / 2n;
5
10
  /**
6
11
  * 验证合约地址是否有效(是否部署了代码)
7
12
  */
@@ -408,7 +413,8 @@ export async function approveTokenRaw(rpcUrl, privateKey, tokenAddress, spenderA
408
413
  await validateContractAddress(provider, normalizedToken, 'Token');
409
414
  await validateContractAddress(provider, normalizedSpender, 'Spender');
410
415
  const erc20 = new Contract(normalizedToken, ERC20_ABI, signer);
411
- const requiredAmount = amount === 'max' ? BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') : amount;
416
+ const isMax = amount === 'max';
417
+ const requiredAmount = isMax ? MAX_UINT256 : amount;
412
418
  // 检查当前授权额度
413
419
  let currentAllowance;
414
420
  try {
@@ -418,7 +424,8 @@ export async function approveTokenRaw(rpcUrl, privateKey, tokenAddress, spenderA
418
424
  throw new Error(`❌ 查询授权额度失败: ${error.message}`);
419
425
  }
420
426
  // 如果已经授权足够,直接返回
421
- if (currentAllowance >= requiredAmount) {
427
+ // max 授权:使用阈值判断,避免每次消耗一点 allowance 都重新授权
428
+ if (isMax ? (currentAllowance >= MAX_APPROVAL_THRESHOLD) : (currentAllowance >= requiredAmount)) {
422
429
  return {
423
430
  alreadyApproved: true,
424
431
  currentAllowance,
@@ -495,8 +502,9 @@ export async function approveTokenBatchRaw(params) {
495
502
  // ✅ 优化:批量创建钱包和合约实例
496
503
  const wallets = privateKeys.map(key => new Wallet(key, provider));
497
504
  const ownerAddresses = wallets.map(w => w.address);
505
+ const isMaxApprovals = amounts.map(a => a === 'max');
498
506
  const requiredAmounts = amounts.map(amount => amount === 'max'
499
- ? BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')
507
+ ? MAX_UINT256
500
508
  : amount);
501
509
  // ==================== signOnly=true:只签名不提交 ====================
502
510
  if (signOnly) {
@@ -517,8 +525,10 @@ export async function approveTokenBatchRaw(params) {
517
525
  const ownerAddress = ownerAddresses[i];
518
526
  const currentAllowance = currentAllowances[i];
519
527
  const requiredAmount = requiredAmounts[i];
528
+ const isMax = isMaxApprovals[i];
520
529
  // 如果已经授权足够,跳过
521
- if (currentAllowance >= requiredAmount) {
530
+ // max 授权:使用阈值判断(与 BSC 一致)
531
+ if (isMax ? (currentAllowance >= MAX_APPROVAL_THRESHOLD) : (currentAllowance >= requiredAmount)) {
522
532
  return {
523
533
  owner: ownerAddress,
524
534
  alreadyApproved: true,
@@ -568,9 +578,11 @@ export async function approveTokenBatchRaw(params) {
568
578
  const ownerAddress = ownerAddresses[i];
569
579
  const currentAllowance = currentAllowances[i];
570
580
  const requiredAmount = requiredAmounts[i];
581
+ const isMax = isMaxApprovals[i];
571
582
  try {
572
583
  // 如果已经授权足够,跳过
573
- if (currentAllowance >= requiredAmount) {
584
+ // max 授权:使用阈值判断(与 BSC 一致)
585
+ if (isMax ? (currentAllowance >= MAX_APPROVAL_THRESHOLD) : (currentAllowance >= requiredAmount)) {
574
586
  return {
575
587
  owner: ownerAddress,
576
588
  alreadyApproved: true,
@@ -27,7 +27,7 @@ export declare const QUOTE_CONFIG: {
27
27
  readonly v2Router: "0x881fb2f98c13d521009464e7d1cbf16e1b394e8e";
28
28
  readonly v3Quoter: "";
29
29
  readonly wrappedNative: "0xe538905cf8410324e03a5a23c1c177a474d59b2b";
30
- readonly stableCoins: readonly ["0x1E4a5963aBFD975d8c9021ce480b42188849D41d"];
30
+ readonly stableCoins: readonly ["0x1E4a5963aBFD975d8c9021ce480b42188849D41d", "0x74b7f16337b8972027f6196a17a631ac6de26d22", "0x779ded0c9e1022225f8e0630b35a9b54be713736"];
31
31
  };
32
32
  };
33
33
  export type SupportedChain = keyof typeof QUOTE_CONFIG;
@@ -39,6 +39,8 @@ export const QUOTE_CONFIG = {
39
39
  wrappedNative: '0xe538905cf8410324e03a5a23c1c177a474d59b2b', // WOKB
40
40
  stableCoins: [
41
41
  '0x1E4a5963aBFD975d8c9021ce480b42188849D41d', // USDT
42
+ '0x74b7f16337b8972027f6196a17a631ac6de26d22', // USDC
43
+ '0x779ded0c9e1022225f8e0630b35a9b54be713736', // USD₮0
42
44
  ],
43
45
  },
44
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "four-flap-meme-sdk",
3
- "version": "1.5.12",
3
+ "version": "1.5.13",
4
4
  "description": "SDK for Flap bonding curve and four.meme TokenManager",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",