opacity-issuer-core 0.2.2 → 0.3.0

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.js CHANGED
@@ -3,7 +3,7 @@ export { SANDBOX_CHAIN_ID, SANDBOX_DEPLOYMENTS, SANDBOX_IMPLEMENTATION_VERSION,
3
3
  export { DOCUMENT_ACCEPTANCE_PRIMARY_TYPE, DOCUMENT_ACCEPTANCE_TYPEHASH, DOCUMENT_ACCEPTANCE_TYPES, DOCUMENT_ATTESTOR_DOMAIN_NAME, DOCUMENT_ATTESTOR_DOMAIN_VERSION, ECDSA_SIGNATURE_BYTES, EIP712_DOMAIN_TYPE, MAX_ATTESTATION_LIFETIME_SECONDS } from './chunk-2STMWRIV.js';
4
4
  import { OpacityIssuerError } from './chunk-54Q3MU62.js';
5
5
  export { OpacityAttestationError, OpacityConfigError, OpacityIssuerError } from './chunk-54Q3MU62.js';
6
- import { parseAbi, keccak256, stringToHex, isAddress, zeroAddress, getAddress, maxUint256, zeroHash, encodeFunctionData, encodeDeployData, encodeAbiParameters, toBytes, defineChain, createWalletClient, custom, decodeEventLog, hashTypedData, BaseError, ContractFunctionRevertedError, ExecutionRevertedError, decodeFunctionData, ContractFunctionZeroDataError, decodeFunctionResult } from 'viem';
6
+ import { parseAbi, keccak256, stringToHex, isAddress, zeroAddress, getAddress, maxUint256, zeroHash, encodeFunctionData, encodeDeployData, encodeAbiParameters, decodeEventLog, BaseError, ContractFunctionZeroDataError, ContractFunctionRevertedError, toBytes, defineChain, createWalletClient, custom, hashTypedData, ExecutionRevertedError, decodeFunctionData, decodeFunctionResult } from 'viem';
7
7
  import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
8
8
 
9
9
  var securityTokenVaultAbi = parseAbi([
@@ -524,12 +524,12 @@ function createPurchasesNamespace(options = {}) {
524
524
  "Payment token returned false from approve."
525
525
  );
526
526
  const wallet = await walletFor(params);
527
- const hash = await wallet.writeContract({
527
+ const hash2 = await wallet.writeContract({
528
528
  ...step.request,
529
529
  account: wallet.account ?? params.buyer,
530
530
  chain: sendChain(wallet, params.deployment.chainId)
531
531
  });
532
- return { ...params, kind: "approval", step: step.kind, approvedAmount: step.amount, hash };
532
+ return { ...params, kind: "approval", step: step.kind, approvedAmount: step.amount, hash: hash2 };
533
533
  });
534
534
  }
535
535
  async function sendPurchase(input) {
@@ -538,17 +538,17 @@ function createPurchasesNamespace(options = {}) {
538
538
  await walletFor(params);
539
539
  const prepared = await simulatePurchase(params);
540
540
  const wallet = await walletFor(params);
541
- const hash = await wallet.writeContract({
541
+ const hash2 = await wallet.writeContract({
542
542
  ...prepared.request,
543
543
  account: wallet.account ?? params.buyer,
544
544
  chain: sendChain(wallet, params.deployment.chainId)
545
545
  });
546
- return { ...params, kind: "purchase", hash };
546
+ return { ...params, kind: "purchase", hash: hash2 };
547
547
  });
548
548
  }
549
549
  async function receiptFor(submitted, options2) {
550
550
  const params = purchaseParams(submitted);
551
- const hash = bytes32(submitted.hash, "hash", true);
551
+ const hash2 = bytes32(submitted.hash, "hash", true);
552
552
  for (const [name, value] of Object.entries(options2)) {
553
553
  if (value !== void 0 && (!Number.isSafeInteger(value) || value <= 0)) {
554
554
  throw new OpacityPurchaseError("invalid-input", `${name} must be a positive safe integer.`);
@@ -557,7 +557,7 @@ function createPurchasesNamespace(options = {}) {
557
557
  const client = await clientFor(params.deployment);
558
558
  let replacementReason;
559
559
  const receipt = await client.waitForTransactionReceipt({
560
- hash,
560
+ hash: hash2,
561
561
  ...options2.confirmations === void 0 ? {} : { confirmations: options2.confirmations },
562
562
  ...options2.timeout === void 0 ? {} : { timeout: options2.timeout },
563
563
  ...options2.pollingInterval === void 0 ? {} : { pollingInterval: options2.pollingInterval },
@@ -565,10 +565,10 @@ function createPurchasesNamespace(options = {}) {
565
565
  replacementReason = replacement.reason;
566
566
  }
567
567
  });
568
- const replaced = receipt.transactionHash.toLowerCase() !== hash.toLowerCase();
568
+ const replaced = receipt.transactionHash.toLowerCase() !== hash2.toLowerCase();
569
569
  return {
570
570
  status: replaced || replacementReason !== void 0 ? "replaced" : receipt.status === "reverted" ? "reverted" : "unverified",
571
- submittedHash: hash,
571
+ submittedHash: hash2,
572
572
  hash: receipt.transactionHash,
573
573
  receipt,
574
574
  ...replacementReason === void 0 ? {} : { replacementReason }
@@ -6246,14 +6246,14 @@ function createTransfersNamespace(options = {}) {
6246
6246
  rpcUrls: { default: { http: [] } }
6247
6247
  });
6248
6248
  const { gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas } = prepared.gas;
6249
- const hash = await wallet.writeContract({
6249
+ const hash2 = await wallet.writeContract({
6250
6250
  ...prepared.request,
6251
6251
  account: wallet.account ?? params.sender,
6252
6252
  chain: chain2,
6253
6253
  gas,
6254
6254
  ...gasPrice === void 0 ? { maxFeePerGas, maxPriorityFeePerGas } : { gasPrice }
6255
6255
  });
6256
- return Object.freeze({ ...params, kind: "transfer", hash });
6256
+ return Object.freeze({ ...params, kind: "transfer", hash: hash2 });
6257
6257
  } finally {
6258
6258
  sendsInProgress.delete(key);
6259
6259
  }
@@ -6262,8 +6262,8 @@ function createTransfersNamespace(options = {}) {
6262
6262
  if (submitted?.kind !== "transfer")
6263
6263
  throw new OpacityTransferError("invalid-input", "Expected a submitted transfer record.");
6264
6264
  const params = transferParams(submitted);
6265
- const hash = submitted.hash;
6266
- if (typeof hash !== "string" || !/^0x[\da-fA-F]{64}$/.test(hash) || /^0x0+$/.test(hash)) {
6265
+ const hash2 = submitted.hash;
6266
+ if (typeof hash2 !== "string" || !/^0x[\da-fA-F]{64}$/.test(hash2) || /^0x0+$/.test(hash2)) {
6267
6267
  throw new OpacityTransferError("invalid-input", "hash must be nonzero bytes32.");
6268
6268
  }
6269
6269
  const waitOptions3 = {
@@ -6282,7 +6282,7 @@ function createTransfersNamespace(options = {}) {
6282
6282
  const client = await clientFor(params.deployment);
6283
6283
  let replacementReason;
6284
6284
  const received = await client.waitForTransactionReceipt({
6285
- hash,
6285
+ hash: hash2,
6286
6286
  ...waitOptions3,
6287
6287
  onReplaced: (replacement) => {
6288
6288
  replacementReason = replacement.reason;
@@ -6294,8 +6294,8 @@ function createTransfersNamespace(options = {}) {
6294
6294
  };
6295
6295
  await clientFor(params.deployment);
6296
6296
  const result = {
6297
- status: receipt.transactionHash.toLowerCase() !== hash.toLowerCase() || replacementReason !== void 0 ? "replaced" : receipt.status === "reverted" ? "reverted" : "unverified",
6298
- submittedHash: hash,
6297
+ status: receipt.transactionHash.toLowerCase() !== hash2.toLowerCase() || replacementReason !== void 0 ? "replaced" : receipt.status === "reverted" ? "reverted" : "unverified",
6298
+ submittedHash: hash2,
6299
6299
  hash: receipt.transactionHash,
6300
6300
  receipt,
6301
6301
  ...replacementReason === void 0 ? {} : { replacementReason }
@@ -6305,15 +6305,15 @@ function createTransfersNamespace(options = {}) {
6305
6305
  return result;
6306
6306
  let transaction;
6307
6307
  try {
6308
- transaction = { ...await client.getTransaction({ hash }) };
6308
+ transaction = { ...await client.getTransaction({ hash: hash2 }) };
6309
6309
  } catch {
6310
6310
  return result;
6311
6311
  }
6312
6312
  await clientFor(params.deployment);
6313
- if (transaction.chainId !== params.deployment.chainId || typeof transaction.hash !== "string" || transaction.hash.toLowerCase() !== hash.toLowerCase() || !sameAddress2(transaction.from, params.sender) || !sameAddress2(transaction.to, params.deployment.token) || transaction.value !== 0n || typeof transaction.input !== "string" || transaction.input.toLowerCase() !== buildTransferTransaction(params).data.toLowerCase())
6313
+ if (transaction.chainId !== params.deployment.chainId || typeof transaction.hash !== "string" || transaction.hash.toLowerCase() !== hash2.toLowerCase() || !sameAddress2(transaction.from, params.sender) || !sameAddress2(transaction.to, params.deployment.token) || transaction.value !== 0n || typeof transaction.input !== "string" || transaction.input.toLowerCase() !== buildTransferTransaction(params).data.toLowerCase())
6314
6314
  return result;
6315
6315
  for (const log of receipt.logs) {
6316
- if (!sameAddress2(log.address, params.deployment.token) || log.removed || log.transactionHash?.toLowerCase() !== hash.toLowerCase())
6316
+ if (!sameAddress2(log.address, params.deployment.token) || log.removed || log.transactionHash?.toLowerCase() !== hash2.toLowerCase())
6317
6317
  continue;
6318
6318
  try {
6319
6319
  const event = decodeEventLog({
@@ -7199,6 +7199,357 @@ function createPolicyReplacementBatch(currentCount, policies) {
7199
7199
  return createPolicyBatch(changes);
7200
7200
  }
7201
7201
 
7202
+ // src/issuers/discovery.ts
7203
+ var discoveryAbi = parseAbi([
7204
+ "function allowlistRegistry() view returns (address)",
7205
+ "function beaconRegistry() view returns (address)",
7206
+ "function platformOperator() view returns (address)",
7207
+ "function policyEngine() view returns (address)",
7208
+ "function policyRegistry() view returns (address)",
7209
+ "function getDefaultVariant() view returns (bytes32)",
7210
+ "function getBeacon(bytes32) view returns (address)",
7211
+ "function isVariantActive(bytes32) view returns (bool)",
7212
+ "function isAuthorizedFactory(address) view returns (bool)",
7213
+ "function getIssuerTokens(address) view returns (address[])",
7214
+ "function implementationsOf(bytes32) view returns (address[])",
7215
+ "function isApproved(address) view returns (bool)",
7216
+ "function policyTypeOf(address) view returns (bytes32)",
7217
+ "function policyType() view returns (bytes32)"
7218
+ ]);
7219
+ var policyKinds = Object.keys(issuerPolicyTypes);
7220
+ function fail(message) {
7221
+ throw new OpacityIssuerOperationError("deployment-mismatch", message);
7222
+ }
7223
+ function address4(value, optional = false) {
7224
+ if (optional && value === null) return zeroAddress;
7225
+ if (typeof value !== "string" || !isAddress(value, { strict: false }) || !optional && value.toLowerCase() === zeroAddress)
7226
+ fail("Issuer discovery returned an invalid contract address.");
7227
+ return value.toLowerCase();
7228
+ }
7229
+ function hash(value) {
7230
+ if (typeof value !== "string" || !/^0x[0-9a-fA-F]{64}$/.test(value))
7231
+ fail("Issuer discovery requires valid block and transaction hashes.");
7232
+ return value.toLowerCase();
7233
+ }
7234
+ function positiveBigint(value) {
7235
+ return typeof value === "bigint" && value > 0n;
7236
+ }
7237
+ function validateHead(meta) {
7238
+ if (!meta || meta.hasIndexingErrors !== false || typeof meta.deployment !== "string" || !meta.deployment || !positiveBigint(meta.block?.number) || !positiveBigint(meta.block.timestamp))
7239
+ fail("Issuer discovery requires a healthy subgraph with complete block evidence.");
7240
+ const age = BigInt(Math.floor(Date.now() / 1e3)) - meta.block.timestamp;
7241
+ if (age > 600n || age < -60n)
7242
+ fail("Issuer discovery requires a subgraph block from the last 10 minutes.");
7243
+ return {
7244
+ deployment: meta.deployment,
7245
+ number: meta.block.number,
7246
+ hash: hash(meta.block.hash),
7247
+ timestamp: meta.block.timestamp
7248
+ };
7249
+ }
7250
+ async function resolveIssuerDeployment(input, options) {
7251
+ if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some((key) => !["chainId", "token", "maxTokens"].includes(key)) || !options || typeof options !== "object" || Array.isArray(options))
7252
+ throw new OpacityIssuerOperationError("invalid-input", "Invalid issuer discovery arguments.");
7253
+ const chainId4 = issuerChainId(input.chainId);
7254
+ const selectedToken = input.token === void 0 ? void 0 : issuerAddress(input.token, "token").toLowerCase();
7255
+ const maxTokens = input.maxTokens === void 0 ? 100 : input.maxTokens;
7256
+ if (!Number.isSafeInteger(maxTokens) || maxTokens < 1 || maxTokens > 1e3)
7257
+ throw new OpacityIssuerOperationError(
7258
+ "invalid-input",
7259
+ "maxTokens must be an integer between 1 and 1000."
7260
+ );
7261
+ const { indexer, publicClient: client } = options;
7262
+ if (!client || !indexer || ["getMetadata", "getRegistry", "listTokens", "getToken"].some(
7263
+ (method) => typeof indexer[method] !== "function"
7264
+ ) || typeof client.getChainId !== "function")
7265
+ throw new OpacityIssuerOperationError(
7266
+ "missing-client",
7267
+ "Issuer discovery requires publicClient and a configured indexer."
7268
+ );
7269
+ if (client.chain && client.chain.id !== chainId4 || await client.getChainId() !== chainId4)
7270
+ throw new OpacityIssuerOperationError(
7271
+ "chain-mismatch",
7272
+ "RPC and requested issuer discovery chains must agree."
7273
+ );
7274
+ const snapshot2 = validateHead(await indexer.getMetadata());
7275
+ function validateSnapshot(meta) {
7276
+ if (!meta || meta.hasIndexingErrors !== false || meta.deployment !== snapshot2.deployment || meta.block?.number !== snapshot2.number || meta.block.hash !== null && hash(meta.block.hash) !== snapshot2.hash || meta.block.timestamp !== null && meta.block.timestamp !== snapshot2.timestamp)
7277
+ fail("The subgraph snapshot changed during issuer discovery. Retry discovery.");
7278
+ }
7279
+ const atSnapshot = { blockHash: snapshot2.hash };
7280
+ const registryResult = await indexer.getRegistry(atSnapshot);
7281
+ validateSnapshot(registryResult.meta);
7282
+ if (!registryResult.item) fail("The configured subgraph has no indexed protocol registry.");
7283
+ const registry = address4(registryResult.item.contractAddress);
7284
+ const tokens = [];
7285
+ if (selectedToken !== void 0) {
7286
+ const result = await indexer.getToken(selectedToken, atSnapshot);
7287
+ validateSnapshot(result.meta);
7288
+ if (!result.item || address4(result.item.id) !== selectedToken)
7289
+ fail("The selected source token is not indexed in this environment.");
7290
+ tokens.push(result.item);
7291
+ } else {
7292
+ let cursor = null;
7293
+ const seenCursors = /* @__PURE__ */ new Set();
7294
+ do {
7295
+ const page = await indexer.listTokens({
7296
+ registry,
7297
+ ...atSnapshot,
7298
+ pageSize: Math.min(100, maxTokens - tokens.length),
7299
+ ...cursor ? { cursor } : {}
7300
+ });
7301
+ validateSnapshot(page.meta);
7302
+ if (!Array.isArray(page.items) || page.items.length > maxTokens - tokens.length)
7303
+ fail("Issuer discovery returned an invalid token page.");
7304
+ tokens.push(...page.items);
7305
+ cursor = page.nextCursor;
7306
+ if (cursor) {
7307
+ if (tokens.length >= maxTokens)
7308
+ fail("Issuer discovery exceeded maxTokens. Select a source token or raise maxTokens.");
7309
+ if (!page.items.length || seenCursors.has(cursor.after))
7310
+ fail("Issuer discovery pagination did not advance.");
7311
+ seenCursors.add(cursor.after);
7312
+ }
7313
+ } while (cursor);
7314
+ }
7315
+ if (!tokens.length)
7316
+ fail(
7317
+ "The configured subgraph has no indexed token deployments. Index the protocol deployment before discovering its factory; a new issuer does not need an existing token of their own."
7318
+ );
7319
+ const tokenAddresses = tokens.map((token) => address4(token.id));
7320
+ if (new Set(tokenAddresses).size !== tokens.length)
7321
+ fail("Issuer discovery returned duplicate source tokens.");
7322
+ const [indexedBlock, latest] = await Promise.all([
7323
+ client.getBlock({ blockNumber: snapshot2.number }),
7324
+ client.getBlock({ blockTag: "latest" })
7325
+ ]);
7326
+ if (indexedBlock.number !== snapshot2.number || hash(indexedBlock.hash) !== snapshot2.hash || indexedBlock.timestamp !== snapshot2.timestamp || !positiveBigint(latest.number) || latest.number < snapshot2.number || !positiveBigint(latest.timestamp) || latest.timestamp < snapshot2.timestamp)
7327
+ fail("Subgraph block evidence does not match the requested RPC chain.");
7328
+ const latestHash = hash(latest.hash);
7329
+ validateHead({
7330
+ deployment: snapshot2.deployment,
7331
+ hasIndexingErrors: false,
7332
+ block: { number: latest.number, hash: latestHash, timestamp: latest.timestamp }
7333
+ });
7334
+ const blocks = [.../* @__PURE__ */ new Set([snapshot2.number, latest.number])];
7335
+ const readCache = /* @__PURE__ */ new Map();
7336
+ function read(contract, functionName, args, blockNumber) {
7337
+ const key = `${contract}:${functionName}:${args.join(",")}:${blockNumber}`;
7338
+ let result = readCache.get(key);
7339
+ if (!result) {
7340
+ result = client.readContract({
7341
+ address: contract,
7342
+ abi: discoveryAbi,
7343
+ functionName,
7344
+ args,
7345
+ blockNumber
7346
+ });
7347
+ readCache.set(key, result);
7348
+ }
7349
+ return result;
7350
+ }
7351
+ const codeCache = /* @__PURE__ */ new Set();
7352
+ async function requireCode(contract, blockNumber) {
7353
+ const key = `${contract}:${blockNumber}`;
7354
+ if (codeCache.has(key)) return;
7355
+ const code = await client.getBytecode({ address: contract, blockNumber });
7356
+ if (!code || code === "0x") fail(`No contract code at discovered address ${contract}.`);
7357
+ codeCache.add(key);
7358
+ }
7359
+ async function sameAddressAtBoth(contract, functionName, expected, optional = false) {
7360
+ for (const block of blocks) {
7361
+ if (address4(await read(contract, functionName, [], block), optional) !== expected)
7362
+ fail(`Discovered ${functionName} differs from the indexed or current chain state.`);
7363
+ }
7364
+ }
7365
+ const factories = /* @__PURE__ */ new Set();
7366
+ const receiptCache = /* @__PURE__ */ new Map();
7367
+ for (const token of tokens) {
7368
+ const tokenAddress = address4(token.id);
7369
+ const tokenIssuer = address4(token.issuer?.id);
7370
+ if (address4(token.allowlistRegistry) !== registry)
7371
+ fail("An indexed source token belongs to a different registry.");
7372
+ if (!positiveBigint(token.deployedAtBlock) || token.deployedAtBlock > snapshot2.number)
7373
+ fail("The indexed token deployment block is invalid.");
7374
+ for (const block of blocks) await requireCode(tokenAddress, block);
7375
+ await sameAddressAtBoth(tokenAddress, "allowlistRegistry", registry);
7376
+ const engine = address4(token.policyEngine, true);
7377
+ await sameAddressAtBoth(tokenAddress, "policyEngine", engine, true);
7378
+ const txHash = hash(token.deployTxHash);
7379
+ let receipt = receiptCache.get(txHash);
7380
+ if (!receipt) {
7381
+ receipt = await client.getTransactionReceipt({ hash: txHash });
7382
+ receiptCache.set(txHash, receipt);
7383
+ }
7384
+ if (receipt.status !== "success" || hash(receipt.transactionHash) !== txHash || receipt.blockNumber !== token.deployedAtBlock)
7385
+ fail("The indexed token deployment receipt does not match the chain.");
7386
+ const deployedBlock = await client.getBlock({ blockNumber: receipt.blockNumber });
7387
+ if (deployedBlock.number !== token.deployedAtBlock || hash(deployedBlock.hash) !== hash(receipt.blockHash) || deployedBlock.timestamp !== token.deployedAtTimestamp)
7388
+ fail("The indexed token deployment receipt is not on the canonical chain.");
7389
+ const emitters = [];
7390
+ for (const log of receipt.logs) {
7391
+ if (log.removed) continue;
7392
+ try {
7393
+ const event = decodeEventLog({
7394
+ abi: issuerFactoryAbi,
7395
+ eventName: "TokenDeployed",
7396
+ topics: log.topics,
7397
+ data: log.data,
7398
+ strict: true
7399
+ });
7400
+ if (address4(event.args.token) === tokenAddress && address4(event.args.issuer) === tokenIssuer && address4(event.args.allowlistRegistry) === registry)
7401
+ emitters.push(address4(log.address));
7402
+ } catch {
7403
+ }
7404
+ }
7405
+ if (emitters.length !== 1)
7406
+ fail("Expected exactly one matching TokenDeployed event in the indexed receipt.");
7407
+ const emitter = emitters[0];
7408
+ for (const block of blocks) {
7409
+ const issued = await read(emitter, "getIssuerTokens", [tokenIssuer], block);
7410
+ if (!Array.isArray(issued) || !issued.some((item) => address4(item) === tokenAddress))
7411
+ fail("The indexed token is not recorded by its deployment factory for that issuer.");
7412
+ }
7413
+ factories.add(emitter);
7414
+ }
7415
+ if (factories.size !== 1)
7416
+ fail(
7417
+ "Multiple protocol deployments are indexed. Select a source token explicitly; discovery never guesses a factory."
7418
+ );
7419
+ const factory = [...factories][0];
7420
+ for (const block of blocks) {
7421
+ await requireCode(factory, block);
7422
+ await requireCode(registry, block);
7423
+ }
7424
+ await sameAddressAtBoth(factory, "allowlistRegistry", registry);
7425
+ const beaconRegistry = address4(await read(factory, "beaconRegistry", [], snapshot2.number));
7426
+ await sameAddressAtBoth(factory, "beaconRegistry", beaconRegistry);
7427
+ const defaultBeaconVariant = hash(
7428
+ await read(beaconRegistry, "getDefaultVariant", [], snapshot2.number)
7429
+ );
7430
+ const beacon = address4(
7431
+ await read(beaconRegistry, "getBeacon", [defaultBeaconVariant], snapshot2.number)
7432
+ );
7433
+ for (const block of blocks) {
7434
+ await requireCode(beaconRegistry, block);
7435
+ await requireCode(beacon, block);
7436
+ const [variant, actualBeacon, active3, authorized] = await Promise.all([
7437
+ read(beaconRegistry, "getDefaultVariant", [], block),
7438
+ read(beaconRegistry, "getBeacon", [defaultBeaconVariant], block),
7439
+ read(beaconRegistry, "isVariantActive", [defaultBeaconVariant], block),
7440
+ read(beaconRegistry, "isAuthorizedFactory", [factory], block)
7441
+ ]);
7442
+ if (hash(variant) !== defaultBeaconVariant || address4(actualBeacon) !== beacon || active3 !== true || authorized !== true)
7443
+ fail("Discovered factory or default beacon is inactive, unauthorized, or changed.");
7444
+ }
7445
+ const deployment2 = {
7446
+ chainId: chainId4,
7447
+ factory,
7448
+ allowlistRegistry: registry,
7449
+ beaconRegistry
7450
+ };
7451
+ const policies = Object.fromEntries(policyKinds.map((kind) => [kind, []]));
7452
+ const policyEngine = await (async () => {
7453
+ try {
7454
+ const operator = address4(await read(registry, "platformOperator", [], snapshot2.number));
7455
+ await sameAddressAtBoth(registry, "platformOperator", operator);
7456
+ for (const block of blocks) await requireCode(operator, block);
7457
+ const governedEngine = address4(await read(operator, "policyEngine", [], snapshot2.number));
7458
+ await sameAddressAtBoth(operator, "policyEngine", governedEngine);
7459
+ return governedEngine;
7460
+ } catch (cause) {
7461
+ const unsupported = cause instanceof BaseError ? cause.walk(
7462
+ (error) => error instanceof ContractFunctionZeroDataError || error instanceof ContractFunctionRevertedError
7463
+ ) : void 0;
7464
+ if (!(cause instanceof OpacityIssuerOperationError && cause.code === "deployment-mismatch") && !(unsupported instanceof ContractFunctionZeroDataError) && !(unsupported instanceof ContractFunctionRevertedError))
7465
+ throw cause;
7466
+ throw new OpacityIssuerOperationError(
7467
+ "deployment-mismatch",
7468
+ "Cannot verify registry-governed policy infrastructure. Automatic discovery requires a contract platformOperator exposing policyEngine at the indexed and current blocks; an EOA operator or incompatible deployment must be configured by protocol governance before discovery can proceed.",
7469
+ { cause }
7470
+ );
7471
+ }
7472
+ })();
7473
+ if (policyEngine) {
7474
+ const policyRegistry = address4(await read(policyEngine, "policyRegistry", [], snapshot2.number));
7475
+ for (const block of blocks) {
7476
+ await requireCode(policyEngine, block);
7477
+ await requireCode(policyRegistry, block);
7478
+ }
7479
+ await sameAddressAtBoth(policyEngine, "policyRegistry", policyRegistry);
7480
+ await sameAddressAtBoth(policyRegistry, "allowlistRegistry", registry);
7481
+ deployment2.policyEngine = policyEngine;
7482
+ deployment2.policyRegistry = policyRegistry;
7483
+ await Promise.all(
7484
+ policyKinds.map(async (kind) => {
7485
+ const policyType = issuerPolicyTypes[kind];
7486
+ const raw = await read(policyRegistry, "implementationsOf", [policyType], snapshot2.number);
7487
+ if (!Array.isArray(raw) || raw.length > 1e3)
7488
+ fail("The policy registry returned an invalid or excessive implementation catalog.");
7489
+ const implementations = raw.map((item) => address4(item));
7490
+ if (new Set(implementations).size !== implementations.length)
7491
+ fail("The policy registry returned duplicate implementations.");
7492
+ const current = await read(
7493
+ policyRegistry,
7494
+ "implementationsOf",
7495
+ [policyType],
7496
+ latest.number
7497
+ );
7498
+ if (!Array.isArray(current) || current.length !== implementations.length || current.some((item, i) => address4(item) !== implementations[i]))
7499
+ fail("The policy catalog changed since the indexed block. Wait for indexing and retry.");
7500
+ for (const implementation of implementations) {
7501
+ const approved = await read(
7502
+ policyRegistry,
7503
+ "isApproved",
7504
+ [implementation],
7505
+ snapshot2.number
7506
+ );
7507
+ if (typeof approved !== "boolean") fail("The policy registry returned invalid approval.");
7508
+ if (await read(policyRegistry, "isApproved", [implementation], latest.number) !== approved)
7509
+ fail("Policy approval changed since the indexed block. Wait for indexing and retry.");
7510
+ if (!approved) continue;
7511
+ for (const block of blocks) {
7512
+ await requireCode(implementation, block);
7513
+ const [registeredType, actualType] = await Promise.all([
7514
+ read(policyRegistry, "policyTypeOf", [implementation], block),
7515
+ read(implementation, "policyType", [], block)
7516
+ ]);
7517
+ if (hash(registeredType) !== policyType || hash(actualType) !== policyType)
7518
+ fail("An approved policy implementation does not match its registered policy type.");
7519
+ }
7520
+ policies[kind].push(implementation);
7521
+ }
7522
+ })
7523
+ );
7524
+ }
7525
+ const [finalIndexed, finalLatest] = await Promise.all([
7526
+ client.getBlock({ blockNumber: snapshot2.number }),
7527
+ client.getBlock({ blockNumber: latest.number })
7528
+ ]);
7529
+ if (hash(finalIndexed.hash) !== snapshot2.hash || hash(finalLatest.hash) !== latestHash)
7530
+ fail("The chain reorganized during issuer discovery. Retry discovery.");
7531
+ validateHead({
7532
+ deployment: snapshot2.deployment,
7533
+ hasIndexingErrors: false,
7534
+ block: { number: snapshot2.number, hash: snapshot2.hash, timestamp: snapshot2.timestamp }
7535
+ });
7536
+ return {
7537
+ deployment: deployment2,
7538
+ policies,
7539
+ defaultBeaconVariant,
7540
+ beacon,
7541
+ evidence: {
7542
+ subgraphDeployment: snapshot2.deployment,
7543
+ blockNumber: snapshot2.number,
7544
+ blockHash: snapshot2.hash,
7545
+ timestamp: snapshot2.timestamp,
7546
+ verifiedAtBlock: latest.number,
7547
+ verifiedAtBlockHash: latestHash,
7548
+ sourceTokens: tokenAddresses
7549
+ }
7550
+ };
7551
+ }
7552
+
7202
7553
  // src/issuers/sandbox-deployment.ts
7203
7554
  var { chainId: chainId3, addresses } = SEPOLIA_SANDBOX_MANIFEST;
7204
7555
  var SANDBOX_ISSUER_DEPLOYMENT = Object.freeze({
@@ -7217,6 +7568,37 @@ var SANDBOX_ISSUER_DEPLOYMENT = Object.freeze({
7217
7568
  function createIssuersNamespace(options = {}) {
7218
7569
  const configuredChain = options.chainId === void 0 ? void 0 : issuerChainId(options.chainId);
7219
7570
  const busy = /* @__PURE__ */ new Set();
7571
+ async function discoverDeployment(params = {}) {
7572
+ if (!params || typeof params !== "object" || Array.isArray(params) || ![Object.prototype, null].includes(Object.getPrototypeOf(params)))
7573
+ throw new OpacityIssuerOperationError(
7574
+ "invalid-input",
7575
+ "Discovery parameters must be a plain object."
7576
+ );
7577
+ const chainId4 = params.chainId === void 0 ? configuredChain : params.chainId;
7578
+ if (chainId4 === void 0)
7579
+ throw new OpacityIssuerOperationError(
7580
+ "invalid-input",
7581
+ "Configure chainId before discovering an issuer deployment."
7582
+ );
7583
+ issuerChainId(chainId4);
7584
+ if (configuredChain !== void 0 && chainId4 !== configuredChain)
7585
+ throw new OpacityIssuerOperationError(
7586
+ "chain-mismatch",
7587
+ "Discovery chain must match the configured issuer chain."
7588
+ );
7589
+ if (!options.indexer || !options.publicClient)
7590
+ throw new OpacityIssuerOperationError(
7591
+ "missing-client",
7592
+ "Deployment discovery requires an indexer and publicClient."
7593
+ );
7594
+ return resolveIssuerDeployment(
7595
+ { ...params, chainId: chainId4 },
7596
+ {
7597
+ indexer: options.indexer,
7598
+ publicClient: options.publicClient
7599
+ }
7600
+ );
7601
+ }
7220
7602
  async function clientFor(chainId4) {
7221
7603
  issuerChainId(chainId4);
7222
7604
  const client = options.publicClient;
@@ -7246,15 +7628,15 @@ function createIssuersNamespace(options = {}) {
7246
7628
  );
7247
7629
  return wallet;
7248
7630
  }
7249
- async function requireCode(client, address4, blockNumber) {
7631
+ async function requireCode(client, address5, blockNumber) {
7250
7632
  const code = await client.getBytecode({
7251
- address: address4,
7633
+ address: address5,
7252
7634
  ...blockNumber === void 0 ? {} : { blockNumber }
7253
7635
  });
7254
7636
  if (!code || code === "0x")
7255
7637
  throw new OpacityIssuerOperationError(
7256
7638
  "deployment-mismatch",
7257
- `No contract code at ${address4}.`
7639
+ `No contract code at ${address5}.`
7258
7640
  );
7259
7641
  }
7260
7642
  async function sandboxVersionAt(client, registry, blockNumber) {
@@ -7545,10 +7927,10 @@ function createIssuersNamespace(options = {}) {
7545
7927
  "deployment-blocked",
7546
7928
  `Issuer deployment blocked: ${prepared.blockers.join(", ")}.`
7547
7929
  );
7548
- const hash = await write(prepared.transaction);
7930
+ const hash2 = await write(prepared.transaction);
7549
7931
  return {
7550
7932
  kind: "deployment",
7551
- hash,
7933
+ hash: hash2,
7552
7934
  transaction: prepared.transaction,
7553
7935
  params,
7554
7936
  predictedToken: prepared.predictedToken,
@@ -7721,28 +8103,28 @@ function createIssuersNamespace(options = {}) {
7721
8103
  }
7722
8104
  async function waitForTransaction(record2, wait = {}) {
7723
8105
  const tx = issuerTransaction(record2.transaction);
7724
- const hash = issuerBytes(record2.hash, "hash", 32);
8106
+ const hash2 = issuerBytes(record2.hash, "hash", 32);
7725
8107
  const client = await clientFor(tx.chainId);
7726
8108
  let replacementReason;
7727
8109
  const receipt = await client.waitForTransactionReceipt({
7728
- hash,
8110
+ hash: hash2,
7729
8111
  ...wait,
7730
8112
  onReplaced: ({ reason }) => {
7731
8113
  replacementReason = reason;
7732
8114
  }
7733
8115
  });
7734
- const base = { submittedHash: hash, hash: receipt.transactionHash, receipt };
7735
- if (replacementReason || receipt.transactionHash.toLowerCase() !== hash.toLowerCase())
8116
+ const base = { submittedHash: hash2, hash: receipt.transactionHash, receipt };
8117
+ if (replacementReason || receipt.transactionHash.toLowerCase() !== hash2.toLowerCase())
7736
8118
  return {
7737
8119
  ...base,
7738
8120
  status: "replaced",
7739
8121
  ...replacementReason === void 0 ? {} : { replacementReason }
7740
8122
  };
7741
8123
  if (receipt.status === "reverted") return { ...base, status: "reverted" };
7742
- const actual = await client.getTransaction({ hash });
8124
+ const actual = await client.getTransaction({ hash: hash2 });
7743
8125
  const actualTo = actual.to ?? void 0;
7744
8126
  const sameTarget = tx.to === void 0 ? actualTo === void 0 : actualTo !== void 0 && sameIssuerAddress(tx.to, actualTo);
7745
- const verified = actual.hash.toLowerCase() === hash.toLowerCase() && sameIssuerAddress(actual.from, tx.from) && sameTarget && actual.input.toLowerCase() === tx.data.toLowerCase() && actual.value === tx.value && (actual.chainId === void 0 || actual.chainId === tx.chainId) && (tx.to !== void 0 || !!receipt.contractAddress);
8127
+ const verified = actual.hash.toLowerCase() === hash2.toLowerCase() && sameIssuerAddress(actual.from, tx.from) && sameTarget && actual.input.toLowerCase() === tx.data.toLowerCase() && actual.value === tx.value && (actual.chainId === void 0 || actual.chainId === tx.chainId) && (tx.to !== void 0 || !!receipt.contractAddress);
7746
8128
  return { ...base, status: verified ? "confirmed" : "unverified" };
7747
8129
  }
7748
8130
  async function waitForDeployment(record2, wait) {
@@ -7887,10 +8269,10 @@ function createIssuersNamespace(options = {}) {
7887
8269
  }
7888
8270
  async function getApprovedPolicies(input) {
7889
8271
  const client = await clientFor(input.chainId);
7890
- const address4 = issuerAddress(input.policyRegistry, "policyRegistry");
8272
+ const address5 = issuerAddress(input.policyRegistry, "policyRegistry");
7891
8273
  const policyType = issuerBytes(input.policyType, "policyType", 32);
7892
8274
  const { number: blockNumber } = await client.getBlock({ blockTag: "latest" });
7893
- const req = { address: address4, abi: issuerPolicyRegistryAbi, blockNumber };
8275
+ const req = { address: address5, abi: issuerPolicyRegistryAbi, blockNumber };
7894
8276
  const implementations = await client.readContract({
7895
8277
  ...req,
7896
8278
  functionName: "implementationsOf",
@@ -7990,6 +8372,7 @@ function createIssuersNamespace(options = {}) {
7990
8372
  };
7991
8373
  }
7992
8374
  return {
8375
+ discoverDeployment,
7993
8376
  prepareDeployment,
7994
8377
  simulateDeployment,
7995
8378
  sendDeployment,
@@ -8182,21 +8565,21 @@ async function waitForSandboxUserFunding(publicClient, submission, wait) {
8182
8565
  };
8183
8566
  if (tx.value === 0n || tx.data !== "0x")
8184
8567
  invalid("Funding must be a positive native transfer with empty data.");
8185
- const hash = issuerBytes(submission.hash, "hash", 32);
8568
+ const hash2 = issuerBytes(submission.hash, "hash", 32);
8186
8569
  const options = waitOptions(wait);
8187
8570
  await checkChain(publicClient, tx.chainId);
8188
8571
  let replacementReason;
8189
8572
  const receipt = structuredClone(
8190
8573
  await publicClient.waitForTransactionReceipt({
8191
- hash,
8574
+ hash: hash2,
8192
8575
  ...options,
8193
8576
  onReplaced: ({ reason }) => {
8194
8577
  replacementReason = reason;
8195
8578
  }
8196
8579
  })
8197
8580
  );
8198
- const base = { submittedHash: hash, hash: receipt.transactionHash, receipt };
8199
- if (replacementReason || receipt.transactionHash.toLowerCase() !== hash.toLowerCase())
8581
+ const base = { submittedHash: hash2, hash: receipt.transactionHash, receipt };
8582
+ if (replacementReason || receipt.transactionHash.toLowerCase() !== hash2.toLowerCase())
8200
8583
  return {
8201
8584
  ...base,
8202
8585
  status: "replaced",
@@ -8205,11 +8588,11 @@ async function waitForSandboxUserFunding(publicClient, submission, wait) {
8205
8588
  if (receipt.status === "reverted") return { ...base, status: "reverted" };
8206
8589
  let actual;
8207
8590
  try {
8208
- actual = await publicClient.getTransaction({ hash });
8591
+ actual = await publicClient.getTransaction({ hash: hash2 });
8209
8592
  } catch {
8210
8593
  return { ...base, status: "unverified" };
8211
8594
  }
8212
- const verified = actual.hash.toLowerCase() === hash.toLowerCase() && sameIssuerAddress(actual.from, tx.from) && actual.to !== null && sameIssuerAddress(actual.to, tx.to) && actual.input === "0x" && actual.value === tx.value && (actual.chainId === void 0 || actual.chainId === tx.chainId);
8595
+ const verified = actual.hash.toLowerCase() === hash2.toLowerCase() && sameIssuerAddress(actual.from, tx.from) && actual.to !== null && sameIssuerAddress(actual.to, tx.to) && actual.input === "0x" && actual.value === tx.value && (actual.chainId === void 0 || actual.chainId === tx.chainId);
8213
8596
  return { ...base, status: verified ? "confirmed" : "unverified" };
8214
8597
  }
8215
8598
  function sameTransaction(a, b) {
@@ -8327,15 +8710,15 @@ async function createSandboxUser(publicClient, params) {
8327
8710
  await checkChain(publicClient, chainId4);
8328
8711
  if (!sameIssuerAddress(await walletAddress(sponsor, chainId4), from))
8329
8712
  invalid("Selected funding account changed before sending.");
8330
- const hash = await sponsor.sendTransaction({
8713
+ const hash2 = await sponsor.sendTransaction({
8331
8714
  account: sponsor.account ?? from,
8332
8715
  chain: sponsor.chain ?? chain2,
8333
8716
  to: account.address,
8334
8717
  value: transaction.value,
8335
8718
  data: "0x"
8336
8719
  });
8337
- state.funding = { kind: "funding", hash, transaction };
8338
- state.pending.hash = hash;
8720
+ state.funding = { kind: "funding", hash: hash2, transaction };
8721
+ state.pending.hash = hash2;
8339
8722
  state.stage = "waiting-funding";
8340
8723
  await save();
8341
8724
  const result = await waitForSandboxUserFunding(publicClient, state.funding, wait);
@@ -8590,15 +8973,15 @@ async function transferSandboxUser(publicClient, params) {
8590
8973
  await checkChain2(publicClient, chainId4);
8591
8974
  if (!sameIssuerAddress(await fundingAccount(sponsor, chainId4), from))
8592
8975
  invalid("Selected funding account changed before sending.");
8593
- const hash = await sponsor.sendTransaction({
8976
+ const hash2 = await sponsor.sendTransaction({
8594
8977
  account: sendAccount,
8595
8978
  chain: chain2,
8596
8979
  to: wallet,
8597
8980
  value: transaction.value,
8598
8981
  data: "0x"
8599
8982
  });
8600
- state.funding = { kind: "funding", hash, transaction: structuredClone(transaction) };
8601
- state.pending.hash = hash;
8983
+ state.funding = { kind: "funding", hash: hash2, transaction: structuredClone(transaction) };
8984
+ state.pending.hash = hash2;
8602
8985
  state.stage = "waiting-funding";
8603
8986
  await save();
8604
8987
  const result2 = structuredClone(
@@ -9065,7 +9448,7 @@ function createSandboxWalletLinksNamespace(options) {
9065
9448
  );
9066
9449
  const tx = buildSandboxWalletLinkTransaction(intent, signature);
9067
9450
  attempted = true;
9068
- const hash = await wallet.sendTransaction({
9451
+ const hash2 = await wallet.sendTransaction({
9069
9452
  account: wallet.account ?? intent.existingWallet,
9070
9453
  chain: wallet.chain ?? defineChain({
9071
9454
  id: intent.chainId,
@@ -9078,7 +9461,7 @@ function createSandboxWalletLinksNamespace(options) {
9078
9461
  value: 0n,
9079
9462
  nonce: progress.senderNonce
9080
9463
  });
9081
- progress.hash = issuerBytes(hash, "transaction hash", 32);
9464
+ progress.hash = issuerBytes(hash2, "transaction hash", 32);
9082
9465
  progress.stage = "submitted";
9083
9466
  await save();
9084
9467
  return structuredClone(progress);
@@ -9118,7 +9501,7 @@ function createSandboxWalletLinksNamespace(options) {
9118
9501
  if (input.kind !== "wallet-link" || !["submitted", "complete"].includes(input.stage))
9119
9502
  invalid("Expected a submitted wallet link.");
9120
9503
  const intent = validateSandboxWalletLinkIntent(input.intent);
9121
- const hash = issuerBytes(input.hash, "hash", 32);
9504
+ const hash2 = issuerBytes(input.hash, "hash", 32);
9122
9505
  const senderNonce = input.senderNonce;
9123
9506
  if (!Number.isSafeInteger(senderNonce) || senderNonce < 0)
9124
9507
  invalid("senderNonce must be a nonnegative safe integer.");
@@ -9127,7 +9510,7 @@ function createSandboxWalletLinksNamespace(options) {
9127
9510
  let replacementReason;
9128
9511
  const receipt = structuredClone(
9129
9512
  await client.waitForTransactionReceipt({
9130
- hash,
9513
+ hash: hash2,
9131
9514
  ...waitOptions3,
9132
9515
  onReplaced: ({ reason }) => {
9133
9516
  replacementReason = reason;
@@ -9135,22 +9518,22 @@ function createSandboxWalletLinksNamespace(options) {
9135
9518
  })
9136
9519
  );
9137
9520
  await clientFor(intent.chainId);
9138
- const base = { submittedHash: hash, hash: receipt.transactionHash, receipt };
9521
+ const base = { submittedHash: hash2, hash: receipt.transactionHash, receipt };
9139
9522
  let exactTransaction = false;
9140
9523
  let result = { ...base, status: "unverified" };
9141
- if (replacementReason || receipt.transactionHash.toLowerCase() !== hash.toLowerCase())
9524
+ if (replacementReason || receipt.transactionHash.toLowerCase() !== hash2.toLowerCase())
9142
9525
  result = { ...base, status: "replaced", ...replacementReason ? { replacementReason } : {} };
9143
9526
  else if (receipt.status === "reverted") result = { ...base, status: "reverted" };
9144
9527
  else if (receipt.status === "success") {
9145
9528
  try {
9146
- const tx = await client.getTransaction({ hash });
9529
+ const tx = await client.getTransaction({ hash: hash2 });
9147
9530
  await clientFor(intent.chainId);
9148
9531
  const decoded = decodeFunctionData({ abi: sandboxWalletLinkAbi, data: tx.input });
9149
- const matches = sameIssuerAddress(receipt.from, intent.existingWallet) && receipt.to !== null && sameIssuerAddress(receipt.to, intent.registryAddress) && tx.blockHash === receipt.blockHash && tx.blockNumber === receipt.blockNumber && tx.hash.toLowerCase() === hash.toLowerCase() && tx.chainId === intent.chainId && sameIssuerAddress(tx.from, intent.existingWallet) && tx.to !== null && sameIssuerAddress(tx.to, intent.registryAddress) && tx.value === 0n && (senderNonce === void 0 || tx.nonce === senderNonce) && decoded.functionName === "sandboxLinkWallet" && sameIssuerAddress(decoded.args[0], intent.newWallet) && decoded.args[1].toLowerCase() === intent.nonce.toLowerCase() && decoded.args[2] === intent.deadline;
9532
+ const matches = sameIssuerAddress(receipt.from, intent.existingWallet) && receipt.to !== null && sameIssuerAddress(receipt.to, intent.registryAddress) && tx.blockHash === receipt.blockHash && tx.blockNumber === receipt.blockNumber && tx.hash.toLowerCase() === hash2.toLowerCase() && tx.chainId === intent.chainId && sameIssuerAddress(tx.from, intent.existingWallet) && tx.to !== null && sameIssuerAddress(tx.to, intent.registryAddress) && tx.value === 0n && (senderNonce === void 0 || tx.nonce === senderNonce) && decoded.functionName === "sandboxLinkWallet" && sameIssuerAddress(decoded.args[0], intent.newWallet) && decoded.args[1].toLowerCase() === intent.nonce.toLowerCase() && decoded.args[2] === intent.deadline;
9150
9533
  exactTransaction = matches;
9151
9534
  if (matches)
9152
9535
  for (const log of receipt.logs) {
9153
- if (!sameIssuerAddress(log.address, intent.registryAddress) || log.removed || log.blockHash !== receipt.blockHash || log.blockNumber !== receipt.blockNumber || log.transactionHash?.toLowerCase() !== hash.toLowerCase())
9536
+ if (!sameIssuerAddress(log.address, intent.registryAddress) || log.removed || log.blockHash !== receipt.blockHash || log.blockNumber !== receipt.blockNumber || log.transactionHash?.toLowerCase() !== hash2.toLowerCase())
9154
9537
  continue;
9155
9538
  try {
9156
9539
  const { args } = decodeEventLog({
@@ -9171,14 +9554,14 @@ function createSandboxWalletLinksNamespace(options) {
9171
9554
  const current = pending.get(keyFor(intent));
9172
9555
  if (current?.hash === void 0 && current?.stage === "sending" && result.status === "reverted") {
9173
9556
  try {
9174
- const tx = await client.getTransaction({ hash });
9557
+ const tx = await client.getTransaction({ hash: hash2 });
9175
9558
  await clientFor(intent.chainId);
9176
9559
  const decoded = decodeFunctionData({ abi: sandboxWalletLinkAbi, data: tx.input });
9177
- exactTransaction = tx.hash.toLowerCase() === hash.toLowerCase() && tx.chainId === intent.chainId && sameIssuerAddress(tx.from, intent.existingWallet) && tx.to !== null && sameIssuerAddress(tx.to, intent.registryAddress) && tx.value === 0n && tx.nonce === senderNonce && tx.blockHash === receipt.blockHash && tx.blockNumber === receipt.blockNumber && decoded.functionName === "sandboxLinkWallet" && sameIssuerAddress(decoded.args[0], intent.newWallet) && decoded.args[1].toLowerCase() === intent.nonce.toLowerCase() && decoded.args[2] === intent.deadline;
9560
+ exactTransaction = tx.hash.toLowerCase() === hash2.toLowerCase() && tx.chainId === intent.chainId && sameIssuerAddress(tx.from, intent.existingWallet) && tx.to !== null && sameIssuerAddress(tx.to, intent.registryAddress) && tx.value === 0n && tx.nonce === senderNonce && tx.blockHash === receipt.blockHash && tx.blockNumber === receipt.blockNumber && decoded.functionName === "sandboxLinkWallet" && sameIssuerAddress(decoded.args[0], intent.newWallet) && decoded.args[1].toLowerCase() === intent.nonce.toLowerCase() && decoded.args[2] === intent.deadline;
9178
9561
  } catch {
9179
9562
  }
9180
9563
  }
9181
- if (current && pending.get(keyFor(intent)) === current && sameIntent(current.intent, intent) && (current.hash?.toLowerCase() === hash.toLowerCase() || current.hash === void 0 && current.stage === "sending" && current.senderNonce === senderNonce && exactTransaction) && (result.status === "confirmed" || result.status === "reverted" || result.status === "replaced"))
9564
+ if (current && pending.get(keyFor(intent)) === current && sameIntent(current.intent, intent) && (current.hash?.toLowerCase() === hash2.toLowerCase() || current.hash === void 0 && current.stage === "sending" && current.senderNonce === senderNonce && exactTransaction) && (result.status === "confirmed" || result.status === "reverted" || result.status === "replaced"))
9182
9565
  pending.delete(keyFor(intent));
9183
9566
  return result;
9184
9567
  }
@@ -9413,6 +9796,6 @@ function restoreSandboxLinkedWallet(input, options) {
9413
9796
  );
9414
9797
  }
9415
9798
 
9416
- export { DEFAULT_ISSUER_BEACON_VARIANT, EMPTY_ISSUER_ENGINE, ISSUER_CONTRACTS_COMMIT, ISSUER_CONTRACTS_PR, IssuerDenominatorMode, IssuerGuardMode, IssuerRuleType, OpacityIssuerOperationError, OpacityPurchaseError, OpacityTransferError, SANDBOX_ISSUER_DEPLOYMENT, SANDBOX_PURCHASE_DEPLOYMENT, SandboxLinkedWalletCreationError, SandboxTransferError, SandboxUserCreationError, SandboxWalletLinkError, buildAdapterOperation, buildConfigureVaultTransaction, buildForcedTransferTransaction, buildIssuerAdapterDeployment, buildIssuerDeployTokenTransaction, buildIssuerSandboxAddSelfTransaction, buildIssuerSandboxRegisterIssuerTransaction, buildIssuerSandboxSetSelfTraitTransaction, buildIssuerSandboxVaultDeployment, buildIssuerTokenTraitRegistryDeployment, buildIssuerVaultDeployment, buildMintTransaction, buildOverrideOperation, buildOverrideTransferTransaction, buildOverrideTransferTypedData, buildPaymentTokenOperation, buildPolicyEngineOperation, buildPolicyModuleOperation, buildPolicyRegistryOperation, buildPurchaseTransaction, buildPurchaseWriteRequest, buildRuleSetOperation, buildSandboxRegistryOperation, buildSandboxVaultOperation, buildSandboxWalletLinkTransaction, buildSandboxWalletLinkTypedData, buildSetIssuerAdminTransaction, buildSetUserTraitsTransactions, buildSetWalletsTransaction, buildTokenMetadataTransactions, buildTokenOperation, buildTransferTransaction, buildTransferWriteRequest, buildVaultOperation, createIssuersNamespace, createPolicyAttachment, createPolicyBatch, createPolicyReplacementBatch, createPurchasesNamespace, createSandboxLinkedWallet, createSandboxUser, createSandboxWalletLinksNamespace, createTransfersNamespace, encodeAllowedTransfereeConfig, encodeCeilingBalanceConfig, encodeDenylistConfig, encodeFloorBalanceConfig, encodeHolderCountCapConfig, encodeInsiderFreezeConfig, encodeSelfTransferOnlyConfig, encodeTradingDisabledConfig, issuerAdapterAbi, issuerAdapterBytecode, issuerBeaconRegistryAbi, issuerFactoryAbi, issuerLensAbi, issuerOverrideHelperAbi, issuerOverrideTypes, issuerPaymentTokenAbi, issuerPolicyEngineAbi, issuerPolicyModuleAbis, issuerPolicyRegistryAbi, issuerPolicyTypes, issuerRegistryAbi, issuerRuleSetOrchestratorAbi, issuerSandboxVaultAbi, issuerSandboxVaultBytecode, issuerTokenAbi, issuerTokenTraitRegistryAbi, issuerTokenTraitRegistryBytecode, issuerVaultAbi, issuerVaultBytecode, parsePurchaseAmount, parseTransferAmount, prepareSandboxUser, purchasePaymentTokenAbi, purchaseRegistryAbi, purchaseSecurityTokenAbi, resolveSandboxUserTraits, restoreSandboxLinkedWallet, restoreSandboxUserWallet, sandboxJurisdictionTraitId, sandboxTraitId, sandboxWalletLinkAbi, sandboxWalletLinkTypes, securityTokenVaultAbi, transferSandboxUser, validateSandboxLinkedWalletProgress, validateSandboxWalletLinkIntent, validateSandboxWalletLinkParams, waitForSandboxUserFunding, walletLinkData, walletLinkWaitOptions };
9799
+ export { DEFAULT_ISSUER_BEACON_VARIANT, EMPTY_ISSUER_ENGINE, ISSUER_CONTRACTS_COMMIT, ISSUER_CONTRACTS_PR, IssuerDenominatorMode, IssuerGuardMode, IssuerRuleType, OpacityIssuerOperationError, OpacityPurchaseError, OpacityTransferError, SANDBOX_ISSUER_DEPLOYMENT, SANDBOX_PURCHASE_DEPLOYMENT, SandboxLinkedWalletCreationError, SandboxTransferError, SandboxUserCreationError, SandboxWalletLinkError, buildAdapterOperation, buildConfigureVaultTransaction, buildForcedTransferTransaction, buildIssuerAdapterDeployment, buildIssuerDeployTokenTransaction, buildIssuerSandboxAddSelfTransaction, buildIssuerSandboxRegisterIssuerTransaction, buildIssuerSandboxSetSelfTraitTransaction, buildIssuerSandboxVaultDeployment, buildIssuerTokenTraitRegistryDeployment, buildIssuerVaultDeployment, buildMintTransaction, buildOverrideOperation, buildOverrideTransferTransaction, buildOverrideTransferTypedData, buildPaymentTokenOperation, buildPolicyEngineOperation, buildPolicyModuleOperation, buildPolicyRegistryOperation, buildPurchaseTransaction, buildPurchaseWriteRequest, buildRuleSetOperation, buildSandboxRegistryOperation, buildSandboxVaultOperation, buildSandboxWalletLinkTransaction, buildSandboxWalletLinkTypedData, buildSetIssuerAdminTransaction, buildSetUserTraitsTransactions, buildSetWalletsTransaction, buildTokenMetadataTransactions, buildTokenOperation, buildTransferTransaction, buildTransferWriteRequest, buildVaultOperation, createIssuersNamespace, createPolicyAttachment, createPolicyBatch, createPolicyReplacementBatch, createPurchasesNamespace, createSandboxLinkedWallet, createSandboxUser, createSandboxWalletLinksNamespace, createTransfersNamespace, encodeAllowedTransfereeConfig, encodeCeilingBalanceConfig, encodeDenylistConfig, encodeFloorBalanceConfig, encodeHolderCountCapConfig, encodeInsiderFreezeConfig, encodeSelfTransferOnlyConfig, encodeTradingDisabledConfig, issuerAdapterAbi, issuerAdapterBytecode, issuerBeaconRegistryAbi, issuerFactoryAbi, issuerLensAbi, issuerOverrideHelperAbi, issuerOverrideTypes, issuerPaymentTokenAbi, issuerPolicyEngineAbi, issuerPolicyModuleAbis, issuerPolicyRegistryAbi, issuerPolicyTypes, issuerRegistryAbi, issuerRuleSetOrchestratorAbi, issuerSandboxVaultAbi, issuerSandboxVaultBytecode, issuerTokenAbi, issuerTokenTraitRegistryAbi, issuerTokenTraitRegistryBytecode, issuerVaultAbi, issuerVaultBytecode, parsePurchaseAmount, parseTransferAmount, prepareSandboxUser, purchasePaymentTokenAbi, purchaseRegistryAbi, purchaseSecurityTokenAbi, resolveIssuerDeployment, resolveSandboxUserTraits, restoreSandboxLinkedWallet, restoreSandboxUserWallet, sandboxJurisdictionTraitId, sandboxTraitId, sandboxWalletLinkAbi, sandboxWalletLinkTypes, securityTokenVaultAbi, transferSandboxUser, validateSandboxLinkedWalletProgress, validateSandboxWalletLinkIntent, validateSandboxWalletLinkParams, waitForSandboxUserFunding, walletLinkData, walletLinkWaitOptions };
9417
9800
  //# sourceMappingURL=index.js.map
9418
9801
  //# sourceMappingURL=index.js.map