@zkp2p/sdk 0.2.0 → 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,44 +1890,6 @@ 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
1894
  var IntentOperations = class {
1994
1895
  constructor(config) {
@@ -2004,16 +1905,13 @@ var IntentOperations = class {
2004
1905
  "signalIntent referrerFeeConfig cannot be combined with referralFees, referrer, or referrerFee."
2005
1906
  );
2006
1907
  }
2007
- const preferV2 = this.config.getDefaultPreferV2();
2008
1908
  const escrowContext = this.config.host.resolveEscrowContext({
2009
1909
  escrowAddress: params.escrowAddress,
2010
- depositId: params.depositId,
2011
- preferV2
1910
+ depositId: params.depositId
2012
1911
  });
2013
1912
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2014
1913
  orchestratorAddress: params.orchestratorAddress,
2015
- escrowAddress: escrowContext.address,
2016
- preferV2
1914
+ escrowAddress: escrowContext.address
2017
1915
  });
2018
1916
  const catalog = getPaymentMethodsCatalog(this.config.getChainId(), this.config.getRuntimeEnv());
2019
1917
  const paymentMethod = resolvePaymentMethodHashFromCatalog(params.processorName, catalog);
@@ -2033,28 +1931,25 @@ var IntentOperations = class {
2033
1931
  const apiKey = this.config.getApiKey();
2034
1932
  const authorizationToken = this.config.getAuthorizationToken();
2035
1933
  if ((!gatingServiceSignature || !signatureExpiration) && baseApiUrl && (apiKey || authorizationToken)) {
2036
- const baseRequest = {
2037
- processorName: params.processorName,
2038
- payeeDetails: params.payeeDetails,
2039
- depositId: depositId.toString(),
2040
- amount: amount.toString(),
2041
- toAddress: params.toAddress,
2042
- paymentMethod,
2043
- fiatCurrency,
2044
- conversionRate: conversionRate.toString(),
2045
- chainId: this.config.getChainId().toString(),
2046
- orchestratorAddress: orchestratorContext.address,
2047
- escrowAddress: escrowContext.address
2048
- };
2049
1934
  const apiOpts = {
2050
1935
  baseApiUrl,
2051
1936
  apiKey,
2052
1937
  authorizationToken,
2053
1938
  timeoutMs: this.config.getApiTimeoutMs()
2054
1939
  };
2055
- const response = orchestratorContext.version === "v2" ? await apiSignIntentV3(
1940
+ const response = await apiSignIntentV3(
2056
1941
  {
2057
- ...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,
2058
1953
  callerAddress: this.config.getWalletClient().account.address,
2059
1954
  referralFees: referralFees.map((referralFee) => ({
2060
1955
  recipient: referralFee.recipient,
@@ -2062,7 +1957,7 @@ var IntentOperations = class {
2062
1957
  }))
2063
1958
  },
2064
1959
  apiOpts
2065
- ) : await apiSignIntentV2(baseRequest, apiOpts);
1960
+ );
2066
1961
  gatingServiceSignature = response.signature;
2067
1962
  signatureExpiration = response.signatureExpiration;
2068
1963
  preIntentHookData = response.preIntentHookData ?? preIntentHookData;
@@ -2070,31 +1965,22 @@ var IntentOperations = class {
2070
1965
  if (!gatingServiceSignature || !signatureExpiration) {
2071
1966
  throw new Error("Missing gatingServiceSignature/signatureExpiration");
2072
1967
  }
2073
- const commonFields = {
2074
- escrow: escrowContext.address,
2075
- depositId,
2076
- amount,
2077
- to: params.toAddress,
2078
- paymentMethod,
2079
- fiatCurrency,
2080
- conversionRate,
2081
- gatingServiceSignature,
2082
- signatureExpiration: typeof signatureExpiration === "bigint" ? signatureExpiration : BigInt(signatureExpiration),
2083
- postIntentHook: params.postIntentHook ?? ZERO_ADDRESS,
2084
- data: params.data ?? "0x"
2085
- };
2086
- const args = orchestratorContext.version === "v2" ? [
1968
+ const args = [
2087
1969
  {
2088
- ...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",
2089
1981
  referralFees,
2090
1982
  preIntentHookData: preIntentHookData ?? "0x"
2091
1983
  }
2092
- ] : [
2093
- {
2094
- ...commonFields,
2095
- referrer: referralFees[0]?.recipient ?? ZERO_ADDRESS,
2096
- referrerFee: referralFees[0]?.fee ?? 0n
2097
- }
2098
1984
  ];
2099
1985
  const { referrer } = params.txOverrides ?? {};
2100
1986
  const data = encodeWithAttribution(
@@ -2118,8 +2004,7 @@ var IntentOperations = class {
2118
2004
  async prepareCancelIntent(params) {
2119
2005
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2120
2006
  orchestratorAddress: params.orchestratorAddress,
2121
- intentHash: params.intentHash,
2122
- preferV2: this.config.getDefaultPreferV2()
2007
+ intentHash: params.intentHash
2123
2008
  });
2124
2009
  const args = [params.intentHash];
2125
2010
  const { referrer } = params.txOverrides ?? {};
@@ -2144,8 +2029,7 @@ var IntentOperations = class {
2144
2029
  async prepareReleaseFundsToPayer(params) {
2145
2030
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2146
2031
  orchestratorAddress: params.orchestratorAddress,
2147
- intentHash: params.intentHash,
2148
- preferV2: this.config.getDefaultPreferV2()
2032
+ intentHash: params.intentHash
2149
2033
  });
2150
2034
  const args = [params.intentHash];
2151
2035
  const { referrer } = params.txOverrides ?? {};
@@ -2171,13 +2055,11 @@ var IntentOperations = class {
2171
2055
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2172
2056
  params.escrowAddress,
2173
2057
  params.depositId,
2174
- "setDepositPreIntentHook",
2175
- { preferV2: this.config.getDefaultPreferV2() }
2058
+ "setDepositPreIntentHook"
2176
2059
  );
2177
2060
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2178
2061
  orchestratorAddress: params.orchestratorAddress,
2179
- escrowAddress,
2180
- preferV2: this.config.getDefaultPreferV2()
2062
+ escrowAddress
2181
2063
  });
2182
2064
  return this.config.host.prepareResolvedOrchestratorTransaction({
2183
2065
  orchestrator: orchestratorContext,
@@ -2190,13 +2072,11 @@ var IntentOperations = class {
2190
2072
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2191
2073
  params.escrowAddress,
2192
2074
  params.depositId,
2193
- "setDepositWhitelistHook",
2194
- { preferV2: this.config.getDefaultPreferV2() }
2075
+ "setDepositWhitelistHook"
2195
2076
  );
2196
2077
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2197
2078
  orchestratorAddress: params.orchestratorAddress,
2198
- escrowAddress,
2199
- preferV2: this.config.getDefaultPreferV2()
2079
+ escrowAddress
2200
2080
  });
2201
2081
  return this.config.host.prepareResolvedOrchestratorTransaction({
2202
2082
  orchestrator: orchestratorContext,
@@ -2208,8 +2088,7 @@ var IntentOperations = class {
2208
2088
  async prepareCleanupOrphanedIntents(params) {
2209
2089
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2210
2090
  orchestratorAddress: params.orchestratorAddress,
2211
- escrowAddress: params.escrowAddress,
2212
- preferV2: this.config.getDefaultPreferV2()
2091
+ escrowAddress: params.escrowAddress
2213
2092
  });
2214
2093
  return this.config.host.prepareResolvedOrchestratorTransaction({
2215
2094
  orchestrator: orchestratorContext,
@@ -2222,13 +2101,11 @@ var IntentOperations = class {
2222
2101
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2223
2102
  options?.escrowAddress,
2224
2103
  depositId,
2225
- "getDepositPreIntentHook",
2226
- { preferV2: this.config.getDefaultPreferV2() }
2104
+ "getDepositPreIntentHook"
2227
2105
  );
2228
2106
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2229
2107
  orchestratorAddress: options?.orchestratorAddress,
2230
- escrowAddress,
2231
- preferV2: this.config.getDefaultPreferV2()
2108
+ escrowAddress
2232
2109
  });
2233
2110
  const functionName = resolveAbiFunctionName(orchestratorContext.abi, [
2234
2111
  "getDepositPreIntentHook"
@@ -2244,13 +2121,11 @@ var IntentOperations = class {
2244
2121
  const escrowAddress = this.config.host.resolveEscrowAddressOrThrow(
2245
2122
  options?.escrowAddress,
2246
2123
  depositId,
2247
- "getDepositWhitelistHook",
2248
- { preferV2: this.config.getDefaultPreferV2() }
2124
+ "getDepositWhitelistHook"
2249
2125
  );
2250
2126
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2251
2127
  orchestratorAddress: options?.orchestratorAddress,
2252
- escrowAddress,
2253
- preferV2: this.config.getDefaultPreferV2()
2128
+ escrowAddress
2254
2129
  });
2255
2130
  const functionName = resolveAbiFunctionName(orchestratorContext.abi, [
2256
2131
  "getDepositWhitelistHook"
@@ -2266,8 +2141,7 @@ var IntentOperations = class {
2266
2141
  const intentHash = params.intentHash;
2267
2142
  const orchestratorContext = await this.config.host.resolveOrchestratorContext({
2268
2143
  orchestratorAddress: params.orchestratorAddress,
2269
- intentHash,
2270
- preferV2: this.config.getDefaultPreferV2()
2144
+ intentHash
2271
2145
  });
2272
2146
  const precomputed = params.precomputedAttestation;
2273
2147
  let paymentProof;
@@ -2280,7 +2154,9 @@ var IntentOperations = class {
2280
2154
  verificationData = precomputed.verificationData;
2281
2155
  } else {
2282
2156
  const attestationServiceUrl = params.attestationServiceUrl ?? this.defaultAttestationService();
2283
- const inputs = await this.config.host.getFulfillIntentInputs(intentHash);
2157
+ const inputs = await this.config.host.getFulfillIntentInputs(intentHash, {
2158
+ orchestratorAddress: orchestratorContext.address
2159
+ });
2284
2160
  const paymentMethodHash = inputs.paymentMethodHash || "0x";
2285
2161
  const catalog = getPaymentMethodsCatalog(
2286
2162
  this.config.getChainId(),
@@ -2350,31 +2226,30 @@ var IntentOperations = class {
2350
2226
  defaultAttestationService() {
2351
2227
  return this.config.getRuntimeEnv() === "staging" ? "https://attestation-service-staging.zkp2p.xyz" : "https://attestation-service.zkp2p.xyz";
2352
2228
  }
2353
- async getFulfillIntentInputs(intentHash) {
2354
- try {
2355
- if (this.config.getProtocolViewerAddress() && this.config.getProtocolViewerAbi()) {
2356
- const view = await this.config.host.getPvIntent(intentHash);
2357
- const paymentMethodHash = view.intent.paymentMethod.toLowerCase();
2358
- const matched = (view.deposit.paymentMethods || []).find(
2359
- (pm) => pm.paymentMethod?.toLowerCase?.() === paymentMethodHash
2360
- );
2361
- const payee2 = matched?.verificationData?.payeeDetails;
2362
- if (payee2) {
2363
- return {
2364
- amount: view.intent.amount.toString(),
2365
- fiatCurrency: view.intent.fiatCurrency,
2366
- conversionRate: view.intent.conversionRate.toString(),
2367
- payeeDetails: payee2,
2368
- intentTimestampMs: (BigInt(view.intent.timestamp) * 1000n).toString(),
2369
- paymentMethodHash: view.intent.paymentMethod
2370
- };
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
+ }
2371
2250
  }
2251
+ } catch {
2372
2252
  }
2373
- } catch (error) {
2374
- logger.debug("ProtocolViewer lookup failed, falling back to indexer", {
2375
- intentHash,
2376
- error: error instanceof Error ? error.message : String(error)
2377
- });
2378
2253
  }
2379
2254
  const response = await this.config.getIndexerClient().query({
2380
2255
  query: (
@@ -3089,8 +2964,7 @@ var VaultOperations = class {
3089
2964
  }
3090
2965
  supportsInlineOracleRateConfig(params) {
3091
2966
  const escrowContext = this.config.host.resolveEscrowContext({
3092
- escrowAddress: params?.escrowAddress,
3093
- preferV2: params?.preferV2
2967
+ escrowAddress: params?.escrowAddress
3094
2968
  });
3095
2969
  return escrowCurrencyHasOracleConfig(escrowContext.abi);
3096
2970
  }
@@ -3207,8 +3081,7 @@ var VaultOperations = class {
3207
3081
  prepareSetOracleRateConfigTransaction(params) {
3208
3082
  const escrowContext = this.config.host.resolveEscrowContext({
3209
3083
  escrowAddress: params.escrowAddress,
3210
- depositId: params.depositId,
3211
- preferV2: true
3084
+ depositId: params.depositId
3212
3085
  });
3213
3086
  if (escrowContext.version !== "v2") {
3214
3087
  throw new Error("setOracleRateConfig requires EscrowV2");
@@ -3230,8 +3103,7 @@ var VaultOperations = class {
3230
3103
  prepareRemoveOracleRateConfigTransaction(params) {
3231
3104
  const escrowContext = this.config.host.resolveEscrowContext({
3232
3105
  escrowAddress: params.escrowAddress,
3233
- depositId: params.depositId,
3234
- preferV2: true
3106
+ depositId: params.depositId
3235
3107
  });
3236
3108
  if (escrowContext.version !== "v2") {
3237
3109
  throw new Error("removeOracleRateConfig requires EscrowV2");
@@ -3248,8 +3120,7 @@ var VaultOperations = class {
3248
3120
  prepareSetOracleRateConfigBatchTransaction(params) {
3249
3121
  const escrowContext = this.config.host.resolveEscrowContext({
3250
3122
  escrowAddress: params.escrowAddress,
3251
- depositId: params.depositId,
3252
- preferV2: true
3123
+ depositId: params.depositId
3253
3124
  });
3254
3125
  if (escrowContext.version !== "v2") {
3255
3126
  throw new Error("setOracleRateConfigBatch requires EscrowV2");
@@ -3271,8 +3142,7 @@ var VaultOperations = class {
3271
3142
  prepareUpdateCurrencyConfigBatchTransaction(params) {
3272
3143
  const escrowContext = this.config.host.resolveEscrowContext({
3273
3144
  escrowAddress: params.escrowAddress,
3274
- depositId: params.depositId,
3275
- preferV2: true
3145
+ depositId: params.depositId
3276
3146
  });
3277
3147
  if (escrowContext.version !== "v2") {
3278
3148
  throw new Error("updateCurrencyConfigBatch requires EscrowV2");
@@ -3300,8 +3170,7 @@ var VaultOperations = class {
3300
3170
  prepareDeactivateCurrenciesBatchTransaction(params) {
3301
3171
  const escrowContext = this.config.host.resolveEscrowContext({
3302
3172
  escrowAddress: params.escrowAddress,
3303
- depositId: params.depositId,
3304
- preferV2: true
3173
+ depositId: params.depositId
3305
3174
  });
3306
3175
  if (escrowContext.version !== "v2") {
3307
3176
  throw new Error("deactivateCurrenciesBatch requires EscrowV2");
@@ -5106,6 +4975,7 @@ var IndexerDepositService = class {
5106
4975
  init_bigint();
5107
4976
  var DEFAULT_LIMIT2 = 50;
5108
4977
  var RATE_MANAGER_HISTORY_PAGE_SIZE = 250;
4978
+ var EVM_ADDRESS_REGEX = /^0x[a-f0-9]{40}$/;
5109
4979
  function normalizeRateManagerId(value) {
5110
4980
  if (!value) return "";
5111
4981
  return value.toLowerCase();
@@ -5114,6 +4984,9 @@ function normalizeAddress3(value) {
5114
4984
  if (!value) return "";
5115
4985
  return value.toLowerCase();
5116
4986
  }
4987
+ function escapeLikePatternLiteral(value) {
4988
+ return value.replace(/\\/g, "\\\\").replace(/%/g, "\\%").replace(/_/g, "\\_");
4989
+ }
5117
4990
  function parseScopedRateManagerFilterId(value) {
5118
4991
  const trimmed = value.trim().toLowerCase();
5119
4992
  if (!trimmed) return null;
@@ -5121,7 +4994,7 @@ function parseScopedRateManagerFilterId(value) {
5121
4994
  if (separatorIndex <= 0) return null;
5122
4995
  const rateManagerAddress = normalizeAddress3(trimmed.slice(0, separatorIndex));
5123
4996
  const rateManagerId = normalizeRateManagerId(trimmed.slice(separatorIndex + 1));
5124
- if (!rateManagerAddress.startsWith("0x") || !rateManagerId) {
4997
+ if (!EVM_ADDRESS_REGEX.test(rateManagerAddress) || !rateManagerId) {
5125
4998
  return null;
5126
4999
  }
5127
5000
  return { rateManagerAddress, rateManagerId };
@@ -5139,12 +5012,14 @@ function extractRateManagerAddressFromScopedId(id) {
5139
5012
  return rateManagerAddress.startsWith("0x") ? rateManagerAddress.toLowerCase() : null;
5140
5013
  }
5141
5014
  function buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress) {
5142
- const normalizedId = normalizeRateManagerId(rateManagerId);
5143
- const normalizedRateManagerAddress = normalizeAddress3(rateManagerAddress);
5144
- return `%_${normalizedRateManagerAddress}_${normalizedId}`;
5015
+ const normalizedId = escapeLikePatternLiteral(normalizeRateManagerId(rateManagerId));
5016
+ const normalizedRateManagerAddress = escapeLikePatternLiteral(
5017
+ normalizeAddress3(rateManagerAddress)
5018
+ );
5019
+ return `%\\_${normalizedRateManagerAddress}\\_${normalizedId}`;
5145
5020
  }
5146
5021
  function buildRateManagerScopedIdPattern(rateManagerId, rateManagerAddress) {
5147
- return `${buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress)}_%`;
5022
+ return `${buildRateManagerAddressScopedIdPattern(rateManagerId, rateManagerAddress)}\\_%`;
5148
5023
  }
5149
5024
  function normalizeCompositeDepositId(depositId, escrowAddress) {
5150
5025
  const normalizedDepositId = depositId.trim().toLowerCase();
@@ -5179,6 +5054,9 @@ function parseRateManagerFilterIds(rateManagerIds) {
5179
5054
  );
5180
5055
  continue;
5181
5056
  }
5057
+ if (value.includes(":")) {
5058
+ continue;
5059
+ }
5182
5060
  const normalizedRateManagerId = normalizeRateManagerId(value);
5183
5061
  if (normalizedRateManagerId) {
5184
5062
  bare.add(normalizedRateManagerId);
@@ -5717,21 +5595,12 @@ var IndexerRateManagerService = class {
5717
5595
  async fetchManualRateUpdates(rateManagerId, options) {
5718
5596
  if (!rateManagerId) return [];
5719
5597
  const normalizedId = normalizeRateManagerId(rateManagerId);
5720
- const normalizedRateManagerAddress = normalizeAddress3(options?.rateManagerAddress);
5721
5598
  try {
5722
5599
  const result = await this.client.query({
5723
5600
  query: MANUAL_RATE_UPDATES_QUERY,
5724
5601
  variables: {
5725
5602
  where: {
5726
- rateManagerId: { _eq: normalizedId },
5727
- ...normalizedRateManagerAddress ? {
5728
- id: {
5729
- _ilike: buildRateManagerScopedIdPattern(
5730
- normalizedId,
5731
- normalizedRateManagerAddress
5732
- )
5733
- }
5734
- } : {}
5603
+ rateManagerId: { _eq: normalizedId }
5735
5604
  },
5736
5605
  order_by: [{ id: "desc" }],
5737
5606
  limit: options?.limit ?? 100
@@ -5805,15 +5674,7 @@ var IndexerRateManagerService = class {
5805
5674
  query: LEGACY_ORACLE_CONFIG_UPDATES_QUERY,
5806
5675
  variables: {
5807
5676
  where: {
5808
- rateManagerId: { _eq: normalizedId },
5809
- ...normalizedRateManagerAddress ? {
5810
- id: {
5811
- _ilike: buildRateManagerScopedIdPattern(
5812
- normalizedId,
5813
- normalizedRateManagerAddress
5814
- )
5815
- }
5816
- } : {}
5677
+ rateManagerId: { _eq: normalizedId }
5817
5678
  },
5818
5679
  order_by: [{ id: "desc" }],
5819
5680
  limit
@@ -7101,7 +6962,7 @@ var Zkp2pClient = class {
7101
6962
  ...configuredOrchestratorAddresses
7102
6963
  ]);
7103
6964
  this.orchestratorAddress = this.orchestratorV2Address ?? toAddress(addresses.orchestrator) ?? this.orchestratorAddresses[0];
7104
- this.orchestratorAbi = this.orchestratorV2Abi ?? abis.orchestrator;
6965
+ this.orchestratorAbi = abis.orchestrator ?? this.orchestratorV2Abi;
7105
6966
  this.unifiedPaymentVerifier = toAddress(
7106
6967
  addresses.unifiedPaymentVerifierV2 ?? addresses.unifiedPaymentVerifier
7107
6968
  );
@@ -7218,13 +7079,13 @@ var Zkp2pClient = class {
7218
7079
  getProtocolViewerAbi: () => this.protocolViewerAbi,
7219
7080
  getIndexerClient: () => this._indexerClient,
7220
7081
  getIndexerService: () => this._indexerService,
7221
- getDefaultPreferV2: () => this._router.defaultPreferV2,
7082
+ getOrchestratorV2Address: () => this.orchestratorV2Address,
7222
7083
  host: {
7223
7084
  resolveEscrowContext: (options) => this.resolveEscrowContext(options),
7224
7085
  resolveOrchestratorContext: (options) => this.resolveOrchestratorContext(options),
7225
- resolveEscrowAddressOrThrow: (escrowAddress, depositId, methodName, options) => this.resolveEscrowAddressOrThrow(escrowAddress, depositId, methodName, options),
7086
+ resolveEscrowAddressOrThrow: (escrowAddress, depositId, methodName) => this.resolveEscrowAddressOrThrow(escrowAddress, depositId, methodName),
7226
7087
  prepareResolvedOrchestratorTransaction: (tx) => this.prepareResolvedOrchestratorTransaction(tx),
7227
- getFulfillIntentInputs: (intentHash) => this.getFulfillIntentInputs(intentHash),
7088
+ getFulfillIntentInputs: (intentHash, options) => this.getFulfillIntentInputs(intentHash, options),
7228
7089
  getPvIntent: (intentHash) => this.getPvIntent(intentHash)
7229
7090
  }
7230
7091
  });
@@ -7256,8 +7117,7 @@ var Zkp2pClient = class {
7256
7117
  }
7257
7118
  supportsInlineOracleRateConfig(params) {
7258
7119
  return this._vaultOps.supportsInlineOracleRateConfig({
7259
- escrowAddress: params?.escrowAddress,
7260
- preferV2: params?.preferV2 ?? this._router.defaultPreferV2
7120
+ escrowAddress: params?.escrowAddress
7261
7121
  });
7262
7122
  }
7263
7123
  parseManagerFeeFromRead(result) {
@@ -7275,13 +7135,10 @@ var Zkp2pClient = class {
7275
7135
  abiFunctionHasInput(abi, functionName, inputName) {
7276
7136
  return abiFunctionHasInput(abi, functionName, inputName);
7277
7137
  }
7278
- resolveEscrowAddressOrThrow(escrowAddress, depositId, methodName, options) {
7138
+ resolveEscrowAddressOrThrow(escrowAddress, depositId, _methodName) {
7279
7139
  const resolved = escrowAddress ?? this.parseEscrowAddressFromCompositeDepositId(depositId);
7280
7140
  if (resolved) return resolved;
7281
- if (options?.preferV2 !== void 0) {
7282
- return this.resolveEscrowContext().address;
7283
- }
7284
- throw new Error(`${methodName} requires escrowAddress or composite depositId`);
7141
+ return this.resolveEscrowContext().address;
7285
7142
  }
7286
7143
  prepareCreateRateManagerTransaction(params) {
7287
7144
  return this._vaultOps.prepareCreateRateManagerTransaction(params);
@@ -7369,8 +7226,8 @@ var Zkp2pClient = class {
7369
7226
  getEscrowContexts() {
7370
7227
  return this._router.getEscrowContexts();
7371
7228
  }
7372
- resolveOrchestratorForEscrow(escrowAddress, preferV2 = false) {
7373
- return this._router.resolveOrchestratorForEscrow(escrowAddress, preferV2);
7229
+ resolveOrchestratorForEscrow(escrowAddress) {
7230
+ return this._router.resolveOrchestratorForEscrow(escrowAddress);
7374
7231
  }
7375
7232
  async lookupIntentRouting(intentHash) {
7376
7233
  try {
@@ -7404,12 +7261,8 @@ var Zkp2pClient = class {
7404
7261
  try {
7405
7262
  const view = await this.getPvIntent(intentHash);
7406
7263
  return this.normalizeAddress(view?.intent?.escrow);
7407
- } catch (error) {
7408
- if (error instanceof Error && error.message === "Intent not found") {
7409
- return void 0;
7410
- }
7411
- const message = error instanceof Error ? error.message : "Unknown on-chain routing error";
7412
- throw new Error(`Failed to resolve intent escrow on-chain for ${intentHash}: ${message}`);
7264
+ } catch {
7265
+ return void 0;
7413
7266
  }
7414
7267
  }
7415
7268
  warnOrchestratorFallback(intentHash, source, error) {
@@ -7433,10 +7286,7 @@ var Zkp2pClient = class {
7433
7286
  const fromIntent = this.getOrchestratorContextByAddress(routing.orchestratorAddress);
7434
7287
  if (fromIntent) return fromIntent;
7435
7288
  if (routing.escrowAddress) {
7436
- const fromIntentEscrow = this.resolveOrchestratorForEscrow(
7437
- routing.escrowAddress,
7438
- options.preferV2
7439
- );
7289
+ const fromIntentEscrow = this.resolveOrchestratorForEscrow(routing.escrowAddress);
7440
7290
  if (fromIntentEscrow) return fromIntentEscrow;
7441
7291
  }
7442
7292
  } catch (error) {
@@ -7445,10 +7295,7 @@ var Zkp2pClient = class {
7445
7295
  try {
7446
7296
  const onchainEscrow = await this.lookupIntentEscrowOnchain(options.intentHash);
7447
7297
  if (onchainEscrow) {
7448
- const fromOnchainEscrow = this.resolveOrchestratorForEscrow(
7449
- onchainEscrow,
7450
- options.preferV2
7451
- );
7298
+ const fromOnchainEscrow = this.resolveOrchestratorForEscrow(onchainEscrow);
7452
7299
  if (fromOnchainEscrow) return fromOnchainEscrow;
7453
7300
  }
7454
7301
  } catch (error) {
@@ -7456,7 +7303,7 @@ var Zkp2pClient = class {
7456
7303
  }
7457
7304
  }
7458
7305
  if (options?.escrowAddress) {
7459
- const fromEscrow = this.resolveOrchestratorForEscrow(options.escrowAddress, options.preferV2);
7306
+ const fromEscrow = this.resolveOrchestratorForEscrow(options.escrowAddress);
7460
7307
  if (fromEscrow) return fromEscrow;
7461
7308
  }
7462
7309
  if (options?.intentHash) {
@@ -7474,7 +7321,7 @@ var Zkp2pClient = class {
7474
7321
  }
7475
7322
  }
7476
7323
  }
7477
- const fallback = this.resolveOrchestratorForEscrow(void 0, options?.preferV2);
7324
+ const fallback = this.resolveOrchestratorForEscrow();
7478
7325
  if (fallback) return fallback;
7479
7326
  throw new Error("Orchestrator not available");
7480
7327
  }
@@ -7694,8 +7541,7 @@ var Zkp2pClient = class {
7694
7541
  async (params) => {
7695
7542
  const orchestratorContext = await this.resolveOrchestratorContext({
7696
7543
  orchestratorAddress: params.orchestratorAddress,
7697
- escrowAddress: params.escrowAddress,
7698
- preferV2: params.preferV2
7544
+ escrowAddress: params.escrowAddress
7699
7545
  });
7700
7546
  const prepared = this.prepareOrchestratorTransaction({
7701
7547
  functionName,
@@ -7711,8 +7557,7 @@ var Zkp2pClient = class {
7711
7557
  prepare: async (params) => {
7712
7558
  const orchestratorContext = await this.resolveOrchestratorContext({
7713
7559
  orchestratorAddress: params.orchestratorAddress,
7714
- escrowAddress: params.escrowAddress,
7715
- preferV2: params.preferV2
7560
+ escrowAddress: params.escrowAddress
7716
7561
  });
7717
7562
  const prepared = this.prepareOrchestratorTransaction({
7718
7563
  functionName,
@@ -8047,7 +7892,6 @@ var Zkp2pClient = class {
8047
7892
  * @param params.amount - Minimum required allowance amount
8048
7893
  * @param params.spender - Spender address override
8049
7894
  * @param params.escrowAddress - Escrow context used for default spender resolution
8050
- * @param params.preferV2 - Prefer EscrowV2 for default spender resolution
8051
7895
  * @param params.maxApprove - If true, approves MaxUint256 instead of exact amount
8052
7896
  * @param params.txOverrides - Optional viem transaction overrides
8053
7897
  * @returns Object with `hadAllowance` (true if no approval needed) and optional `hash`
@@ -8070,8 +7914,7 @@ var Zkp2pClient = class {
8070
7914
  const owner = this.walletClient.account?.address;
8071
7915
  if (!owner) throw new Error("Wallet client is missing account");
8072
7916
  const spender = params.spender ?? this.resolveEscrowContext({
8073
- escrowAddress: params.escrowAddress,
8074
- preferV2: params.preferV2 ?? this._router.defaultPreferV2
7917
+ escrowAddress: params.escrowAddress
8075
7918
  }).address;
8076
7919
  const allowance = await this.publicClient.readContract({
8077
7920
  address: params.token,
@@ -8305,8 +8148,7 @@ var Zkp2pClient = class {
8305
8148
  currencies = mapConversionRatesToOnchainMinRate2(normalized, paymentMethods.length);
8306
8149
  }
8307
8150
  const escrowContext = this.resolveEscrowContext({
8308
- escrowAddress: params.escrowAddress,
8309
- preferV2: this._router.defaultPreferV2
8151
+ escrowAddress: params.escrowAddress
8310
8152
  });
8311
8153
  const normalizedCurrencies = currencies.map(
8312
8154
  (group) => this.normalizeCurrencyTuples(group, escrowContext.abi)
@@ -8626,8 +8468,8 @@ var Zkp2pClient = class {
8626
8468
  * @returns Intent parameters needed for fulfillment
8627
8469
  * @throws Error if intent not found or payee details cannot be resolved
8628
8470
  */
8629
- async getFulfillIntentInputs(intentHash) {
8630
- return this._intentOps.getFulfillIntentInputs(intentHash);
8471
+ async getFulfillIntentInputs(intentHash, options) {
8472
+ return this._intentOps.getFulfillIntentInputs(intentHash, options);
8631
8473
  }
8632
8474
  };
8633
8475
 
@@ -8829,6 +8671,46 @@ init_paymentResolution();
8829
8671
  init_contracts();
8830
8672
  init_bytes32();
8831
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
8832
8714
  init_errors();
8833
8715
 
8834
8716
  // src/react/hooks/vaultUtils.ts