@gvnrdao/dh-sdk 0.0.300 → 0.0.301

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
@@ -416,6 +416,20 @@ var init_deployment_addresses = __esm({
416
416
  upgradedAt: "2026-06-16T17:53:24.979Z",
417
417
  upgradedBy: "0xEba7BfAeB35ee18408b424Ee0BB45AdDf776589f",
418
418
  reason: "Initial PSM deploy / artifact sync"
419
+ },
420
+ CollateralManagerModule: {
421
+ previousImplementation: "0x1919860e528Cd2AbbD31a17858c986b8aCc8C185",
422
+ newImplementation: "0x55110B9dd6B2c9f812564e7a1ef42b3c76E1A3Bb",
423
+ upgradedAt: "2026-07-08T20:33:59Z",
424
+ upgradedBy: "AdminModule generic-op 0x740efe0cfe85044479cbd8ee3058aa244057d90703dd2b37044dd6787cbf3485 (3-of-5 ADMIN_ROLE Safes, 24h timelock; executed by 0xfb3B8cbeFB7D666A6Af34C53e189EdC31862a7be in tx 0x430c8e450f12d3d9359cde356ac5e2ef39661d7a89884b5674a596c1090f6cff)",
425
+ reason: "Validator gas fix (#420): BitcoinAddressValidator packed-table lookups; VERSION 1.3.0 -> 1.3.1"
426
+ },
427
+ BitcoinWithdrawalAddressRegistry: {
428
+ previousImplementation: "0x11731bFEC3068F2cc19D016381dfEA3B93013b1C",
429
+ newImplementation: "0x190c08300Ae650fb88ed8156445BBeb13bE9E8a3",
430
+ upgradedAt: "2026-07-08T20:33:59Z",
431
+ upgradedBy: "AdminModule generic-op 0x2603a486c0f34554b864cc1d909b325c7e105331da10ec0fd7e0b9373fa76207 (3-of-5 ADMIN_ROLE Safes, 24h timelock; executed by 0xfb3B8cbeFB7D666A6Af34C53e189EdC31862a7be in tx 0x430c8e450f12d3d9359cde356ac5e2ef39661d7a89884b5674a596c1090f6cff)",
432
+ reason: "Validator gas fix (#420): BitcoinAddressValidator packed-table lookups; VERSION 1.0.0 -> 1.0.1"
419
433
  }
420
434
  },
421
435
  latestEnv: {
@@ -1190,17 +1204,17 @@ var require_pkg_src = __commonJS({
1190
1204
  }
1191
1205
  },
1192
1206
  btcTransactionSigner: {
1193
- cid: "QmZs56sVTCJv7mgvyRYfpYHFvFLcSeXa4H44qUYT7z14QP",
1207
+ cid: "QmcPG9C5Yx9JGrBKCfSVWbKuiRXn8XFwb91yNxQqY4VSJD",
1194
1208
  authorizedCidHex: cidToHex(
1195
- "QmZs56sVTCJv7mgvyRYfpYHFvFLcSeXa4H44qUYT7z14QP"
1209
+ "QmcPG9C5Yx9JGrBKCfSVWbKuiRXn8XFwb91yNxQqY4VSJD"
1196
1210
  ),
1197
1211
  name: "Btc Transaction Signer",
1198
1212
  description: "Production Btc Transaction Signer",
1199
- version: "1.0.0",
1213
+ version: "1.0.1",
1200
1214
  deployed: true,
1201
- deployedAt: 1781542204806,
1202
- size: 42376,
1203
- hash: "f4aed3d88f6fbff6623ed2047436cecd4f561a74883171ea6f4ebe0a1129973c"
1215
+ deployedAt: 1783451891948,
1216
+ size: 43688,
1217
+ hash: "1ea0f0ac66cc68fc9b098dabb3c5e3ba96c25f13b133b95a06eac477028fdb1a"
1204
1218
  },
1205
1219
  ucdMintValidator: {
1206
1220
  cid: "QmPir8F8jmJ4ssQpEC3xFxkEnZxMHcgS6VxBQE1jkTLj5K",
@@ -2140,7 +2154,7 @@ ${errorReport}`);
2140
2154
  }
2141
2155
  init_debug_logger();
2142
2156
  init_session_signature_cache();
2143
- var import_ethers15 = require("ethers");
2157
+ var import_ethers16 = require("ethers");
2144
2158
  var EXPIRED_LOAN_MIN_LIQUIDATION_THRESHOLD_BPS = 11e3;
2145
2159
  var GRACE_PERIOD_DAYS = 30;
2146
2160
  var SATOSHIS_PER_BITCOIN = 100000000n;
@@ -4375,12 +4389,12 @@ ${auth.clientId}`;
4375
4389
  }
4376
4390
  async function executeVaultSnapshot(params) {
4377
4391
  global.ethers = {
4378
- ...import_ethers15.ethers,
4392
+ ...import_ethers16.ethers,
4379
4393
  providers: {
4380
- StaticJsonRpcProvider: import_ethers15.ethers.JsonRpcProvider
4394
+ StaticJsonRpcProvider: import_ethers16.ethers.JsonRpcProvider
4381
4395
  },
4382
- Contract: import_ethers15.ethers.Contract,
4383
- utils: import_ethers15.ethers
4396
+ Contract: import_ethers16.ethers.Contract,
4397
+ utils: import_ethers16.ethers
4384
4398
  // v6 moved utils to top level
4385
4399
  };
4386
4400
  global.Lit = {
@@ -4913,7 +4927,7 @@ __export(src_exports, {
4913
4927
  module.exports = __toCommonJS(src_exports);
4914
4928
 
4915
4929
  // src/modules/diamond-hands-sdk.ts
4916
- var import_ethers13 = require("ethers");
4930
+ var import_ethers14 = require("ethers");
4917
4931
 
4918
4932
  // src/types/result.ts
4919
4933
  function success(value) {
@@ -5297,22 +5311,12 @@ var SDKError = class _SDKError extends Error {
5297
5311
 
5298
5312
  // src/utils/chunks/eip1559-broadcast.utils.ts
5299
5313
  var import_ethers = require("ethers");
5300
- var MINT_UCD_GAS_CEILING = BigInt(2e6);
5314
+ var MINT_UCD_GAS_CEILING = BigInt(13e5);
5301
5315
  var WITHDRAW_BTC_GAS_CEILING = BigInt(3e6);
5302
5316
  var MAKE_PAYMENT_GAS_CEILING = BigInt(1e6);
5303
5317
  var EXTEND_POSITION_GAS_CEILING = BigInt(1e6);
5304
5318
  var LIQUIDATION_COMMIT_GAS_CEILING = BigInt(1e6);
5305
5319
  var LIQUIDATION_REVEAL_GAS_CEILING = BigInt(2e6);
5306
- var MINT_UCD_ESTIMATE_MARGIN_BPS = 2500;
5307
- async function estimateContractCallGasWithMargin(provider, from, to, data, marginBps, ceiling) {
5308
- try {
5309
- const estimated = await provider.estimateGas({ from, to, data });
5310
- const withMargin = estimated * BigInt(1e4 + marginBps) / 10000n;
5311
- return withMargin > ceiling ? ceiling : withMargin;
5312
- } catch {
5313
- return null;
5314
- }
5315
- }
5316
5320
  async function resolveEip1559FeeFields(provider) {
5317
5321
  const feeData = await provider.getFeeData();
5318
5322
  let maxFeePerGas = feeData.maxFeePerGas ?? void 0;
@@ -5916,7 +5920,10 @@ var ServerSession = class {
5916
5920
  };
5917
5921
 
5918
5922
  // src/utils/quantum-revert.utils.ts
5923
+ var import_ethers5 = require("ethers");
5919
5924
  var DEAD_ZONE_VIOLATION_SELECTOR = "0xbe4b82c1";
5925
+ var ERROR_STRING_SELECTOR = "0x08c379a0";
5926
+ var PANIC_SELECTOR = "0x4e487b71";
5920
5927
  var QUANTUM_REVERT_NAMES = {
5921
5928
  "0xbe4b82c1": "DeadZoneViolation()",
5922
5929
  "0x137f3b70": "InDeadZone()",
@@ -5940,12 +5947,96 @@ function decodeQuantumRevert(e) {
5940
5947
  e?.error?.data?.data ?? e?.error?.data ?? e?.error?.error?.data;
5941
5948
  const data = typeof raw === "string" && raw.startsWith("0x") ? raw : null;
5942
5949
  const selector = data && data.length >= 10 ? data.slice(0, 10) : null;
5943
- const name = selector ? QUANTUM_REVERT_NAMES[selector] ?? null : null;
5950
+ let name = selector ? QUANTUM_REVERT_NAMES[selector] ?? null : null;
5951
+ if (!name && selector && data) {
5952
+ try {
5953
+ if (selector === ERROR_STRING_SELECTOR) {
5954
+ const [message] = import_ethers5.AbiCoder.defaultAbiCoder().decode(
5955
+ ["string"],
5956
+ "0x" + data.slice(10)
5957
+ );
5958
+ name = `Error("${message}")`;
5959
+ } else if (selector === PANIC_SELECTOR) {
5960
+ const [code] = import_ethers5.AbiCoder.defaultAbiCoder().decode(
5961
+ ["uint256"],
5962
+ "0x" + data.slice(10)
5963
+ );
5964
+ name = `Panic(0x${code.toString(16)})`;
5965
+ }
5966
+ } catch {
5967
+ }
5968
+ }
5944
5969
  return { data, selector, name };
5945
5970
  }
5946
5971
 
5972
+ // src/utils/quantum-submission.utils.ts
5973
+ var MAX_DEADZONE_RESIMULATIONS = 3;
5974
+ var QuantumRevertError = class extends Error {
5975
+ constructor(errorName, selector, data, cause) {
5976
+ super(
5977
+ `Pre-send simulation reverted: ${errorName ?? selector ?? "unknown"}`
5978
+ );
5979
+ this.errorName = errorName;
5980
+ this.selector = selector;
5981
+ this.data = data;
5982
+ this.cause = cause;
5983
+ this.name = "QuantumRevertError";
5984
+ }
5985
+ };
5986
+ async function assertSafeQuantumSubmission(opts) {
5987
+ const { provider, to, from, data, quantumTimestamp } = opts;
5988
+ const maxResimulations = opts.maxResimulations ?? MAX_DEADZONE_RESIMULATIONS;
5989
+ const now = opts.now ?? (() => Math.floor(Date.now() / 1e3));
5990
+ const onDebug = opts.onDebug ?? (() => {
5991
+ });
5992
+ const gateOpts = {
5993
+ now,
5994
+ ...opts.sleep ? { sleep: opts.sleep } : {}
5995
+ };
5996
+ await awaitSafeSubmissionWindow(quantumTimestamp, gateOpts);
5997
+ for (let sim = 1; ; sim++) {
5998
+ try {
5999
+ await provider.call({ to, from, data });
6000
+ break;
6001
+ } catch (simError) {
6002
+ const decoded = decodeQuantumRevert(simError);
6003
+ if (decoded.selector === DEAD_ZONE_VIOLATION_SELECTOR && sim <= maxResimulations) {
6004
+ const sigQuantum = Math.floor(quantumTimestamp / QUANTUM_WINDOW_SECONDS) * QUANTUM_WINDOW_SECONDS;
6005
+ const realCurrentQuantum = Math.floor(now() / QUANTUM_WINDOW_SECONDS) * QUANTUM_WINDOW_SECONDS;
6006
+ if (sigQuantum === realCurrentQuantum) {
6007
+ onDebug(
6008
+ "\u21AA\uFE0F Simulated DeadZoneViolation is a stale-latest-block artifact (signature is the current quantum) \u2014 proceeding to broadcast"
6009
+ );
6010
+ break;
6011
+ }
6012
+ const gate = await awaitSafeSubmissionWindow(quantumTimestamp, gateOpts);
6013
+ if (gate.waited) {
6014
+ onDebug(
6015
+ `\u{1F501} Re-simulating after crossing the quantum boundary (attempt ${sim}/${maxResimulations})`
6016
+ );
6017
+ continue;
6018
+ }
6019
+ }
6020
+ if (!decoded.data) {
6021
+ const label = simError instanceof Error ? simError.message : String(simError);
6022
+ onDebug(
6023
+ `\u26A0\uFE0F Pre-send simulation failed without revert data (${label}) \u2014 proceeding to broadcast`
6024
+ );
6025
+ break;
6026
+ }
6027
+ throw new QuantumRevertError(
6028
+ decoded.name,
6029
+ decoded.selector,
6030
+ decoded.data,
6031
+ simError
6032
+ );
6033
+ }
6034
+ }
6035
+ await awaitSafeSubmissionWindow(quantumTimestamp, gateOpts);
6036
+ }
6037
+
5947
6038
  // src/utils/btc-withdrawal-message.ts
5948
- var import_ethers5 = require("ethers");
6039
+ var import_ethers6 = require("ethers");
5949
6040
  var QUANTUM_SECONDS = 60;
5950
6041
  var QUANTUM_SAFE_THRESHOLD = 40;
5951
6042
  async function buildBtcExecuteEnvelope(params) {
@@ -5980,15 +6071,15 @@ async function buildBtcExecuteEnvelope(params) {
5980
6071
  } else {
5981
6072
  timestamp = currentQuantumStart;
5982
6073
  }
5983
- const actionHash = (0, import_ethers5.keccak256)(
5984
- (0, import_ethers5.toUtf8Bytes)("execute-btc-withdrawal")
6074
+ const actionHash = (0, import_ethers6.keccak256)(
6075
+ (0, import_ethers6.toUtf8Bytes)("execute-btc-withdrawal")
5985
6076
  );
5986
6077
  const utxoIdentifier = `${txid}:${vout}`;
5987
- const positionIdBytes32 = (0, import_ethers5.zeroPadValue)(
6078
+ const positionIdBytes32 = (0, import_ethers6.zeroPadValue)(
5988
6079
  positionId.startsWith("0x") ? positionId : `0x${positionId}`,
5989
6080
  32
5990
6081
  );
5991
- const messageHash = (0, import_ethers5.solidityPackedKeccak256)(
6082
+ const messageHash = (0, import_ethers6.solidityPackedKeccak256)(
5992
6083
  [
5993
6084
  "bytes32",
5994
6085
  // positionId
@@ -6018,7 +6109,7 @@ async function buildBtcExecuteEnvelope(params) {
6018
6109
  actionHash
6019
6110
  ]
6020
6111
  );
6021
- const userSignature = await signer.signMessage((0, import_ethers5.getBytes)(messageHash));
6112
+ const userSignature = await signer.signMessage((0, import_ethers6.getBytes)(messageHash));
6022
6113
  const borrowerAddress = await signer.getAddress();
6023
6114
  return {
6024
6115
  positionId,
@@ -6081,7 +6172,7 @@ function maybeTemperSignature(signature, shouldTemper, operationName) {
6081
6172
  }
6082
6173
 
6083
6174
  // src/utils/address-conversion.utils.ts
6084
- var import_ethers6 = require("ethers");
6175
+ var import_ethers7 = require("ethers");
6085
6176
 
6086
6177
  // src/utils/chunks/bitcoin-utils.ts
6087
6178
  var import_sha256 = require("@noble/hashes/sha256");
@@ -6365,7 +6456,7 @@ function normalizeBitcoinAddress(address) {
6365
6456
  }
6366
6457
 
6367
6458
  // src/protocol/protocol-pause.ts
6368
- var import_ethers7 = require("ethers");
6459
+ var import_ethers8 = require("ethers");
6369
6460
  var GET_PROTOCOL_PAUSE_STATUS_ABI = [
6370
6461
  "function getProtocolPauseStatus() view returns (tuple(bool positionManagerPaused, bool positionManagerLiquidationsPaused, bool positionManagerCorePaused, bool loanOperationsPaused, bool collateralManagerPaused, bool liquidationManagerPaused, bool circuitBreakerPaused, bool ucdControllerPaused, bool ucdTokenPaused, bool simplePsmPaused))"
6371
6462
  ];
@@ -6387,7 +6478,7 @@ function rowToStatus(row) {
6387
6478
  return row;
6388
6479
  }
6389
6480
  async function fetchProtocolPauseStatus(provider, positionManagerAddress) {
6390
- const iface = new import_ethers7.Interface(GET_PROTOCOL_PAUSE_STATUS_ABI);
6481
+ const iface = new import_ethers8.Interface(GET_PROTOCOL_PAUSE_STATUS_ABI);
6391
6482
  const data = iface.encodeFunctionData("getProtocolPauseStatus", []);
6392
6483
  const raw = await provider.call({ to: positionManagerAddress, data });
6393
6484
  const decoded = iface.decodeFunctionResult("getProtocolPauseStatus", raw);
@@ -6520,7 +6611,7 @@ function extractOptionalLitSignature(raw) {
6520
6611
  }
6521
6612
 
6522
6613
  // src/modules/contract/contract-manager.module.ts
6523
- var import_ethers8 = require("ethers");
6614
+ var import_ethers9 = require("ethers");
6524
6615
  init_deployment_addresses();
6525
6616
  var POSITION_MANAGER_ABI = [
6526
6617
  "function createPosition(bytes32 pkpId, bytes calldata validatorSignature, string mainnetVaultAddress, string regtestVaultAddress, uint256 selectedTermMonths, uint256 validatorVersion, bytes calldata pkpPublicKey) external returns (bytes32 positionId)",
@@ -6597,43 +6688,43 @@ var ContractManager = class {
6597
6688
  }
6598
6689
  const contractRunner = runner;
6599
6690
  const contracts = {
6600
- positionManager: new import_ethers8.Contract(
6691
+ positionManager: new import_ethers9.Contract(
6601
6692
  contractAddresses.positionManager,
6602
6693
  POSITION_MANAGER_ABI,
6603
6694
  contractRunner
6604
6695
  ),
6605
- loanOperationsManager: new import_ethers8.Contract(
6606
- contractAddresses.loanOperationsManager || import_ethers8.ZeroAddress,
6696
+ loanOperationsManager: new import_ethers9.Contract(
6697
+ contractAddresses.loanOperationsManager || import_ethers9.ZeroAddress,
6607
6698
  LOAN_OPS_ABI,
6608
6699
  contractRunner
6609
6700
  ),
6610
- ucdController: new import_ethers8.Contract(
6701
+ ucdController: new import_ethers9.Contract(
6611
6702
  contractAddresses.ucdToken,
6612
6703
  UCD_CONTROLLER_ABI,
6613
6704
  contractRunner
6614
6705
  ),
6615
- priceFeed: new import_ethers8.Contract(
6616
- contractAddresses.priceFeedConsumer || import_ethers8.ZeroAddress,
6706
+ priceFeed: new import_ethers9.Contract(
6707
+ contractAddresses.priceFeedConsumer || import_ethers9.ZeroAddress,
6617
6708
  PRICE_FEED_ABI,
6618
6709
  contractRunner
6619
6710
  ),
6620
- termManager: new import_ethers8.Contract(
6621
- contractAddresses.termManager || import_ethers8.ZeroAddress,
6711
+ termManager: new import_ethers9.Contract(
6712
+ contractAddresses.termManager || import_ethers9.ZeroAddress,
6622
6713
  TERM_MANAGER_ABI,
6623
6714
  contractRunner
6624
6715
  ),
6625
- circuitBreaker: new import_ethers8.Contract(
6626
- contractAddresses.circuitBreaker || import_ethers8.ZeroAddress,
6716
+ circuitBreaker: new import_ethers9.Contract(
6717
+ contractAddresses.circuitBreaker || import_ethers9.ZeroAddress,
6627
6718
  CIRCUIT_BREAKER_ABI,
6628
6719
  contractRunner
6629
6720
  ),
6630
- liquidationManager: new import_ethers8.Contract(
6631
- contractAddresses.liquidationManager || import_ethers8.ZeroAddress,
6721
+ liquidationManager: new import_ethers9.Contract(
6722
+ contractAddresses.liquidationManager || import_ethers9.ZeroAddress,
6632
6723
  LIQUIDATION_MANAGER_ABI,
6633
6724
  contractRunner
6634
6725
  ),
6635
- bitcoinWithdrawalAddressRegistry: new import_ethers8.Contract(
6636
- contractAddresses.bitcoinWithdrawalAddressRegistry || import_ethers8.ZeroAddress,
6726
+ bitcoinWithdrawalAddressRegistry: new import_ethers9.Contract(
6727
+ contractAddresses.bitcoinWithdrawalAddressRegistry || import_ethers9.ZeroAddress,
6637
6728
  BITCOIN_WITHDRAWAL_ADDRESS_REGISTRY_ABI,
6638
6729
  contractRunner
6639
6730
  )
@@ -6683,13 +6774,13 @@ var ContractManager = class {
6683
6774
  const address = addresses[key];
6684
6775
  if (!address) {
6685
6776
  missing.push(String(key));
6686
- } else if (!(0, import_ethers8.isAddress)(address)) {
6777
+ } else if (!(0, import_ethers9.isAddress)(address)) {
6687
6778
  invalid.push(String(key));
6688
6779
  }
6689
6780
  }
6690
6781
  for (const key of optionalAddresses) {
6691
6782
  const address = addresses[key];
6692
- if (address && !(0, import_ethers8.isAddress)(address)) {
6783
+ if (address && !(0, import_ethers9.isAddress)(address)) {
6693
6784
  invalid.push(String(key));
6694
6785
  }
6695
6786
  }
@@ -7665,7 +7756,7 @@ function createPKPManager(config) {
7665
7756
  }
7666
7757
 
7667
7758
  // src/modules/loan/loan-creator.module.ts
7668
- var import_ethers9 = require("ethers");
7759
+ var import_ethers10 = require("ethers");
7669
7760
  var import_dh_lit_actions = __toESM(require_pkg_src());
7670
7761
  var LoanCreator = class {
7671
7762
  config;
@@ -7995,11 +8086,11 @@ var LoanCreator = class {
7995
8086
  try {
7996
8087
  const mainnetVaultAddress = bitcoinAddresses.mainnet;
7997
8088
  const regtestVaultAddress = bitcoinAddresses.regtest;
7998
- const pkpIdBytes32 = (0, import_ethers9.zeroPadValue)(
7999
- (0, import_ethers9.toBeHex)(BigInt(pkpData.tokenId)),
8089
+ const pkpIdBytes32 = (0, import_ethers10.zeroPadValue)(
8090
+ (0, import_ethers10.toBeHex)(BigInt(pkpData.tokenId)),
8000
8091
  32
8001
8092
  );
8002
- const pkpPublicKeyUncompressed = import_ethers9.SigningKey.computePublicKey(
8093
+ const pkpPublicKeyUncompressed = import_ethers10.SigningKey.computePublicKey(
8003
8094
  pkpData.publicKey,
8004
8095
  false
8005
8096
  );
@@ -8012,7 +8103,7 @@ var LoanCreator = class {
8012
8103
  );
8013
8104
  log.debug(`BigInt conversion: ${BigInt(pkpData.tokenId).toString()}`);
8014
8105
  log.debug(
8015
- `Hex from BigInt: ${(0, import_ethers9.toBeHex)(BigInt(pkpData.tokenId))}`
8106
+ `Hex from BigInt: ${(0, import_ethers10.toBeHex)(BigInt(pkpData.tokenId))}`
8016
8107
  );
8017
8108
  log.debug(`Final bytes32 (zero-padded): ${pkpIdBytes32}`);
8018
8109
  log.debug(
@@ -8176,8 +8267,8 @@ var LoanCreator = class {
8176
8267
  }
8177
8268
  }
8178
8269
  if (this.config.debug) {
8179
- const pkpIdBytes32Check = (0, import_ethers9.zeroPadValue)(
8180
- (0, import_ethers9.toBeHex)(BigInt(pkpData.tokenId)),
8270
+ const pkpIdBytes32Check = (0, import_ethers10.zeroPadValue)(
8271
+ (0, import_ethers10.toBeHex)(BigInt(pkpData.tokenId)),
8181
8272
  32
8182
8273
  );
8183
8274
  log.error("\u274C Loan creation transaction failed", {
@@ -8223,8 +8314,8 @@ var LoanCreator = class {
8223
8314
  const newEventAbi = [
8224
8315
  "event PositionCreated(bytes32 indexed positionId, bytes32 indexed pkpId, address indexed borrower, uint256 requestedCollateralRatio, uint256 selectedTerm, uint256 expiryAt)"
8225
8316
  ];
8226
- const oldIface = new import_ethers9.Interface(oldEventAbi);
8227
- const newIface = new import_ethers9.Interface(newEventAbi);
8317
+ const oldIface = new import_ethers10.Interface(oldEventAbi);
8318
+ const newIface = new import_ethers10.Interface(newEventAbi);
8228
8319
  let positionId;
8229
8320
  if (this.config.debug) {
8230
8321
  log.info("\u{1F50D} Parsing transaction receipt logs", {
@@ -8318,7 +8409,7 @@ var LoanStatus = /* @__PURE__ */ ((LoanStatus2) => {
8318
8409
  })(LoanStatus || {});
8319
8410
 
8320
8411
  // src/modules/loan/loan-query.module.ts
8321
- var import_ethers10 = require("ethers");
8412
+ var import_ethers11 = require("ethers");
8322
8413
  var POSITION_CORE_ABI = [
8323
8414
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
8324
8415
  ];
@@ -8616,7 +8707,7 @@ var LoanQuery = class {
8616
8707
  const isChipotlePkpId2 = typeof rawId === "string" && rawId.length === 40 && !rawId.toLowerCase().startsWith("04");
8617
8708
  if (isChipotlePkpId2) {
8618
8709
  if (this.config.positionManagerCoreAddress && this.config.provider) {
8619
- const pmContract = new import_ethers10.Contract(
8710
+ const pmContract = new import_ethers11.Contract(
8620
8711
  this.config.positionManagerCoreAddress,
8621
8712
  POSITION_CORE_ABI,
8622
8713
  this.config.provider
@@ -8889,7 +8980,7 @@ function createLoanQuery(config) {
8889
8980
  }
8890
8981
 
8891
8982
  // src/modules/withdrawal-address/withdrawal-address.module.ts
8892
- var import_ethers11 = require("ethers");
8983
+ var import_ethers12 = require("ethers");
8893
8984
  var WithdrawalAddressModule = class {
8894
8985
  config;
8895
8986
  graphClient;
@@ -8906,7 +8997,7 @@ var WithdrawalAddressModule = class {
8906
8997
  if (!res.success)
8907
8998
  return res;
8908
8999
  const target = res.value.target;
8909
- if (!target || target === import_ethers11.ZeroAddress) {
9000
+ if (!target || target === import_ethers12.ZeroAddress) {
8910
9001
  return failure(
8911
9002
  new SDKError({
8912
9003
  code: "SDK_WITHDRAWAL_REGISTRY_NOT_CONFIGURED",
@@ -8924,7 +9015,7 @@ var WithdrawalAddressModule = class {
8924
9015
  }
8925
9016
  /** keccak256 of the canonicalized address — matches the on-chain key. */
8926
9017
  static addressHash(btcAddress) {
8927
- return (0, import_ethers11.keccak256)((0, import_ethers11.toUtf8Bytes)(normalizeBitcoinAddress(btcAddress)));
9018
+ return (0, import_ethers12.keccak256)((0, import_ethers12.toUtf8Bytes)(normalizeBitcoinAddress(btcAddress)));
8928
9019
  }
8929
9020
  /**
8930
9021
  * Add a Bitcoin address to the caller's allowlist. It becomes usable only
@@ -11937,7 +12028,7 @@ var DiamondHandsGraph = class {
11937
12028
  };
11938
12029
 
11939
12030
  // src/contracts/typechain-contracts/factories/src/psm/SimplePSMV2__factory.ts
11940
- var import_ethers12 = require("ethers");
12031
+ var import_ethers13 = require("ethers");
11941
12032
  var _abi = [
11942
12033
  {
11943
12034
  inputs: [],
@@ -14505,7 +14596,7 @@ var _abi = [
14505
14596
  ];
14506
14597
  var _bytecode = "0x60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161485a90816100f0823960805181818161278e01526128870152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe6080604052600436101561001257600080fd5b6000803560e01c8062f7fce91461384657806301ffc9a7146137d5578063021d28931461377c5780630871b20614613743578063114249d214610f6157806311d954f81461371a57806313da3166146136e15780631d44a904146136385780631f77bf65146135ff578063248a9ca3146135e05780632b83cccd146131205780632f2ff15d146130ee57806334bac370146130b557806334e181251461307c57806336568abe14613037578063373c86b614612ffe5780633f4ba83a14612f375780634373b57214612f0e5780634451e89b14612b3a5780634ebd25a514612b015780634f1ef2861461280c5780635273b6f6146127e357806352d1902d1461277b578063568fafca146126ed57806359d5d02a146124205780635bc26aea146123eb5780635c975abb146123bb5780635ecc27081461229d5780638456cb59146121a257806385c15d9a1461216957806389d3ad00146120a25780638bff608e146120695780639010d07c1461201657806390ad8b4014611ffa57806391d1485414611fa15780639b759bf714611f5e5780639baf58d214611f415780639f1d0f59146118a8578063a217fddf1461188c578063a3246ad3146117cf578063ad3cb1cc14611788578063b492fc691461168e578063b9f637af14611463578063bf7d911914611424578063c4c5f62414611371578063c55f15ea1461134e578063ca15c87314611317578063ca2ce65d146112de578063cc1f8ffa146112ac578063cf46075e146111a2578063d21a74ff14611165578063d2f8253614611142578063d547741f14611107578063d5d3f78b14610f9a578063d66bd52414610f61578063e1f1c4a714610f44578063e1f3962c14610f18578063ec2f96fe14610ef4578063eda5a26a14610af7578063f1a1eb8414610ab4578063f385116d14610a7b578063f77c479114610a54578063f8c8765e14610661578063faaebd2114610628578063facdfb5e14610488578063fc99bd9a14610377578063fe32e7281461033e5763ffa1ad741461030857600080fd5b3461033b578060031936011261033b57610337610323613a68565b604051918291602083526020830190613a17565b0390f35b80fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361036661392e565b168152601283522054604051908152f35b503461033b57604036600319011261033b5761039161392e565b6010546024359291906001600160a01b03163303610479576001600160a01b03168082526002602052604082205490929060ff16156104665780156104575782825260076020526040822054926103e88285613cb0565b848110610448576001600160ff1b0381116104395760008051602061482e833981519152604085968493846104369852600760205280838a205582519182526020820152a23090339061421c565b80f35b630700fcb360e11b8452600484fd5b63446c8cc960e01b8452600484fd5b63162908e360e11b8252600482fd5b506024916374ed46ad60e01b8252600452fd5b6349db3bd360e01b8252600482fd5b503461033b57602036600319011261033b576104a261392e565b6104aa613f12565b6010546001600160a01b03163303610479576001600160a01b03168082526002602052604082205460ff161561061657808252600760205260408220546040516370a0823160e01b8152306004820152602081602481865afa90811561060b5784916105d4575b50818111156105c5576105248282613b6c565b8215908115610570575b505060008051602061482e833981519152916040918486526007602052808387205582519182526020820152a260016000805160206147ce8339815191525580f35b61271081029080820461271014901517156105b157606484029184830460641417156105b157116105a257388061052e565b63a73af74d60e01b8452600484fd5b634e487b7160e01b86526011600452602486fd5b6105cf8183613b6c565b610524565b90506020813d602011610603575b816105ef602093836139c3565b810103126105fe575138610511565b600080fd5b3d91506105e2565b6040513d86823e3d90fd5b6374ed46ad60e01b8252600452602490fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361065061392e565b168152600483522054604051908152f35b503461033b57608036600319011261033b5761067b61392e565b610683613944565b6044356001600160a01b03811690818103610a50576064356001600160a01b0381169390849003610a4c5760008051602061480e83398151915254604081901c60ff161595906001600160401b031680159081610a44575b6001149081610a3a575b159081610a31575b50610a225760008051602061480e83398151915280546001600160401b0319166001179055856109fd575b6001600160a01b03169081156109ee576001600160a01b03169081156109df5783156109d05761074661448a565b61074e61448a565b61075661448a565b61075e61448a565b60016000805160206147ce8339815191525561077861448a565b61078061448a565b86546001600160a01b0319908116919091178755600180549182168317905560405163313ce56760e01b8152909190602081600481855afa88918161099f575b506107d457633a24e95b60e11b8852600488fd5b6001600160a81b03199092161760a091821b60ff60a01b16176001819055901c60ff16601119810161098d575061080b8186614348565b80610965575b156109205761082e816000805160206147ee833981519152614348565b8061092f575b15610920576108519060008051602061470e833981519152614348565b90816108e9575b50156108da57806108af575b5061086c5780f35b60ff60401b1960008051602061480e833981519152541660008051602061480e833981519152556000805160206146ee833981519152602060405160018152a180f35b601080546001600160a01b031916821790558260008051602061474e8339815191528180a338610864565b63cf5a8e3360e01b8352600483fd5b6109199060008051602061470e83398151915286526000805160206146ae833981519152602052604086206144d0565b5038610858565b63cf5a8e3360e01b8552600485fd5b6000805160206147ee83398151915286526000805160206146ae83398151915260205261095f83604088206144d0565b50610834565b8580526000805160206146ae83398151915260205261098783604088206144d0565b50610811565b63167738cf60e21b8652600452602485fd5b6109c291925060203d6020116109c9575b6109ba81836139c3565b810190613ba9565b90386107c0565b503d6109b0565b630b5eba9f60e41b8752600487fd5b63c1ab6dc160e01b8752600487fd5b6336abb4df60e11b8752600487fd5b60008051602061480e833981519152805460ff60401b1916600160401b179055610718565b63f92ee8a960e01b8752600487fd5b905015386106ed565b303b1591506106e5565b8791506106db565b8580fd5b8480fd5b503461033b578060031936011261033b57546040516001600160a01b039091168152602090f35b503461033b57602036600319011261033b576020906040906001600160a01b03610aa361392e565b168152600a83522054604051908152f35b503461033b57604036600319011261033b576020906040906001600160a01b03610adc61392e565b16815260158352818120602435825283522054604051908152f35b503461033b5761016036600319011261033b57610b1261392e565b90606435604435602435610b24613a58565b9160a4359160c43560e43561010435916101243595610144359760018060a01b03601054163303610ee5576001600160a01b038c16808c52600260205260408c2054909a9060ff16610ed1578a15610ec2578615610eb3576127108811610e99576103e88111610e815760ff82169c60128e118e8115610e76575b50610e6257803b15610e4e578915610e3a578a15610e265782610bc191614260565b84151580610e1d575b610e065785151580610dfd575b610de6578b9c602460208d9e9d604051928380926370a0823160e01b82523060048301525afa9c8d15610dda579c610da6575b506001600160ff1b038c11610d97578a8d8f9760408f97838f918f8f8f8f90859f988f99879f9660008051602061476e8339815191529f978b9f988f8d6000805160206146ce8339815191529f988e8e610d4f9b60008051602061468e8339815191529f8f8f8487526002602052878720600160ff198254161790558487526003602052878720558386526004602052868620558285526006602052878686205582855260056020528585209060ff19825416179055818452600c6020528885852055818452600d6020528985852055818452600e6020528a85852055818452600f6020528b8585205581845260076020528484205582526012602052828220558d8152601360205220558a7f991d1ef1b5c0820d213328cba6682059e00a50e49c469a454eb3557e78eaf6668e80518b81528c6020820152a28c5198899889613cbd565b0390a28151908b82526020820152a28151908782526020820152a280610d73578280f35b604060008051602061482e833981519152918151908582526020820152a281808280f35b63556e7a8160e01b8e5260048efd5b909b506020813d602011610dd2575b81610dc2602093836139c3565b810103126105fe57519a38610c0a565b3d9150610db5565b604051903d90823e3d90fd5b60448c858863dd85772b60e01b8352600452602452fd5b50838610610bd7565b60448c8487637449915760e01b8352600452602452fd5b50828510610bca565b636835314760e11b8d52600160045260248dfd5b636835314760e11b8d5260048d905260248dfd5b63377e3f9960e21b8d5260048c905260248dfd5b63ca95039160e01b8d5260048e905260248dfd5b60069150108e610b9f565b631051834f60e11b8c526004526103e860245260448bfd5b63c1e9a14160e01b8c52600488905261271060245260448cfd5b63a2ec3a5560e01b8c5260048cfd5b63df407ac560e01b8c5260048cfd5b6317f4215b60e21b8c5260048b905260248cfd5b6349db3bd360e01b8b5260048bfd5b503461033b578060031936011261033b57602060ff60015460a01c16604051908152f35b503461033b57602036600319011261033b576020610f3c610f3761392e565b613df5565b604051908152f35b503461033b578060031936011261033b5760206040516127108152f35b503461033b57602036600319011261033b576020906040906001600160a01b03610f8961392e565b168152600783522054604051908152f35b503461033b57602036600319011261033b57610fb461392e565b6010546001600160a01b03163303610479576001600160a01b03168082526002602052604082205460ff16156106165780825260076020526040822054806110f1575080825260026020526040822060ff1981541690558082526003602052816040812055808252600460205281604081205580825260056020526040822060ff198154169055808252600c602052816040812055808252600d602052816040812055808252600e602052816040812055808252600f602052816040812055808252600660205281604081205580825260076020526040822054818352600760205282604081205560405190827f3302a1b37f04242bb55603f5449e7ecd690a35eef08ba1353c48c20e2aae9cda8580a2806110ce578380f35b8160409160008051602061482e8339815191529352846020820152a23880808380f35b604492916376bc059760e11b8352600452602452fd5b503461033b57604036600319011261033b5761113e600435611127613944565b9061113961113482613b79565b614088565b61411a565b5080f35b503461033b578060031936011261033b57602060ff600854166040519015158152f35b503461033b57602036600319011261033b5760209060ff906040906001600160a01b0361119061392e565b16815260058452205416604051908152f35b503461033b57602036600319011261033b576111bc61392e565b6111c4613f12565b6010546001600160a01b03163303610479576001600160a01b03168082526002602052604082205460ff161561061657808252600760205260408220546040516370a0823160e01b8152306004820152602081602481865afa90811561060b57849161126c575b5060008051602061482e833981519152916040918486526007602052808387205582519182526020820152a260016000805160206147ce8339815191525580f35b90506020813d6020116112a4575b81611287602093836139c3565b810103126105fe575160008051602061482e83398151915261122b565b3d915061127a565b503461033b57604036600319011261033b5760206112d46112cb61392e565b60243590613cf6565b6040519015158152f35b503461033b57602036600319011261033b576020906040906001600160a01b0361130661392e565b168152601383522054604051908152f35b503461033b57602036600319011261033b57604060209160043581526000805160206146ae83398151915283522054604051908152f35b503461033b578060031936011261033b576020604051670de0b6b3a76400008152f35b503461033b57604036600319011261033b5761138b61392e565b6010546024359291906001600160a01b03163303610479576001600160a01b031680825260076020526040822054929081841061140d578060008051602061482e8339815191526040866113e3866104369899613b6c565b84895260076020528289205583885260076020528188205482519182526020820152a2339061404c565b5091604492633cb8e07360e01b8352600452602452fd5b503461033b57602036600319011261033b5760209060ff906040906001600160a01b0361144f61392e565b168152600284522054166040519015158152f35b503461033b5761012036600319011261033b5761147e61392e565b6064359190604435602435611491613a58565b601054610104359660e4359260c4359260a43592906001600160a01b0316330361167f576001600160a01b038816808a52600260205260408a205490989060ff161561166b57861561165c576127108811611642576103e882116116285760ff83169060128211801561161e575b61160a578361150d91614260565b85151580611601575b6115ea578a1515806115e1575b6115ca579260008051602061468e83398151915297969592828c956115c4979460408e8e80825260036020528c8383205580825260046020528d838320558152600660205220558b8d52600560205260408d209060ff198254161790558a8c52600c6020528260408d20558a8c52600d6020528360408d20558a8c52600e6020528460408d20558a8c52600f6020528560408d205560405198899889613cbd565b0390a280f35b60448a868d63dd85772b60e01b8352600452602452fd5b50848b10611523565b60448a8588637449915760e01b8352600452602452fd5b50838610611516565b63ca95039160e01b8b52600482905260248bfd5b50600682106114ff565b631051834f60e11b8a5260048290526103e860245260448afd5b63c1e9a14160e01b8a52600488905261271060245260448afd5b63a2ec3a5560e01b8a5260048afd5b6374ed46ad60e01b8a52600489905260248afd5b6349db3bd360e01b8952600489fd5b503461033b57604036600319011261033b576116a861392e565b6001600160a01b0316808252600260205260408220546024359060ff16156117745780156117655761271061172a604085670de0b6b3a76400006117196117329688859a52600560205260ff85852054169080916012811061173f575b505088845260036020528484205490613a8b565b049581526004602052205484613a8b565b048092613b6c565b9082519182526020820152f35b61175e925060ff61175261175892613ad4565b16613ae5565b90613a8b565b3880611705565b63162908e360e11b8352600483fd5b6374ed46ad60e01b83526004829052602483fd5b503461033b578060031936011261033b5761033760408051906117ab81836139c3565b60058252640352e302e360dc1b602083015251918291602083526020830190613a17565b503461033b57602036600319011261033b5760043581526000805160206146ae83398151915260205260408120604051908160208254918281520190819285526020852090855b818110611876575050508261182c9103836139c3565b604051928392602084019060208552518091526040840192915b818110611854575050500390f35b82516001600160a01b0316845285945060209384019390920191600101611846565b8254845260209093019260019283019201611816565b503461033b578060031936011261033b57602090604051908152f35b503461033b576118b736613969565b9190926118c2613f12565b6118ca613f4e565b338152600960205260408120544303611f1f57338152600a602052600360408220541015611f1057338152600a602052604081206119088154613b9a565b90555b6001600160a01b0382168082526002602052604082205490929060ff16611e6f575b828252600260205260ff60408320541615610466578415610457578315611e6057828252600c60205260408220548510611e3b57828252600e60205260408220548015611e2c57808611611e155750846119869161415e565b6040516370a0823160e01b8152306004820152602081602481865afa908115611e0a578291611dd8575b506119bd8530338661421c565b6040516370a0823160e01b8152306004820152602081602481875afa908115611cef57908692918491611d9f575b50906119f691613b6c565b10611d905781815260076020526040812054611a128582613cb0565b818110611d81576001600160ff1b038111611d72576040849260008051602061482e833981519152928486526007602052808387205582519182526020820152a2818152600560205260ff604082205416849060128110611d11575b50611a8f670de0b6b3a7640000918484526003602052604084205490613a8b565b04908281526004602052612710611aaa604083205484613a8b565b0491611ab68382613b6c565b94808610611cfa57506001546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa908115611cef578391611cbd575b5082546001600160a01b0316803b15611ca45783809160846040518094819363ae494fa160e01b83523360048401528c60248401528b60448401528d60648401525af1801561060b57908491611ca8575b505083611c34575b6001546040516318160ddd60e01b81529190602090839060049082906001600160a01b03165afa801561060b578490611c00575b611b8a9250613b6c565b90808203611bea575050507fb3e2773606abfd36b5bd91394b3a54d1398336c65005baf7bf7a05efeffaf75b611bcd602095604051918291339588429285613bdd565b0390a360016000805160206147ce83398151915255604051908152f35b632d8562a360e11b835260045260245260449150fd5b506020823d602011611c2c575b81611c1a602093836139c3565b810103126105fe57611b8a9151611b80565b3d9150611c0d565b82546001600160a01b0316803b15611ca45783809160846040518094819363ae494fa160e01b83523060048401528a60248401528b60448401528160648401525af1801561060b57908491611c8b575b5050611b4c565b81611c95916139c3565b611ca0578238611c84565b8280fd5b8380fd5b81611cb2916139c3565b611ca0578238611b44565b90506020813d602011611ce7575b81611cd8602093836139c3565b810103126105fe575138611af3565b3d9150611ccb565b6040513d85823e3d90fd5b6371c4efed60e01b83526004869052602452604482fd5b611d21915061175260ff91613ad4565b8015611d5e5780600019048511611d4f57611a8f611d48670de0b6b3a76400009287613a8b565b9150611a6e565b63035fc53d60e41b8252600482fd5b634e487b7160e01b82526012600452602482fd5b630700fcb360e11b8352600483fd5b63446c8cc960e01b8352600483fd5b639bfa3c1760e01b8152600490fd5b919250506020813d602011611dd0575b81611dbc602093836139c3565b810103126105fe57518591906119f66119eb565b3d9150611daf565b90506020813d602011611e02575b81611df3602093836139c3565b810103126105fe5751386119b0565b3d9150611de6565b6040513d84823e3d90fd5b631d7f2ac360e01b83526004869052602452604482fd5b633b5db2f360e11b8352600483fd5b50908152600c6020526040812054630d54e9e160e01b82526004849052602452604490fd5b632cd84af360e01b8252600482fd5b60405163313ce56760e01b815291939291602081600481865afa859181611eef575b50611ea55763105482c760e21b8552600485fd5b93919293838352600560205260ff806040852054169116908103611ec9575061192d565b90506044928252600560205260ff604083205416631e43476360e11b8352600452602452fd5b611f0991925060203d6020116109c9576109ba81836139c3565b9038611e91565b63a74c1c5f60e01b8152600490fd5b3381526009602052436040822055338152600a6020526001604082205561190b565b503461033b578060031936011261033b5760206040516103e88152f35b503461033b57604036600319011261033b576020906040906001600160a01b03611f8661392e565b16815260148352818120602435825283522054604051908152f35b503461033b57604036600319011261033b576040611fbd613944565b91600435815260008051602061478e833981519152602052209060018060a01b0316600052602052602060ff604060002054166040519015158152f35b503461033b578060031936011261033b57602060405160648152f35b503461033b57604036600319011261033b5761205060209160043581526000805160206146ae8339815191528352604060243591206144b8565b905460405160039290921b1c6001600160a01b03168152f35b503461033b57602036600319011261033b576020906040906001600160a01b0361209161392e565b168152600983522054604051908152f35b503461033b57604036600319011261033b576120bc61392e565b60105460243591906001600160a01b0316330361215a576001600160a01b031690811561214b57604060008051602061476e8339815191529183855260136020528185205490848652601360205280838720558486526015602052828620438752602052828620548587526019602052838720558486526017602052438387205582519182526020820152a280f35b63df407ac560e01b8352600483fd5b6349db3bd360e01b8352600483fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361219161392e565b168152600383522054604051908152f35b503461033b578060031936011261033b5760008051602061470e833981519152815260008051602061478e83398151915260209081526040808320336000908152925290205460ff1615612278576121f8613f4e565b600160ff196000805160206147ae8339815191525416176000805160206147ae833981519152557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a16040514281527f80170b5fcdd2bf1e0660ef4b8851f86685f64d41b1a19de1471947ece8725aac60203392a280f35b63e2517d3f60e01b81523360045260008051602061470e833981519152602452604490fd5b503461033b57602036600319011261033b576122b761392e565b60008051602061480e8339815191525460ff8160401c169081156123a3575b506123945760008051602061480e83398151915280546001600160481b0319166003600160401b0117905581805260008051602061478e83398151915260209081526040808420336000908152925290205460ff161561237c5761233990613c5e565b60ff60401b1960008051602061480e833981519152541660008051602061480e833981519152556000805160206146ee833981519152602060405160038152a180f35b63e2517d3f60e01b8252336004526024829052604482fd5b63f92ee8a960e01b8252600482fd5b60036001600160401b039190911610159050386122d6565b503461033b578060031936011261033b57602060ff6000805160206147ae83398151915254166040519015158152f35b503461033b57602036600319011261033b5761240561392e565b6010546001600160a01b031633036104795761043690613c5e565b503461033b57606036600319011261033b5761243a61392e565b612442613944565b60105490926044359290916001600160a01b0316330361047957612464613f4e565b6011546001600160a01b03169182156126de5760405163babcc53960e01b81526001600160a01b0386166004820181905293602090829060249082905afa908115611e0a57829161269f575b5015612690578215612681576001546001600160a01b03928316921682036125d1576040516370a0823160e01b8152306004820152602081602481865afa908115611e0a57829161259f575b50935b841561259057600019810361258a5750835b841561257b5780851161256357505061252d836020958361404c565b7f0bf519e4b3821615dbdd874fa1a5fbb4bb651b4e6beabedd4ac318e770233b2c604080518581524287820152a3604051908152f35b630555ed4f60e31b8252600485905260245260449150fd5b632e11316f60e11b8252600482fd5b93612511565b63f09872eb60e01b8252600482fd5b90506020813d6020116125c9575b816125ba602093836139c3565b810103126105fe5751386124fc565b3d91506125ad565b8181526002602052604081205460ff161561266f576040516370a0823160e01b8152306004820152602081602481865afa908115611e0a57829161263d575b5082825260076020526040822054808211156126355761262f91613b6c565b936124ff565b50508061262f565b90506020813d602011612667575b81612658602093836139c3565b810103126105fe575138612610565b3d915061264b565b60249163eef7849760e01b8252600452fd5b634e46966960e11b8152600490fd5b63133307bb60e21b8152600490fd5b90506020813d6020116126d6575b816126ba602093836139c3565b810103126126d2575180151581036126d257386124b0565b5080fd5b3d91506126ad565b630e048e7160e41b8152600490fd5b503461033b57602036600319011261033b5761270761392e565b6010546001600160a01b03163303610479576001600160a01b0316801561276c57601180546001600160a01b0319811683179091556001600160a01b03167f1e9c406f2707909cfd9f61e744f73bcab77e5997d063276f67883c5257d51cf08380a380f35b634e46966960e11b8252600482fd5b503461033b578060031936011261033b577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031630036127d457602060405160008051602061472e8339815191528152f35b63703e46dd60e11b8152600490fd5b503461033b578060031936011261033b576010546040516001600160a01b039091168152602090f35b50604036600319011261033b5761282161392e565b602435906001600160401b038211611ca05736602383011215611ca0578160040135908361284e836139fc565b9361285c60405195866139c3565b83855260208501933660248284010111611ca057806024602093018637850101526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016308114908115612ade575b50612acf576010546001600160a01b03163303612ac0576001600160a01b038116928315612ab157813b15612aa25760008051602061472e83398151915254846128fa613a68565b7f6ea8b34d59b2818d3f37a08dddaa06f5886b9c20c907b36f03ca6528e106e86f61293060405192604084526040840190613a17565b4260208401526001600160a01b038516929081900390a36040516352d1902d60e01b8152602081600481895afa879181612a6a575b5061297e57634c9c8ce360e01b87526004869052602487fd5b908160008051602061472e83398151915288979303612a585750833b15612a44576001600160a01b031916811760008051602061472e833981519152558491907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8380a2805115612a295761113e9382915190845af43d15612a21573d91612a05836139fc565b92612a1360405194856139c3565b83523d85602085013e61460c565b60609161460c565b5050505034612a355780f35b63b398979f60e01b8152600490fd5b634c9c8ce360e01b86526004829052602486fd5b632a87526960e21b8752600452602486fd5b9091506020813d602011612a9a575b81612a86602093836139c3565b81010312612a9657519038612965565b8780fd5b3d9150612a79565b636f7c43f160e01b8552600485fd5b63e6c4247b60e01b8552600485fd5b6349db3bd360e01b8452600484fd5b63703e46dd60e11b8452600484fd5b60008051602061472e833981519152546001600160a01b031614159050386128b2565b503461033b57602036600319011261033b576020906040906001600160a01b03612b2961392e565b168152600e83522054604051908152f35b503461033b57606036600319011261033b57612b5461395a565b6024356001600160401b038111611ca057612b73903690600401613993565b916044356001600160401b038111610a5057612b93903690600401613993565b60008051602061480e8339815191529291925460ff8160401c16908115612ef6575b50612ee75760008051602061480e83398151915280546001600160481b0319166002600160401b011790556000805160206147ee833981519152865260008051602061478e83398151915260209081526040808820336000908152925290205460ff1615612ec257612c2561448a565b612c2d61448a565b60016000805160206147ce83398151915255600b549160ff8316612eb357818603612ea457612c5b86613bf9565b92612c6960405194856139c3565b868452601f19612c7888613bf9565b01366020860137875b878110612daf575060019060ff191617600b5515159460ff196008541660ff871617600855865b818110612d0c578760008051602061466e833981519152602089604051908152a160ff60401b1960008051602061480e833981519152541660008051602061480e833981519152556000805160206146ee833981519152602060405160028152a180f35b808860008051602061482e8339815191526040612d34612d2f600196888d613c10565b613c36565b612d3f85898c613c10565b357f8f955fa878b4aae8b1ac37b1ab715307470f2822ceff87e23d33ef1e044814a783612d6c888d613c4a565b5193898060a01b0316968793848252600660205280838320558482526007602052858383205582519182526020820152a28151908d82526020820152a201612ca8565b612dbd612d2f828a8a613c10565b612dc8828689613c10565b6001600160a01b03909116808b52600260205260408b20549091359060ff1615612e90576103e88111612e785750906020602492604051938480926370a0823160e01b82523060048301525afa8015612e6d578a90612e37575b60019250612e308288613c4a565b5201612c81565b509060203d8111612e66575b612e4d81836139c3565b6020826000928101031261033b57509060019151612e22565b503d612e43565b6040513d8c823e3d90fd5b631051834f60e11b8b526004526103e860245260448afd5b6351104c5960e01b8b52600482905260248bfd5b63512509d360e11b8752600487fd5b6324d0d1fd60e01b8752600487fd5b63e2517d3f60e01b8652336004526000805160206147ee833981519152602452604486fd5b63f92ee8a960e01b8652600486fd5b60026001600160401b03919091161015905038612bb5565b503461033b578060031936011261033b576011546040516001600160a01b039091168152602090f35b503461033b578060031936011261033b576010546001600160a01b03163303612fef576000805160206147ae8339815191525460ff811615612fe05760ff19166000805160206147ae833981519152557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a16040514281527f107553d8191d85b405879cf752997865edd48d94e20bda4dd27223c94b31a7cc60203392a280f35b638dfc202b60e01b8252600482fd5b6349db3bd360e01b8152600490fd5b503461033b57602036600319011261033b576020906040906001600160a01b0361302661392e565b168152601683522054604051908152f35b503461033b57604036600319011261033b57613051613944565b336001600160a01b0382160361306d5761113e9060043561411a565b63334bd91960e11b8252600482fd5b503461033b57602036600319011261033b576020906040906001600160a01b036130a461392e565b168152600c83522054604051908152f35b503461033b57602036600319011261033b576020906040906001600160a01b036130dd61392e565b168152601783522054604051908152f35b503461033b57604036600319011261033b5761113e60043561310e613944565b9061311b61113482613b79565b6140d2565b503461033b5761312f36613969565b91909261313a613f12565b613142613f4e565b3381526009602052604081205443036135be57338152600a602052600360408220541015611f1057338152600a602052604081206131808154613b9a565b90555b6001600160a01b0382168082526002602052604082205490929060ff16613543575b828252600260205260ff604083205416156104665760ff6008541615613534578415610457578315611e6057828252600d602052604082205480861061351d5750828252600f6020526040822054801561350e578086116134f857508461320b91613f78565b670de0b6b3a76400008402848104670de0b6b3a7640000036134e4578282526003602052604082205461323d91613ab4565b90828152600560205260ff604082205416601281106134c4575b50828152600660205261327c612710613274604084205485613a8b565b048093613b6c565b938085106134ac575082815260076020528360408220541061348857828152600760205260408120548481106134795760008051602061482e8339815191526040826132c9888895613b6c565b8486526007602052808387205582519182526020820152a26001546040516318160ddd60e01b815290602090829060049082906001600160a01b03165afa908115611e0a578291613447575b5081546001600160a01b0316803b15611ca057826040518092633a52b90760e11b82528183816133498d3360048401613bc2565b03925af18015611cef57613432575b506001546040516318160ddd60e01b81529190602090839060049082906001600160a01b03165afa908115611cef5783916133fc575b6133989250613b6c565b8581036133e45750507f8caf04742286d017f9ac3924388e188c73e6e5094311c5e59a61a7ef86dda8bf611bcd6020956133d386338761404c565b604051918291339588429285613bdd565b635ab6e2db60e01b8252600486905260245260449150fd5b90506020823d60201161342a575b81613417602093836139c3565b810103126105fe5761339891519061338e565b3d915061340a565b9161344081600493946139c3565b9190613358565b90506020813d602011613471575b81613462602093836139c3565b810103126126d2575138613315565b3d9150613455565b6308aed4ef60e31b8252600482fd5b82815260076020526040812054635960d22160e01b82526004526024849052604490fd5b6371c4efed60e01b8252600485905260245260449150fd5b916134d760ff6117526134dd9495613ad4565b90613ab4565b9038613257565b634e487b7160e01b82526011600452602482fd5b625502a360e91b83526004869052602452604482fd5b636c6ff70d60e11b8352600483fd5b6361767b8560e01b83526004869052602452604482fd5b630df65d9f60e01b8252600482fd5b60405163313ce56760e01b815291939291602081600481865afa85918161359d575b506135795763105482c760e21b8552600485fd5b93919293838352600560205260ff806040852054169116908103611ec957506131a5565b6135b791925060203d6020116109c9576109ba81836139c3565b9038613565565b3381526009602052436040822055338152600a60205260016040822055613183565b503461033b57602036600319011261033b576020610f3c600435613b79565b503461033b57602036600319011261033b576020906040906001600160a01b0361362761392e565b168152600f83522054604051908152f35b503461033b57604036600319011261033b5761365261392e565b60105460243591906001600160a01b0316330361215a576001600160a01b031690811561214b5760406000805160206146ce8339815191529183855260126020528185205490848652601260205280838720558486526014602052828620438752602052828620548587526018602052838720558486526016602052438387205582519182526020820152a280f35b503461033b57602036600319011261033b576020906040906001600160a01b0361370961392e565b168152600683522054604051908152f35b503461033b578060031936011261033b576001546040516001600160a01b039091168152602090f35b503461033b57602036600319011261033b576020906040906001600160a01b0361376b61392e565b168152600d83522054604051908152f35b503461033b57602036600319011261033b5761379661395a565b6010546001600160a01b0316330361047957602060008051602061466e83398151915291151560ff196008541660ff821617600855604051908152a180f35b503461033b57602036600319011261033b5760043563ffffffff60e01b81168091036126d257602090635a05180f60e01b811490811561381b575b506040519015158152f35b637965db0b60e01b811491508115613835575b5082613810565b6301ffc9a760e01b1490508261382e565b503461033b57604036600319011261033b5761386061392e565b6001600160a01b0316808252600260205260408220546024359060ff161561177457670de0b6b3a7640000810290808204670de0b6b3a7640000149015171561391a57916138bc60409383835260036020528483205490613ab4565b91808252600560205260ff8483205416601281106138f1575b5061172a84836127109361173295526006602052205484613a8b565b846117329361390f61271094966134d760ff61175261172a97613ad4565b9593509350506138d5565b634e487b7160e01b83526011600452602483fd5b600435906001600160a01b03821682036105fe57565b602435906001600160a01b03821682036105fe57565b6004359081151582036105fe57565b60609060031901126105fe576004356001600160a01b03811681036105fe57906024359060443590565b9181601f840112156105fe578235916001600160401b0383116105fe576020808501948460051b0101116105fe57565b601f909101601f19168101906001600160401b038211908210176139e657604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b0381116139e657601f01601f191660200190565b919082519283825260005b848110613a43575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201613a22565b6084359060ff821682036105fe57565b60405190613a776040836139c3565b6005825264322e332e3360d81b6020830152565b81810292918115918404141715613a9e57565b634e487b7160e01b600052601160045260246000fd5b8115613abe570490565b634e487b7160e01b600052601260045260246000fd5b60ff166012039060ff8211613a9e57565b8015613b665760009060208110600116604e821060011617613b5e57600a916001915b60018111613b35575082600019048211613b2157500290565b634e487b7160e01b81526011600452602490fd5b92806000190481116134e45760018416613b55575b80029260011c613b08565b80920291613b4a565b9050600a0a90565b50600190565b91908203918211613a9e57565b60005260008051602061478e83398151915260205260016040600020015490565b6000198114613a9e5760010190565b908160209103126105fe575160ff811681036105fe5790565b6001600160a01b039091168152602081019190915260400190565b9094939260609260808301968352602083015260408201520152565b6001600160401b0381116139e65760051b60200190565b9190811015613c205760051b0190565b634e487b7160e01b600052603260045260246000fd5b356001600160a01b03811681036105fe5790565b8051821015613c205760209160051b010190565b6001600160a01b03168015613c9f57601080546001600160a01b0319811683179091556001600160a01b031660008051602061474e833981519152600080a3565b63e6c4247b60e01b60005260046000fd5b91908201809211613a9e57565b94919360e0969360ff929a99989561010088019b885260208801526040870152166060850152608084015260a083015260c08201520152565b6001600160a01b03811660008181526002602052604090205490919060ff16158015613de8575b8015613de0575b613dce5781600052600f6020526040600020548015908115613dd6575b50613dce57613d66926040918251948592839262f7fce960e01b845260048401613bc2565b0381305afa918215613dc257600092613d8e575b506000526007602052604060002054101590565b9091506040813d604011613dba575b81613daa604093836139c3565b810103126105fe57519038613d7a565b3d9150613d9d565b6040513d6000823e3d90fd5b505050600090565b9050831138613d41565b508215613d24565b5060ff6008541615613d1d565b6001546001600160a01b0391821691168103613e6a576020602491604051928380926370a0823160e01b82523060048301525afa908115613dc257600091613e3b575090565b90506020813d602011613e62575b81613e56602093836139c3565b810103126105fe575190565b3d9150613e49565b80600052600260205260ff60406000205416613e865750600090565b6040516370a0823160e01b815230600482015290602082602481845afa918215613dc257600092613ede575b506000526007602052604060002054808211600014613ed757613ed491613b6c565b90565b5050600090565b90916020823d602011613f0a575b81613ef9602093836139c3565b8101031261033b5750519038613eb2565b3d9150613eec565b60026000805160206147ce8339815191525414613f3d5760026000805160206147ce83398151915255565b633ee5aeb560e01b60005260046000fd5b60ff6000805160206147ae8339815191525416613f6757565b63d93c066560e01b60005260046000fd5b6001600160a01b0316600081815260136020526040902054801561404757816000526015602052604060002043600052602052613fbb6040600020549384613cb0565b92831061403657808260005260176020524360406000205414614018575b8311613ffc57506000526015602052604060002043600052602052604060002055565b925063029359d560e41b60005260045260245260445260646000fd5b5081600052601960205261403160406000205482613cb0565b613fd9565b63446c8cc960e01b60005260046000fd5b505050565b614081614086939261407360405194859263a9059cbb60e01b602085015260248401613bc2565b03601f1981018452836139c3565b6142ed565b565b600081815260008051602061478e8339815191526020908152604080832033845290915290205460ff16156140ba5750565b63e2517d3f60e01b6000523360045260245260446000fd5b6140dc8282614348565b91826140e757505090565b60009182526000805160206146ae8339815191526020526040909120614116916001600160a01b0316906144d0565b5090565b61412482826143ea565b918261412f57505090565b60009182526000805160206146ae8339815191526020526040909120614116916001600160a01b031690614539565b6001600160a01b03166000818152601260205260409020548015614047578160005260146020526040600020436000526020526141a16040600020549384613cb0565b928310614036578082600052601660205243604060002054146141fe575b83116141e257506000526014602052604060002043600052602052604060002055565b92506319a4e2a760e01b60005260045260245260445260646000fd5b5081600052601860205261421760406000205482613cb0565b6141bf565b6040516323b872dd60e01b60208201526001600160a01b039283166024820152929091166044830152606480830193909352918152614086916140816084836139c3565b60405163313ce56760e01b81529190602090839060049082906001600160a01b03165afa600092816142cc575b506142a357631eecbb6560e01b60005260046000fd5b60ff91821691168082036142b5575050565b631e43476360e11b60005260045260245260446000fd5b6142e691935060203d6020116109c9576109ba81836139c3565b913861428d565b906000602091828151910182855af115613dc2576000513d61433f57506001600160a01b0381163b155b61431e5750565b635274afe760e01b60009081526001600160a01b0391909116600452602490fd5b60011415614317565b600081815260008051602061478e833981519152602090815260408083206001600160a01b038616845290915290205460ff16613ed757600081815260008051602061478e833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19166001179055339291907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9080a4600190565b600081815260008051602061478e833981519152602090815260408083206001600160a01b038616845290915290205460ff1615613ed757600081815260008051602061478e833981519152602090815260408083206001600160a01b0395909516808452949091528120805460ff19169055339291907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9080a4600190565b60ff60008051602061480e8339815191525460401c16156144a757565b631afcd79f60e31b60005260046000fd5b8054821015613c205760005260206000200190600090565b6001810190826000528160205260406000205415600014613dce578054600160401b8110156139e65761452461450d8260018794018555846144b8565b819391549060031b91821b91600019901b19161790565b90555491600052602052604060002055600190565b9060018201918160005282602052604060002054801515600014614603576000198101818111613a9e578254600019810191908211613a9e578181036145cc575b505050805480156145b657600019019061459482826144b8565b8154906000199060031b1b191690555560005260205260006040812055600190565b634e487b7160e01b600052603160045260246000fd5b6145ec6145dc61450d93866144b8565b90549060031b1c928392866144b8565b90556000528360205260406000205538808061457a565b50505050600090565b90614632575080511561462157602081519101fd5b63d6bda27560e01b60005260046000fd5b81511580614664575b614643575090565b639996b31560e01b60009081526001600160a01b0391909116600452602490fd5b50803b1561463b56fe2c0a5f5ab0ba371221bb3612c2d2f90d36566279309f526000c5b354efd1b0658c67aaac7f77de07240e5a9b36dfdccb2a89c438635abbb27a73142d2aa0f629c1f6fe24621ce81ec5827caf0253cadb74709b061630e6b55e8237170593200048b07fab687f450848f1df8a96db08fef7840f53415f18fdc2ec8e9f810f0930c7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d275027301df982f5215b4963a854cf9c73219df80cb6acd8f098189c9480c7bbc360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc17dc5b1290f7495d7f8cc68476e6941aaf510598fa925d0d2720edc8805a846c4460507c21097c15f6883572ebd157a9ee4b1d989a312314e93afd9d2ecd494002dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800cd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775f0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a006d129bd71f2401cbe77f49f546d7d5f58992faecfca6e51ba06b50b261e83331a164736f6c6343000822000a";
14507
14598
  var isSuperArgs = (xs) => xs.length > 1;
14508
- var SimplePSMV2__factory = class extends import_ethers12.ContractFactory {
14599
+ var SimplePSMV2__factory = class extends import_ethers13.ContractFactory {
14509
14600
  constructor(...args) {
14510
14601
  if (isSuperArgs(args)) {
14511
14602
  super(...args);
@@ -14525,10 +14616,10 @@ var SimplePSMV2__factory = class extends import_ethers12.ContractFactory {
14525
14616
  static bytecode = _bytecode;
14526
14617
  static abi = _abi;
14527
14618
  static createInterface() {
14528
- return new import_ethers12.Interface(_abi);
14619
+ return new import_ethers13.Interface(_abi);
14529
14620
  }
14530
14621
  static connect(address, runner) {
14531
- return new import_ethers12.Contract(address, _abi, runner);
14622
+ return new import_ethers13.Contract(address, _abi, runner);
14532
14623
  }
14533
14624
  };
14534
14625
 
@@ -15095,7 +15186,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
15095
15186
  */
15096
15187
  constructor(config) {
15097
15188
  if (!config.provider && config.ethRpcUrl) {
15098
- config.provider = new import_ethers13.JsonRpcProvider(config.ethRpcUrl);
15189
+ config.provider = new import_ethers14.JsonRpcProvider(config.ethRpcUrl);
15099
15190
  }
15100
15191
  this.config = config;
15101
15192
  if (config.debug) {
@@ -15361,7 +15452,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
15361
15452
  const network = await config.provider.getNetwork();
15362
15453
  chainId = Number(network.chainId);
15363
15454
  } else if (config.ethRpcUrl) {
15364
- const tempProvider = new import_ethers13.JsonRpcProvider(
15455
+ const tempProvider = new import_ethers14.JsonRpcProvider(
15365
15456
  config.ethRpcUrl
15366
15457
  );
15367
15458
  const network = await tempProvider.getNetwork();
@@ -15884,7 +15975,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
15884
15975
  }
15885
15976
  const loanOps = this.loanOps();
15886
15977
  const protocolConfig = await loanOps.getProtocolConfig();
15887
- const requestAmountWei = (0, import_ethers13.parseEther)(
15978
+ const requestAmountWei = (0, import_ethers14.parseEther)(
15888
15979
  request.amount.toString()
15889
15980
  );
15890
15981
  const minLoanValueWei = BigInt(protocolConfig.minimumLoanValueWei);
@@ -15966,7 +16057,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
15966
16057
  pkpNftAddress,
15967
16058
  this.getChipotlePublicKeyFallback()
15968
16059
  );
15969
- pkpEthAddress = (0, import_ethers13.computeAddress)(pkpPublicKey);
16060
+ pkpEthAddress = (0, import_ethers14.computeAddress)(pkpPublicKey);
15970
16061
  pkpCache.set(request.positionId, {
15971
16062
  publicKey: pkpPublicKey,
15972
16063
  ethAddress: pkpEthAddress,
@@ -16295,8 +16386,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
16295
16386
  throw new Error(`Position not found: ${request.positionId}`);
16296
16387
  }
16297
16388
  const currentDebt = position.ucdDebt.toString();
16298
- const ucdDebtHash = (0, import_ethers13.keccak256)(import_ethers13.AbiCoder.defaultAbiCoder().encode(["uint256"], [currentDebt]));
16299
- const contractHash = (0, import_ethers13.keccak256)(import_ethers13.AbiCoder.defaultAbiCoder().encode(
16389
+ const ucdDebtHash = (0, import_ethers14.keccak256)(import_ethers14.AbiCoder.defaultAbiCoder().encode(["uint256"], [currentDebt]));
16390
+ const contractHash = (0, import_ethers14.keccak256)(import_ethers14.AbiCoder.defaultAbiCoder().encode(
16300
16391
  ["address", "address", "address", "address"],
16301
16392
  [
16302
16393
  positionManagerAddress,
@@ -16357,214 +16448,6 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
16357
16448
  {}
16358
16449
  );
16359
16450
  }
16360
- if (this.config.debug) {
16361
- log.info("\u{1F50D} PREFLIGHT: Attempting diagnostic gas estimation...", {});
16362
- }
16363
- try {
16364
- const iface = new import_ethers13.Interface(positionManagerAbi);
16365
- const signatureHex = finalSignature.startsWith("0x") ? finalSignature : "0x" + finalSignature;
16366
- if (this.config.debug) {
16367
- log.info("\u{1F50D} DEBUG: Signature details:", {
16368
- finalSignature: finalSignature ? `${finalSignature.substring(0, 20)}... (length: ${finalSignature.length})` : "UNDEFINED/EMPTY",
16369
- signatureHex: signatureHex ? `${signatureHex.substring(0, 22)}... (length: ${signatureHex.length})` : "UNDEFINED/EMPTY"
16370
- });
16371
- }
16372
- const calldata = iface.encodeFunctionData("mintUCD", [
16373
- positionIdBytes32,
16374
- validationResponse.mintAmount,
16375
- validationResponse.mintFee,
16376
- validationResponse.newDebt,
16377
- validationResponse.newCollateral,
16378
- validationResponse.btcPrice,
16379
- validationResponse.authorizedSpendsHash,
16380
- ucdDebtHash,
16381
- contractHash,
16382
- validationResponse.timestamp,
16383
- signatureHex
16384
- ]);
16385
- if (this.config.debug) {
16386
- log.info("\u{1F50D} DEBUG: Encoded calldata:", {
16387
- length: calldata.length,
16388
- signaturePortion: calldata.substring(650, 670)
16389
- });
16390
- }
16391
- const provider = this.getSignerOrThrow().provider;
16392
- if (!provider) {
16393
- throw new Error("Provider not available");
16394
- }
16395
- const signerAddress = await this.getSignerOrThrow().getAddress();
16396
- if (this.config.debug) {
16397
- log.info(" Executing diagnostic eth_call...", {});
16398
- }
16399
- await provider.call({
16400
- to: positionManagerAddress,
16401
- from: signerAddress,
16402
- data: calldata
16403
- });
16404
- if (this.config.debug) {
16405
- log.info(" \u2705 Diagnostic eth_call succeeded!", {});
16406
- }
16407
- } catch (preflightError) {
16408
- if (this.config.debug) {
16409
- log.error(
16410
- "\u274C PREFLIGHT CHECK FAILED - Diagnostic eth_call reverted",
16411
- {}
16412
- );
16413
- log.error(` Error message: ${preflightError?.message}`, {});
16414
- log.error(` Error code: ${preflightError?.code}`, {});
16415
- log.error(` Error data: ${preflightError?.data || "none"}`, {});
16416
- log.error(` Error reason: ${preflightError?.reason || "none"}`, {});
16417
- log.error(
16418
- ` Error.error: ${JSON.stringify(preflightError?.error || {})}`,
16419
- {}
16420
- );
16421
- }
16422
- let errorData = preflightError?.data || preflightError?.info?.error?.data || preflightError?.error?.data?.data || preflightError?.error?.data || preflightError?.error?.error?.data;
16423
- const errorMessage = preflightError?.reason || preflightError?.error?.reason || preflightError?.error?.error?.reason || preflightError?.message || "Unknown error";
16424
- let requireMessage;
16425
- if (errorData && typeof errorData === "string" && errorData.startsWith("0x") && errorData.length > 138) {
16426
- try {
16427
- const errorSelector = errorData.slice(0, 10);
16428
- if (errorSelector === "0x08c379a0") {
16429
- const iface = new import_ethers13.Interface([
16430
- "function Error(string)"
16431
- ]);
16432
- const decoded = iface.decodeFunctionData("Error", errorData);
16433
- requireMessage = decoded[0];
16434
- }
16435
- } catch (e) {
16436
- }
16437
- }
16438
- const isDeadZonePreflightArtifact = decodeQuantumRevert(preflightError).selector === DEAD_ZONE_VIOLATION_SELECTOR;
16439
- if (isDeadZonePreflightArtifact) {
16440
- const nowSec = Math.floor(Date.now() / 1e3);
16441
- const sigQuantum2 = Math.floor(Number(validationResponse.timestamp) / 60) * 60;
16442
- const realCurrentQuantum = Math.floor(nowSec / 60) * 60;
16443
- if (sigQuantum2 === realCurrentQuantum) {
16444
- if (this.config.debug) {
16445
- log.info(
16446
- "\u21AA\uFE0F Preflight DeadZoneViolation is a stale-latest-block artifact (signature is the current quantum) \u2014 proceeding to broadcast",
16447
- {}
16448
- );
16449
- }
16450
- } else {
16451
- if (this.config.debug) {
16452
- log.info(
16453
- "\u{1F501} Preflight DeadZoneViolation near the boundary \u2014 deferring across it, then proceeding",
16454
- {}
16455
- );
16456
- }
16457
- await awaitSafeSubmissionWindow(
16458
- Number(validationResponse.timestamp)
16459
- );
16460
- }
16461
- }
16462
- if (requireMessage && !isDeadZonePreflightArtifact) {
16463
- throw new Error(
16464
- `Preflight check failed - mintUCD would revert:
16465
- ${requireMessage}
16466
- Context: Quantum timestamp=${validationResponse.timestamp}, Position=${request.positionId}`
16467
- );
16468
- }
16469
- if (errorData && typeof errorData === "string" && errorData.startsWith("0x") && errorData.length > 10) {
16470
- const selector = errorData.slice(0, 10);
16471
- const knownErrors = {
16472
- "0x8baa579f": "InvalidSignature()",
16473
- "0xd92e233d": "ValidationFailed()",
16474
- "0x3ee5aeb5": "OperationNotAuthorized()",
16475
- "0x70f4b32a": "UnauthorizedSigner()",
16476
- "0x48f5c3ed": "Unauthorized()",
16477
- "0x36bfdeea": "StateHashMismatch()",
16478
- "0x131d9a21": "QuantumExpired()",
16479
- "0x52ce5d58": "QuantumAlreadyUsed()",
16480
- "0x137f3b70": "InDeadZone()",
16481
- "0xbe4b82c1": "DeadZoneViolation()",
16482
- "0x3e76a3c9": "QuantumOutsideWindow()",
16483
- "0x62278171": "InvalidValidatorSignature()",
16484
- "0xb9d419a7": "DebtUpdateVerificationFailed()",
16485
- "0xc7e20553": "DebtUpdateVerificationFailedDetailed(bytes32,uint256,uint256,uint256,uint256,uint256)",
16486
- "0x0cfd2a97": "MintVerificationMismatch(uint256,uint256)",
16487
- "0x07637bd8": "MintFailed()"
16488
- };
16489
- const errorName = knownErrors[selector] || `Unknown error ${selector}`;
16490
- const mintDebtDiagnostics = selector === "0xb9d419a7" || selector === "0xc7e20553" || selector === "0x0cfd2a97" || selector === "0x07637bd8" ? `
16491
-
16492
- Mint/debt diagnostics (LoanOperationsManager mint path \u2192 increaseDebtFromMint):
16493
- positionId: ${request.positionId}
16494
- on-chain ucdDebt before tx: ${currentDebt}
16495
- Lit newDebt: ${validationResponse.newDebt}
16496
- Lit mintAmount: ${validationResponse.mintAmount}
16497
- Lit mintFee: ${validationResponse.mintFee}
16498
- Call path: mintUCD -> mintUCDWithAuthorization -> increaseDebtFromMint -> finalizeMintDebtIncrease
16499
- Contract expects UCD supply increase to match mintAmount+mintFee and debt update to newDebt.
16500
- ` : "";
16501
- let quantumContext = "";
16502
- if (selector === "0x131d9a21" || selector === "0x52ce5d58" || selector === "0x137f3b70" || selector === "0xbe4b82c1" || selector === "0x3e76a3c9") {
16503
- const currentTime2 = Math.floor(Date.now() / 1e3);
16504
- const currentQuantum = Math.floor(currentTime2 / 60) * 60;
16505
- const sigQuantum2 = Math.floor(validationResponse.timestamp / 60) * 60;
16506
- const timeDiff = currentTime2 - validationResponse.timestamp;
16507
- quantumContext = `
16508
-
16509
- Quantum Timing Analysis:
16510
- Signature created: ${validationResponse.timestamp} (${new Date(
16511
- validationResponse.timestamp * 1e3
16512
- ).toISOString()})
16513
- Current time: ${currentTime2} (${new Date(
16514
- currentTime2 * 1e3
16515
- ).toISOString()})
16516
- Time elapsed: ${timeDiff} seconds
16517
- Signature quantum: ${sigQuantum2}
16518
- Current quantum: ${currentQuantum}
16519
- Quantum window: 60 seconds
16520
- Status: ${sigQuantum2 < currentQuantum ? "\u274C EXPIRED - Signature created in older quantum window" : "\u2705 VALID"}
16521
- Note: QuantumOutsideWindow can also occur if the tx is mined outside the accepted past/current/next quantum set.`;
16522
- }
16523
- if (!isDeadZonePreflightArtifact) {
16524
- throw new Error(
16525
- `Preflight check failed - mintUCD would revert:
16526
- Error: ${errorName}
16527
- Selector: ${selector}
16528
- Message: ${errorMessage}
16529
- Data: ${errorData}${quantumContext}${mintDebtDiagnostics}`
16530
- );
16531
- }
16532
- } else {
16533
- const currentTime2 = Math.floor(Date.now() / 1e3);
16534
- const timeSinceSig = currentTime2 - validationResponse.timestamp;
16535
- const currentQuantum = Math.floor(currentTime2 / 60) * 60;
16536
- const sigQuantum2 = Math.floor(validationResponse.timestamp / 60) * 60;
16537
- throw new Error(
16538
- `Preflight check failed - mintUCD would revert:
16539
- ${errorMessage}
16540
-
16541
- Error Details:
16542
- Error data: ${errorData || "0x (empty - no custom error)"}
16543
- Error code: ${preflightError?.code || "none"}
16544
-
16545
- Quantum Timing Analysis:
16546
- Signature created: ${validationResponse.timestamp} (${new Date(
16547
- validationResponse.timestamp * 1e3
16548
- ).toISOString()})
16549
- Current time: ${currentTime2} (${new Date(
16550
- currentTime2 * 1e3
16551
- ).toISOString()})
16552
- Time elapsed: ${timeSinceSig} seconds
16553
- Signature quantum: ${sigQuantum2}
16554
- Current quantum: ${currentQuantum}
16555
- Status: ${sigQuantum2 < currentQuantum ? "\u274C EXPIRED - Signature too old" : "\u2705 VALID"}
16556
-
16557
- Possible Causes (when error data is empty):
16558
- \u2022 Quantum signature expired (current=${currentQuantum}, signature=${sigQuantum2})
16559
- \u2022 Contract paused or circuit breaker active
16560
- \u2022 Position state changed since LIT Action signed
16561
- \u2022 Authorization registry validation failed
16562
- \u2022 RPC provider not returning detailed revert data
16563
-
16564
- Position: ${request.positionId}`
16565
- );
16566
- }
16567
- }
16568
16451
  try {
16569
16452
  const coreAddress = this.getContractAddressesOrThrow().positionManagerCore;
16570
16453
  if (!coreAddress) {
@@ -16573,7 +16456,7 @@ Position: ${request.positionId}`
16573
16456
  const coreAbi = [
16574
16457
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
16575
16458
  ];
16576
- const positionCore = new import_ethers13.Contract(
16459
+ const positionCore = new import_ethers14.Contract(
16577
16460
  coreAddress,
16578
16461
  coreAbi,
16579
16462
  this.getSignerOrThrow().provider
@@ -16581,8 +16464,8 @@ Position: ${request.positionId}`
16581
16464
  const currentPosition = await positionCore["getPositionDetails"](
16582
16465
  positionIdBytes32
16583
16466
  );
16584
- const currentDebtHash = (0, import_ethers13.keccak256)(
16585
- import_ethers13.AbiCoder.defaultAbiCoder().encode(
16467
+ const currentDebtHash = (0, import_ethers14.keccak256)(
16468
+ import_ethers14.AbiCoder.defaultAbiCoder().encode(
16586
16469
  ["uint256"],
16587
16470
  [currentPosition.ucdDebt]
16588
16471
  )
@@ -16629,7 +16512,7 @@ Position: ${request.positionId}`
16629
16512
  "function getCurrentQuantum() view returns (uint256)",
16630
16513
  "function isQuantumValid(bytes32,uint256) view returns (bool)"
16631
16514
  ];
16632
- const registry = new import_ethers13.Contract(
16515
+ const registry = new import_ethers14.Contract(
16633
16516
  registryAddress,
16634
16517
  registryAbi,
16635
16518
  this.getSignerOrThrow().provider
@@ -16745,7 +16628,7 @@ Position: ${request.positionId}`
16745
16628
  });
16746
16629
  }
16747
16630
  const signatureHexMint = finalSignature.startsWith("0x") ? finalSignature : "0x" + finalSignature;
16748
- const mintIface = new import_ethers13.Interface(positionManagerAbi);
16631
+ const mintIface = new import_ethers14.Interface(positionManagerAbi);
16749
16632
  const mintCalldata = mintIface.encodeFunctionData("mintUCD", [
16750
16633
  positionIdBytes32,
16751
16634
  validationResponse.mintAmount,
@@ -16760,146 +16643,121 @@ Position: ${request.positionId}`
16760
16643
  signatureHexMint
16761
16644
  ]);
16762
16645
  const fromAddress = await signer.getAddress();
16763
- const estimatedGas = await estimateContractCallGasWithMargin(
16764
- signerProvider,
16765
- fromAddress,
16766
- positionManagerAddress,
16767
- mintCalldata,
16768
- MINT_UCD_ESTIMATE_MARGIN_BPS,
16769
- MINT_UCD_GAS_CEILING
16770
- );
16771
- let tx;
16772
- if (estimatedGas !== null) {
16773
- if (this.config.debug) {
16774
- log.info(
16775
- `\u{1F4DD} Broadcasting mintUCD (gasLimit=${estimatedGas.toString()})`,
16776
- {}
16777
- );
16778
- }
16779
- await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
16780
- tx = await sendEip1559Transaction({
16781
- signer,
16646
+ try {
16647
+ await assertSafeQuantumSubmission({
16648
+ provider: signerProvider,
16782
16649
  to: positionManagerAddress,
16650
+ from: fromAddress,
16783
16651
  data: mintCalldata,
16784
- gasLimit: estimatedGas
16652
+ quantumTimestamp: Number(validationResponse.timestamp),
16653
+ onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
16785
16654
  });
16786
- } else {
16787
- if (this.config.debug) {
16788
- log.info(
16789
- "\u{1F50D} eth_estimateGas failed for mintUCD; running static call",
16790
- {}
16791
- );
16792
- }
16793
- try {
16794
- await signerProvider.call({
16795
- to: positionManagerAddress,
16796
- from: fromAddress,
16797
- data: mintCalldata
16798
- });
16799
- } catch (callError) {
16800
- if (this.config.debug) {
16801
- log.info("\u{1F50D} DEBUG: mintUCD static call failed", {});
16802
- log.info(` Error message: ${callError?.message}`, {});
16803
- log.info(` Error code: ${callError?.code}`, {});
16804
- log.info(` Error data type: ${typeof callError?.data}`, {});
16805
- log.info(` Error data value: ${callError?.data}`, {});
16806
- }
16807
- let errorData = callError?.data || callError?.info?.error?.data || callError?.error?.data?.data || callError?.error?.data;
16808
- const errorMessage = callError?.reason || callError?.message || "Unknown error";
16809
- const isDeadZoneArtifact = decodeQuantumRevert(callError).selector === DEAD_ZONE_VIOLATION_SELECTOR;
16810
- if (isDeadZoneArtifact && this.config.debug) {
16811
- log.info(
16812
- "\u{1F536} mintUCD static-call DeadZoneViolation is a stale-latest-block artifact; broadcasting anyway (gated)",
16813
- {}
16814
- );
16815
- }
16816
- if (!isDeadZoneArtifact && errorData && typeof errorData === "string" && errorData.startsWith("0x") && errorData.length > 10) {
16817
- const selector = errorData.slice(0, 10);
16818
- const knownErrors = {
16819
- "0x8baa579f": "InvalidSignature()",
16820
- "0xd92e233d": "ValidationFailed()",
16821
- "0x3ee5aeb5": "OperationNotAuthorized()",
16822
- "0x70f4b32a": "UnauthorizedSigner()",
16823
- "0x48f5c3ed": "Unauthorized()",
16824
- "0x36bfdeea": "StateHashMismatch()",
16825
- "0x131d9a21": "QuantumExpired()",
16826
- "0x52ce5d58": "QuantumAlreadyUsed()",
16827
- "0x137f3b70": "InDeadZone()",
16828
- "0xbe4b82c1": "DeadZoneViolation()",
16829
- "0x3e76a3c9": "QuantumOutsideWindow()",
16830
- "0x62278171": "InvalidValidatorSignature()",
16831
- "0xb9d419a7": "DebtUpdateVerificationFailed()",
16832
- "0xc7e20553": "DebtUpdateVerificationFailedDetailed(bytes32,uint256,uint256,uint256,uint256,uint256)",
16833
- "0x0cfd2a97": "MintVerificationMismatch(uint256,uint256)",
16834
- "0x07637bd8": "MintFailed()"
16835
- };
16836
- const errorName = knownErrors[selector] || `Unknown error ${selector}`;
16837
- throw new Error(
16838
- `mintUCD reverted: ${errorName}
16839
- Error selector: ${selector}
16840
- Error data: ${errorData}
16841
- Call path: mintUCD -> mintUCDWithAuthorization -> increaseDebtFromMint -> finalizeMintDebtIncrease
16842
- Message: ${errorMessage}`
16843
- );
16844
- }
16845
- if (errorData === "0x" || !errorData) {
16846
- const viewsAddress = this.config.contractAddresses?.positionManagerViews;
16847
- if (viewsAddress) {
16848
- try {
16849
- const views = new import_ethers13.Contract(
16850
- viewsAddress,
16851
- [
16852
- "function diagnoseMintUCD(bytes32,uint256,uint256,uint256,uint256,uint256,bytes32,bytes32,bytes32,uint256,bytes) view returns (string)"
16853
- ],
16854
- signerProvider
16855
- );
16856
- const diagnosis = await views["diagnoseMintUCD"](
16857
- request.positionId,
16858
- validationResponse.mintAmount,
16859
- validationResponse.mintFee,
16860
- validationResponse.newDebt,
16861
- validationResponse.newCollateral,
16862
- validationResponse.btcPrice,
16863
- validationResponse.authorizedSpendsHash,
16864
- ucdDebtHash,
16865
- contractHash,
16866
- validationResponse.timestamp,
16867
- signatureHexMint
16868
- );
16869
- throw new Error(
16870
- `mintUCD reverted with empty data; diagnosis: ${diagnosis}`
16655
+ } catch (simError) {
16656
+ if (!(simError instanceof QuantumRevertError)) {
16657
+ throw simError;
16658
+ }
16659
+ const simCause = simError.cause;
16660
+ const causeMessage = simCause?.reason ?? simCause?.shortMessage ?? (simCause instanceof Error ? simCause.message : String(simCause));
16661
+ if (!simError.data) {
16662
+ const viewsAddress = this.config.contractAddresses?.positionManagerViews;
16663
+ if (viewsAddress) {
16664
+ let diagnosis = null;
16665
+ try {
16666
+ const views = new import_ethers14.Contract(
16667
+ viewsAddress,
16668
+ [
16669
+ "function diagnoseMintUCD(bytes32,uint256,uint256,uint256,uint256,uint256,bytes32,bytes32,bytes32,uint256,bytes) view returns (string)"
16670
+ ],
16671
+ signerProvider
16672
+ );
16673
+ diagnosis = await views["diagnoseMintUCD"](
16674
+ request.positionId,
16675
+ validationResponse.mintAmount,
16676
+ validationResponse.mintFee,
16677
+ validationResponse.newDebt,
16678
+ validationResponse.newCollateral,
16679
+ validationResponse.btcPrice,
16680
+ validationResponse.authorizedSpendsHash,
16681
+ ucdDebtHash,
16682
+ contractHash,
16683
+ validationResponse.timestamp,
16684
+ signatureHexMint
16685
+ );
16686
+ } catch (diagErr) {
16687
+ if (this.config.debug) {
16688
+ log.info(
16689
+ ` diagnoseMintUCD unavailable or failed: ${diagErr?.message || diagErr}`,
16690
+ {}
16871
16691
  );
16872
- } catch (diagErr) {
16873
- if (this.config.debug) {
16874
- log.info(
16875
- ` diagnoseMintUCD unavailable or failed: ${diagErr?.message || diagErr}`,
16876
- {}
16877
- );
16878
- }
16879
16692
  }
16880
16693
  }
16694
+ if (diagnosis !== null) {
16695
+ throw new Error(
16696
+ `mintUCD reverted with empty data; diagnosis: ${diagnosis}`
16697
+ );
16698
+ }
16881
16699
  }
16882
- if (!isDeadZoneArtifact) {
16883
- throw new Error(
16884
- `mintUCD reverted: ${errorMessage}
16885
- Error data: ${errorData || "none"}`
16886
- );
16887
- }
16888
- }
16889
- if (this.config.debug) {
16890
- log.info(
16891
- "\u2705 Static call clear \u2014 broadcasting mintUCD with fixed gas ceiling",
16892
- {}
16700
+ throw new Error(
16701
+ `mintUCD would revert (pre-send simulation): ${causeMessage}
16702
+ Error data: none`
16893
16703
  );
16894
16704
  }
16895
- await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
16896
- tx = await sendEip1559Transaction({
16897
- signer,
16898
- to: positionManagerAddress,
16899
- data: mintCalldata,
16900
- gasLimit: MINT_UCD_GAS_CEILING
16901
- });
16705
+ const selector = simError.selector;
16706
+ const errorName = simError.errorName ?? (selector ? `Unknown error ${selector}` : "unknown");
16707
+ const mintDebtDiagnostics = selector === "0xb9d419a7" || // DebtUpdateVerificationFailed()
16708
+ selector === "0xc7e20553" || // DebtUpdateVerificationFailedDetailed(...)
16709
+ selector === "0x0cfd2a97" || // MintVerificationMismatch(uint256,uint256)
16710
+ selector === "0x07637bd8" ? `
16711
+
16712
+ Mint/debt diagnostics (LoanOperationsManager mint path \u2192 increaseDebtFromMint):
16713
+ positionId: ${request.positionId}
16714
+ on-chain ucdDebt before tx: ${currentDebt}
16715
+ Lit newDebt: ${validationResponse.newDebt}
16716
+ Lit mintAmount: ${validationResponse.mintAmount}
16717
+ Lit mintFee: ${validationResponse.mintFee}
16718
+ Call path: mintUCD -> mintUCDWithAuthorization -> increaseDebtFromMint -> finalizeMintDebtIncrease
16719
+ Contract expects UCD supply increase to match mintAmount+mintFee and debt update to newDebt.
16720
+ ` : "";
16721
+ let quantumContext = "";
16722
+ if (selector === "0x131d9a21" || // QuantumExpired()
16723
+ selector === "0x52ce5d58" || // QuantumAlreadyUsed()
16724
+ selector === "0x137f3b70" || // InDeadZone()
16725
+ selector === "0xbe4b82c1" || // DeadZoneViolation()
16726
+ selector === "0x3e76a3c9") {
16727
+ const nowSecs = Math.floor(Date.now() / 1e3);
16728
+ const nowQuantum = Math.floor(nowSecs / 60) * 60;
16729
+ const signedQuantum = Math.floor(Number(validationResponse.timestamp) / 60) * 60;
16730
+ const timeDiff = nowSecs - Number(validationResponse.timestamp);
16731
+ quantumContext = `
16732
+
16733
+ Quantum Timing Analysis:
16734
+ Signature created: ${validationResponse.timestamp} (${new Date(
16735
+ Number(validationResponse.timestamp) * 1e3
16736
+ ).toISOString()})
16737
+ Current time: ${nowSecs} (${new Date(
16738
+ nowSecs * 1e3
16739
+ ).toISOString()})
16740
+ Time elapsed: ${timeDiff} seconds
16741
+ Signature quantum: ${signedQuantum}
16742
+ Current quantum: ${nowQuantum}
16743
+ Quantum window: 60 seconds
16744
+ Status: ${signedQuantum < nowQuantum ? "\u274C EXPIRED - Signature created in older quantum window" : "\u2705 VALID"}
16745
+ Note: QuantumOutsideWindow can also occur if the tx is mined outside the accepted past/current/next quantum set.`;
16746
+ }
16747
+ throw new Error(
16748
+ `mintUCD would revert (pre-send simulation): ${errorName}
16749
+ Error selector: ${selector}
16750
+ Error data: ${simError.data}
16751
+ Call path: mintUCD -> mintUCDWithAuthorization -> increaseDebtFromMint -> finalizeMintDebtIncrease
16752
+ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
16753
+ );
16902
16754
  }
16755
+ const tx = await sendEip1559Transaction({
16756
+ signer,
16757
+ to: positionManagerAddress,
16758
+ data: mintCalldata,
16759
+ gasLimit: MINT_UCD_GAS_CEILING
16760
+ });
16903
16761
  const receipt = await signerProvider.waitForTransaction(
16904
16762
  tx.hash,
16905
16763
  1,
@@ -16915,7 +16773,7 @@ Error data: ${errorData || "none"}`
16915
16773
  if (receipt.logs && receipt.logs.length > 0) {
16916
16774
  for (const receiptLog of receipt.logs) {
16917
16775
  if (receiptLog.topics && receiptLog.topics[0] === "0x08c379a0") {
16918
- const iface = new import_ethers13.Interface([
16776
+ const iface = new import_ethers14.Interface([
16919
16777
  "error Error(string)"
16920
16778
  ]);
16921
16779
  const decoded = iface.decodeErrorResult("Error", receiptLog.data);
@@ -16932,7 +16790,7 @@ Error data: ${errorData || "none"}`
16932
16790
  const minimalAbi = [
16933
16791
  "event UCDMintedWithAuthorization(bytes32 indexed positionId, address indexed borrower, uint256 mintAmount, uint256 mintFee, uint256 newDebt, uint256 newCollateral, uint256 btcPrice, uint256 quantumTimestamp, bytes32 authorizedSpendsHash)"
16934
16792
  ];
16935
- const iface = new import_ethers13.Interface(minimalAbi);
16793
+ const iface = new import_ethers14.Interface(minimalAbi);
16936
16794
  for (const receiptLog of receipt.logs) {
16937
16795
  const parsed = (() => {
16938
16796
  const logIface = iface;
@@ -17119,7 +16977,7 @@ Error data: ${errorData || "none"}`
17119
16977
  pkpNftAddress,
17120
16978
  this.getChipotlePublicKeyFallback()
17121
16979
  );
17122
- const pkpEthAddress = (0, import_ethers13.computeAddress)(pkpPublicKey);
16980
+ const pkpEthAddress = (0, import_ethers14.computeAddress)(pkpPublicKey);
17123
16981
  pkpData = {
17124
16982
  publicKey: pkpPublicKey,
17125
16983
  ethAddress: pkpEthAddress,
@@ -17521,7 +17379,7 @@ Error data: ${errorData || "none"}`
17521
17379
  }
17522
17380
  const loanOpsForUcd = loanOpsForUcdResult.value;
17523
17381
  const ucdTokenAddress = await loanOpsForUcd.ucdToken();
17524
- const ucdToken = new import_ethers13.Contract(
17382
+ const ucdToken = new import_ethers14.Contract(
17525
17383
  ucdTokenAddress,
17526
17384
  [
17527
17385
  "function balanceOf(address) view returns (uint256)",
@@ -17537,9 +17395,9 @@ Error data: ${errorData || "none"}`
17537
17395
  if (ucdBalance < debtWei) {
17538
17396
  return {
17539
17397
  success: false,
17540
- error: `Insufficient UCD balance for liquidation: ${(0, import_ethers13.formatEther)(
17398
+ error: `Insufficient UCD balance for liquidation: ${(0, import_ethers14.formatEther)(
17541
17399
  ucdBalance
17542
- )} UCD (need ${(0, import_ethers13.formatEther)(debtWei)} UCD)`,
17400
+ )} UCD (need ${(0, import_ethers14.formatEther)(debtWei)} UCD)`,
17543
17401
  positionId: request.positionId,
17544
17402
  wasLiquidated: false
17545
17403
  };
@@ -17548,7 +17406,7 @@ Error data: ${errorData || "none"}`
17548
17406
  if (request.skipUcdApproval) {
17549
17407
  return {
17550
17408
  success: false,
17551
- error: `Insufficient UCD allowance for UCDController: need at least ${(0, import_ethers13.formatEther)(
17409
+ error: `Insufficient UCD allowance for UCDController: need at least ${(0, import_ethers14.formatEther)(
17552
17410
  debtWei
17553
17411
  )} UCD, or omit skipUcdApproval to let the SDK submit approve`,
17554
17412
  positionId: request.positionId,
@@ -18052,7 +17910,7 @@ Error data: ${errorData || "none"}`
18052
17910
  if (typeof signatureBytes === "string" && signatureBytes.startsWith("{")) {
18053
17911
  try {
18054
17912
  const parsed = JSON.parse(signatureBytes);
18055
- signatureBytes = parsed.signature ?? (parsed.r && parsed.s && parsed.v ? import_ethers13.Signature.from({
17913
+ signatureBytes = parsed.signature ?? (parsed.r && parsed.s && parsed.v ? import_ethers14.Signature.from({
18056
17914
  r: parsed.r,
18057
17915
  s: parsed.s,
18058
17916
  v: parsed.v
@@ -18063,26 +17921,43 @@ Error data: ${errorData || "none"}`
18063
17921
  if (!signatureBytes.startsWith("0x")) {
18064
17922
  signatureBytes = "0x" + signatureBytes;
18065
17923
  }
18066
- const contractManager = this.getContractManager();
18067
- const positionManagerResult = contractManager.getPositionManager();
18068
- if (!positionManagerResult.success) {
18069
- throw new Error(
18070
- `Failed to get PositionManager: ${positionManagerResult.error.message}`
18071
- );
18072
- }
18073
- const positionManager = positionManagerResult.value;
18074
- await awaitSafeSubmissionWindow(Number(quantumTimestamp));
18075
- const extendPositionFn = positionManager["extendPosition"];
18076
- const tx = await extendPositionFn(
17924
+ const extendIface = new import_ethers14.Interface([
17925
+ "function extendPosition(bytes32 positionId, uint256 selectedTerm, uint256 quantumTimestamp, uint256 btcPrice, uint256 availableBTCBalance, uint256 proRataRenewalFee, bytes calldata extensionValidatorSignature) external returns (bool)"
17926
+ ]);
17927
+ const extendCalldata = extendIface.encodeFunctionData("extendPosition", [
18077
17928
  positionIdBytes32,
18078
17929
  BigInt(_selectedTerm),
18079
17930
  quantumTimestamp,
18080
17931
  btcPrice,
18081
17932
  availableBTCBalance,
18082
17933
  proRataRenewalFee,
18083
- signatureBytes,
18084
- { gasLimit: EXTEND_POSITION_GAS_CEILING }
18085
- );
17934
+ signatureBytes
17935
+ ]);
17936
+ const extendTo = this.getContractAddressesOrThrow().positionManager;
17937
+ const extendSigner = this.getSignerOrThrow();
17938
+ try {
17939
+ await assertSafeQuantumSubmission({
17940
+ provider: this.getProviderOrThrow(),
17941
+ to: extendTo,
17942
+ from: await extendSigner.getAddress(),
17943
+ data: extendCalldata,
17944
+ quantumTimestamp: Number(quantumTimestamp),
17945
+ onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
17946
+ });
17947
+ } catch (simError) {
17948
+ if (!(simError instanceof QuantumRevertError)) {
17949
+ throw simError;
17950
+ }
17951
+ throw new Error(
17952
+ `extendPosition would revert (pre-send simulation): ${simError.errorName ?? simError.selector ?? "unknown"}`
17953
+ );
17954
+ }
17955
+ const tx = await sendEip1559Transaction({
17956
+ signer: extendSigner,
17957
+ to: extendTo,
17958
+ data: extendCalldata,
17959
+ gasLimit: EXTEND_POSITION_GAS_CEILING
17960
+ });
18086
17961
  const txWithProvider = tx;
18087
17962
  if (!txWithProvider.provider) {
18088
17963
  const signer2 = this.getSignerOrThrow();
@@ -18595,7 +18470,7 @@ Error data: ${errorData || "none"}`
18595
18470
  ` Converting payment amount: ${request.paymentAmount} (type: ${typeof request.paymentAmount})`
18596
18471
  );
18597
18472
  }
18598
- const paymentAmountWei = (0, import_ethers13.parseEther)(
18473
+ const paymentAmountWei = (0, import_ethers14.parseEther)(
18599
18474
  request.paymentAmount.toString()
18600
18475
  );
18601
18476
  if (this.config.debug) {
@@ -18657,7 +18532,7 @@ Error data: ${errorData || "none"}`
18657
18532
  };
18658
18533
  }
18659
18534
  const ucdTokenAddress = await loanOps.ucdToken();
18660
- const ucdToken = new import_ethers13.Contract(
18535
+ const ucdToken = new import_ethers14.Contract(
18661
18536
  ucdTokenAddress,
18662
18537
  [
18663
18538
  "function balanceOf(address) view returns (uint256)",
@@ -18672,16 +18547,16 @@ Error data: ${errorData || "none"}`
18672
18547
  ucdToken["allowance"](signerAddress, positionManagerAddress)
18673
18548
  ]);
18674
18549
  if (this.config.debug) {
18675
- log.info(` UCD Balance: ${(0, import_ethers13.formatEther)(balance)} UCD`);
18550
+ log.info(` UCD Balance: ${(0, import_ethers14.formatEther)(balance)} UCD`);
18676
18551
  log.info(
18677
- ` UCD Allowance: ${(0, import_ethers13.formatEther)(allowance)} UCD`
18552
+ ` UCD Allowance: ${(0, import_ethers14.formatEther)(allowance)} UCD`
18678
18553
  );
18679
18554
  log.info(` Required: ${request.paymentAmount} UCD`);
18680
18555
  }
18681
18556
  if (balance < paymentAmountWei) {
18682
18557
  return {
18683
18558
  success: false,
18684
- error: `Insufficient UCD balance: ${(0, import_ethers13.formatEther)(
18559
+ error: `Insufficient UCD balance: ${(0, import_ethers14.formatEther)(
18685
18560
  balance
18686
18561
  )} UCD (need ${request.paymentAmount} UCD)`
18687
18562
  };
@@ -18942,7 +18817,6 @@ Error data: ${errorData || "none"}`
18942
18817
  quantumTimestamp: quantumTimestamp.toString()
18943
18818
  });
18944
18819
  }
18945
- await awaitSafeSubmissionWindow(Number(quantumTimestamp));
18946
18820
  const paymentAmountStr = paymentAmountWei.toString();
18947
18821
  const quantumTimestampStr = quantumTimestamp.toString();
18948
18822
  const btcPriceStr = btcPrice.toString();
@@ -18950,7 +18824,7 @@ Error data: ${errorData || "none"}`
18950
18824
  const paymentSigner = this.getSignerOrThrow();
18951
18825
  const paymentFrom = await paymentSigner.getAddress();
18952
18826
  const paymentProvider = contractManager.getProvider();
18953
- const paymentIface = new import_ethers13.Interface([
18827
+ const paymentIface = new import_ethers14.Interface([
18954
18828
  "function makePayment(bytes32 positionId, uint256 paymentAmount, uint256 quantumTimestamp, uint256 btcPrice, bytes calldata paymentValidatorSignature) external returns (bool)"
18955
18829
  ]);
18956
18830
  const paymentCalldata = paymentIface.encodeFunctionData("makePayment", [
@@ -18960,58 +18834,30 @@ Error data: ${errorData || "none"}`
18960
18834
  btcPriceStr,
18961
18835
  signature
18962
18836
  ]);
18963
- const decodePaymentRevert = (e) => {
18964
- const { selector, name } = decodeQuantumRevert(e);
18965
- if (!selector)
18966
- return null;
18967
- return name ?? `Unknown error ${selector}`;
18968
- };
18969
- const MAX_DEADZONE_RESIMULATIONS = 3;
18970
- for (let sim = 1; ; sim++) {
18971
- try {
18972
- await paymentProvider.call({
18973
- to: paymentContractAddress,
18974
- from: paymentFrom,
18975
- data: paymentCalldata
18976
- });
18977
- break;
18978
- } catch (simError) {
18979
- const decoded = decodePaymentRevert(simError);
18980
- if (decoded === "DeadZoneViolation()" && sim <= MAX_DEADZONE_RESIMULATIONS) {
18981
- const nowSec = Math.floor(Date.now() / 1e3);
18982
- const sigQuantum = Math.floor(Number(quantumTimestamp) / 60) * 60;
18983
- const realCurrentQuantum = Math.floor(nowSec / 60) * 60;
18984
- if (sigQuantum === realCurrentQuantum) {
18985
- if (this.config.debug) {
18986
- log.info(
18987
- "\u21AA\uFE0F Simulated DeadZoneViolation is a stale-latest-block artifact (signature is the current quantum) \u2014 proceeding to broadcast",
18988
- {}
18989
- );
18990
- }
18991
- break;
18992
- }
18993
- const gate = await awaitSafeSubmissionWindow(Number(quantumTimestamp));
18994
- if (gate.waited) {
18995
- if (this.config.debug) {
18996
- log.info(
18997
- `\u{1F501} Re-simulating makePayment after crossing the quantum boundary (attempt ${sim}/${MAX_DEADZONE_RESIMULATIONS})`,
18998
- {}
18999
- );
19000
- }
19001
- continue;
19002
- }
19003
- }
19004
- const label = decoded ?? simError?.reason ?? simError?.shortMessage ?? (simError instanceof Error ? simError.message : String(simError));
19005
- if (this.config.debug) {
19006
- log.error("\u274C makePayment pre-send simulation reverted", { error: label });
19007
- }
19008
- return {
19009
- success: false,
19010
- error: `Payment would revert (pre-send simulation): ${label}`,
19011
- positionId: request.positionId,
19012
- paymentAmountUCD: request.paymentAmount
19013
- };
18837
+ try {
18838
+ await assertSafeQuantumSubmission({
18839
+ provider: paymentProvider,
18840
+ to: paymentContractAddress,
18841
+ from: paymentFrom,
18842
+ data: paymentCalldata,
18843
+ quantumTimestamp: Number(quantumTimestamp),
18844
+ onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
18845
+ });
18846
+ } catch (simError) {
18847
+ if (!(simError instanceof QuantumRevertError)) {
18848
+ throw simError;
18849
+ }
18850
+ const simCause = simError.cause;
18851
+ const label = simError.errorName ?? (simError.selector ? `Unknown error ${simError.selector}` : null) ?? simCause?.reason ?? simCause?.shortMessage ?? (simCause instanceof Error ? simCause.message : String(simCause));
18852
+ if (this.config.debug) {
18853
+ log.error("\u274C makePayment pre-send simulation reverted", { error: label });
19014
18854
  }
18855
+ return {
18856
+ success: false,
18857
+ error: `Payment would revert (pre-send simulation): ${label}`,
18858
+ positionId: request.positionId,
18859
+ paymentAmountUCD: request.paymentAmount
18860
+ };
19015
18861
  }
19016
18862
  const tx = await sendEip1559Transaction({
19017
18863
  signer: paymentSigner,
@@ -19294,7 +19140,7 @@ Error data: ${errorData || "none"}`
19294
19140
  const pkpId = position.pkpId;
19295
19141
  if (litValidatorAddr && pkpId) {
19296
19142
  try {
19297
- const litValidator = new import_ethers13.Contract(
19143
+ const litValidator = new import_ethers14.Contract(
19298
19144
  litValidatorAddr,
19299
19145
  ["function pkpOwners(bytes32) view returns (address)"],
19300
19146
  this.getProviderOrThrow()
@@ -19302,7 +19148,7 @@ Error data: ${errorData || "none"}`
19302
19148
  const owner = await litValidator.pkpOwners(
19303
19149
  pkpId
19304
19150
  );
19305
- if (owner && owner !== import_ethers13.ZeroAddress) {
19151
+ if (owner && owner !== import_ethers14.ZeroAddress) {
19306
19152
  controller = owner;
19307
19153
  }
19308
19154
  } catch {
@@ -19354,7 +19200,7 @@ Error data: ${errorData || "none"}`
19354
19200
  pkpNftAddress,
19355
19201
  this.getChipotlePublicKeyFallback()
19356
19202
  );
19357
- pkpEthAddress = (0, import_ethers13.computeAddress)(pkpPublicKey);
19203
+ pkpEthAddress = (0, import_ethers14.computeAddress)(pkpPublicKey);
19358
19204
  pkpCache.set(positionId, {
19359
19205
  publicKey: pkpPublicKey,
19360
19206
  ethAddress: pkpEthAddress,
@@ -19685,13 +19531,6 @@ Error data: ${errorData || "none"}`
19685
19531
  error: "PositionManager address not configured"
19686
19532
  };
19687
19533
  }
19688
- const positionManagerContract = new import_ethers13.Contract(
19689
- positionManagerAddress,
19690
- [
19691
- "function withdrawBTC((bytes32 positionId, bytes32 actionHash, bytes32 authorizedSpendsHash, bytes32 ucdDebtHash, bytes32 contractBundleHash, string withdrawalAddress, uint256 totalDeduction, uint256 newCollateral, uint256 quantumTimestamp, uint256 btcPrice, string utxoTxid, uint32 utxoVout) params, bytes withdrawalValidatorSignature, bytes btcSpendAuthSignature) external returns (bool)"
19692
- ],
19693
- this.getSignerOrThrow()
19694
- );
19695
19534
  const withdrawalParams = {
19696
19535
  positionId: positionIdBytes32,
19697
19536
  actionHash: validationResponse.actionHash,
@@ -19724,86 +19563,56 @@ Error data: ${errorData || "none"}`
19724
19563
  utxoVout: withdrawalParams.utxoVout
19725
19564
  });
19726
19565
  }
19727
- await awaitSafeSubmissionWindow(Number(withdrawalParams.quantumTimestamp));
19566
+ const withdrawIface = new import_ethers14.Interface([
19567
+ "function withdrawBTC((bytes32 positionId, bytes32 actionHash, bytes32 authorizedSpendsHash, bytes32 ucdDebtHash, bytes32 contractBundleHash, string withdrawalAddress, uint256 totalDeduction, uint256 newCollateral, uint256 quantumTimestamp, uint256 btcPrice, string utxoTxid, uint32 utxoVout) params, bytes withdrawalValidatorSignature, bytes btcSpendAuthSignature) external returns (bool)"
19568
+ ]);
19569
+ const withdrawCalldata = withdrawIface.encodeFunctionData("withdrawBTC", [
19570
+ withdrawalParams,
19571
+ signatureBytes,
19572
+ btcSpendAuthBytes
19573
+ ]);
19574
+ const withdrawSigner = this.getSignerOrThrow();
19728
19575
  let tx;
19729
19576
  try {
19730
- tx = await positionManagerContract["withdrawBTC"](
19731
- withdrawalParams,
19732
- signatureBytes,
19733
- btcSpendAuthBytes,
19734
- { gasLimit: WITHDRAW_BTC_GAS_CEILING }
19735
- );
19577
+ await assertSafeQuantumSubmission({
19578
+ provider: this.getProviderOrThrow(),
19579
+ to: positionManagerAddress,
19580
+ from: await withdrawSigner.getAddress(),
19581
+ data: withdrawCalldata,
19582
+ quantumTimestamp: Number(withdrawalParams.quantumTimestamp),
19583
+ onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
19584
+ });
19585
+ tx = await sendEip1559Transaction({
19586
+ signer: withdrawSigner,
19587
+ to: positionManagerAddress,
19588
+ data: withdrawCalldata,
19589
+ gasLimit: WITHDRAW_BTC_GAS_CEILING
19590
+ });
19736
19591
  } catch (txError) {
19737
- const txErrorMsg = txError instanceof Error ? txError.message : String(txError);
19592
+ const txErrorMsg = txError instanceof QuantumRevertError ? `Withdrawal would revert (pre-send simulation): ${txError.errorName ?? txError.selector ?? "unknown"}` : txError instanceof Error ? txError.message : String(txError);
19738
19593
  if (this.config.debug) {
19739
- log.warn(
19740
- "\u26A0\uFE0F withdrawBTC contract interface failed, falling back to raw transaction",
19741
- { error: txErrorMsg }
19742
- );
19594
+ log.error("\u274C withdrawBTC transaction submission failed", {
19595
+ error: txErrorMsg,
19596
+ withdrawalParams,
19597
+ signatureBytesLength: signatureBytes.length
19598
+ });
19743
19599
  }
19744
19600
  try {
19745
- const contractAddress = this.getContractAddressesOrThrow().positionManager;
19746
- const iface = new import_ethers13.Interface([
19747
- "function withdrawBTC((bytes32 positionId, bytes32 actionHash, bytes32 authorizedSpendsHash, bytes32 ucdDebtHash, bytes32 contractBundleHash, string withdrawalAddress, uint256 totalDeduction, uint256 newCollateral, uint256 quantumTimestamp, uint256 btcPrice, string utxoTxid, uint32 utxoVout) params, bytes withdrawalValidatorSignature, bytes btcSpendAuthSignature) external returns (bool)"
19748
- ]);
19749
- const calldata = iface.encodeFunctionData("withdrawBTC", [
19750
- withdrawalParams,
19751
- signatureBytes,
19752
- btcSpendAuthBytes
19753
- ]);
19754
- const signer = this.getSignerOrThrow();
19755
- const fromAddress = await signer.getAddress();
19756
- const estimatedGas = await estimateContractCallGasWithMargin(
19757
- this.getProviderOrThrow(),
19758
- fromAddress,
19759
- contractAddress,
19760
- calldata,
19761
- MINT_UCD_ESTIMATE_MARGIN_BPS,
19762
- WITHDRAW_BTC_GAS_CEILING
19763
- );
19764
- const gasLimit = estimatedGas ?? WITHDRAW_BTC_GAS_CEILING;
19765
- await awaitSafeSubmissionWindow(
19766
- Number(withdrawalParams.quantumTimestamp)
19601
+ const position = await this.getPosition(positionId);
19602
+ const btcAmount = (Number(withdrawalAmount) / 1e8).toFixed(8);
19603
+ const message = formatBTCWithdrawalFailureMessage(
19604
+ btcAmount,
19605
+ position?.vaultAddress || "unknown",
19606
+ withdrawalAddress,
19607
+ positionId
19767
19608
  );
19768
- tx = await signer.sendTransaction({
19769
- to: contractAddress,
19770
- data: calldata,
19771
- value: "0x0",
19772
- gasLimit
19773
- });
19774
- if (this.config.debug) {
19775
- log.info("\u2705 withdrawBTC raw transaction fallback succeeded", {
19776
- txHash: tx.hash,
19777
- gasLimit: gasLimit.toString(),
19778
- estimated: estimatedGas !== null
19779
- });
19780
- }
19781
- } catch (rawError) {
19782
- const rawErrorMsg = rawError instanceof Error ? rawError.message : String(rawError);
19783
- if (this.config.debug) {
19784
- log.error("\u274C withdrawBTC transaction failed (raw fallback also failed)", {
19785
- error: rawErrorMsg,
19786
- withdrawalParams,
19787
- signatureBytesLength: signatureBytes.length
19788
- });
19789
- }
19790
- try {
19791
- const position = await this.getPosition(positionId);
19792
- const btcAmount = (Number(withdrawalAmount) / 1e8).toFixed(8);
19793
- const message = formatBTCWithdrawalFailureMessage(
19794
- btcAmount,
19795
- position?.vaultAddress || "unknown",
19796
- withdrawalAddress,
19797
- positionId
19798
- );
19799
- await this._relayNotification(message);
19800
- } catch {
19801
- }
19802
- return {
19803
- success: false,
19804
- error: `Transaction submission failed: ${rawErrorMsg}`
19805
- };
19609
+ await this._relayNotification(message);
19610
+ } catch {
19806
19611
  }
19612
+ return {
19613
+ success: false,
19614
+ error: `Transaction submission failed: ${txErrorMsg}`
19615
+ };
19807
19616
  }
19808
19617
  if (this.config.debug) {
19809
19618
  log.info("\u2705 Transaction submitted, waiting for confirmation:", {
@@ -19826,6 +19635,12 @@ Error data: ${errorData || "none"}`
19826
19635
  error: `Transaction confirmation failed: ${waitErrorMsg}`
19827
19636
  };
19828
19637
  }
19638
+ if (!receipt) {
19639
+ return {
19640
+ success: false,
19641
+ error: `Transaction confirmation returned no receipt. Hash: ${tx.hash}`
19642
+ };
19643
+ }
19829
19644
  if (this.config.debug) {
19830
19645
  log.info("\u2705 BTC withdrawal confirmed", {
19831
19646
  blockNumber: receipt.blockNumber,
@@ -20093,7 +19908,7 @@ Error data: ${errorData || "none"}`
20093
19908
  const btcSpendAuthorizerAbi = [
20094
19909
  "function getAuthorizedSpends(bytes32) view returns (tuple(string txid, uint32 vout, uint256 satoshis, string targetAddress, uint256 targetAmount, uint256 authorizedAt)[])"
20095
19910
  ];
20096
- const btcSpendAuthorizer = new import_ethers13.Contract(
19911
+ const btcSpendAuthorizer = new import_ethers14.Contract(
20097
19912
  btcSpendAuthorizerAddress,
20098
19913
  btcSpendAuthorizerAbi,
20099
19914
  this.getProviderOrThrow()
@@ -20179,7 +19994,7 @@ Error data: ${errorData || "none"}`
20179
19994
  const abi = [
20180
19995
  "function getAuthorizedSpends(bytes32) view returns (tuple(string txid, uint32 vout, uint256 satoshis, string targetAddress, uint256 targetAmount, uint256 authorizedAt)[])"
20181
19996
  ];
20182
- const contract = new import_ethers13.Contract(
19997
+ const contract = new import_ethers14.Contract(
20183
19998
  btcSpendAuthorizerAddress,
20184
19999
  abi,
20185
20000
  this.getProviderOrThrow()
@@ -20193,7 +20008,7 @@ Error data: ${errorData || "none"}`
20193
20008
  targetAddress: spend.targetAddress,
20194
20009
  targetAmount: Number(spend.targetAmount),
20195
20010
  authorizedAt: Number(spend.authorizedAt),
20196
- utxoKey: (0, import_ethers13.solidityPackedKeccak256)(
20011
+ utxoKey: (0, import_ethers14.solidityPackedKeccak256)(
20197
20012
  ["string", "uint32"],
20198
20013
  [spend.txid, Number(spend.vout)]
20199
20014
  )
@@ -20329,7 +20144,7 @@ Error data: ${errorData || "none"}`
20329
20144
  error: attRes.error ?? attRes.reason ?? `LIT recovery attestation rejected${attRes.failedStep ? ` at step ${attRes.failedStep}` : ""}`
20330
20145
  };
20331
20146
  }
20332
- const btcSpendAuthorizer = new import_ethers13.Contract(
20147
+ const btcSpendAuthorizer = new import_ethers14.Contract(
20333
20148
  btcSpendAuthorizerAddress,
20334
20149
  [
20335
20150
  "function cancelStaleSpendWithProof(bytes32 positionId, bytes32 utxoKey, uint256 authorizedAt, string calldata invalidatorTxid, uint256 attestationTimestamp, bytes calldata litSignature) external"
@@ -20724,10 +20539,10 @@ Error data: ${errorData || "none"}`
20724
20539
  "function allowance(address owner, address spender) view returns (uint256)",
20725
20540
  "function approve(address spender, uint256 amount) returns (bool)"
20726
20541
  ];
20727
- const stablecoin = new import_ethers13.Contract(params.stablecoinAddress, erc20Abi, params.signer);
20542
+ const stablecoin = new import_ethers14.Contract(params.stablecoinAddress, erc20Abi, params.signer);
20728
20543
  const allowance = await stablecoin.allowance(signerAddress, psmAddress);
20729
20544
  if (allowance < params.amountWei) {
20730
- const approveTx = await stablecoin.approve(psmAddress, import_ethers13.MaxUint256);
20545
+ const approveTx = await stablecoin.approve(psmAddress, import_ethers14.MaxUint256);
20731
20546
  await approveTx.wait();
20732
20547
  }
20733
20548
  const psm = SimplePSMV2__factory.connect(psmAddress, params.signer);
@@ -20762,10 +20577,10 @@ Error data: ${errorData || "none"}`
20762
20577
  "function allowance(address owner, address spender) view returns (uint256)",
20763
20578
  "function approve(address spender, uint256 amount) returns (bool)"
20764
20579
  ];
20765
- const ucdToken = new import_ethers13.Contract(ucdAddress, erc20Abi, params.signer);
20580
+ const ucdToken = new import_ethers14.Contract(ucdAddress, erc20Abi, params.signer);
20766
20581
  const allowance = await ucdToken.allowance(signerAddress, ucdControllerAddress);
20767
20582
  if (allowance < params.ucdAmountWei) {
20768
- const approveTx = await ucdToken.approve(ucdControllerAddress, import_ethers13.MaxUint256);
20583
+ const approveTx = await ucdToken.approve(ucdControllerAddress, import_ethers14.MaxUint256);
20769
20584
  await approveTx.wait();
20770
20585
  }
20771
20586
  const psm = SimplePSMV2__factory.connect(psmAddress, params.signer);
@@ -20977,7 +20792,7 @@ Error data: ${errorData || "none"}`
20977
20792
  const maxUcdWhole = BigInt(result[3].toString());
20978
20793
  return success({
20979
20794
  liquidationThreshold: result[0].toString(),
20980
- minimumLoanValueUcd: (0, import_ethers13.formatUnits)(result[2], 18),
20795
+ minimumLoanValueUcd: (0, import_ethers14.formatUnits)(result[2], 18),
20981
20796
  minimumLoanValueWei: result[2].toString(),
20982
20797
  maxSingleLoanValueUcd: maxUcdWhole.toString(),
20983
20798
  maxSingleLoanValueWei: (maxUcdWhole * 10n ** 18n).toString()
@@ -21014,7 +20829,7 @@ Error data: ${errorData || "none"}`
21014
20829
  const balanceWei = await provider.getBalance(address);
21015
20830
  return success({
21016
20831
  balanceWei: balanceWei.toString(),
21017
- balanceEth: (0, import_ethers13.formatEther)(balanceWei)
20832
+ balanceEth: (0, import_ethers14.formatEther)(balanceWei)
21018
20833
  });
21019
20834
  } catch (error) {
21020
20835
  return failure(new SDKError({
@@ -21353,7 +21168,7 @@ Error data: ${errorData || "none"}`
21353
21168
  * Convert decimal position ID to bytes32 format
21354
21169
  */
21355
21170
  toBytes32(value) {
21356
- return (0, import_ethers13.zeroPadValue)((0, import_ethers13.toBeHex)(BigInt(value)), 32);
21171
+ return (0, import_ethers14.zeroPadValue)((0, import_ethers14.toBeHex)(BigInt(value)), 32);
21357
21172
  }
21358
21173
  /**
21359
21174
  * Check if an error indicates a technical failure vs business logic rejection
@@ -21394,7 +21209,7 @@ Error data: ${errorData || "none"}`
21394
21209
  const coreModuleAbi = [
21395
21210
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
21396
21211
  ];
21397
- const coreModule = new import_ethers13.Contract(
21212
+ const coreModule = new import_ethers14.Contract(
21398
21213
  coreModuleAddress,
21399
21214
  coreModuleAbi,
21400
21215
  provider
@@ -21461,7 +21276,7 @@ Error data: ${errorData || "none"}`
21461
21276
  const corePositionAbi = [
21462
21277
  "function getPositionDetails(bytes32) view returns (tuple(bytes32 positionId, bytes32 pkpId, uint256 ucdDebt, string vaultAddress, address borrower, uint40 createdAt, uint40 lastUpdated, uint16 selectedTerm, uint40 expiryAt, uint8 status, uint40 previousExpiryAt, uint16 totalTerm))"
21463
21278
  ];
21464
- const corePositionContract = new import_ethers13.Contract(
21279
+ const corePositionContract = new import_ethers14.Contract(
21465
21280
  coreAddress,
21466
21281
  corePositionAbi,
21467
21282
  provider
@@ -21472,7 +21287,7 @@ Error data: ${errorData || "none"}`
21472
21287
  positionIdBytes32
21473
21288
  );
21474
21289
  const positionIdFromCore = corePosition?.positionId || corePosition?.[0] || null;
21475
- if (positionIdFromCore && positionIdFromCore !== import_ethers13.ZeroHash && positionIdFromCore !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
21290
+ if (positionIdFromCore && positionIdFromCore !== import_ethers14.ZeroHash && positionIdFromCore !== "0x0000000000000000000000000000000000000000000000000000000000000000") {
21476
21291
  if (this.config.debug) {
21477
21292
  log.info("Position exists in core contract", {
21478
21293
  positionId,
@@ -21540,7 +21355,7 @@ Error data: ${errorData || "none"}`
21540
21355
  throw new Error("loanOperationsManager address not configured");
21541
21356
  }
21542
21357
  const runner = this.config.contractSigner || this.getProviderOrThrow();
21543
- const contract = new import_ethers13.Contract(
21358
+ const contract = new import_ethers14.Contract(
21544
21359
  addr.loanOperationsManager,
21545
21360
  [
21546
21361
  "function getProtocolConfig() external view returns (uint256 liquidationThreshold, uint256 minimumLoanValueUcd, uint256 minimumLoanValueWei, uint256 maxSingleLoanValueUcd)"
@@ -21553,7 +21368,7 @@ Error data: ${errorData || "none"}`
21553
21368
  const maxUcdWhole = BigInt(result[3].toString());
21554
21369
  return {
21555
21370
  liquidationThreshold: result[0].toString(),
21556
- minimumLoanValueUcd: (0, import_ethers13.formatUnits)(result[2], 18),
21371
+ minimumLoanValueUcd: (0, import_ethers14.formatUnits)(result[2], 18),
21557
21372
  minimumLoanValueWei: result[2].toString(),
21558
21373
  maxSingleLoanValueUcd: maxUcdWhole.toString(),
21559
21374
  maxSingleLoanValueWei: (maxUcdWhole * 10n ** 18n).toString()
@@ -21571,8 +21386,8 @@ Error data: ${errorData || "none"}`
21571
21386
  const MIN_REVEAL_DELAY = 60;
21572
21387
  const MAX_RANDOM_DELAY = 240;
21573
21388
  const entropyInput = positionId + quantumTimestamp.toString();
21574
- const hash = (0, import_ethers13.keccak256)(
21575
- (0, import_ethers13.toUtf8Bytes)(entropyInput)
21389
+ const hash = (0, import_ethers14.keccak256)(
21390
+ (0, import_ethers14.toUtf8Bytes)(entropyInput)
21576
21391
  );
21577
21392
  const randomValue = BigInt(hash);
21578
21393
  const randomDelay = Number(randomValue % BigInt(MAX_RANDOM_DELAY));
@@ -21635,7 +21450,7 @@ Error data: ${errorData || "none"}`
21635
21450
  const vrfSeedRaw = await lmResult.value["vrfSeeds"](positionId);
21636
21451
  const vrfSeed = BigInt(vrfSeedRaw.toString());
21637
21452
  if (vrfSeed !== 0n) {
21638
- const finalEntropy = (0, import_ethers13.solidityPackedKeccak256)(
21453
+ const finalEntropy = (0, import_ethers14.solidityPackedKeccak256)(
21639
21454
  ["uint256", "uint256", "bytes32"],
21640
21455
  [vrfSeed, BigInt(quantumTimestamp.toString()), positionId]
21641
21456
  );
@@ -21913,14 +21728,14 @@ var EventHelpers = {
21913
21728
  };
21914
21729
 
21915
21730
  // src/utils/position-delegate.utils.ts
21916
- var import_ethers14 = require("ethers");
21731
+ var import_ethers15 = require("ethers");
21917
21732
  var POSITION_DELEGATE_REGISTRY_ABI = [
21918
21733
  "function positionDelegate(bytes32 positionId) view returns (address)",
21919
21734
  "function setPositionDelegate(bytes32 positionId, address newDelegate) external",
21920
21735
  "event PositionDelegateUpdated(bytes32 indexed positionId, address indexed oldDelegate, address indexed newDelegate)"
21921
21736
  ];
21922
21737
  async function setPositionDelegate(positionId, delegate, signer, registryAddress) {
21923
- const registry = new import_ethers14.Contract(
21738
+ const registry = new import_ethers15.Contract(
21924
21739
  registryAddress,
21925
21740
  POSITION_DELEGATE_REGISTRY_ABI,
21926
21741
  signer
@@ -21928,7 +21743,7 @@ async function setPositionDelegate(positionId, delegate, signer, registryAddress
21928
21743
  return registry["setPositionDelegate"](positionId, delegate);
21929
21744
  }
21930
21745
  async function getPositionDelegate(positionId, provider, registryAddress) {
21931
- const registry = new import_ethers14.Contract(
21746
+ const registry = new import_ethers15.Contract(
21932
21747
  registryAddress,
21933
21748
  POSITION_DELEGATE_REGISTRY_ABI,
21934
21749
  provider