@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/browser/dist/browser.js +2 -2
- package/dist/index.js +107 -73
- package/dist/index.mjs +107 -73
- package/package.json +2 -2
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-
|
|
12705
|
+
"timestamp": "2025-12-08T20:44:11.397Z",
|
|
12706
12706
|
"deployer": "",
|
|
12707
12707
|
"contracts": {
|
|
12708
|
-
"UpgradeValidator": "
|
|
12708
|
+
"UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
|
|
12709
12709
|
"UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
|
|
12710
|
-
"UCDController": "
|
|
12711
|
-
"PriceFeedConsumer": "
|
|
12712
|
-
"BTCProofValidator": "
|
|
12713
|
-
"UCDMintingRewards": "
|
|
12714
|
-
"PositionManagerCoreModule": "
|
|
12715
|
-
"TermManagerModule": "
|
|
12716
|
-
"LoanOperationsManagerModule": "
|
|
12717
|
-
"CollateralManagerModule": "
|
|
12718
|
-
"LiquidationManagerModule": "
|
|
12719
|
-
"CircuitBreakerModule": "
|
|
12720
|
-
"CommunityManagerModule": "
|
|
12721
|
-
"AdminModule": "
|
|
12722
|
-
"PositionManagerViews": "
|
|
12723
|
-
"PositionManager": "
|
|
12724
|
-
"OperationAuthorizationRegistry": "
|
|
12725
|
-
"PKPValidation": "
|
|
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": "
|
|
12729
|
+
"UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
|
|
12730
12730
|
"UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
|
|
12731
|
-
"UCDController": "
|
|
12732
|
-
"PriceFeedConsumer": "
|
|
12733
|
-
"BTCProofValidator": "
|
|
12734
|
-
"UCDMintingRewards": "
|
|
12735
|
-
"PositionManagerCoreModule": "
|
|
12736
|
-
"TermManagerModule": "
|
|
12737
|
-
"LoanOperationsManagerModule": "
|
|
12738
|
-
"CollateralManagerModule": "
|
|
12739
|
-
"LiquidationManagerModule": "
|
|
12740
|
-
"CircuitBreakerModule": "
|
|
12741
|
-
"CommunityManagerModule": "
|
|
12742
|
-
"AdminModule": "
|
|
12743
|
-
"PositionManagerViews": "
|
|
12744
|
-
"PositionManager": "
|
|
12745
|
-
"OperationAuthorizationRegistry": "
|
|
12746
|
-
"PKPValidation": "
|
|
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
|
-
|
|
29167
|
-
|
|
29168
|
-
|
|
29169
|
-
|
|
29170
|
-
|
|
29171
|
-
|
|
29172
|
-
|
|
29173
|
-
|
|
29174
|
-
|
|
29175
|
-
|
|
29176
|
-
|
|
29177
|
-
|
|
29178
|
-
|
|
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
|
-
|
|
29189
|
-
|
|
29190
|
-
|
|
29191
|
-
|
|
29192
|
-
|
|
29193
|
-
console.log("
|
|
29194
|
-
console.log("
|
|
29195
|
-
console.log("
|
|
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
|
-
|
|
29198
|
-
timeInQuantumNow,
|
|
29199
|
-
"seconds (OPTIMAL: 16)"
|
|
29199
|
+
`[Quantum Timing] Waiting ${waitSeconds}s until timestamp ${targetTimestamp}...`
|
|
29200
29200
|
);
|
|
29201
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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() ===
|
|
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-
|
|
12711
|
+
"timestamp": "2025-12-08T20:44:11.397Z",
|
|
12712
12712
|
"deployer": "",
|
|
12713
12713
|
"contracts": {
|
|
12714
|
-
"UpgradeValidator": "
|
|
12714
|
+
"UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
|
|
12715
12715
|
"UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
|
|
12716
|
-
"UCDController": "
|
|
12717
|
-
"PriceFeedConsumer": "
|
|
12718
|
-
"BTCProofValidator": "
|
|
12719
|
-
"UCDMintingRewards": "
|
|
12720
|
-
"PositionManagerCoreModule": "
|
|
12721
|
-
"TermManagerModule": "
|
|
12722
|
-
"LoanOperationsManagerModule": "
|
|
12723
|
-
"CollateralManagerModule": "
|
|
12724
|
-
"LiquidationManagerModule": "
|
|
12725
|
-
"CircuitBreakerModule": "
|
|
12726
|
-
"CommunityManagerModule": "
|
|
12727
|
-
"AdminModule": "
|
|
12728
|
-
"PositionManagerViews": "
|
|
12729
|
-
"PositionManager": "
|
|
12730
|
-
"OperationAuthorizationRegistry": "
|
|
12731
|
-
"PKPValidation": "
|
|
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": "
|
|
12735
|
+
"UpgradeValidator": "0x865843ec94a6444Ad6f6b8Ca389c03D4a2D96e67",
|
|
12736
12736
|
"UCDToken": "0x86060fa5b3e01e003b8afd9c1295f1f444a7dc60",
|
|
12737
|
-
"UCDController": "
|
|
12738
|
-
"PriceFeedConsumer": "
|
|
12739
|
-
"BTCProofValidator": "
|
|
12740
|
-
"UCDMintingRewards": "
|
|
12741
|
-
"PositionManagerCoreModule": "
|
|
12742
|
-
"TermManagerModule": "
|
|
12743
|
-
"LoanOperationsManagerModule": "
|
|
12744
|
-
"CollateralManagerModule": "
|
|
12745
|
-
"LiquidationManagerModule": "
|
|
12746
|
-
"CircuitBreakerModule": "
|
|
12747
|
-
"CommunityManagerModule": "
|
|
12748
|
-
"AdminModule": "
|
|
12749
|
-
"PositionManagerViews": "
|
|
12750
|
-
"PositionManager": "
|
|
12751
|
-
"OperationAuthorizationRegistry": "
|
|
12752
|
-
"PKPValidation": "
|
|
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
|
-
|
|
29072
|
-
|
|
29073
|
-
|
|
29074
|
-
|
|
29075
|
-
|
|
29076
|
-
|
|
29077
|
-
|
|
29078
|
-
|
|
29079
|
-
|
|
29080
|
-
|
|
29081
|
-
|
|
29082
|
-
|
|
29083
|
-
|
|
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
|
-
|
|
29094
|
-
|
|
29095
|
-
|
|
29096
|
-
|
|
29097
|
-
|
|
29098
|
-
console.log("
|
|
29099
|
-
console.log("
|
|
29100
|
-
console.log("
|
|
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
|
-
|
|
29103
|
-
timeInQuantumNow,
|
|
29104
|
-
"seconds (OPTIMAL: 16)"
|
|
29104
|
+
`[Quantum Timing] Waiting ${waitSeconds}s until timestamp ${targetTimestamp}...`
|
|
29105
29105
|
);
|
|
29106
|
-
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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() ===
|
|
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.
|
|
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.
|
|
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",
|