@gvnrdao/dh-sdk 0.0.128 → 0.0.130

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
@@ -12702,48 +12702,48 @@ var init_deployment_addresses = __esm({
12702
12702
  SEPOLIA_DEPLOYMENT = {
12703
12703
  "network": "sepolia",
12704
12704
  "chainId": 11155111,
12705
- "timestamp": "2025-12-05T19:34:00.994Z",
12705
+ "timestamp": "2025-12-08T20:44:11.397Z",
12706
12706
  "deployer": "",
12707
12707
  "contracts": {
12708
- "UpgradeValidator": "0xb86C8F6f3a877586C9B0D05E523062837ABD4dF5",
12708
+ "UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
12709
12709
  "UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
12710
- "UCDController": "0xa853609Bf8064bfbA1Cb8C01D102d0Efcc5ad10E",
12711
- "PriceFeedConsumer": "0xB0eB31Df2b7E2b95304115b6f0427d622113c641",
12712
- "BTCProofValidator": "0x2b6bCddd0788300db6622cE5050848068eC6faC5",
12713
- "UCDMintingRewards": "0xeD271B85Ecc1239983F92D5E05a5080bcb5F00a4",
12714
- "PositionManagerCoreModule": "0xD265B579Cb707b344292a2130ee90392735d8Ec1",
12715
- "TermManagerModule": "0xa445be9b6AF389e15cd0dF5D31E5A9C3DD62d95D",
12716
- "LoanOperationsManagerModule": "0x2110694692930a70d6698c7B4958f287ec79AAeA",
12717
- "CollateralManagerModule": "0xa7EAC2c6B26a57eBd0b9A9A4845F29913067963B",
12718
- "LiquidationManagerModule": "0x81711D8075A6e1496607DbfBF83E4f0e68f41840",
12719
- "CircuitBreakerModule": "0xa17c1653d33d4F4cd6f903c1142f55D604c8F102",
12720
- "CommunityManagerModule": "0xa90027E1010f41B91f27C1335E71507E1e423118",
12721
- "AdminModule": "0x73edc6fE737a7381d01fe35a15287460aB4d8992",
12722
- "PositionManagerViews": "0x0e297165d8C48fB20cCbA92B97B99bfE5FF0b227",
12723
- "PositionManager": "0x817b43308427fb46627e21942F639888A83D6196",
12724
- "OperationAuthorizationRegistry": "0xd4a68AC3d7Fb441658fEA6f916c66A2481f5e413",
12725
- "PKPValidation": "0x987bcEA333b0F2ab0Ea7d1eF8811845b581472E0"
12710
+ "UCDController": "0x8956368203475DeECA21bc79F5FDeA249937E20C",
12711
+ "PriceFeedConsumer": "0xbAB704d9d2F701aE3ec0B39ded1F1a27ba3544EE",
12712
+ "BTCProofValidator": "0x760DD5b1524d1C907e03A99A02C6b9634c569aE8",
12713
+ "UCDMintingRewards": "0x92ea837DCF6e757cA19D524f02b49A4650FAaB46",
12714
+ "PositionManagerCoreModule": "0xAA2893395159550730C02075D5a7b5F905464c7b",
12715
+ "TermManagerModule": "0x89a2ffBE000e0dcfd4D5893592fC8d7D07E43618",
12716
+ "LoanOperationsManagerModule": "0x0644ae669DaA9aB7561d59d902a5F0811230a83c",
12717
+ "CollateralManagerModule": "0xc11E2c128F2Be64AD1D020eA188973CFBeADAcb9",
12718
+ "LiquidationManagerModule": "0xa8608AB8b6F16947F5379f1971e0851A436a856A",
12719
+ "CircuitBreakerModule": "0xB522e59e750C4B84b3E7Ed5E9176A4B9c89704Ec",
12720
+ "CommunityManagerModule": "0x6C022640Afe32B853FC908066da7a160B71FE864",
12721
+ "AdminModule": "0xB570bf6a5ae0589c0E67eBdc09e17e2eFba90f0b",
12722
+ "PositionManagerViews": "0xdc7e1Db596B3A787386d144aCE485F02BBb43bA7",
12723
+ "PositionManager": "0x2d654736b8fcc385BD27Bf5b936A7c92Ea951Cc8",
12724
+ "OperationAuthorizationRegistry": "0xE55b4d77b235155cF534A28e897Ddc028395B8F9",
12725
+ "PKPValidation": "0x0d448F827b1803865F6D4135Fb5FBcD285D34Aac"
12726
12726
  }
12727
12727
  };
12728
12728
  SEPOLIA_CONTRACTS = {
12729
- "UpgradeValidator": "0xb86C8F6f3a877586C9B0D05E523062837ABD4dF5",
12729
+ "UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
12730
12730
  "UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
12731
- "UCDController": "0xa853609Bf8064bfbA1Cb8C01D102d0Efcc5ad10E",
12732
- "PriceFeedConsumer": "0xB0eB31Df2b7E2b95304115b6f0427d622113c641",
12733
- "BTCProofValidator": "0x2b6bCddd0788300db6622cE5050848068eC6faC5",
12734
- "UCDMintingRewards": "0xeD271B85Ecc1239983F92D5E05a5080bcb5F00a4",
12735
- "PositionManagerCoreModule": "0xD265B579Cb707b344292a2130ee90392735d8Ec1",
12736
- "TermManagerModule": "0xa445be9b6AF389e15cd0dF5D31E5A9C3DD62d95D",
12737
- "LoanOperationsManagerModule": "0x2110694692930a70d6698c7B4958f287ec79AAeA",
12738
- "CollateralManagerModule": "0xa7EAC2c6B26a57eBd0b9A9A4845F29913067963B",
12739
- "LiquidationManagerModule": "0x81711D8075A6e1496607DbfBF83E4f0e68f41840",
12740
- "CircuitBreakerModule": "0xa17c1653d33d4F4cd6f903c1142f55D604c8F102",
12741
- "CommunityManagerModule": "0xa90027E1010f41B91f27C1335E71507E1e423118",
12742
- "AdminModule": "0x73edc6fE737a7381d01fe35a15287460aB4d8992",
12743
- "PositionManagerViews": "0x0e297165d8C48fB20cCbA92B97B99bfE5FF0b227",
12744
- "PositionManager": "0x817b43308427fb46627e21942F639888A83D6196",
12745
- "OperationAuthorizationRegistry": "0xd4a68AC3d7Fb441658fEA6f916c66A2481f5e413",
12746
- "PKPValidation": "0x987bcEA333b0F2ab0Ea7d1eF8811845b581472E0"
12731
+ "UCDController": "0x8956368203475DeECA21bc79F5FDeA249937E20C",
12732
+ "PriceFeedConsumer": "0xbAB704d9d2F701aE3ec0B39ded1F1a27ba3544EE",
12733
+ "BTCProofValidator": "0x760DD5b1524d1C907e03A99A02C6b9634c569aE8",
12734
+ "UCDMintingRewards": "0x92ea837DCF6e757cA19D524f02b49A4650FAaB46",
12735
+ "PositionManagerCoreModule": "0xAA2893395159550730C02075D5a7b5F905464c7b",
12736
+ "TermManagerModule": "0x89a2ffBE000e0dcfd4D5893592fC8d7D07E43618",
12737
+ "LoanOperationsManagerModule": "0x0644ae669DaA9aB7561d59d902a5F0811230a83c",
12738
+ "CollateralManagerModule": "0xc11E2c128F2Be64AD1D020eA188973CFBeADAcb9",
12739
+ "LiquidationManagerModule": "0xa8608AB8b6F16947F5379f1971e0851A436a856A",
12740
+ "CircuitBreakerModule": "0xB522e59e750C4B84b3E7Ed5E9176A4B9c89704Ec",
12741
+ "CommunityManagerModule": "0x6C022640Afe32B853FC908066da7a160B71FE864",
12742
+ "AdminModule": "0xB570bf6a5ae0589c0E67eBdc09e17e2eFba90f0b",
12743
+ "PositionManagerViews": "0xdc7e1Db596B3A787386d144aCE485F02BBb43bA7",
12744
+ "PositionManager": "0x2d654736b8fcc385BD27Bf5b936A7c92Ea951Cc8",
12745
+ "OperationAuthorizationRegistry": "0xE55b4d77b235155cF534A28e897Ddc028395B8F9",
12746
+ "PKPValidation": "0x0d448F827b1803865F6D4135Fb5FBcD285D34Aac"
12747
12747
  };
12748
12748
  LOCALHOST_DEPLOYMENT = {
12749
12749
  "network": "localhost",
@@ -29163,42 +29163,70 @@ function validateSDKConfig(config) {
29163
29163
  }
29164
29164
 
29165
29165
  // src/utils/quantum-timing.ts
29166
- async function calculateValidQuantumTimestamp() {
29167
- console.log(" \u{1F3AF} Finding OPTIMAL quantum moment for signature...");
29168
- let now2 = Math.floor(Date.now() / 1e3);
29169
- let timeInQuantum = now2 % 100;
29170
- if (timeInQuantum !== 16) {
29171
- let waitSeconds;
29172
- if (timeInQuantum < 16) {
29173
- waitSeconds = 16 - timeInQuantum;
29174
- console.log(
29175
- ` \u23F3 Current: second ${timeInQuantum} - waiting ${waitSeconds}s for optimal moment (second 16)...`
29176
- );
29177
- } else {
29178
- waitSeconds = 100 - timeInQuantum + 16;
29179
- console.log(
29180
- ` \u23F3 Current: second ${timeInQuantum} - waiting ${waitSeconds}s for next optimal moment (second 16)...`
29181
- );
29182
- }
29183
- await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1e3));
29184
- now2 = Math.floor(Date.now() / 1e3);
29185
- timeInQuantum = now2 % 100;
29186
- console.log(` \u2705 Optimal moment reached: second ${timeInQuantum}`);
29166
+ function calculateNextQuantumTimestamp() {
29167
+ const now2 = Math.floor(Date.now() / 1e3);
29168
+ const timeInQuantum = now2 % 100;
29169
+ const currentQuantum = Math.floor(now2 / 100) * 100;
29170
+ let targetTimestamp;
29171
+ if (timeInQuantum >= 16 && timeInQuantum <= 30) {
29172
+ targetTimestamp = now2;
29173
+ console.log(
29174
+ "[Quantum Timing] Already at optimal moment in current quantum"
29175
+ );
29176
+ } else if (timeInQuantum < 16 && timeInQuantum >= 8) {
29177
+ targetTimestamp = currentQuantum + 16;
29178
+ console.log("[Quantum Timing] Targeting second 16 of CURRENT quantum");
29187
29179
  } else {
29188
- console.log(` \u2705 Already at optimal moment: second ${timeInQuantum}`);
29189
- }
29190
- const timestamp = Math.floor(Date.now() / 1e3);
29191
- const quantumWindow = Math.floor(timestamp / 100) * 100;
29192
- const timeInQuantumNow = timestamp % 100;
29193
- console.log(" \u{1F4DD} Timestamp Details:");
29194
- console.log(" Timestamp:", timestamp);
29195
- console.log(" Quantum window:", quantumWindow);
29180
+ const nextQuantum = currentQuantum + 100;
29181
+ targetTimestamp = nextQuantum + 16;
29182
+ console.log("[Quantum Timing] Targeting second 16 of NEXT quantum");
29183
+ }
29184
+ console.log("[Quantum Timing] Calculated quantum timing:");
29185
+ console.log(" Current time:", now2);
29186
+ console.log(" Time in quantum:", timeInQuantum);
29187
+ console.log(" Target timestamp:", targetTimestamp);
29188
+ console.log(" Seconds until target:", targetTimestamp - now2);
29189
+ return targetTimestamp;
29190
+ }
29191
+ async function waitUntilTimestamp(targetTimestamp) {
29192
+ const now2 = Math.floor(Date.now() / 1e3);
29193
+ const waitSeconds = targetTimestamp - now2;
29194
+ if (waitSeconds <= 0) {
29195
+ console.log("[Quantum Timing] Target timestamp already reached");
29196
+ return;
29197
+ }
29196
29198
  console.log(
29197
- " Time in quantum:",
29198
- timeInQuantumNow,
29199
- "seconds (OPTIMAL: 16)"
29199
+ `[Quantum Timing] Waiting ${waitSeconds}s until timestamp ${targetTimestamp}...`
29200
29200
  );
29201
- return timestamp;
29201
+ await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1e3));
29202
+ console.log("[Quantum Timing] Target timestamp reached");
29203
+ }
29204
+ function validateQuantumTiming(signedTimestamp, bufferSeconds = 30) {
29205
+ const now2 = Math.floor(Date.now() / 1e3);
29206
+ const signedQuantum = Math.floor(signedTimestamp / 100) * 100;
29207
+ const currentQuantum = Math.floor(now2 / 100) * 100;
29208
+ if (currentQuantum !== signedQuantum) {
29209
+ throw new Error(
29210
+ `Quantum window expired. User took too long to sign. Signed quantum: ${signedQuantum}, Current quantum: ${currentQuantum}`
29211
+ );
29212
+ }
29213
+ const timeInQuantum = now2 % 100;
29214
+ const isInDeadZone = timeInQuantum < 8 || timeInQuantum >= 92;
29215
+ if (isInDeadZone) {
29216
+ throw new Error(
29217
+ `Current time (${timeInQuantum}s in quantum) is in dead zone. Operation cannot proceed safely.`
29218
+ );
29219
+ }
29220
+ const secondsRemaining = 92 - timeInQuantum;
29221
+ if (secondsRemaining < bufferSeconds) {
29222
+ throw new Error(
29223
+ `Insufficient time remaining in quantum. Required: ${bufferSeconds}s, Available: ${secondsRemaining}s`
29224
+ );
29225
+ }
29226
+ console.log("[Quantum Timing] Validation passed:");
29227
+ console.log(" Time in quantum:", timeInQuantum);
29228
+ console.log(" Seconds remaining:", secondsRemaining);
29229
+ console.log(" Required buffer:", bufferSeconds);
29202
29230
  }
29203
29231
 
29204
29232
  // src/utils/mint-authorization.utils.ts
@@ -29212,7 +29240,7 @@ var PKP_NFT_ADDRESSES = {
29212
29240
  // Yellowstone/Datil (PKP native network) - same as Datil testnet
29213
29241
  };
29214
29242
  async function generateMintAuthorization(positionId, amount, chainId, mode, signer) {
29215
- const timestamp = await calculateValidQuantumTimestamp();
29243
+ const timestamp = calculateNextQuantumTimestamp();
29216
29244
  const action = "mint-ucd";
29217
29245
  const actionHash = ethers_exports.utils.keccak256(ethers_exports.utils.toUtf8Bytes(action));
29218
29246
  const types = [
@@ -29246,7 +29274,8 @@ async function generateMintAuthorization(positionId, amount, chainId, mode, sign
29246
29274
  console.log(" Action Hash:", actionHash);
29247
29275
  console.log(" Message Hash (solidityKeccak256):", messageHash);
29248
29276
  console.log(" Message Hash Bytes Length:", messageHashBytes.length);
29249
- console.log(" Signer Address:", signer.address);
29277
+ const signerAddress = await signer.getAddress();
29278
+ console.log(" Signer Address:", signerAddress);
29250
29279
  const signature2 = await signer.signMessage(messageHashBytes);
29251
29280
  return {
29252
29281
  positionId,
@@ -29290,7 +29319,7 @@ async function getPKPPublicKeyFromTokenId(pkpTokenId, provider) {
29290
29319
  return pubkeyBytes.startsWith("0x") ? pubkeyBytes : `0x${pubkeyBytes}`;
29291
29320
  }
29292
29321
  async function generateWithdrawAuthorization(positionId, amount, chainId, mode, signer, destinationAddress) {
29293
- const timestamp = await calculateValidQuantumTimestamp();
29322
+ const timestamp = calculateNextQuantumTimestamp();
29294
29323
  const action = "withdraw-btc";
29295
29324
  const actionHash = ethers_exports.utils.keccak256(ethers_exports.utils.toUtf8Bytes(action));
29296
29325
  const types = [
@@ -29326,7 +29355,8 @@ async function generateWithdrawAuthorization(positionId, amount, chainId, mode,
29326
29355
  console.log(" Action:", action);
29327
29356
  console.log(" Action Hash:", actionHash);
29328
29357
  console.log(" Message Hash (solidityKeccak256):", messageHash);
29329
- console.log(" Signer Address:", signer.address);
29358
+ const signerAddress = await signer.getAddress();
29359
+ console.log(" Signer Address:", signerAddress);
29330
29360
  const signature2 = await signer.signMessage(messageHashBytes);
29331
29361
  console.log("[SDK Withdrawal Authorization] Signature generated:");
29332
29362
  console.log(" Signature:", signature2);
@@ -29335,7 +29365,7 @@ async function generateWithdrawAuthorization(positionId, amount, chainId, mode,
29335
29365
  console.log(" Recovered Address (for verification):", recovered);
29336
29366
  console.log(
29337
29367
  " Signer Matches Recovered:",
29338
- recovered.toLowerCase() === signer.address.toLowerCase() ? "\u2705 YES" : "\u274C NO"
29368
+ recovered.toLowerCase() === signerAddress.toLowerCase() ? "\u2705 YES" : "\u274C NO"
29339
29369
  );
29340
29370
  return {
29341
29371
  positionId,
@@ -47535,6 +47565,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
47535
47565
  log.info(` Mode: ${auth.mode}`);
47536
47566
  log.info(` Signature: ${auth.signature.substring(0, 20)}...`);
47537
47567
  }
47568
+ await waitUntilTimestamp(auth.timestamp);
47569
+ validateQuantumTiming(auth.timestamp, 30);
47538
47570
  litActionResult = await this.litOps.requestMintAuthorization({
47539
47571
  authMessage: {
47540
47572
  ...auth,
@@ -48306,6 +48338,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
48306
48338
  log.info(` Mode: ${auth.mode}`);
48307
48339
  log.info(` Signature: ${auth.signature.substring(0, 20)}...`);
48308
48340
  }
48341
+ await waitUntilTimestamp(auth.timestamp);
48342
+ validateQuantumTiming(auth.timestamp, 30);
48309
48343
  litActionResult = await this.litOps.requestWithdrawalAuthorization({
48310
48344
  authMessage: {
48311
48345
  ...auth,
package/dist/index.mjs CHANGED
@@ -12708,48 +12708,48 @@ var init_deployment_addresses = __esm({
12708
12708
  SEPOLIA_DEPLOYMENT = {
12709
12709
  "network": "sepolia",
12710
12710
  "chainId": 11155111,
12711
- "timestamp": "2025-12-05T19:34:00.994Z",
12711
+ "timestamp": "2025-12-08T20:44:11.397Z",
12712
12712
  "deployer": "",
12713
12713
  "contracts": {
12714
- "UpgradeValidator": "0xb86C8F6f3a877586C9B0D05E523062837ABD4dF5",
12714
+ "UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
12715
12715
  "UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
12716
- "UCDController": "0xa853609Bf8064bfbA1Cb8C01D102d0Efcc5ad10E",
12717
- "PriceFeedConsumer": "0xB0eB31Df2b7E2b95304115b6f0427d622113c641",
12718
- "BTCProofValidator": "0x2b6bCddd0788300db6622cE5050848068eC6faC5",
12719
- "UCDMintingRewards": "0xeD271B85Ecc1239983F92D5E05a5080bcb5F00a4",
12720
- "PositionManagerCoreModule": "0xD265B579Cb707b344292a2130ee90392735d8Ec1",
12721
- "TermManagerModule": "0xa445be9b6AF389e15cd0dF5D31E5A9C3DD62d95D",
12722
- "LoanOperationsManagerModule": "0x2110694692930a70d6698c7B4958f287ec79AAeA",
12723
- "CollateralManagerModule": "0xa7EAC2c6B26a57eBd0b9A9A4845F29913067963B",
12724
- "LiquidationManagerModule": "0x81711D8075A6e1496607DbfBF83E4f0e68f41840",
12725
- "CircuitBreakerModule": "0xa17c1653d33d4F4cd6f903c1142f55D604c8F102",
12726
- "CommunityManagerModule": "0xa90027E1010f41B91f27C1335E71507E1e423118",
12727
- "AdminModule": "0x73edc6fE737a7381d01fe35a15287460aB4d8992",
12728
- "PositionManagerViews": "0x0e297165d8C48fB20cCbA92B97B99bfE5FF0b227",
12729
- "PositionManager": "0x817b43308427fb46627e21942F639888A83D6196",
12730
- "OperationAuthorizationRegistry": "0xd4a68AC3d7Fb441658fEA6f916c66A2481f5e413",
12731
- "PKPValidation": "0x987bcEA333b0F2ab0Ea7d1eF8811845b581472E0"
12716
+ "UCDController": "0x8956368203475DeECA21bc79F5FDeA249937E20C",
12717
+ "PriceFeedConsumer": "0xbAB704d9d2F701aE3ec0B39ded1F1a27ba3544EE",
12718
+ "BTCProofValidator": "0x760DD5b1524d1C907e03A99A02C6b9634c569aE8",
12719
+ "UCDMintingRewards": "0x92ea837DCF6e757cA19D524f02b49A4650FAaB46",
12720
+ "PositionManagerCoreModule": "0xAA2893395159550730C02075D5a7b5F905464c7b",
12721
+ "TermManagerModule": "0x89a2ffBE000e0dcfd4D5893592fC8d7D07E43618",
12722
+ "LoanOperationsManagerModule": "0x0644ae669DaA9aB7561d59d902a5F0811230a83c",
12723
+ "CollateralManagerModule": "0xc11E2c128F2Be64AD1D020eA188973CFBeADAcb9",
12724
+ "LiquidationManagerModule": "0xa8608AB8b6F16947F5379f1971e0851A436a856A",
12725
+ "CircuitBreakerModule": "0xB522e59e750C4B84b3E7Ed5E9176A4B9c89704Ec",
12726
+ "CommunityManagerModule": "0x6C022640Afe32B853FC908066da7a160B71FE864",
12727
+ "AdminModule": "0xB570bf6a5ae0589c0E67eBdc09e17e2eFba90f0b",
12728
+ "PositionManagerViews": "0xdc7e1Db596B3A787386d144aCE485F02BBb43bA7",
12729
+ "PositionManager": "0x2d654736b8fcc385BD27Bf5b936A7c92Ea951Cc8",
12730
+ "OperationAuthorizationRegistry": "0xE55b4d77b235155cF534A28e897Ddc028395B8F9",
12731
+ "PKPValidation": "0x0d448F827b1803865F6D4135Fb5FBcD285D34Aac"
12732
12732
  }
12733
12733
  };
12734
12734
  SEPOLIA_CONTRACTS = {
12735
- "UpgradeValidator": "0xb86C8F6f3a877586C9B0D05E523062837ABD4dF5",
12735
+ "UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
12736
12736
  "UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
12737
- "UCDController": "0xa853609Bf8064bfbA1Cb8C01D102d0Efcc5ad10E",
12738
- "PriceFeedConsumer": "0xB0eB31Df2b7E2b95304115b6f0427d622113c641",
12739
- "BTCProofValidator": "0x2b6bCddd0788300db6622cE5050848068eC6faC5",
12740
- "UCDMintingRewards": "0xeD271B85Ecc1239983F92D5E05a5080bcb5F00a4",
12741
- "PositionManagerCoreModule": "0xD265B579Cb707b344292a2130ee90392735d8Ec1",
12742
- "TermManagerModule": "0xa445be9b6AF389e15cd0dF5D31E5A9C3DD62d95D",
12743
- "LoanOperationsManagerModule": "0x2110694692930a70d6698c7B4958f287ec79AAeA",
12744
- "CollateralManagerModule": "0xa7EAC2c6B26a57eBd0b9A9A4845F29913067963B",
12745
- "LiquidationManagerModule": "0x81711D8075A6e1496607DbfBF83E4f0e68f41840",
12746
- "CircuitBreakerModule": "0xa17c1653d33d4F4cd6f903c1142f55D604c8F102",
12747
- "CommunityManagerModule": "0xa90027E1010f41B91f27C1335E71507E1e423118",
12748
- "AdminModule": "0x73edc6fE737a7381d01fe35a15287460aB4d8992",
12749
- "PositionManagerViews": "0x0e297165d8C48fB20cCbA92B97B99bfE5FF0b227",
12750
- "PositionManager": "0x817b43308427fb46627e21942F639888A83D6196",
12751
- "OperationAuthorizationRegistry": "0xd4a68AC3d7Fb441658fEA6f916c66A2481f5e413",
12752
- "PKPValidation": "0x987bcEA333b0F2ab0Ea7d1eF8811845b581472E0"
12737
+ "UCDController": "0x8956368203475DeECA21bc79F5FDeA249937E20C",
12738
+ "PriceFeedConsumer": "0xbAB704d9d2F701aE3ec0B39ded1F1a27ba3544EE",
12739
+ "BTCProofValidator": "0x760DD5b1524d1C907e03A99A02C6b9634c569aE8",
12740
+ "UCDMintingRewards": "0x92ea837DCF6e757cA19D524f02b49A4650FAaB46",
12741
+ "PositionManagerCoreModule": "0xAA2893395159550730C02075D5a7b5F905464c7b",
12742
+ "TermManagerModule": "0x89a2ffBE000e0dcfd4D5893592fC8d7D07E43618",
12743
+ "LoanOperationsManagerModule": "0x0644ae669DaA9aB7561d59d902a5F0811230a83c",
12744
+ "CollateralManagerModule": "0xc11E2c128F2Be64AD1D020eA188973CFBeADAcb9",
12745
+ "LiquidationManagerModule": "0xa8608AB8b6F16947F5379f1971e0851A436a856A",
12746
+ "CircuitBreakerModule": "0xB522e59e750C4B84b3E7Ed5E9176A4B9c89704Ec",
12747
+ "CommunityManagerModule": "0x6C022640Afe32B853FC908066da7a160B71FE864",
12748
+ "AdminModule": "0xB570bf6a5ae0589c0E67eBdc09e17e2eFba90f0b",
12749
+ "PositionManagerViews": "0xdc7e1Db596B3A787386d144aCE485F02BBb43bA7",
12750
+ "PositionManager": "0x2d654736b8fcc385BD27Bf5b936A7c92Ea951Cc8",
12751
+ "OperationAuthorizationRegistry": "0xE55b4d77b235155cF534A28e897Ddc028395B8F9",
12752
+ "PKPValidation": "0x0d448F827b1803865F6D4135Fb5FBcD285D34Aac"
12753
12753
  };
12754
12754
  LOCALHOST_DEPLOYMENT = {
12755
12755
  "network": "localhost",
@@ -29068,42 +29068,70 @@ function validateSDKConfig(config) {
29068
29068
  }
29069
29069
 
29070
29070
  // src/utils/quantum-timing.ts
29071
- async function calculateValidQuantumTimestamp() {
29072
- console.log(" \u{1F3AF} Finding OPTIMAL quantum moment for signature...");
29073
- let now2 = Math.floor(Date.now() / 1e3);
29074
- let timeInQuantum = now2 % 100;
29075
- if (timeInQuantum !== 16) {
29076
- let waitSeconds;
29077
- if (timeInQuantum < 16) {
29078
- waitSeconds = 16 - timeInQuantum;
29079
- console.log(
29080
- ` \u23F3 Current: second ${timeInQuantum} - waiting ${waitSeconds}s for optimal moment (second 16)...`
29081
- );
29082
- } else {
29083
- waitSeconds = 100 - timeInQuantum + 16;
29084
- console.log(
29085
- ` \u23F3 Current: second ${timeInQuantum} - waiting ${waitSeconds}s for next optimal moment (second 16)...`
29086
- );
29087
- }
29088
- await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1e3));
29089
- now2 = Math.floor(Date.now() / 1e3);
29090
- timeInQuantum = now2 % 100;
29091
- console.log(` \u2705 Optimal moment reached: second ${timeInQuantum}`);
29071
+ function calculateNextQuantumTimestamp() {
29072
+ const now2 = Math.floor(Date.now() / 1e3);
29073
+ const timeInQuantum = now2 % 100;
29074
+ const currentQuantum = Math.floor(now2 / 100) * 100;
29075
+ let targetTimestamp;
29076
+ if (timeInQuantum >= 16 && timeInQuantum <= 30) {
29077
+ targetTimestamp = now2;
29078
+ console.log(
29079
+ "[Quantum Timing] Already at optimal moment in current quantum"
29080
+ );
29081
+ } else if (timeInQuantum < 16 && timeInQuantum >= 8) {
29082
+ targetTimestamp = currentQuantum + 16;
29083
+ console.log("[Quantum Timing] Targeting second 16 of CURRENT quantum");
29092
29084
  } else {
29093
- console.log(` \u2705 Already at optimal moment: second ${timeInQuantum}`);
29094
- }
29095
- const timestamp = Math.floor(Date.now() / 1e3);
29096
- const quantumWindow = Math.floor(timestamp / 100) * 100;
29097
- const timeInQuantumNow = timestamp % 100;
29098
- console.log(" \u{1F4DD} Timestamp Details:");
29099
- console.log(" Timestamp:", timestamp);
29100
- console.log(" Quantum window:", quantumWindow);
29085
+ const nextQuantum = currentQuantum + 100;
29086
+ targetTimestamp = nextQuantum + 16;
29087
+ console.log("[Quantum Timing] Targeting second 16 of NEXT quantum");
29088
+ }
29089
+ console.log("[Quantum Timing] Calculated quantum timing:");
29090
+ console.log(" Current time:", now2);
29091
+ console.log(" Time in quantum:", timeInQuantum);
29092
+ console.log(" Target timestamp:", targetTimestamp);
29093
+ console.log(" Seconds until target:", targetTimestamp - now2);
29094
+ return targetTimestamp;
29095
+ }
29096
+ async function waitUntilTimestamp(targetTimestamp) {
29097
+ const now2 = Math.floor(Date.now() / 1e3);
29098
+ const waitSeconds = targetTimestamp - now2;
29099
+ if (waitSeconds <= 0) {
29100
+ console.log("[Quantum Timing] Target timestamp already reached");
29101
+ return;
29102
+ }
29101
29103
  console.log(
29102
- " Time in quantum:",
29103
- timeInQuantumNow,
29104
- "seconds (OPTIMAL: 16)"
29104
+ `[Quantum Timing] Waiting ${waitSeconds}s until timestamp ${targetTimestamp}...`
29105
29105
  );
29106
- return timestamp;
29106
+ await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1e3));
29107
+ console.log("[Quantum Timing] Target timestamp reached");
29108
+ }
29109
+ function validateQuantumTiming(signedTimestamp, bufferSeconds = 30) {
29110
+ const now2 = Math.floor(Date.now() / 1e3);
29111
+ const signedQuantum = Math.floor(signedTimestamp / 100) * 100;
29112
+ const currentQuantum = Math.floor(now2 / 100) * 100;
29113
+ if (currentQuantum !== signedQuantum) {
29114
+ throw new Error(
29115
+ `Quantum window expired. User took too long to sign. Signed quantum: ${signedQuantum}, Current quantum: ${currentQuantum}`
29116
+ );
29117
+ }
29118
+ const timeInQuantum = now2 % 100;
29119
+ const isInDeadZone = timeInQuantum < 8 || timeInQuantum >= 92;
29120
+ if (isInDeadZone) {
29121
+ throw new Error(
29122
+ `Current time (${timeInQuantum}s in quantum) is in dead zone. Operation cannot proceed safely.`
29123
+ );
29124
+ }
29125
+ const secondsRemaining = 92 - timeInQuantum;
29126
+ if (secondsRemaining < bufferSeconds) {
29127
+ throw new Error(
29128
+ `Insufficient time remaining in quantum. Required: ${bufferSeconds}s, Available: ${secondsRemaining}s`
29129
+ );
29130
+ }
29131
+ console.log("[Quantum Timing] Validation passed:");
29132
+ console.log(" Time in quantum:", timeInQuantum);
29133
+ console.log(" Seconds remaining:", secondsRemaining);
29134
+ console.log(" Required buffer:", bufferSeconds);
29107
29135
  }
29108
29136
 
29109
29137
  // src/utils/mint-authorization.utils.ts
@@ -29117,7 +29145,7 @@ var PKP_NFT_ADDRESSES = {
29117
29145
  // Yellowstone/Datil (PKP native network) - same as Datil testnet
29118
29146
  };
29119
29147
  async function generateMintAuthorization(positionId, amount, chainId, mode, signer) {
29120
- const timestamp = await calculateValidQuantumTimestamp();
29148
+ const timestamp = calculateNextQuantumTimestamp();
29121
29149
  const action = "mint-ucd";
29122
29150
  const actionHash = ethers_exports.utils.keccak256(ethers_exports.utils.toUtf8Bytes(action));
29123
29151
  const types = [
@@ -29151,7 +29179,8 @@ async function generateMintAuthorization(positionId, amount, chainId, mode, sign
29151
29179
  console.log(" Action Hash:", actionHash);
29152
29180
  console.log(" Message Hash (solidityKeccak256):", messageHash);
29153
29181
  console.log(" Message Hash Bytes Length:", messageHashBytes.length);
29154
- console.log(" Signer Address:", signer.address);
29182
+ const signerAddress = await signer.getAddress();
29183
+ console.log(" Signer Address:", signerAddress);
29155
29184
  const signature2 = await signer.signMessage(messageHashBytes);
29156
29185
  return {
29157
29186
  positionId,
@@ -29195,7 +29224,7 @@ async function getPKPPublicKeyFromTokenId(pkpTokenId, provider) {
29195
29224
  return pubkeyBytes.startsWith("0x") ? pubkeyBytes : `0x${pubkeyBytes}`;
29196
29225
  }
29197
29226
  async function generateWithdrawAuthorization(positionId, amount, chainId, mode, signer, destinationAddress) {
29198
- const timestamp = await calculateValidQuantumTimestamp();
29227
+ const timestamp = calculateNextQuantumTimestamp();
29199
29228
  const action = "withdraw-btc";
29200
29229
  const actionHash = ethers_exports.utils.keccak256(ethers_exports.utils.toUtf8Bytes(action));
29201
29230
  const types = [
@@ -29231,7 +29260,8 @@ async function generateWithdrawAuthorization(positionId, amount, chainId, mode,
29231
29260
  console.log(" Action:", action);
29232
29261
  console.log(" Action Hash:", actionHash);
29233
29262
  console.log(" Message Hash (solidityKeccak256):", messageHash);
29234
- console.log(" Signer Address:", signer.address);
29263
+ const signerAddress = await signer.getAddress();
29264
+ console.log(" Signer Address:", signerAddress);
29235
29265
  const signature2 = await signer.signMessage(messageHashBytes);
29236
29266
  console.log("[SDK Withdrawal Authorization] Signature generated:");
29237
29267
  console.log(" Signature:", signature2);
@@ -29240,7 +29270,7 @@ async function generateWithdrawAuthorization(positionId, amount, chainId, mode,
29240
29270
  console.log(" Recovered Address (for verification):", recovered);
29241
29271
  console.log(
29242
29272
  " Signer Matches Recovered:",
29243
- recovered.toLowerCase() === signer.address.toLowerCase() ? "\u2705 YES" : "\u274C NO"
29273
+ recovered.toLowerCase() === signerAddress.toLowerCase() ? "\u2705 YES" : "\u274C NO"
29244
29274
  );
29245
29275
  return {
29246
29276
  positionId,
@@ -47440,6 +47470,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
47440
47470
  log.info(` Mode: ${auth.mode}`);
47441
47471
  log.info(` Signature: ${auth.signature.substring(0, 20)}...`);
47442
47472
  }
47473
+ await waitUntilTimestamp(auth.timestamp);
47474
+ validateQuantumTiming(auth.timestamp, 30);
47443
47475
  litActionResult = await this.litOps.requestMintAuthorization({
47444
47476
  authMessage: {
47445
47477
  ...auth,
@@ -48211,6 +48243,8 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
48211
48243
  log.info(` Mode: ${auth.mode}`);
48212
48244
  log.info(` Signature: ${auth.signature.substring(0, 20)}...`);
48213
48245
  }
48246
+ await waitUntilTimestamp(auth.timestamp);
48247
+ validateQuantumTiming(auth.timestamp, 30);
48214
48248
  litActionResult = await this.litOps.requestWithdrawalAuthorization({
48215
48249
  authMessage: {
48216
48250
  ...auth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.128",
3
+ "version": "0.0.130",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.cjs",
6
6
  "types": "dist/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "license": "MIT",
51
51
  "dependencies": {
52
52
  "@gvnrdao/dh-lit-actions": "0.0.82",
53
- "@gvnrdao/dh-lit-ops": "0.0.75",
53
+ "@gvnrdao/dh-lit-ops": "0.0.76",
54
54
  "@lit-protocol/lit-node-client": "^7.3.1",
55
55
  "@noble/hashes": "^1.5.0",
56
56
  "axios": "^1.5.0",