@wtflabs/x402 0.0.1-beta.11 → 0.0.1-beta.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.
@@ -2955,6 +2955,22 @@ async function createPaymentHeader3(client, x402Version, paymentRequirements) {
2955
2955
  }
2956
2956
 
2957
2957
  // src/schemes/exact/evm/utils/tokenDetection.ts
2958
+ var paymentMethodsCache = /* @__PURE__ */ new Map();
2959
+ var recommendedMethodCache = /* @__PURE__ */ new Map();
2960
+ var PRESET_TOKEN_CAPABILITIES = {
2961
+ // World Liberty Financial USD - 只支持 permit
2962
+ "0x8d0d000ee44948fc98c9b98a4fa4921476f08b0d": {
2963
+ supportedMethods: ["permit"],
2964
+ supportedNetworks: [56],
2965
+ description: "World Liberty Financial USD (WLFI)"
2966
+ }
2967
+ // 可以继续添加更多预设代币
2968
+ // 示例:
2969
+ // "0x其他代币地址": {
2970
+ // supportedMethods: ["eip3009", "permit"],
2971
+ // description: "代币名称",
2972
+ // },
2973
+ };
2958
2974
  var EIP3009_SIGNATURES = ["0xe3ee160e", "0xcf092995"];
2959
2975
  var EIP2612_PERMIT = "0xd505accf";
2960
2976
  var PERMIT2_ADDRESS2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
@@ -3085,6 +3101,48 @@ async function checkPermit2Support(client) {
3085
3101
  }
3086
3102
  async function detectTokenPaymentMethods(tokenAddress, client) {
3087
3103
  const address = tokenAddress.toLowerCase();
3104
+ const chainId = await client.getChainId();
3105
+ const cacheKey = `${chainId}:${address}`;
3106
+ const cached = paymentMethodsCache.get(cacheKey);
3107
+ if (cached) {
3108
+ console.log(`\u{1F4BE} Using cached payment methods for token ${address}`);
3109
+ return cached;
3110
+ }
3111
+ const presetCapabilities = PRESET_TOKEN_CAPABILITIES[address];
3112
+ if (presetCapabilities) {
3113
+ if (!chainId || !presetCapabilities.supportedNetworks.includes(chainId)) {
3114
+ return {
3115
+ address,
3116
+ supportedMethods: [],
3117
+ details: {
3118
+ hasEIP3009: false,
3119
+ hasPermit: false,
3120
+ hasPermit2Approval: false
3121
+ }
3122
+ };
3123
+ }
3124
+ const hasEIP30092 = presetCapabilities.supportedMethods.includes("eip3009");
3125
+ const hasPermit2 = presetCapabilities.supportedMethods.includes("permit");
3126
+ const hasPermit2Approval2 = presetCapabilities.supportedMethods.includes("permit2") || presetCapabilities.supportedMethods.includes("permit2-witness");
3127
+ if (hasEIP30092) {
3128
+ console.log(" \u2705 EIP-3009 (transferWithAuthorization) - from preset");
3129
+ }
3130
+ if (hasPermit2) {
3131
+ console.log(" \u2705 EIP-2612 (permit) - from preset");
3132
+ }
3133
+ if (hasPermit2Approval2) {
3134
+ console.log(" \u2705 Permit2 support - from preset");
3135
+ }
3136
+ return {
3137
+ address,
3138
+ supportedMethods: presetCapabilities.supportedMethods,
3139
+ details: {
3140
+ hasEIP3009: hasEIP30092,
3141
+ hasPermit: hasPermit2,
3142
+ hasPermit2Approval: hasPermit2Approval2
3143
+ }
3144
+ };
3145
+ }
3088
3146
  console.log(`\u{1F50D} Detecting payment methods for token ${address}...`);
3089
3147
  const [hasEIP3009, hasPermit, hasPermit2Approval] = await Promise.all([
3090
3148
  hasAnyMethod(client, address, EIP3009_SIGNATURES),
@@ -3108,7 +3166,7 @@ async function detectTokenPaymentMethods(tokenAddress, client) {
3108
3166
  if (supportedMethods.length === 0) {
3109
3167
  console.log(" \u26A0\uFE0F No advanced payment methods detected (standard ERC-20 only)");
3110
3168
  }
3111
- return {
3169
+ const result = {
3112
3170
  address,
3113
3171
  supportedMethods,
3114
3172
  details: {
@@ -3117,16 +3175,30 @@ async function detectTokenPaymentMethods(tokenAddress, client) {
3117
3175
  hasPermit2Approval
3118
3176
  }
3119
3177
  };
3178
+ paymentMethodsCache.set(cacheKey, result);
3179
+ return result;
3120
3180
  }
3121
3181
  async function getRecommendedPaymentMethod(tokenAddress, client) {
3182
+ const address = tokenAddress.toLowerCase();
3183
+ const chainId = await client.getChainId();
3184
+ const cacheKey = `${chainId}:${address}`;
3185
+ const cached = recommendedMethodCache.get(cacheKey);
3186
+ if (cached !== void 0) {
3187
+ console.log(`\u{1F4BE} Using cached recommended method for token ${address}`);
3188
+ return cached;
3189
+ }
3122
3190
  const capabilities = await detectTokenPaymentMethods(tokenAddress, client);
3123
3191
  const { supportedMethods } = capabilities;
3124
- if (supportedMethods.includes("eip3009")) return "eip3009";
3125
- if (supportedMethods.includes("permit")) return "permit";
3126
- if (supportedMethods.includes("permit2") || supportedMethods.includes("permit2-witness")) {
3127
- return "permit2";
3128
- }
3129
- return null;
3192
+ let result = null;
3193
+ if (supportedMethods.includes("eip3009")) {
3194
+ result = "eip3009";
3195
+ } else if (supportedMethods.includes("permit")) {
3196
+ result = "permit";
3197
+ } else if (supportedMethods.includes("permit2") || supportedMethods.includes("permit2-witness")) {
3198
+ result = "permit2";
3199
+ }
3200
+ recommendedMethodCache.set(cacheKey, result);
3201
+ return result;
3130
3202
  }
3131
3203
  async function getTokenInfo(tokenAddress, client) {
3132
3204
  const address = tokenAddress.toLowerCase();