@zkp2p/sdk 0.2.1 → 0.2.3

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.
package/dist/index.cjs CHANGED
@@ -305,13 +305,12 @@ function getContracts(chainId, env = "production") {
305
305
  escrowV2: pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"]),
306
306
  escrowAddresses: uniqueAddresses(
307
307
  pickAddress(baseContracts, ["EscrowV2", "Escrow_V2"]),
308
- ...exports.HISTORICAL_ESCROW_ADDRESSES.base
308
+ pickAddress(baseContracts, ["Escrow"])
309
309
  ),
310
310
  orchestrator: pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"]) ?? pickAddress(baseContracts, ["Orchestrator"]),
311
311
  orchestratorV2: pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"]),
312
312
  orchestratorAddresses: uniqueAddresses(
313
- pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"]),
314
- ...HISTORICAL_ORCHESTRATOR_ADDRESSES.base
313
+ pickAddress(baseContracts, ["OrchestratorV2", "Orchestrator_V2"])
315
314
  ),
316
315
  unifiedPaymentVerifier: pickAddress(baseContracts, [
317
316
  "UnifiedPaymentVerifierV2",
@@ -369,28 +368,22 @@ function getContracts(chainId, env = "production") {
369
368
  "VITE_BASE_STAGING_ESCROW_V2_ADDRESS",
370
369
  "VITE_ESCROW_V2_ADDRESS"
371
370
  ]);
372
- const stagingEscrowCurrent = stagingEscrowV2Override ?? pickAddress(sc, ["EscrowV2", "Escrow_V2"]) ?? pickAddress(sc, ["Escrow"]) ?? STAGING_ESCROW_V2_FALLBACK;
371
+ const stagingEscrowCurrent = stagingEscrowV2Override ?? pickAddress(sc, ["EscrowV2", "Escrow_V2"]) ?? pickAddress(sc, ["Escrow"]);
373
372
  const stagingOrchestratorV2Override = resolveRuntimeAddressOverride([
374
373
  "VITE_BASE_STAGING_ORCHESTRATOR_V2_ADDRESS",
375
374
  "VITE_ORCHESTRATOR_V2_ADDRESS",
376
375
  "VITE_ORCHESTRATORV2_ADDRESS"
377
376
  ]);
378
- const stagingOrchestratorCurrent = stagingOrchestratorV2Override ?? pickAddress(sc, ["OrchestratorV2", "Orchestrator_V2"]) ?? pickAddress(sc, ["Orchestrator"]) ?? STAGING_ORCHESTRATOR_V2_FALLBACK;
377
+ const stagingOrchestratorCurrent = stagingOrchestratorV2Override ?? pickAddress(sc, ["OrchestratorV2", "Orchestrator_V2"]) ?? pickAddress(sc, ["Orchestrator"]);
379
378
  const stagingRateManagerV1 = pickAddress(sc, ["RateManagerV1", "DepositRateManagerRegistryV1"]);
380
379
  return {
381
380
  addresses: {
382
381
  escrow: stagingEscrowCurrent,
383
382
  escrowV2: stagingEscrowCurrent,
384
- escrowAddresses: uniqueAddresses(
385
- stagingEscrowCurrent,
386
- ...exports.HISTORICAL_ESCROW_ADDRESSES.base_staging
387
- ),
383
+ escrowAddresses: uniqueAddresses(stagingEscrowCurrent),
388
384
  orchestrator: stagingOrchestratorCurrent,
389
385
  orchestratorV2: stagingOrchestratorCurrent,
390
- orchestratorAddresses: uniqueAddresses(
391
- stagingOrchestratorCurrent,
392
- ...HISTORICAL_ORCHESTRATOR_ADDRESSES.base_staging
393
- ),
386
+ orchestratorAddresses: uniqueAddresses(stagingOrchestratorCurrent),
394
387
  unifiedPaymentVerifier: pickAddress(sc, [
395
388
  "UnifiedPaymentVerifierV2",
396
389
  "UnifiedPaymentVerifier"
@@ -466,10 +459,7 @@ function getPaymentMethodsCatalog(_chainId, env = "production") {
466
459
  const methods = src?.methods ?? {};
467
460
  return methods;
468
461
  }
469
- function getGatingServiceAddress(_chainId, env = "production") {
470
- if (env === "staging") {
471
- return "0x396D31055Db28C0C6f36e8b36f18FE7227248a97";
472
- }
462
+ function getGatingServiceAddress(_chainId, _env = "production") {
473
463
  return "0x396D31055Db28C0C6f36e8b36f18FE7227248a97";
474
464
  }
475
465
  function getRateManagerContracts(chainId, env = "production") {
@@ -492,41 +482,9 @@ function getRateManagerContracts(chainId, env = "production") {
492
482
  }
493
483
  };
494
484
  }
495
- exports.HISTORICAL_ESCROW_ADDRESSES = void 0; var HISTORICAL_ORCHESTRATOR_ADDRESSES, STAGING_ESCROW_V2_FALLBACK, STAGING_ORCHESTRATOR_V2_FALLBACK, ZERO_ADDRESS2, baseAddresses, baseStagingAddresses, basePaymentMethods, baseStagingPaymentMethods, baseConstants, baseStagingConstants;
485
+ var ZERO_ADDRESS2, baseAddresses, baseStagingAddresses, basePaymentMethods, baseStagingPaymentMethods, baseConstants, baseStagingConstants;
496
486
  var init_contracts = __esm({
497
487
  "src/contracts.ts"() {
498
- exports.HISTORICAL_ESCROW_ADDRESSES = {
499
- base: [
500
- "0x2f121CDDCA6d652f35e8B3E560f9760898888888"
501
- // EscrowV2 production (contracts-v2 0.2.0-rc.6)
502
- ],
503
- base_staging: [
504
- "0x5C2a8D9246777eE4501B6C426a8B8C7635C7b5b5",
505
- // EscrowV2 staging (contracts-v2 0.2.0-rc.5)
506
- "0x18EAcBf3FF19528ABe8035CF5cA266F31A2e3f14",
507
- // EscrowV2 staging (contracts-v2 0.1.11-rc.3)
508
- "0x07Cc97c254A5Fb0957553E9F58E4040699357f28",
509
- // EscrowV2 staging (contracts-v2 0.1.11-rc.2)
510
- "0x8455b9a31041125C785044f45458eCf2cbB12eF7",
511
- // v2.1 staging Escrow (2025-10-18, PR #83)
512
- "0x21f007107269ea1c8Fe0730736548090F4945736"
513
- // v2.1 staging Escrow (2025-10-04, PR #71)
514
- ]
515
- };
516
- HISTORICAL_ORCHESTRATOR_ADDRESSES = {
517
- base: [
518
- "0x88888883Ed048FF0a415271B28b2F52d431810D0"
519
- // OrchestratorV2 production (contracts-v2 0.2.0-rc.6)
520
- ],
521
- base_staging: [
522
- "0xF9b9CD27Deea496B960b3cb5221b514705fCaF5e",
523
- // OrchestratorV2 staging (contracts-v2 0.2.0-rc.5)
524
- "0xC0389b3d7A4E6B823e361e562C4a29F04B6C4fB5"
525
- // OrchestratorV2 staging (contracts-v2 0.1.11-rc.3)
526
- ]
527
- };
528
- STAGING_ESCROW_V2_FALLBACK = "0x77e8f808FE201075e0bD651CD46fdF239fc83265";
529
- STAGING_ORCHESTRATOR_V2_FALLBACK = "0xc17a59227B136c45fAa153086a15EF87ED14bE00";
530
488
  ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
531
489
  baseAddresses = unwrapAddresses(baseAddressesRaw__default.default);
532
490
  baseStagingAddresses = unwrapAddresses(baseStagingAddressesRaw__default.default);
@@ -1391,7 +1349,7 @@ var ContractRouter = class {
1391
1349
  }
1392
1350
  ];
1393
1351
  }
1394
- resolveOrchestratorForEscrow(escrowAddress, _preferV2 = false) {
1352
+ resolveOrchestratorForEscrow(escrowAddress) {
1395
1353
  if (escrowAddress) {
1396
1354
  const escrowContext = this.getEscrowContextByAddress(escrowAddress);
1397
1355
  const fromEscrow = this.getOrchestratorContextByAddress(escrowContext?.orchestratorAddress);
@@ -1447,9 +1405,6 @@ var ContractRouter = class {
1447
1405
  }
1448
1406
  return contexts;
1449
1407
  }
1450
- get defaultPreferV2() {
1451
- return true;
1452
- }
1453
1408
  };
1454
1409
 
1455
1410
  // src/adapters/verification.ts
@@ -1503,9 +1458,9 @@ function createHeaders(apiKey, authorizationToken) {
1503
1458
  headers2["Authorization"] = authorizationToken.startsWith("Bearer ") ? authorizationToken : `Bearer ${authorizationToken}`;
1504
1459
  return headers2;
1505
1460
  }
1506
- async function postSignIntentWithRetry(endpoint, request, opts) {
1507
- const url = `${opts.baseApiUrl.replace(/\/$/, "")}${endpoint}`;
1508
- return withRetry(
1461
+ async function apiSignIntentV3(request, opts) {
1462
+ const url = `${opts.baseApiUrl.replace(/\/$/, "")}/v3/intent`;
1463
+ const json = await withRetry(
1509
1464
  async () => {
1510
1465
  let res;
1511
1466
  try {
@@ -1515,7 +1470,10 @@ async function postSignIntentWithRetry(endpoint, request, opts) {
1515
1470
  body: JSON.stringify(request)
1516
1471
  });
1517
1472
  } catch (error) {
1518
- throw new exports.NetworkError("Failed to connect to API server", { endpoint, error });
1473
+ throw new exports.NetworkError("Failed to connect to API server", {
1474
+ endpoint: "/v3/intent",
1475
+ error
1476
+ });
1519
1477
  }
1520
1478
  if (!res.ok) {
1521
1479
  const text = await res.text().catch(() => "");
@@ -1527,9 +1485,6 @@ async function postSignIntentWithRetry(endpoint, request, opts) {
1527
1485
  1e3,
1528
1486
  opts.timeoutMs
1529
1487
  );
1530
- }
1531
- async function apiSignIntentV3(request, opts) {
1532
- const json = await postSignIntentWithRetry("/v3/intent", request, opts);
1533
1488
  const sig = json?.responseObject?.signedIntent;
1534
1489
  const expStr = json?.responseObject?.intentData?.signatureExpiration ?? json?.responseObject?.signatureExpiration;
1535
1490
  const preIntentHookData = json?.responseObject?.intentData?.preIntentHookData ?? json?.responseObject?.preIntentHookData;
@@ -1540,22 +1495,6 @@ async function apiSignIntentV3(request, opts) {
1540
1495
  preIntentHookData
1541
1496
  };
1542
1497
  }
1543
- async function apiSignIntentV2(request, opts) {
1544
- const json = await postSignIntentWithRetry(
1545
- "/v2/verify/intent",
1546
- request,
1547
- opts
1548
- );
1549
- const sig = json?.responseObject?.signedIntent;
1550
- const expStr = json?.responseObject?.intentData?.signatureExpiration ?? json?.responseObject?.signatureExpiration;
1551
- const preIntentHookData = json?.responseObject?.intentData?.preIntentHookData ?? json?.responseObject?.preIntentHookData;
1552
- if (!sig || !expStr) throw new Error("verify/intent missing signature or expiration");
1553
- return {
1554
- signature: sig,
1555
- signatureExpiration: BigInt(expStr),
1556
- preIntentHookData
1557
- };
1558
- }
1559
1498
 
1560
1499
  // src/adapters/attestation.ts
1561
1500
  init_errors();
@@ -1951,59 +1890,7 @@ function resolvePlatformAttestationConfig(platformName) {
1951
1890
  return config;
1952
1891
  }
1953
1892
 
1954
- // src/utils/logger.ts
1955
- var currentLevel = "info";
1956
- function setLogLevel(level) {
1957
- currentLevel = level;
1958
- }
1959
- function shouldLog(level) {
1960
- switch (currentLevel) {
1961
- case "debug":
1962
- return true;
1963
- case "info":
1964
- return level !== "debug";
1965
- case "error":
1966
- return level === "error";
1967
- default:
1968
- return true;
1969
- }
1970
- }
1971
- var logger = {
1972
- debug: (...args) => {
1973
- if (shouldLog("debug")) {
1974
- console.log("[DEBUG]", ...args);
1975
- }
1976
- },
1977
- info: (...args) => {
1978
- if (shouldLog("info")) {
1979
- console.log("[INFO]", ...args);
1980
- }
1981
- },
1982
- warn: (...args) => {
1983
- if (shouldLog("info")) {
1984
- console.warn("[WARN]", ...args);
1985
- }
1986
- },
1987
- error: (...args) => {
1988
- console.error("[ERROR]", ...args);
1989
- }
1990
- };
1991
-
1992
1893
  // src/client/IntentOperations.ts
1993
- function isV2SignalIntentAbi(abi) {
1994
- for (const item of abi) {
1995
- if (item.type === "function" && item.name === "signalIntent" && Array.isArray(item.inputs)) {
1996
- const inputs = item.inputs;
1997
- for (const input of inputs) {
1998
- if (input.components) {
1999
- if (input.components.some((c) => c.name === "referralFees")) return true;
2000
- if (input.components.some((c) => c.name === "referrerFee")) return false;
2001
- }
2002
- }
2003
- }
2004
- }
2005
- return true;
2006
- }
2007
1894
  var IntentOperations = class {
2008
1895
  constructor(config) {
2009
1896
  this.config = config;
@@ -2018,18 +1905,14 @@ var IntentOperations = class {
2018
1905
  "signalIntent referrerFeeConfig cannot be combined with referralFees, referrer, or referrerFee."
2019
1906
  );
2020
1907
  }
2021
- const preferV2 = this.config.getDefaultPreferV2();
2022
1908
  const escrowContext = this.config.host.resolveEscrowContext({
2023
1909
  escrowAddress: params.escrowAddress,
2024
- depositId: params.depositId,
2025
- preferV2
1910
+ depositId: params.depositId
2026
1911
  });
2027
1912
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2028
1913
  orchestratorAddress: params.orchestratorAddress,
2029
- escrowAddress: escrowContext.address,
2030
- preferV2
1914
+ escrowAddress: escrowContext.address
2031
1915
  });
2032
- const useV2Encoding = isV2SignalIntentAbi(orchestratorContext.abi);
2033
1916
  const catalog = getPaymentMethodsCatalog(this.config.getChainId(), this.config.getRuntimeEnv());
2034
1917
  const paymentMethod = resolvePaymentMethodHashFromCatalog(params.processorName, catalog);
2035
1918
  const fiatCurrency = resolveFiatCurrencyBytes32(params.fiatCurrencyCode);
@@ -2048,28 +1931,25 @@ var IntentOperations = class {
2048
1931
  const apiKey = this.config.getApiKey();
2049
1932
  const authorizationToken = this.config.getAuthorizationToken();
2050
1933
  if ((!gatingServiceSignature || !signatureExpiration) && baseApiUrl && (apiKey || authorizationToken)) {
2051
- const baseRequest = {
2052
- processorName: params.processorName,
2053
- payeeDetails: params.payeeDetails,
2054
- depositId: depositId.toString(),
2055
- amount: amount.toString(),
2056
- toAddress: params.toAddress,
2057
- paymentMethod,
2058
- fiatCurrency,
2059
- conversionRate: conversionRate.toString(),
2060
- chainId: this.config.getChainId().toString(),
2061
- orchestratorAddress: orchestratorContext.address,
2062
- escrowAddress: escrowContext.address
2063
- };
2064
1934
  const apiOpts = {
2065
1935
  baseApiUrl,
2066
1936
  apiKey,
2067
1937
  authorizationToken,
2068
1938
  timeoutMs: this.config.getApiTimeoutMs()
2069
1939
  };
2070
- const response = useV2Encoding ? await apiSignIntentV3(
1940
+ const response = await apiSignIntentV3(
2071
1941
  {
2072
- ...baseRequest,
1942
+ processorName: params.processorName,
1943
+ payeeDetails: params.payeeDetails,
1944
+ depositId: depositId.toString(),
1945
+ amount: amount.toString(),
1946
+ toAddress: params.toAddress,
1947
+ paymentMethod,
1948
+ fiatCurrency,
1949
+ conversionRate: conversionRate.toString(),
1950
+ chainId: this.config.getChainId().toString(),
1951
+ orchestratorAddress: orchestratorContext.address,
1952
+ escrowAddress: escrowContext.address,
2073
1953
  callerAddress: this.config.getWalletClient().account.address,
2074
1954
  referralFees: referralFees.map((referralFee) => ({
2075
1955
  recipient: referralFee.recipient,
@@ -2077,7 +1957,7 @@ var IntentOperations = class {
2077
1957
  }))
2078
1958
  },
2079
1959
  apiOpts
2080
- ) : await apiSignIntentV2(baseRequest, apiOpts);
1960
+ );
2081
1961
  gatingServiceSignature = response.signature;
2082
1962
  signatureExpiration = response.signatureExpiration;
2083
1963
  preIntentHookData = response.preIntentHookData ?? preIntentHookData;
@@ -2085,31 +1965,22 @@ var IntentOperations = class {
2085
1965
  if (!gatingServiceSignature || !signatureExpiration) {
2086
1966
  throw new Error("Missing gatingServiceSignature/signatureExpiration");
2087
1967
  }
2088
- const commonFields = {
2089
- escrow: escrowContext.address,
2090
- depositId,
2091
- amount,
2092
- to: params.toAddress,
2093
- paymentMethod,
2094
- fiatCurrency,
2095
- conversionRate,
2096
- gatingServiceSignature,
2097
- signatureExpiration: typeof signatureExpiration === "bigint" ? signatureExpiration : BigInt(signatureExpiration),
2098
- postIntentHook: params.postIntentHook ?? ZERO_ADDRESS,
2099
- data: params.data ?? "0x"
2100
- };
2101
- const args = useV2Encoding ? [
1968
+ const args = [
2102
1969
  {
2103
- ...commonFields,
1970
+ escrow: escrowContext.address,
1971
+ depositId,
1972
+ amount,
1973
+ to: params.toAddress,
1974
+ paymentMethod,
1975
+ fiatCurrency,
1976
+ conversionRate,
1977
+ gatingServiceSignature,
1978
+ signatureExpiration: typeof signatureExpiration === "bigint" ? signatureExpiration : BigInt(signatureExpiration),
1979
+ postIntentHook: params.postIntentHook ?? ZERO_ADDRESS,
1980
+ data: params.data ?? "0x",
2104
1981
  referralFees,
2105
1982
  preIntentHookData: preIntentHookData ?? "0x"
2106
1983
  }
2107
- ] : [
2108
- {
2109
- ...commonFields,
2110
- referrer: referralFees[0]?.recipient ?? ZERO_ADDRESS,
2111
- referrerFee: referralFees[0]?.fee ?? 0n
2112
- }
2113
1984
  ];
2114
1985
  const { referrer } = params.txOverrides ?? {};
2115
1986
  const data = encodeWithAttribution(
@@ -2133,8 +2004,7 @@ var IntentOperations = class {
2133
2004
  async prepareCancelIntent(params) {
2134
2005
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2135
2006
  orchestratorAddress: params.orchestratorAddress,
2136
- intentHash: params.intentHash,
2137
- preferV2: this.config.getDefaultPreferV2()
2007
+ intentHash: params.intentHash
2138
2008
  });
2139
2009
  const args = [params.intentHash];
2140
2010
  const { referrer } = params.txOverrides ?? {};
@@ -2159,8 +2029,7 @@ var IntentOperations = class {
2159
2029
  async prepareReleaseFundsToPayer(params) {
2160
2030
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2161
2031
  orchestratorAddress: params.orchestratorAddress,
2162
- intentHash: params.intentHash,
2163
- preferV2: this.config.getDefaultPreferV2()
2032
+ intentHash: params.intentHash
2164
2033
  });
2165
2034
  const args = [params.intentHash];
2166
2035
  const { referrer } = params.txOverrides ?? {};
@@ -2186,13 +2055,11 @@ var IntentOperations = class {
2186
2055
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2187
2056
  params.escrowAddress,
2188
2057
  params.depositId,
2189
- "setDepositPreIntentHook",
2190
- { preferV2: this.config.getDefaultPreferV2() }
2058
+ "setDepositPreIntentHook"
2191
2059
  );
2192
2060
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2193
2061
  orchestratorAddress: params.orchestratorAddress,
2194
- escrowAddress,
2195
- preferV2: this.config.getDefaultPreferV2()
2062
+ escrowAddress
2196
2063
  });
2197
2064
  return this.config.host.prepareResolvedOrchestratorTransaction({
2198
2065
  orchestrator: orchestratorContext,
@@ -2205,13 +2072,11 @@ var IntentOperations = class {
2205
2072
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2206
2073
  params.escrowAddress,
2207
2074
  params.depositId,
2208
- "setDepositWhitelistHook",
2209
- { preferV2: this.config.getDefaultPreferV2() }
2075
+ "setDepositWhitelistHook"
2210
2076
  );
2211
2077
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2212
2078
  orchestratorAddress: params.orchestratorAddress,
2213
- escrowAddress,
2214
- preferV2: this.config.getDefaultPreferV2()
2079
+ escrowAddress
2215
2080
  });
2216
2081
  return this.config.host.prepareResolvedOrchestratorTransaction({
2217
2082
  orchestrator: orchestratorContext,
@@ -2223,8 +2088,7 @@ var IntentOperations = class {
2223
2088
  async prepareCleanupOrphanedIntents(params) {
2224
2089
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2225
2090
  orchestratorAddress: params.orchestratorAddress,
2226
- escrowAddress: params.escrowAddress,
2227
- preferV2: this.config.getDefaultPreferV2()
2091
+ escrowAddress: params.escrowAddress
2228
2092
  });
2229
2093
  return this.config.host.prepareResolvedOrchestratorTransaction({
2230
2094
  orchestrator: orchestratorContext,
@@ -2237,13 +2101,11 @@ var IntentOperations = class {
2237
2101
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2238
2102
  options?.escrowAddress,
2239
2103
  depositId,
2240
- "getDepositPreIntentHook",
2241
- { preferV2: this.config.getDefaultPreferV2() }
2104
+ "getDepositPreIntentHook"
2242
2105
  );
2243
2106
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2244
2107
  orchestratorAddress: options?.orchestratorAddress,
2245
- escrowAddress,
2246
- preferV2: this.config.getDefaultPreferV2()
2108
+ escrowAddress
2247
2109
  });
2248
2110
  const functionName = resolveAbiFunctionName(orchestratorContext.abi, [
2249
2111
  "getDepositPreIntentHook"
@@ -2259,13 +2121,11 @@ var IntentOperations = class {
2259
2121
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2260
2122
  options?.escrowAddress,
2261
2123
  depositId,
2262
- "getDepositWhitelistHook",
2263
- { preferV2: this.config.getDefaultPreferV2() }
2124
+ "getDepositWhitelistHook"
2264
2125
  );
2265
2126
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2266
2127
  orchestratorAddress: options?.orchestratorAddress,
2267
- escrowAddress,
2268
- preferV2: this.config.getDefaultPreferV2()
2128
+ escrowAddress
2269
2129
  });
2270
2130
  const functionName = resolveAbiFunctionName(orchestratorContext.abi, [
2271
2131
  "getDepositWhitelistHook"
@@ -2281,8 +2141,7 @@ var IntentOperations = class {
2281
2141
  const intentHash = params.intentHash;
2282
2142
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2283
2143
  orchestratorAddress: params.orchestratorAddress,
2284
- intentHash,
2285
- preferV2: this.config.getDefaultPreferV2()
2144
+ intentHash
2286
2145
  });
2287
2146
  const precomputed = params.precomputedAttestation;
2288
2147
  let paymentProof;
@@ -2295,7 +2154,9 @@ var IntentOperations = class {
2295
2154
  verificationData = precomputed.verificationData;
2296
2155
  } else {
2297
2156
  const attestationServiceUrl = params.attestationServiceUrl ?? this.defaultAttestationService();
2298
- const inputs = await this.config.host.getFulfillIntentInputs(intentHash);
2157
+ const inputs = await this.config.host.getFulfillIntentInputs(intentHash, {
2158
+ orchestratorAddress: orchestratorContext.address
2159
+ });
2299
2160
  const paymentMethodHash = inputs.paymentMethodHash || "0x";
2300
2161
  const catalog = getPaymentMethodsCatalog(
2301
2162
  this.config.getChainId(),
@@ -2365,31 +2226,30 @@ var IntentOperations = class {
2365
2226
  defaultAttestationService() {
2366
2227
  return this.config.getRuntimeEnv() === "staging" ? "https://attestation-service-staging.zkp2p.xyz" : "https://attestation-service.zkp2p.xyz";
2367
2228
  }
2368
- async getFulfillIntentInputs(intentHash) {
2369
- try {
2370
- if (this.config.getProtocolViewerAddress() && this.config.getProtocolViewerAbi()) {
2371
- const view = await this.config.host.getPvIntent(intentHash);
2372
- const paymentMethodHash = view.intent.paymentMethod.toLowerCase();
2373
- const matched = (view.deposit.paymentMethods || []).find(
2374
- (pm) => pm.paymentMethod?.toLowerCase?.() === paymentMethodHash
2375
- );
2376
- const payee2 = matched?.verificationData?.payeeDetails;
2377
- if (payee2) {
2378
- return {
2379
- amount: view.intent.amount.toString(),
2380
- fiatCurrency: view.intent.fiatCurrency,
2381
- conversionRate: view.intent.conversionRate.toString(),
2382
- payeeDetails: payee2,
2383
- intentTimestampMs: (BigInt(view.intent.timestamp) * 1000n).toString(),
2384
- paymentMethodHash: view.intent.paymentMethod
2385
- };
2229
+ async getFulfillIntentInputs(intentHash, options) {
2230
+ const isCurrentOrchestrator = !options?.orchestratorAddress || options.orchestratorAddress.toLowerCase() === this.config.getOrchestratorV2Address()?.toLowerCase();
2231
+ if (isCurrentOrchestrator) {
2232
+ try {
2233
+ if (this.config.getProtocolViewerAddress() && this.config.getProtocolViewerAbi()) {
2234
+ const view = await this.config.host.getPvIntent(intentHash);
2235
+ const paymentMethodHash = view.intent.paymentMethod.toLowerCase();
2236
+ const matched = (view.deposit.paymentMethods || []).find(
2237
+ (pm) => pm.paymentMethod?.toLowerCase?.() === paymentMethodHash
2238
+ );
2239
+ const payee2 = matched?.verificationData?.payeeDetails;
2240
+ if (payee2) {
2241
+ return {
2242
+ amount: view.intent.amount.toString(),
2243
+ fiatCurrency: view.intent.fiatCurrency,
2244
+ conversionRate: view.intent.conversionRate.toString(),
2245
+ payeeDetails: payee2,
2246
+ intentTimestampMs: (BigInt(view.intent.timestamp) * 1000n).toString(),
2247
+ paymentMethodHash: view.intent.paymentMethod
2248
+ };
2249
+ }
2386
2250
  }
2251
+ } catch {
2387
2252
  }
2388
- } catch (error) {
2389
- logger.debug("ProtocolViewer lookup failed, falling back to indexer", {
2390
- intentHash,
2391
- error: error instanceof Error ? error.message : String(error)
2392
- });
2393
2253
  }
2394
2254
  const response = await this.config.getIndexerClient().query({
2395
2255
  query: (
@@ -3104,8 +2964,7 @@ var VaultOperations = class {
3104
2964
  }
3105
2965
  supportsInlineOracleRateConfig(params) {
3106
2966
  const escrowContext = this.config.host.resolveEscrowContext({
3107
- escrowAddress: params?.escrowAddress,
3108
- preferV2: params?.preferV2
2967
+ escrowAddress: params?.escrowAddress
3109
2968
  });
3110
2969
  return escrowCurrencyHasOracleConfig(escrowContext.abi);
3111
2970
  }
@@ -3222,8 +3081,7 @@ var VaultOperations = class {
3222
3081
  prepareSetOracleRateConfigTransaction(params) {
3223
3082
  const escrowContext = this.config.host.resolveEscrowContext({
3224
3083
  escrowAddress: params.escrowAddress,
3225
- depositId: params.depositId,
3226
- preferV2: true
3084
+ depositId: params.depositId
3227
3085
  });
3228
3086
  if (escrowContext.version !== "v2") {
3229
3087
  throw new Error("setOracleRateConfig requires EscrowV2");
@@ -3245,8 +3103,7 @@ var VaultOperations = class {
3245
3103
  prepareRemoveOracleRateConfigTransaction(params) {
3246
3104
  const escrowContext = this.config.host.resolveEscrowContext({
3247
3105
  escrowAddress: params.escrowAddress,
3248
- depositId: params.depositId,
3249
- preferV2: true
3106
+ depositId: params.depositId
3250
3107
  });
3251
3108
  if (escrowContext.version !== "v2") {
3252
3109
  throw new Error("removeOracleRateConfig requires EscrowV2");
@@ -3263,8 +3120,7 @@ var VaultOperations = class {
3263
3120
  prepareSetOracleRateConfigBatchTransaction(params) {
3264
3121
  const escrowContext = this.config.host.resolveEscrowContext({
3265
3122
  escrowAddress: params.escrowAddress,
3266
- depositId: params.depositId,
3267
- preferV2: true
3123
+ depositId: params.depositId
3268
3124
  });
3269
3125
  if (escrowContext.version !== "v2") {
3270
3126
  throw new Error("setOracleRateConfigBatch requires EscrowV2");
@@ -3286,8 +3142,7 @@ var VaultOperations = class {
3286
3142
  prepareUpdateCurrencyConfigBatchTransaction(params) {
3287
3143
  const escrowContext = this.config.host.resolveEscrowContext({
3288
3144
  escrowAddress: params.escrowAddress,
3289
- depositId: params.depositId,
3290
- preferV2: true
3145
+ depositId: params.depositId
3291
3146
  });
3292
3147
  if (escrowContext.version !== "v2") {
3293
3148
  throw new Error("updateCurrencyConfigBatch requires EscrowV2");
@@ -3315,8 +3170,7 @@ var VaultOperations = class {
3315
3170
  prepareDeactivateCurrenciesBatchTransaction(params) {
3316
3171
  const escrowContext = this.config.host.resolveEscrowContext({
3317
3172
  escrowAddress: params.escrowAddress,
3318
- depositId: params.depositId,
3319
- preferV2: true
3173
+ depositId: params.depositId
3320
3174
  });
3321
3175
  if (escrowContext.version !== "v2") {
3322
3176
  throw new Error("deactivateCurrenciesBatch requires EscrowV2");
@@ -5121,6 +4975,7 @@ var IndexerDepositService = class {
5121
4975
  init_bigint();
5122
4976
  var DEFAULT_LIMIT2 = 50;
5123
4977
  var RATE_MANAGER_HISTORY_PAGE_SIZE = 250;
4978
+ var EVM_ADDRESS_REGEX = /^0x[a-f0-9]{40}$/;
5124
4979
  function normalizeRateManagerId(value) {
5125
4980
  if (!value) return "";
5126
4981
  return value.toLowerCase();
@@ -5129,6 +4984,9 @@ function normalizeAddress3(value) {
5129
4984
  if (!value) return "";
5130
4985
  return value.toLowerCase();
5131
4986
  }
4987
+ function escapeLikePatternLiteral(value) {
4988
+ return value.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
4989
+ }
5132
4990
  function parseScopedRateManagerFilterId(value) {
5133
4991
  const trimmed = value.trim().toLowerCase();
5134
4992
  if (!trimmed) return null;
@@ -5136,7 +4994,7 @@ function parseScopedRateManagerFilterId(value) {
5136
4994
  if (separatorIndex <= 0) return null;
5137
4995
  const rateManagerAddress = normalizeAddress3(trimmed.slice(0, separatorIndex));
5138
4996
  const rateManagerId = normalizeRateManagerId(trimmed.slice(separatorIndex + 1));
5139
- if (!rateManagerAddress.startsWith("0x") || !rateManagerId) {
4997
+ if (!EVM_ADDRESS_REGEX.test(rateManagerAddress) || !rateManagerId) {
5140
4998
  return null;
5141
4999
  }
5142
5000
  return { rateManagerAddress, rateManagerId };
@@ -5154,12 +5012,14 @@ function extractRateManagerAddressFromScopedId(id) {
5154
5012
  return rateManagerAddress.startsWith("0x") ? rateManagerAddress.toLowerCase() : null;
5155
5013
  }
5156
5014
  function buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress) {
5157
- const normalizedId = normalizeRateManagerId(rateManagerId);
5158
- const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
5159
- return `%_${normalizedRateManagerAddress}_${normalizedId}`;
5015
+ const normalizedId = escapeLikePatternLiteral(normalizeRateManagerId(rateManagerId));
5016
+ const normalizedRateManagerAddress = escapeLikePatternLiteral(
5017
+ normalizeAddress3(rateManagerAddress)
5018
+ );
5019
+ return `%\\_${normalizedRateManagerAddress}\\_${normalizedId}`;
5160
5020
  }
5161
5021
  function buildRateManagerScopedIdPattern(rateManagerId, rateManagerAddress) {
5162
- return `${buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress)}_%`;
5022
+ return `${buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress)}\\_%`;
5163
5023
  }
5164
5024
  function normalizeCompositeDepositId(depositId, escrowAddress) {
5165
5025
  const normalizedDepositId = depositId.trim().toLowerCase();
@@ -5194,6 +5054,9 @@ function parseRateManagerFilterIds(rateManagerIds) {
5194
5054
  );
5195
5055
  continue;
5196
5056
  }
5057
+ if (value.includes(":")) {
5058
+ continue;
5059
+ }
5197
5060
  const normalizedRateManagerId = normalizeRateManagerId(value);
5198
5061
  if (normalizedRateManagerId) {
5199
5062
  bare.add(normalizedRateManagerId);
@@ -5732,21 +5595,12 @@ var IndexerRateManagerService = class {
5732
5595
  async fetchManualRateUpdates(rateManagerId, options) {
5733
5596
  if (!rateManagerId) return [];
5734
5597
  const normalizedId = normalizeRateManagerId(rateManagerId);
5735
- const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
5736
5598
  try {
5737
5599
  const result = await this.client.query({
5738
5600
  query: MANUAL_RATE_UPDATES_QUERY,
5739
5601
  variables: {
5740
5602
  where: {
5741
- rateManagerId: { _eq: normalizedId },
5742
- ...normalizedRateManagerAddress ? {
5743
- id: {
5744
- _ilike: buildRateManagerScopedIdPattern(
5745
- normalizedId,
5746
- normalizedRateManagerAddress
5747
- )
5748
- }
5749
- } : {}
5603
+ rateManagerId: { _eq: normalizedId }
5750
5604
  },
5751
5605
  order_by: [{ id: "desc" }],
5752
5606
  limit: options?.limit ?? 100
@@ -5820,15 +5674,7 @@ var IndexerRateManagerService = class {
5820
5674
  query: LEGACY_ORACLE_CONFIG_UPDATES_QUERY,
5821
5675
  variables: {
5822
5676
  where: {
5823
- rateManagerId: { _eq: normalizedId },
5824
- ...normalizedRateManagerAddress ? {
5825
- id: {
5826
- _ilike: buildRateManagerScopedIdPattern(
5827
- normalizedId,
5828
- normalizedRateManagerAddress
5829
- )
5830
- }
5831
- } : {}
5677
+ rateManagerId: { _eq: normalizedId }
5832
5678
  },
5833
5679
  order_by: [{ id: "desc" }],
5834
5680
  limit
@@ -7233,13 +7079,13 @@ var Zkp2pClient = class {
7233
7079
  getProtocolViewerAbi: () => this.protocolViewerAbi,
7234
7080
  getIndexerClient: () => this._indexerClient,
7235
7081
  getIndexerService: () => this._indexerService,
7236
- getDefaultPreferV2: () => this._router.defaultPreferV2,
7082
+ getOrchestratorV2Address: () => this.orchestratorV2Address,
7237
7083
  host: {
7238
7084
  resolveEscrowContext: (options) => this.resolveEscrowContext(options),
7239
7085
  resolveOrchestratorContext: (options) => this.resolveOrchestratorContext(options),
7240
- resolveEscrowAddressOrThrow: (escrowAddress, depositId, methodName, options) => this.resolveEscrowAddressOrThrow(escrowAddress, depositId, methodName, options),
7086
+ resolveEscrowAddressOrThrow: (escrowAddress, depositId, methodName) => this.resolveEscrowAddressOrThrow(escrowAddress, depositId, methodName),
7241
7087
  prepareResolvedOrchestratorTransaction: (tx) => this.prepareResolvedOrchestratorTransaction(tx),
7242
- getFulfillIntentInputs: (intentHash) => this.getFulfillIntentInputs(intentHash),
7088
+ getFulfillIntentInputs: (intentHash, options) => this.getFulfillIntentInputs(intentHash, options),
7243
7089
  getPvIntent: (intentHash) => this.getPvIntent(intentHash)
7244
7090
  }
7245
7091
  });
@@ -7271,8 +7117,7 @@ var Zkp2pClient = class {
7271
7117
  }
7272
7118
  supportsInlineOracleRateConfig(params) {
7273
7119
  return this._vaultOps.supportsInlineOracleRateConfig({
7274
- escrowAddress: params?.escrowAddress,
7275
- preferV2: params?.preferV2 ?? this._router.defaultPreferV2
7120
+ escrowAddress: params?.escrowAddress
7276
7121
  });
7277
7122
  }
7278
7123
  parseManagerFeeFromRead(result) {
@@ -7290,13 +7135,10 @@ var Zkp2pClient = class {
7290
7135
  abiFunctionHasInput(abi, functionName, inputName) {
7291
7136
  return abiFunctionHasInput(abi, functionName, inputName);
7292
7137
  }
7293
- resolveEscrowAddressOrThrow(escrowAddress, depositId, methodName, options) {
7138
+ resolveEscrowAddressOrThrow(escrowAddress, depositId, _methodName) {
7294
7139
  const resolved = escrowAddress ?? this.parseEscrowAddressFromCompositeDepositId(depositId);
7295
7140
  if (resolved) return resolved;
7296
- if (options?.preferV2 !== void 0) {
7297
- return this.resolveEscrowContext().address;
7298
- }
7299
- throw new Error(`${methodName} requires escrowAddress or composite depositId`);
7141
+ return this.resolveEscrowContext().address;
7300
7142
  }
7301
7143
  prepareCreateRateManagerTransaction(params) {
7302
7144
  return this._vaultOps.prepareCreateRateManagerTransaction(params);
@@ -7384,8 +7226,8 @@ var Zkp2pClient = class {
7384
7226
  getEscrowContexts() {
7385
7227
  return this._router.getEscrowContexts();
7386
7228
  }
7387
- resolveOrchestratorForEscrow(escrowAddress, preferV2 = false) {
7388
- return this._router.resolveOrchestratorForEscrow(escrowAddress, preferV2);
7229
+ resolveOrchestratorForEscrow(escrowAddress) {
7230
+ return this._router.resolveOrchestratorForEscrow(escrowAddress);
7389
7231
  }
7390
7232
  async lookupIntentRouting(intentHash) {
7391
7233
  try {
@@ -7419,12 +7261,8 @@ var Zkp2pClient = class {
7419
7261
  try {
7420
7262
  const view = await this.getPvIntent(intentHash);
7421
7263
  return this.normalizeAddress(view?.intent?.escrow);
7422
- } catch (error) {
7423
- if (error instanceof Error && error.message === "Intent not found") {
7424
- return void 0;
7425
- }
7426
- const message = error instanceof Error ? error.message : "Unknown on-chain routing error";
7427
- throw new Error(`Failed to resolve intent escrow on-chain for ${intentHash}: ${message}`);
7264
+ } catch {
7265
+ return void 0;
7428
7266
  }
7429
7267
  }
7430
7268
  warnOrchestratorFallback(intentHash, source, error) {
@@ -7448,10 +7286,7 @@ var Zkp2pClient = class {
7448
7286
  const fromIntent = this.getOrchestratorContextByAddress(routing.orchestratorAddress);
7449
7287
  if (fromIntent) return fromIntent;
7450
7288
  if (routing.escrowAddress) {
7451
- const fromIntentEscrow = this.resolveOrchestratorForEscrow(
7452
- routing.escrowAddress,
7453
- options.preferV2
7454
- );
7289
+ const fromIntentEscrow = this.resolveOrchestratorForEscrow(routing.escrowAddress);
7455
7290
  if (fromIntentEscrow) return fromIntentEscrow;
7456
7291
  }
7457
7292
  } catch (error) {
@@ -7460,10 +7295,7 @@ var Zkp2pClient = class {
7460
7295
  try {
7461
7296
  const onchainEscrow = await this.lookupIntentEscrowOnchain(options.intentHash);
7462
7297
  if (onchainEscrow) {
7463
- const fromOnchainEscrow = this.resolveOrchestratorForEscrow(
7464
- onchainEscrow,
7465
- options.preferV2
7466
- );
7298
+ const fromOnchainEscrow = this.resolveOrchestratorForEscrow(onchainEscrow);
7467
7299
  if (fromOnchainEscrow) return fromOnchainEscrow;
7468
7300
  }
7469
7301
  } catch (error) {
@@ -7471,7 +7303,7 @@ var Zkp2pClient = class {
7471
7303
  }
7472
7304
  }
7473
7305
  if (options?.escrowAddress) {
7474
- const fromEscrow = this.resolveOrchestratorForEscrow(options.escrowAddress, options.preferV2);
7306
+ const fromEscrow = this.resolveOrchestratorForEscrow(options.escrowAddress);
7475
7307
  if (fromEscrow) return fromEscrow;
7476
7308
  }
7477
7309
  if (options?.intentHash) {
@@ -7489,7 +7321,7 @@ var Zkp2pClient = class {
7489
7321
  }
7490
7322
  }
7491
7323
  }
7492
- const fallback = this.resolveOrchestratorForEscrow(void 0, options?.preferV2);
7324
+ const fallback = this.resolveOrchestratorForEscrow();
7493
7325
  if (fallback) return fallback;
7494
7326
  throw new Error("Orchestrator not available");
7495
7327
  }
@@ -7709,8 +7541,7 @@ var Zkp2pClient = class {
7709
7541
  async (params) => {
7710
7542
  const orchestratorContext = await this.resolveOrchestratorContext({
7711
7543
  orchestratorAddress: params.orchestratorAddress,
7712
- escrowAddress: params.escrowAddress,
7713
- preferV2: params.preferV2
7544
+ escrowAddress: params.escrowAddress
7714
7545
  });
7715
7546
  const prepared = this.prepareOrchestratorTransaction({
7716
7547
  functionName,
@@ -7726,8 +7557,7 @@ var Zkp2pClient = class {
7726
7557
  prepare: async (params) => {
7727
7558
  const orchestratorContext = await this.resolveOrchestratorContext({
7728
7559
  orchestratorAddress: params.orchestratorAddress,
7729
- escrowAddress: params.escrowAddress,
7730
- preferV2: params.preferV2
7560
+ escrowAddress: params.escrowAddress
7731
7561
  });
7732
7562
  const prepared = this.prepareOrchestratorTransaction({
7733
7563
  functionName,
@@ -8062,7 +7892,6 @@ var Zkp2pClient = class {
8062
7892
  * @param params.amount - Minimum required allowance amount
8063
7893
  * @param params.spender - Spender address override
8064
7894
  * @param params.escrowAddress - Escrow context used for default spender resolution
8065
- * @param params.preferV2 - Prefer EscrowV2 for default spender resolution
8066
7895
  * @param params.maxApprove - If true, approves MaxUint256 instead of exact amount
8067
7896
  * @param params.txOverrides - Optional viem transaction overrides
8068
7897
  * @returns Object with `hadAllowance` (true if no approval needed) and optional `hash`
@@ -8085,8 +7914,7 @@ var Zkp2pClient = class {
8085
7914
  const owner = this.walletClient.account?.address;
8086
7915
  if (!owner) throw new Error("Wallet client is missing account");
8087
7916
  const spender = params.spender ?? this.resolveEscrowContext({
8088
- escrowAddress: params.escrowAddress,
8089
- preferV2: params.preferV2 ?? this._router.defaultPreferV2
7917
+ escrowAddress: params.escrowAddress
8090
7918
  }).address;
8091
7919
  const allowance = await this.publicClient.readContract({
8092
7920
  address: params.token,
@@ -8320,8 +8148,7 @@ var Zkp2pClient = class {
8320
8148
  currencies = mapConversionRatesToOnchainMinRate2(normalized, paymentMethods.length);
8321
8149
  }
8322
8150
  const escrowContext = this.resolveEscrowContext({
8323
- escrowAddress: params.escrowAddress,
8324
- preferV2: this._router.defaultPreferV2
8151
+ escrowAddress: params.escrowAddress
8325
8152
  });
8326
8153
  const normalizedCurrencies = currencies.map(
8327
8154
  (group) => this.normalizeCurrencyTuples(group, escrowContext.abi)
@@ -8641,8 +8468,8 @@ var Zkp2pClient = class {
8641
8468
  * @returns Intent parameters needed for fulfillment
8642
8469
  * @throws Error if intent not found or payee details cannot be resolved
8643
8470
  */
8644
- async getFulfillIntentInputs(intentHash) {
8645
- return this._intentOps.getFulfillIntentInputs(intentHash);
8471
+ async getFulfillIntentInputs(intentHash, options) {
8472
+ return this._intentOps.getFulfillIntentInputs(intentHash, options);
8646
8473
  }
8647
8474
  };
8648
8475
 
@@ -8844,6 +8671,46 @@ init_paymentResolution();
8844
8671
  init_contracts();
8845
8672
  init_bytes32();
8846
8673
  init_protocolViewerParsers();
8674
+
8675
+ // src/utils/logger.ts
8676
+ var currentLevel = "info";
8677
+ function setLogLevel(level) {
8678
+ currentLevel = level;
8679
+ }
8680
+ function shouldLog(level) {
8681
+ switch (currentLevel) {
8682
+ case "debug":
8683
+ return true;
8684
+ case "info":
8685
+ return level !== "debug";
8686
+ case "error":
8687
+ return level === "error";
8688
+ default:
8689
+ return true;
8690
+ }
8691
+ }
8692
+ var logger = {
8693
+ debug: (...args) => {
8694
+ if (shouldLog("debug")) {
8695
+ console.log("[DEBUG]", ...args);
8696
+ }
8697
+ },
8698
+ info: (...args) => {
8699
+ if (shouldLog("info")) {
8700
+ console.log("[INFO]", ...args);
8701
+ }
8702
+ },
8703
+ warn: (...args) => {
8704
+ if (shouldLog("info")) {
8705
+ console.warn("[WARN]", ...args);
8706
+ }
8707
+ },
8708
+ error: (...args) => {
8709
+ console.error("[ERROR]", ...args);
8710
+ }
8711
+ };
8712
+
8713
+ // src/index.ts
8847
8714
  init_errors();
8848
8715
 
8849
8716
  // src/react/hooks/vaultUtils.ts