@gvnrdao/dh-sdk 0.0.305 → 0.0.306
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 +1 -1
- package/dist/deployments.js +32 -30
- package/dist/deployments.mjs +32 -30
- package/dist/index.js +287 -36
- package/dist/index.mjs +288 -37
- package/dist/interfaces/chunks/config.i.d.ts +12 -0
- package/dist/modules/diamond-hands-sdk.d.ts +19 -0
- package/dist/utils/lane-guard.utils.d.ts +36 -0
- package/dist/utils/quantum-submission.utils.d.ts +8 -0
- package/package.json +4 -4
package/dist/deployments.js
CHANGED
|
@@ -546,45 +546,47 @@ var MAINNET_CONTRACTS = {
|
|
|
546
546
|
};
|
|
547
547
|
var LOCALHOST_DEPLOYMENT = {
|
|
548
548
|
network: "localhost",
|
|
549
|
-
chainId:
|
|
550
|
-
timestamp: "2026-
|
|
549
|
+
chainId: 1337,
|
|
550
|
+
timestamp: "2026-07-20T19:45:58.514Z",
|
|
551
551
|
deployer: "",
|
|
552
552
|
contracts: {
|
|
553
|
-
MessageHashBuilder: "
|
|
554
|
-
|
|
553
|
+
MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
|
554
|
+
LITActionValidator: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
555
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
555
556
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
556
557
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
557
|
-
PositionManagerCoreModule: "
|
|
558
|
-
TermManagerModule: "
|
|
559
|
-
LoanOperationsManagerModule: "
|
|
560
|
-
BTCSpendAuthorizer: "
|
|
561
|
-
CollateralManagerModule: "
|
|
562
|
-
LiquidationManagerModule: "
|
|
563
|
-
CircuitBreakerModule: "
|
|
564
|
-
AdminModule: "
|
|
565
|
-
PositionManagerViews: "
|
|
566
|
-
PositionManager: "
|
|
567
|
-
OperationAuthorizationRegistry: "
|
|
568
|
-
PKPValidation: "
|
|
558
|
+
PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
559
|
+
TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
560
|
+
LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
561
|
+
BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
562
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
563
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
564
|
+
CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
565
|
+
AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
566
|
+
PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
567
|
+
PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
|
|
568
|
+
OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
|
|
569
|
+
PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
|
|
569
570
|
}
|
|
570
571
|
};
|
|
571
572
|
var LOCALHOST_CONTRACTS = {
|
|
572
|
-
MessageHashBuilder: "
|
|
573
|
-
|
|
573
|
+
MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
|
574
|
+
LITActionValidator: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
575
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
574
576
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
575
577
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
576
|
-
PositionManagerCoreModule: "
|
|
577
|
-
TermManagerModule: "
|
|
578
|
-
LoanOperationsManagerModule: "
|
|
579
|
-
BTCSpendAuthorizer: "
|
|
580
|
-
CollateralManagerModule: "
|
|
581
|
-
LiquidationManagerModule: "
|
|
582
|
-
CircuitBreakerModule: "
|
|
583
|
-
AdminModule: "
|
|
584
|
-
PositionManagerViews: "
|
|
585
|
-
PositionManager: "
|
|
586
|
-
OperationAuthorizationRegistry: "
|
|
587
|
-
PKPValidation: "
|
|
578
|
+
PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
579
|
+
TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
580
|
+
LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
581
|
+
BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
582
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
583
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
584
|
+
CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
585
|
+
AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
586
|
+
PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
587
|
+
PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
|
|
588
|
+
OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
|
|
589
|
+
PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
|
|
588
590
|
};
|
|
589
591
|
var ALL_DEPLOYMENTS = {
|
|
590
592
|
sepolia: SEPOLIA_DEPLOYMENT,
|
package/dist/deployments.mjs
CHANGED
|
@@ -513,45 +513,47 @@ var MAINNET_CONTRACTS = {
|
|
|
513
513
|
};
|
|
514
514
|
var LOCALHOST_DEPLOYMENT = {
|
|
515
515
|
network: "localhost",
|
|
516
|
-
chainId:
|
|
517
|
-
timestamp: "2026-
|
|
516
|
+
chainId: 1337,
|
|
517
|
+
timestamp: "2026-07-20T19:45:58.514Z",
|
|
518
518
|
deployer: "",
|
|
519
519
|
contracts: {
|
|
520
|
-
MessageHashBuilder: "
|
|
521
|
-
|
|
520
|
+
MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
|
521
|
+
LITActionValidator: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
522
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
522
523
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
523
524
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
524
|
-
PositionManagerCoreModule: "
|
|
525
|
-
TermManagerModule: "
|
|
526
|
-
LoanOperationsManagerModule: "
|
|
527
|
-
BTCSpendAuthorizer: "
|
|
528
|
-
CollateralManagerModule: "
|
|
529
|
-
LiquidationManagerModule: "
|
|
530
|
-
CircuitBreakerModule: "
|
|
531
|
-
AdminModule: "
|
|
532
|
-
PositionManagerViews: "
|
|
533
|
-
PositionManager: "
|
|
534
|
-
OperationAuthorizationRegistry: "
|
|
535
|
-
PKPValidation: "
|
|
525
|
+
PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
526
|
+
TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
527
|
+
LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
528
|
+
BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
529
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
530
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
531
|
+
CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
532
|
+
AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
533
|
+
PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
534
|
+
PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
|
|
535
|
+
OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
|
|
536
|
+
PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
|
|
536
537
|
}
|
|
537
538
|
};
|
|
538
539
|
var LOCALHOST_CONTRACTS = {
|
|
539
|
-
MessageHashBuilder: "
|
|
540
|
-
|
|
540
|
+
MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
|
541
|
+
LITActionValidator: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
542
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
541
543
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
542
544
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
543
|
-
PositionManagerCoreModule: "
|
|
544
|
-
TermManagerModule: "
|
|
545
|
-
LoanOperationsManagerModule: "
|
|
546
|
-
BTCSpendAuthorizer: "
|
|
547
|
-
CollateralManagerModule: "
|
|
548
|
-
LiquidationManagerModule: "
|
|
549
|
-
CircuitBreakerModule: "
|
|
550
|
-
AdminModule: "
|
|
551
|
-
PositionManagerViews: "
|
|
552
|
-
PositionManager: "
|
|
553
|
-
OperationAuthorizationRegistry: "
|
|
554
|
-
PKPValidation: "
|
|
545
|
+
PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
546
|
+
TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
547
|
+
LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
548
|
+
BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
549
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
550
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
551
|
+
CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
552
|
+
AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
553
|
+
PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
554
|
+
PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
|
|
555
|
+
OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
|
|
556
|
+
PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
|
|
555
557
|
};
|
|
556
558
|
var ALL_DEPLOYMENTS = {
|
|
557
559
|
sepolia: SEPOLIA_DEPLOYMENT,
|
package/dist/index.js
CHANGED
|
@@ -571,45 +571,47 @@ var init_deployment_addresses = __esm({
|
|
|
571
571
|
};
|
|
572
572
|
LOCALHOST_DEPLOYMENT = {
|
|
573
573
|
network: "localhost",
|
|
574
|
-
chainId:
|
|
575
|
-
timestamp: "2026-
|
|
574
|
+
chainId: 1337,
|
|
575
|
+
timestamp: "2026-07-20T19:45:58.514Z",
|
|
576
576
|
deployer: "",
|
|
577
577
|
contracts: {
|
|
578
|
-
MessageHashBuilder: "
|
|
579
|
-
|
|
578
|
+
MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
|
579
|
+
LITActionValidator: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
580
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
580
581
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
581
582
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
582
|
-
PositionManagerCoreModule: "
|
|
583
|
-
TermManagerModule: "
|
|
584
|
-
LoanOperationsManagerModule: "
|
|
585
|
-
BTCSpendAuthorizer: "
|
|
586
|
-
CollateralManagerModule: "
|
|
587
|
-
LiquidationManagerModule: "
|
|
588
|
-
CircuitBreakerModule: "
|
|
589
|
-
AdminModule: "
|
|
590
|
-
PositionManagerViews: "
|
|
591
|
-
PositionManager: "
|
|
592
|
-
OperationAuthorizationRegistry: "
|
|
593
|
-
PKPValidation: "
|
|
583
|
+
PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
584
|
+
TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
585
|
+
LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
586
|
+
BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
587
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
588
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
589
|
+
CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
590
|
+
AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
591
|
+
PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
592
|
+
PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
|
|
593
|
+
OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
|
|
594
|
+
PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
|
|
594
595
|
}
|
|
595
596
|
};
|
|
596
597
|
LOCALHOST_CONTRACTS = {
|
|
597
|
-
MessageHashBuilder: "
|
|
598
|
-
|
|
598
|
+
MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
|
|
599
|
+
LITActionValidator: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
|
|
600
|
+
UpgradeValidator: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
|
|
599
601
|
UCDToken: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
600
602
|
UCDController: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
|
|
601
|
-
PositionManagerCoreModule: "
|
|
602
|
-
TermManagerModule: "
|
|
603
|
-
LoanOperationsManagerModule: "
|
|
604
|
-
BTCSpendAuthorizer: "
|
|
605
|
-
CollateralManagerModule: "
|
|
606
|
-
LiquidationManagerModule: "
|
|
607
|
-
CircuitBreakerModule: "
|
|
608
|
-
AdminModule: "
|
|
609
|
-
PositionManagerViews: "
|
|
610
|
-
PositionManager: "
|
|
611
|
-
OperationAuthorizationRegistry: "
|
|
612
|
-
PKPValidation: "
|
|
603
|
+
PositionManagerCoreModule: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
|
|
604
|
+
TermManagerModule: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
|
|
605
|
+
LoanOperationsManagerModule: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
|
|
606
|
+
BTCSpendAuthorizer: "0xc6e7DF5E7b4f2A278906862b61205850344D4e7d",
|
|
607
|
+
CollateralManagerModule: "0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44",
|
|
608
|
+
LiquidationManagerModule: "0x4A679253410272dd5232B3Ff7cF5dbB88f295319",
|
|
609
|
+
CircuitBreakerModule: "0x0B306BF915C4d645ff596e518fAf3F9669b97016",
|
|
610
|
+
AdminModule: "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
|
|
611
|
+
PositionManagerViews: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
|
|
612
|
+
PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
|
|
613
|
+
OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
|
|
614
|
+
PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
|
|
613
615
|
};
|
|
614
616
|
ALL_DEPLOYMENTS = {
|
|
615
617
|
sepolia: SEPOLIA_DEPLOYMENT,
|
|
@@ -5528,7 +5530,12 @@ var init_network_configs = __esm({
|
|
|
5528
5530
|
NETWORK_CONFIGS = {
|
|
5529
5531
|
1: getMainnetConfig(),
|
|
5530
5532
|
11155111: getSepoliaConfig(),
|
|
5531
|
-
1337: getLocalhostConfig()
|
|
5533
|
+
1337: getLocalhostConfig(),
|
|
5534
|
+
// In-process hardhat default chainId — same localhost deployment as 1337
|
|
5535
|
+
// (`npx hardhat node`), so consumers on either local chain resolve config.
|
|
5536
|
+
// chainId overridden so the resolved config self-describes the chain that
|
|
5537
|
+
// was actually looked up (downstream bind/log/validate reads it).
|
|
5538
|
+
31337: { ...getLocalhostConfig(), chainId: 31337 }
|
|
5532
5539
|
};
|
|
5533
5540
|
DEFAULT_NETWORK_CONFIG = {
|
|
5534
5541
|
/** Fallback when chain is unknown — production Chipotle. */
|
|
@@ -6950,12 +6957,20 @@ async function assertSafeQuantumSubmission(opts) {
|
|
|
6950
6957
|
...opts.sleep ? { sleep: opts.sleep } : {}
|
|
6951
6958
|
};
|
|
6952
6959
|
await awaitSafeSubmissionWindow(quantumTimestamp, gateOpts);
|
|
6960
|
+
const SAME_BLOCK_INTERACTION_SELECTOR = "0x3b53d1db";
|
|
6961
|
+
const laneGuardActive = opts.laneGuardActive === true;
|
|
6953
6962
|
for (let sim = 1; ; sim++) {
|
|
6954
6963
|
try {
|
|
6955
6964
|
await provider.call({ to, from, data });
|
|
6956
6965
|
break;
|
|
6957
6966
|
} catch (simError) {
|
|
6958
6967
|
const decoded = decodeQuantumRevert(simError);
|
|
6968
|
+
if (laneGuardActive && decoded.selector === SAME_BLOCK_INTERACTION_SELECTOR) {
|
|
6969
|
+
onDebug(
|
|
6970
|
+
"\u21AA\uFE0F [lane-only] Simulated SameBlockInteraction is a stale-latest-block artifact (the simulated block contains this flow's own previous tx) \u2014 proceeding to broadcast; the on-chain guard stays authoritative"
|
|
6971
|
+
);
|
|
6972
|
+
break;
|
|
6973
|
+
}
|
|
6959
6974
|
if (decoded.selector === DEAD_ZONE_VIOLATION_SELECTOR && sim <= maxResimulations) {
|
|
6960
6975
|
const sigQuantum = Math.floor(quantumTimestamp / QUANTUM_WINDOW_SECONDS) * QUANTUM_WINDOW_SECONDS;
|
|
6961
6976
|
const realCurrentQuantum = Math.floor(now() / QUANTUM_WINDOW_SECONDS) * QUANTUM_WINDOW_SECONDS;
|
|
@@ -6991,6 +7006,28 @@ async function assertSafeQuantumSubmission(opts) {
|
|
|
6991
7006
|
await awaitSafeSubmissionWindow(quantumTimestamp, gateOpts);
|
|
6992
7007
|
}
|
|
6993
7008
|
|
|
7009
|
+
// src/utils/lane-guard.utils.ts
|
|
7010
|
+
var HARDHAT_CHAIN_IDS = /* @__PURE__ */ new Set([1337, 31337]);
|
|
7011
|
+
function laneGuardEnvEnabled() {
|
|
7012
|
+
return typeof process !== "undefined" && process.env?.LIT_LANE_GUARD === "1";
|
|
7013
|
+
}
|
|
7014
|
+
async function isLaneGuardActiveOnProvider(provider) {
|
|
7015
|
+
if (!laneGuardEnvEnabled())
|
|
7016
|
+
return false;
|
|
7017
|
+
if (!provider || typeof provider.send !== "function")
|
|
7018
|
+
return false;
|
|
7019
|
+
try {
|
|
7020
|
+
const [chainIdHex, clientVersion] = await Promise.all([
|
|
7021
|
+
provider.send("eth_chainId", []),
|
|
7022
|
+
provider.send("web3_clientVersion", [])
|
|
7023
|
+
]);
|
|
7024
|
+
const chainId = Number(chainIdHex);
|
|
7025
|
+
return HARDHAT_CHAIN_IDS.has(chainId) && typeof clientVersion === "string" && clientVersion.toLowerCase().includes("hardhat");
|
|
7026
|
+
} catch {
|
|
7027
|
+
return false;
|
|
7028
|
+
}
|
|
7029
|
+
}
|
|
7030
|
+
|
|
6994
7031
|
// src/utils/btc-withdrawal-message.ts
|
|
6995
7032
|
var import_ethers6 = require("ethers");
|
|
6996
7033
|
var QUANTUM_SECONDS = 60;
|
|
@@ -16333,6 +16370,10 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
16333
16370
|
this.litOps = new import_dh_lit_ops.LitOps({
|
|
16334
16371
|
mode: config.mode || "standalone",
|
|
16335
16372
|
network: config.litNetwork || DEFAULT_LIT_NETWORK,
|
|
16373
|
+
// Completes the module's chainId resolution chain (jsParams shapes →
|
|
16374
|
+
// config.chainId) — e.g. the lane validator-override chain binding
|
|
16375
|
+
// reads it when a jsParams shape lacks chainId.
|
|
16376
|
+
chainId: config.chainId,
|
|
16336
16377
|
signer: config.mode === "standalone" ? config.litOpsSigner : void 0,
|
|
16337
16378
|
serviceEndpoint: isServiceModeConfig(config) ? config.serviceEndpoint : void 0,
|
|
16338
16379
|
// Hand lit-ops a session-aware auth getter so every request it makes
|
|
@@ -17010,6 +17051,19 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
17010
17051
|
}
|
|
17011
17052
|
const MAX_FULL_RETRIES = 3;
|
|
17012
17053
|
for (let fullRetry = 1; fullRetry <= MAX_FULL_RETRIES; fullRetry++) {
|
|
17054
|
+
if (await this.isLocalLaneGuardActive()) {
|
|
17055
|
+
const phase = Math.floor(Date.now() / 1e3) % 60;
|
|
17056
|
+
if (phase > 30) {
|
|
17057
|
+
const waitMs = (60 - phase + 1) * 1e3;
|
|
17058
|
+
if (this.config.debug) {
|
|
17059
|
+
log.info(
|
|
17060
|
+
`\u23F3 Quantum-phase alignment (lane-only): ${phase}s into the quantum \u2014 waiting ${Math.ceil(waitMs / 1e3)}s for the next boundary before authorization`,
|
|
17061
|
+
{}
|
|
17062
|
+
);
|
|
17063
|
+
}
|
|
17064
|
+
await new Promise((resolve) => setTimeout(resolve, waitMs));
|
|
17065
|
+
}
|
|
17066
|
+
}
|
|
17013
17067
|
if (fullRetry > 1 && this.config.debug) {
|
|
17014
17068
|
log.info(
|
|
17015
17069
|
`\u{1F504} Full mint retry ${fullRetry}/${MAX_FULL_RETRIES} due to timestamp staleness...`,
|
|
@@ -17758,6 +17812,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
17758
17812
|
from: fromAddress,
|
|
17759
17813
|
data: mintCalldata,
|
|
17760
17814
|
quantumTimestamp: Number(validationResponse.timestamp),
|
|
17815
|
+
laneGuardActive: await this.isLocalLaneGuardActive(),
|
|
17761
17816
|
onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
|
|
17762
17817
|
});
|
|
17763
17818
|
} catch (simError) {
|
|
@@ -19053,6 +19108,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
19053
19108
|
from: await extendSigner.getAddress(),
|
|
19054
19109
|
data: extendCalldata,
|
|
19055
19110
|
quantumTimestamp: Number(quantumTimestamp),
|
|
19111
|
+
laneGuardActive: await this.isLocalLaneGuardActive(),
|
|
19056
19112
|
onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
|
|
19057
19113
|
});
|
|
19058
19114
|
} catch (simError) {
|
|
@@ -19953,6 +20009,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
19953
20009
|
from: paymentFrom,
|
|
19954
20010
|
data: paymentCalldata,
|
|
19955
20011
|
quantumTimestamp: Number(quantumTimestamp),
|
|
20012
|
+
laneGuardActive: await this.isLocalLaneGuardActive(),
|
|
19956
20013
|
onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
|
|
19957
20014
|
});
|
|
19958
20015
|
} catch (simError) {
|
|
@@ -20692,6 +20749,7 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
20692
20749
|
from: await withdrawSigner.getAddress(),
|
|
20693
20750
|
data: withdrawCalldata,
|
|
20694
20751
|
quantumTimestamp: Number(withdrawalParams.quantumTimestamp),
|
|
20752
|
+
laneGuardActive: await this.isLocalLaneGuardActive(),
|
|
20695
20753
|
onDebug: this.config.debug ? (msg) => log.info(msg, {}) : void 0
|
|
20696
20754
|
});
|
|
20697
20755
|
tx = await sendEip1559Transaction({
|
|
@@ -20846,15 +20904,180 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
20846
20904
|
* @param request - Execution request with positionId, utxoIdentifier, and networkFee
|
|
20847
20905
|
* @returns Execution result with Bitcoin txid
|
|
20848
20906
|
*/
|
|
20849
|
-
|
|
20850
|
-
|
|
20851
|
-
|
|
20907
|
+
/**
|
|
20908
|
+
* STANDALONE Phase 2: sign + broadcast the withdrawal Bitcoin transaction
|
|
20909
|
+
* in-process — the same orchestration lit-ops-server performs, composed
|
|
20910
|
+
* from the same primitives (`litOps.signBTCTransaction`, which has always
|
|
20911
|
+
* had a standalone path, and `broadcastSignedBitcoinTransaction`).
|
|
20912
|
+
* Both modes must support withdrawal execution (Master mandate 2026-07-21).
|
|
20913
|
+
*
|
|
20914
|
+
* The service path's post-broadcast CRIT-2 re-verification exists to catch
|
|
20915
|
+
* a LYING SERVER; here the broadcast happens locally from the signatures we
|
|
20916
|
+
* just obtained, so the esplora-returned txid is already first-hand.
|
|
20917
|
+
*/
|
|
20918
|
+
async executeBTCWithdrawalStandalonePhase2(request, envelope, txid, vout, chainId) {
|
|
20919
|
+
const positionDetails = await this.getPositionDetailsView(
|
|
20920
|
+
request.positionId
|
|
20921
|
+
);
|
|
20922
|
+
if (!positionDetails) {
|
|
20923
|
+
return { success: false, error: `Position ${request.positionId} not found` };
|
|
20924
|
+
}
|
|
20925
|
+
const pkpId = positionDetails.pkpId;
|
|
20926
|
+
const vaultAddress = positionDetails.vaultAddress;
|
|
20927
|
+
if (!pkpId || pkpId === import_ethers14.ZeroHash) {
|
|
20928
|
+
return { success: false, error: "Position has no PKP" };
|
|
20929
|
+
}
|
|
20930
|
+
if (!vaultAddress) {
|
|
20931
|
+
return { success: false, error: "Position has no vault address" };
|
|
20932
|
+
}
|
|
20933
|
+
const pkpCache = this.cacheManager.getCache("pkp-data", {
|
|
20934
|
+
maxSize: 500,
|
|
20935
|
+
ttlMs: 24 * 60 * 60 * 1e3
|
|
20936
|
+
});
|
|
20937
|
+
let publicKey = pkpCache.get(request.positionId)?.publicKey;
|
|
20938
|
+
if (!publicKey) {
|
|
20939
|
+
const derived = await this.litOps.deriveDiamondHandsLoanPkpPublicKey({
|
|
20940
|
+
pkpId
|
|
20941
|
+
});
|
|
20942
|
+
publicKey = derived.publicKey;
|
|
20943
|
+
}
|
|
20944
|
+
if (!publicKey) {
|
|
20945
|
+
return { success: false, error: "Failed to resolve PKP public key" };
|
|
20946
|
+
}
|
|
20947
|
+
const chipotlePkpAddress = (0, import_ethers14.computeAddress)(publicKey);
|
|
20948
|
+
const STANDALONE_CHAIN_NAMES = {
|
|
20949
|
+
1: "ethereum",
|
|
20950
|
+
11155111: "sepolia",
|
|
20951
|
+
1337: "hardhat",
|
|
20952
|
+
31337: "hardhat"
|
|
20953
|
+
};
|
|
20954
|
+
const chainName = STANDALONE_CHAIN_NAMES[chainId];
|
|
20955
|
+
if (!chainName) {
|
|
20852
20956
|
return {
|
|
20853
20957
|
success: false,
|
|
20854
|
-
error:
|
|
20958
|
+
error: `Unsupported chainId ${chainId} for standalone BTC withdrawal (supported: 1, 11155111, 1337, 31337)`
|
|
20855
20959
|
};
|
|
20856
20960
|
}
|
|
20857
|
-
|
|
20961
|
+
const bitcoinNetworkName = chainId === 1 ? "mainnet" : "regtest";
|
|
20962
|
+
const bitcoin = await import("bitcoinjs-lib");
|
|
20963
|
+
const bitcoinNetwork = chainId === 1 ? bitcoin.networks.bitcoin : chainId === 1337 || chainId === 31337 ? bitcoin.networks.regtest : bitcoin.networks.testnet;
|
|
20964
|
+
let scriptPubKeyBuffer;
|
|
20965
|
+
if (vaultAddress.startsWith("bcrt1q")) {
|
|
20966
|
+
const bech322 = await import("bech32");
|
|
20967
|
+
const decoded = bech322.bech32.decode(vaultAddress);
|
|
20968
|
+
const witnessProgram = Buffer.from(
|
|
20969
|
+
bech322.bech32.fromWords(decoded.words.slice(1))
|
|
20970
|
+
);
|
|
20971
|
+
if (witnessProgram.length !== 20) {
|
|
20972
|
+
return {
|
|
20973
|
+
success: false,
|
|
20974
|
+
error: `Vault address ${vaultAddress} decodes to a ${witnessProgram.length}-byte witness program \u2014 expected 20-byte P2WPKH`
|
|
20975
|
+
};
|
|
20976
|
+
}
|
|
20977
|
+
scriptPubKeyBuffer = Buffer.concat([
|
|
20978
|
+
Buffer.from([0, witnessProgram.length]),
|
|
20979
|
+
witnessProgram
|
|
20980
|
+
]);
|
|
20981
|
+
} else {
|
|
20982
|
+
scriptPubKeyBuffer = bitcoin.address.toOutputScript(
|
|
20983
|
+
vaultAddress,
|
|
20984
|
+
bitcoinNetwork
|
|
20985
|
+
);
|
|
20986
|
+
}
|
|
20987
|
+
const scriptPubKey = scriptPubKeyBuffer.toString("hex");
|
|
20988
|
+
const executionUtxos = (envelope.utxos && envelope.utxos.length ? envelope.utxos : [{ txid, vout, value: request.utxoSatoshis }]).map((u) => ({ ...u, scriptPubKey }));
|
|
20989
|
+
const dc = this.config.contractAddresses || {};
|
|
20990
|
+
const signerContractAddresses = {
|
|
20991
|
+
LoanOperationsManagerModule: dc.loanOperationsManager ?? "",
|
|
20992
|
+
PositionManager: dc.positionManager ?? "",
|
|
20993
|
+
BTCSpendAuthorizer: dc.btcSpendAuthorizer ?? "",
|
|
20994
|
+
PositionDelegateRegistry: dc.positionDelegateRegistry ?? "",
|
|
20995
|
+
OperationAuthorizationRegistry: dc.operationAuthorizationRegistry ?? "",
|
|
20996
|
+
...dc.bitcoinProviderRegistry ? { BitcoinProviderRegistry: dc.bitcoinProviderRegistry } : {}
|
|
20997
|
+
};
|
|
20998
|
+
const signResult = await this.litOps.signBTCTransaction({
|
|
20999
|
+
auth: {
|
|
21000
|
+
positionId: envelope.positionId,
|
|
21001
|
+
utxo: { txid, vout, value: request.utxoSatoshis, scriptPubKey },
|
|
21002
|
+
utxos: executionUtxos,
|
|
21003
|
+
networkFee: envelope.networkFee,
|
|
21004
|
+
targetAddress: envelope.targetAddress,
|
|
21005
|
+
targetAmount: envelope.targetAmount,
|
|
21006
|
+
timestamp: envelope.timestamp,
|
|
21007
|
+
signature: envelope.userSignature,
|
|
21008
|
+
chainId
|
|
21009
|
+
},
|
|
21010
|
+
publicKey,
|
|
21011
|
+
pkpId: chipotlePkpAddress,
|
|
21012
|
+
chain: chainName,
|
|
21013
|
+
bitcoinNetwork: bitcoinNetworkName,
|
|
21014
|
+
rpcUrl: this.config.ethRpcUrl,
|
|
21015
|
+
contractAddresses: signerContractAddresses
|
|
21016
|
+
});
|
|
21017
|
+
if (!signResult.success) {
|
|
21018
|
+
return {
|
|
21019
|
+
success: false,
|
|
21020
|
+
error: signResult.error ?? "BTC transaction signing failed"
|
|
21021
|
+
};
|
|
21022
|
+
}
|
|
21023
|
+
if (!signResult.unsignedTxHex || !signResult.signatures?.length) {
|
|
21024
|
+
return {
|
|
21025
|
+
success: false,
|
|
21026
|
+
error: "BTC signing returned incomplete data (missing unsignedTxHex/signatures)"
|
|
21027
|
+
};
|
|
21028
|
+
}
|
|
21029
|
+
if (!signResult.userReceivesAmount) {
|
|
21030
|
+
return { success: false, error: "BTC signing did not return userReceivesAmount" };
|
|
21031
|
+
}
|
|
21032
|
+
const broadcastUrl = this.config.bitcoinProviders?.[0]?.url;
|
|
21033
|
+
if (!broadcastUrl) {
|
|
21034
|
+
return {
|
|
21035
|
+
success: false,
|
|
21036
|
+
error: "Standalone Phase 2 broadcast requires config.bitcoinProviders[0].url (esplora base)"
|
|
21037
|
+
};
|
|
21038
|
+
}
|
|
21039
|
+
try {
|
|
21040
|
+
const { txid: btcTxid } = await (0, import_dh_lit_ops.broadcastSignedBitcoinTransaction)({
|
|
21041
|
+
signatures: signResult.signatures,
|
|
21042
|
+
utxos: executionUtxos,
|
|
21043
|
+
pkpPublicKey: signResult.pkpPublicKey ?? publicKey,
|
|
21044
|
+
destination: envelope.targetAddress,
|
|
21045
|
+
userReceivesAmount: signResult.userReceivesAmount,
|
|
21046
|
+
changeAmount: signResult.changeAmount,
|
|
21047
|
+
pkpBtcAddress: signResult.pkpBtcAddress,
|
|
21048
|
+
bitcoinNetwork: bitcoinNetworkName,
|
|
21049
|
+
bitcoinRpcUrl: broadcastUrl,
|
|
21050
|
+
...this.config.debug ? {
|
|
21051
|
+
debug: (level, msg, data) => {
|
|
21052
|
+
if (level === "warn")
|
|
21053
|
+
log.warn(msg, { data });
|
|
21054
|
+
else if (level === "error")
|
|
21055
|
+
log.error(msg, { data });
|
|
21056
|
+
else
|
|
21057
|
+
log.info(msg, { data });
|
|
21058
|
+
}
|
|
21059
|
+
} : {}
|
|
21060
|
+
});
|
|
21061
|
+
if (this.config.debug) {
|
|
21062
|
+
log.info("\u2705 Standalone Phase 2 broadcast successful", { txid: btcTxid });
|
|
21063
|
+
}
|
|
21064
|
+
return {
|
|
21065
|
+
success: true,
|
|
21066
|
+
txid: btcTxid,
|
|
21067
|
+
amountSent: signResult.userReceivesAmount,
|
|
21068
|
+
networkFee: signResult.networkFee,
|
|
21069
|
+
destination: envelope.targetAddress
|
|
21070
|
+
};
|
|
21071
|
+
} catch (broadcastError) {
|
|
21072
|
+
return {
|
|
21073
|
+
success: false,
|
|
21074
|
+
error: `BTC broadcast failed: ${broadcastError instanceof Error ? broadcastError.message : String(broadcastError)}`
|
|
21075
|
+
};
|
|
21076
|
+
}
|
|
21077
|
+
}
|
|
21078
|
+
async executeBTCWithdrawal(request) {
|
|
21079
|
+
this.ensureInitialized();
|
|
21080
|
+
if (this.config.mode === "service" && !this.config.serviceEndpoint) {
|
|
20858
21081
|
return { success: false, error: "serviceEndpoint required for BTC withdrawal" };
|
|
20859
21082
|
}
|
|
20860
21083
|
if (!request.positionId) {
|
|
@@ -20909,6 +21132,15 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
20909
21132
|
signer,
|
|
20910
21133
|
...request.utxos ? { utxos: request.utxos } : {}
|
|
20911
21134
|
});
|
|
21135
|
+
if (this.config.mode !== "service") {
|
|
21136
|
+
return await this.executeBTCWithdrawalStandalonePhase2(
|
|
21137
|
+
request,
|
|
21138
|
+
envelope,
|
|
21139
|
+
txid,
|
|
21140
|
+
vout,
|
|
21141
|
+
chainId
|
|
21142
|
+
);
|
|
21143
|
+
}
|
|
20912
21144
|
const headers = {
|
|
20913
21145
|
"Content-Type": "application/json",
|
|
20914
21146
|
...await this.getAuthHeader()
|
|
@@ -22226,6 +22458,25 @@ Message: ${causeMessage}${quantumContext}${mintDebtDiagnostics}`
|
|
|
22226
22458
|
const chain = this.config.chain?.toLowerCase() || "";
|
|
22227
22459
|
return chain.includes("mainnet");
|
|
22228
22460
|
}
|
|
22461
|
+
/**
|
|
22462
|
+
* Local-lane activation, verified against the LIVE node at call time (not
|
|
22463
|
+
* the chainId cached at init — a provider that switched networks after
|
|
22464
|
+
* init fails the fresh probe). Zero RPC cost outside a lane process tree:
|
|
22465
|
+
* without LIT_LANE_GUARD=1 this short-circuits to false before any probe.
|
|
22466
|
+
*/
|
|
22467
|
+
async isLocalLaneGuardActive() {
|
|
22468
|
+
if (!laneGuardEnvEnabled())
|
|
22469
|
+
return false;
|
|
22470
|
+
let provider;
|
|
22471
|
+
try {
|
|
22472
|
+
provider = this.config.provider ?? this.getProviderOrThrow();
|
|
22473
|
+
} catch {
|
|
22474
|
+
return false;
|
|
22475
|
+
}
|
|
22476
|
+
return isLaneGuardActiveOnProvider(
|
|
22477
|
+
provider
|
|
22478
|
+
);
|
|
22479
|
+
}
|
|
22229
22480
|
/**
|
|
22230
22481
|
* Get Bitcoin network based on chain.
|
|
22231
22482
|
*
|