@gvnrdao/dh-sdk 0.0.299 → 0.0.300
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/index.js +85 -29
- package/dist/index.mjs +85 -29
- package/dist/utils/quantum-revert.utils.d.ts +32 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5915,6 +5915,35 @@ var ServerSession = class {
|
|
|
5915
5915
|
}
|
|
5916
5916
|
};
|
|
5917
5917
|
|
|
5918
|
+
// src/utils/quantum-revert.utils.ts
|
|
5919
|
+
var DEAD_ZONE_VIOLATION_SELECTOR = "0xbe4b82c1";
|
|
5920
|
+
var QUANTUM_REVERT_NAMES = {
|
|
5921
|
+
"0xbe4b82c1": "DeadZoneViolation()",
|
|
5922
|
+
"0x137f3b70": "InDeadZone()",
|
|
5923
|
+
"0x131d9a21": "QuantumExpired()",
|
|
5924
|
+
"0x52ce5d58": "QuantumAlreadyUsed()",
|
|
5925
|
+
"0x3e76a3c9": "QuantumOutsideWindow()",
|
|
5926
|
+
"0x8baa579f": "InvalidSignature()",
|
|
5927
|
+
"0x62278171": "InvalidValidatorSignature()",
|
|
5928
|
+
"0x3ee5aeb5": "OperationNotAuthorized()",
|
|
5929
|
+
"0x48f5c3ed": "Unauthorized()",
|
|
5930
|
+
"0x70f4b32a": "UnauthorizedSigner()",
|
|
5931
|
+
"0xd92e233d": "ValidationFailed()",
|
|
5932
|
+
"0x36bfdeea": "StateHashMismatch()",
|
|
5933
|
+
"0xb9d419a7": "DebtUpdateVerificationFailed()",
|
|
5934
|
+
"0xc7e20553": "DebtUpdateVerificationFailedDetailed(bytes32,uint256,uint256,uint256,uint256,uint256)",
|
|
5935
|
+
"0x0cfd2a97": "MintVerificationMismatch(uint256,uint256)",
|
|
5936
|
+
"0x07637bd8": "MintFailed()"
|
|
5937
|
+
};
|
|
5938
|
+
function decodeQuantumRevert(e) {
|
|
5939
|
+
const raw = e?.data ?? e?.info?.error?.data ?? // ethers v6 BrowserProvider (MetaMask)
|
|
5940
|
+
e?.error?.data?.data ?? e?.error?.data ?? e?.error?.error?.data;
|
|
5941
|
+
const data = typeof raw === "string" && raw.startsWith("0x") ? raw : null;
|
|
5942
|
+
const selector = data && data.length >= 10 ? data.slice(0, 10) : null;
|
|
5943
|
+
const name = selector ? QUANTUM_REVERT_NAMES[selector] ?? null : null;
|
|
5944
|
+
return { data, selector, name };
|
|
5945
|
+
}
|
|
5946
|
+
|
|
5918
5947
|
// src/utils/btc-withdrawal-message.ts
|
|
5919
5948
|
var import_ethers5 = require("ethers");
|
|
5920
5949
|
var QUANTUM_SECONDS = 60;
|
|
@@ -16390,7 +16419,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
16390
16419
|
{}
|
|
16391
16420
|
);
|
|
16392
16421
|
}
|
|
16393
|
-
let errorData = preflightError?.data || preflightError?.error?.data?.data || preflightError?.error?.data || preflightError?.error?.error?.data;
|
|
16422
|
+
let errorData = preflightError?.data || preflightError?.info?.error?.data || preflightError?.error?.data?.data || preflightError?.error?.data || preflightError?.error?.error?.data;
|
|
16394
16423
|
const errorMessage = preflightError?.reason || preflightError?.error?.reason || preflightError?.error?.error?.reason || preflightError?.message || "Unknown error";
|
|
16395
16424
|
let requireMessage;
|
|
16396
16425
|
if (errorData && typeof errorData === "string" && errorData.startsWith("0x") && errorData.length > 138) {
|
|
@@ -16406,7 +16435,31 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
16406
16435
|
} catch (e) {
|
|
16407
16436
|
}
|
|
16408
16437
|
}
|
|
16409
|
-
|
|
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) {
|
|
16410
16463
|
throw new Error(
|
|
16411
16464
|
`Preflight check failed - mintUCD would revert:
|
|
16412
16465
|
${requireMessage}
|
|
@@ -16467,13 +16520,15 @@ Quantum Timing Analysis:
|
|
|
16467
16520
|
Status: ${sigQuantum2 < currentQuantum ? "\u274C EXPIRED - Signature created in older quantum window" : "\u2705 VALID"}
|
|
16468
16521
|
Note: QuantumOutsideWindow can also occur if the tx is mined outside the accepted past/current/next quantum set.`;
|
|
16469
16522
|
}
|
|
16470
|
-
|
|
16471
|
-
|
|
16523
|
+
if (!isDeadZonePreflightArtifact) {
|
|
16524
|
+
throw new Error(
|
|
16525
|
+
`Preflight check failed - mintUCD would revert:
|
|
16472
16526
|
Error: ${errorName}
|
|
16473
16527
|
Selector: ${selector}
|
|
16474
16528
|
Message: ${errorMessage}
|
|
16475
16529
|
Data: ${errorData}${quantumContext}${mintDebtDiagnostics}`
|
|
16476
|
-
|
|
16530
|
+
);
|
|
16531
|
+
}
|
|
16477
16532
|
} else {
|
|
16478
16533
|
const currentTime2 = Math.floor(Date.now() / 1e3);
|
|
16479
16534
|
const timeSinceSig = currentTime2 - validationResponse.timestamp;
|
|
@@ -16704,7 +16759,6 @@ Position: ${request.positionId}`
|
|
|
16704
16759
|
validationResponse.timestamp,
|
|
16705
16760
|
signatureHexMint
|
|
16706
16761
|
]);
|
|
16707
|
-
await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
|
|
16708
16762
|
const fromAddress = await signer.getAddress();
|
|
16709
16763
|
const estimatedGas = await estimateContractCallGasWithMargin(
|
|
16710
16764
|
signerProvider,
|
|
@@ -16722,6 +16776,7 @@ Position: ${request.positionId}`
|
|
|
16722
16776
|
{}
|
|
16723
16777
|
);
|
|
16724
16778
|
}
|
|
16779
|
+
await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
|
|
16725
16780
|
tx = await sendEip1559Transaction({
|
|
16726
16781
|
signer,
|
|
16727
16782
|
to: positionManagerAddress,
|
|
@@ -16749,9 +16804,16 @@ Position: ${request.positionId}`
|
|
|
16749
16804
|
log.info(` Error data type: ${typeof callError?.data}`, {});
|
|
16750
16805
|
log.info(` Error data value: ${callError?.data}`, {});
|
|
16751
16806
|
}
|
|
16752
|
-
let errorData = callError?.data || callError?.error?.data?.data || callError?.error?.data;
|
|
16807
|
+
let errorData = callError?.data || callError?.info?.error?.data || callError?.error?.data?.data || callError?.error?.data;
|
|
16753
16808
|
const errorMessage = callError?.reason || callError?.message || "Unknown error";
|
|
16754
|
-
|
|
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) {
|
|
16755
16817
|
const selector = errorData.slice(0, 10);
|
|
16756
16818
|
const knownErrors = {
|
|
16757
16819
|
"0x8baa579f": "InvalidSignature()",
|
|
@@ -16817,17 +16879,20 @@ Message: ${errorMessage}`
|
|
|
16817
16879
|
}
|
|
16818
16880
|
}
|
|
16819
16881
|
}
|
|
16820
|
-
|
|
16821
|
-
|
|
16882
|
+
if (!isDeadZoneArtifact) {
|
|
16883
|
+
throw new Error(
|
|
16884
|
+
`mintUCD reverted: ${errorMessage}
|
|
16822
16885
|
Error data: ${errorData || "none"}`
|
|
16823
|
-
|
|
16886
|
+
);
|
|
16887
|
+
}
|
|
16824
16888
|
}
|
|
16825
16889
|
if (this.config.debug) {
|
|
16826
16890
|
log.info(
|
|
16827
|
-
"\u2705 Static call
|
|
16891
|
+
"\u2705 Static call clear \u2014 broadcasting mintUCD with fixed gas ceiling",
|
|
16828
16892
|
{}
|
|
16829
16893
|
);
|
|
16830
16894
|
}
|
|
16895
|
+
await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
|
|
16831
16896
|
tx = await sendEip1559Transaction({
|
|
16832
16897
|
signer,
|
|
16833
16898
|
to: positionManagerAddress,
|
|
@@ -18896,23 +18961,10 @@ Error data: ${errorData || "none"}`
|
|
|
18896
18961
|
signature
|
|
18897
18962
|
]);
|
|
18898
18963
|
const decodePaymentRevert = (e) => {
|
|
18899
|
-
const
|
|
18900
|
-
|
|
18901
|
-
if (!data || !data.startsWith("0x") || data.length < 10)
|
|
18964
|
+
const { selector, name } = decodeQuantumRevert(e);
|
|
18965
|
+
if (!selector)
|
|
18902
18966
|
return null;
|
|
18903
|
-
|
|
18904
|
-
const map2 = {
|
|
18905
|
-
"0xbe4b82c1": "DeadZoneViolation()",
|
|
18906
|
-
"0x137f3b70": "InDeadZone()",
|
|
18907
|
-
"0x52ce5d58": "QuantumAlreadyUsed()",
|
|
18908
|
-
"0x3e76a3c9": "QuantumOutsideWindow()",
|
|
18909
|
-
"0x131d9a21": "QuantumExpired()",
|
|
18910
|
-
"0x8baa579f": "InvalidSignature()",
|
|
18911
|
-
"0x62278171": "InvalidValidatorSignature()",
|
|
18912
|
-
"0x3ee5aeb5": "OperationNotAuthorized()",
|
|
18913
|
-
"0x48f5c3ed": "Unauthorized()"
|
|
18914
|
-
};
|
|
18915
|
-
return map2[selector] ?? `Unknown error ${selector}`;
|
|
18967
|
+
return name ?? `Unknown error ${selector}`;
|
|
18916
18968
|
};
|
|
18917
18969
|
const MAX_DEADZONE_RESIMULATIONS = 3;
|
|
18918
18970
|
for (let sim = 1; ; sim++) {
|
|
@@ -19678,7 +19730,8 @@ Error data: ${errorData || "none"}`
|
|
|
19678
19730
|
tx = await positionManagerContract["withdrawBTC"](
|
|
19679
19731
|
withdrawalParams,
|
|
19680
19732
|
signatureBytes,
|
|
19681
|
-
btcSpendAuthBytes
|
|
19733
|
+
btcSpendAuthBytes,
|
|
19734
|
+
{ gasLimit: WITHDRAW_BTC_GAS_CEILING }
|
|
19682
19735
|
);
|
|
19683
19736
|
} catch (txError) {
|
|
19684
19737
|
const txErrorMsg = txError instanceof Error ? txError.message : String(txError);
|
|
@@ -19709,6 +19762,9 @@ Error data: ${errorData || "none"}`
|
|
|
19709
19762
|
WITHDRAW_BTC_GAS_CEILING
|
|
19710
19763
|
);
|
|
19711
19764
|
const gasLimit = estimatedGas ?? WITHDRAW_BTC_GAS_CEILING;
|
|
19765
|
+
await awaitSafeSubmissionWindow(
|
|
19766
|
+
Number(withdrawalParams.quantumTimestamp)
|
|
19767
|
+
);
|
|
19712
19768
|
tx = await signer.sendTransaction({
|
|
19713
19769
|
to: contractAddress,
|
|
19714
19770
|
data: calldata,
|
package/dist/index.mjs
CHANGED
|
@@ -5839,6 +5839,35 @@ var ServerSession = class {
|
|
|
5839
5839
|
}
|
|
5840
5840
|
};
|
|
5841
5841
|
|
|
5842
|
+
// src/utils/quantum-revert.utils.ts
|
|
5843
|
+
var DEAD_ZONE_VIOLATION_SELECTOR = "0xbe4b82c1";
|
|
5844
|
+
var QUANTUM_REVERT_NAMES = {
|
|
5845
|
+
"0xbe4b82c1": "DeadZoneViolation()",
|
|
5846
|
+
"0x137f3b70": "InDeadZone()",
|
|
5847
|
+
"0x131d9a21": "QuantumExpired()",
|
|
5848
|
+
"0x52ce5d58": "QuantumAlreadyUsed()",
|
|
5849
|
+
"0x3e76a3c9": "QuantumOutsideWindow()",
|
|
5850
|
+
"0x8baa579f": "InvalidSignature()",
|
|
5851
|
+
"0x62278171": "InvalidValidatorSignature()",
|
|
5852
|
+
"0x3ee5aeb5": "OperationNotAuthorized()",
|
|
5853
|
+
"0x48f5c3ed": "Unauthorized()",
|
|
5854
|
+
"0x70f4b32a": "UnauthorizedSigner()",
|
|
5855
|
+
"0xd92e233d": "ValidationFailed()",
|
|
5856
|
+
"0x36bfdeea": "StateHashMismatch()",
|
|
5857
|
+
"0xb9d419a7": "DebtUpdateVerificationFailed()",
|
|
5858
|
+
"0xc7e20553": "DebtUpdateVerificationFailedDetailed(bytes32,uint256,uint256,uint256,uint256,uint256)",
|
|
5859
|
+
"0x0cfd2a97": "MintVerificationMismatch(uint256,uint256)",
|
|
5860
|
+
"0x07637bd8": "MintFailed()"
|
|
5861
|
+
};
|
|
5862
|
+
function decodeQuantumRevert(e) {
|
|
5863
|
+
const raw = e?.data ?? e?.info?.error?.data ?? // ethers v6 BrowserProvider (MetaMask)
|
|
5864
|
+
e?.error?.data?.data ?? e?.error?.data ?? e?.error?.error?.data;
|
|
5865
|
+
const data = typeof raw === "string" && raw.startsWith("0x") ? raw : null;
|
|
5866
|
+
const selector = data && data.length >= 10 ? data.slice(0, 10) : null;
|
|
5867
|
+
const name = selector ? QUANTUM_REVERT_NAMES[selector] ?? null : null;
|
|
5868
|
+
return { data, selector, name };
|
|
5869
|
+
}
|
|
5870
|
+
|
|
5842
5871
|
// src/utils/btc-withdrawal-message.ts
|
|
5843
5872
|
import { keccak256 as keccak2563, toUtf8Bytes as toUtf8Bytes3, solidityPackedKeccak256 as solidityPackedKeccak2563, getBytes as getBytes3, zeroPadValue } from "ethers";
|
|
5844
5873
|
var QUANTUM_SECONDS = 60;
|
|
@@ -16318,7 +16347,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
16318
16347
|
{}
|
|
16319
16348
|
);
|
|
16320
16349
|
}
|
|
16321
|
-
let errorData = preflightError?.data || preflightError?.error?.data?.data || preflightError?.error?.data || preflightError?.error?.error?.data;
|
|
16350
|
+
let errorData = preflightError?.data || preflightError?.info?.error?.data || preflightError?.error?.data?.data || preflightError?.error?.data || preflightError?.error?.error?.data;
|
|
16322
16351
|
const errorMessage = preflightError?.reason || preflightError?.error?.reason || preflightError?.error?.error?.reason || preflightError?.message || "Unknown error";
|
|
16323
16352
|
let requireMessage;
|
|
16324
16353
|
if (errorData && typeof errorData === "string" && errorData.startsWith("0x") && errorData.length > 138) {
|
|
@@ -16334,7 +16363,31 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
16334
16363
|
} catch (e) {
|
|
16335
16364
|
}
|
|
16336
16365
|
}
|
|
16337
|
-
|
|
16366
|
+
const isDeadZonePreflightArtifact = decodeQuantumRevert(preflightError).selector === DEAD_ZONE_VIOLATION_SELECTOR;
|
|
16367
|
+
if (isDeadZonePreflightArtifact) {
|
|
16368
|
+
const nowSec = Math.floor(Date.now() / 1e3);
|
|
16369
|
+
const sigQuantum2 = Math.floor(Number(validationResponse.timestamp) / 60) * 60;
|
|
16370
|
+
const realCurrentQuantum = Math.floor(nowSec / 60) * 60;
|
|
16371
|
+
if (sigQuantum2 === realCurrentQuantum) {
|
|
16372
|
+
if (this.config.debug) {
|
|
16373
|
+
log.info(
|
|
16374
|
+
"\u21AA\uFE0F Preflight DeadZoneViolation is a stale-latest-block artifact (signature is the current quantum) \u2014 proceeding to broadcast",
|
|
16375
|
+
{}
|
|
16376
|
+
);
|
|
16377
|
+
}
|
|
16378
|
+
} else {
|
|
16379
|
+
if (this.config.debug) {
|
|
16380
|
+
log.info(
|
|
16381
|
+
"\u{1F501} Preflight DeadZoneViolation near the boundary \u2014 deferring across it, then proceeding",
|
|
16382
|
+
{}
|
|
16383
|
+
);
|
|
16384
|
+
}
|
|
16385
|
+
await awaitSafeSubmissionWindow(
|
|
16386
|
+
Number(validationResponse.timestamp)
|
|
16387
|
+
);
|
|
16388
|
+
}
|
|
16389
|
+
}
|
|
16390
|
+
if (requireMessage && !isDeadZonePreflightArtifact) {
|
|
16338
16391
|
throw new Error(
|
|
16339
16392
|
`Preflight check failed - mintUCD would revert:
|
|
16340
16393
|
${requireMessage}
|
|
@@ -16395,13 +16448,15 @@ Quantum Timing Analysis:
|
|
|
16395
16448
|
Status: ${sigQuantum2 < currentQuantum ? "\u274C EXPIRED - Signature created in older quantum window" : "\u2705 VALID"}
|
|
16396
16449
|
Note: QuantumOutsideWindow can also occur if the tx is mined outside the accepted past/current/next quantum set.`;
|
|
16397
16450
|
}
|
|
16398
|
-
|
|
16399
|
-
|
|
16451
|
+
if (!isDeadZonePreflightArtifact) {
|
|
16452
|
+
throw new Error(
|
|
16453
|
+
`Preflight check failed - mintUCD would revert:
|
|
16400
16454
|
Error: ${errorName}
|
|
16401
16455
|
Selector: ${selector}
|
|
16402
16456
|
Message: ${errorMessage}
|
|
16403
16457
|
Data: ${errorData}${quantumContext}${mintDebtDiagnostics}`
|
|
16404
|
-
|
|
16458
|
+
);
|
|
16459
|
+
}
|
|
16405
16460
|
} else {
|
|
16406
16461
|
const currentTime2 = Math.floor(Date.now() / 1e3);
|
|
16407
16462
|
const timeSinceSig = currentTime2 - validationResponse.timestamp;
|
|
@@ -16632,7 +16687,6 @@ Position: ${request.positionId}`
|
|
|
16632
16687
|
validationResponse.timestamp,
|
|
16633
16688
|
signatureHexMint
|
|
16634
16689
|
]);
|
|
16635
|
-
await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
|
|
16636
16690
|
const fromAddress = await signer.getAddress();
|
|
16637
16691
|
const estimatedGas = await estimateContractCallGasWithMargin(
|
|
16638
16692
|
signerProvider,
|
|
@@ -16650,6 +16704,7 @@ Position: ${request.positionId}`
|
|
|
16650
16704
|
{}
|
|
16651
16705
|
);
|
|
16652
16706
|
}
|
|
16707
|
+
await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
|
|
16653
16708
|
tx = await sendEip1559Transaction({
|
|
16654
16709
|
signer,
|
|
16655
16710
|
to: positionManagerAddress,
|
|
@@ -16677,9 +16732,16 @@ Position: ${request.positionId}`
|
|
|
16677
16732
|
log.info(` Error data type: ${typeof callError?.data}`, {});
|
|
16678
16733
|
log.info(` Error data value: ${callError?.data}`, {});
|
|
16679
16734
|
}
|
|
16680
|
-
let errorData = callError?.data || callError?.error?.data?.data || callError?.error?.data;
|
|
16735
|
+
let errorData = callError?.data || callError?.info?.error?.data || callError?.error?.data?.data || callError?.error?.data;
|
|
16681
16736
|
const errorMessage = callError?.reason || callError?.message || "Unknown error";
|
|
16682
|
-
|
|
16737
|
+
const isDeadZoneArtifact = decodeQuantumRevert(callError).selector === DEAD_ZONE_VIOLATION_SELECTOR;
|
|
16738
|
+
if (isDeadZoneArtifact && this.config.debug) {
|
|
16739
|
+
log.info(
|
|
16740
|
+
"\u{1F536} mintUCD static-call DeadZoneViolation is a stale-latest-block artifact; broadcasting anyway (gated)",
|
|
16741
|
+
{}
|
|
16742
|
+
);
|
|
16743
|
+
}
|
|
16744
|
+
if (!isDeadZoneArtifact && errorData && typeof errorData === "string" && errorData.startsWith("0x") && errorData.length > 10) {
|
|
16683
16745
|
const selector = errorData.slice(0, 10);
|
|
16684
16746
|
const knownErrors = {
|
|
16685
16747
|
"0x8baa579f": "InvalidSignature()",
|
|
@@ -16745,17 +16807,20 @@ Message: ${errorMessage}`
|
|
|
16745
16807
|
}
|
|
16746
16808
|
}
|
|
16747
16809
|
}
|
|
16748
|
-
|
|
16749
|
-
|
|
16810
|
+
if (!isDeadZoneArtifact) {
|
|
16811
|
+
throw new Error(
|
|
16812
|
+
`mintUCD reverted: ${errorMessage}
|
|
16750
16813
|
Error data: ${errorData || "none"}`
|
|
16751
|
-
|
|
16814
|
+
);
|
|
16815
|
+
}
|
|
16752
16816
|
}
|
|
16753
16817
|
if (this.config.debug) {
|
|
16754
16818
|
log.info(
|
|
16755
|
-
"\u2705 Static call
|
|
16819
|
+
"\u2705 Static call clear \u2014 broadcasting mintUCD with fixed gas ceiling",
|
|
16756
16820
|
{}
|
|
16757
16821
|
);
|
|
16758
16822
|
}
|
|
16823
|
+
await awaitSafeSubmissionWindow(Number(validationResponse.timestamp));
|
|
16759
16824
|
tx = await sendEip1559Transaction({
|
|
16760
16825
|
signer,
|
|
16761
16826
|
to: positionManagerAddress,
|
|
@@ -18824,23 +18889,10 @@ Error data: ${errorData || "none"}`
|
|
|
18824
18889
|
signature
|
|
18825
18890
|
]);
|
|
18826
18891
|
const decodePaymentRevert = (e) => {
|
|
18827
|
-
const
|
|
18828
|
-
|
|
18829
|
-
if (!data || !data.startsWith("0x") || data.length < 10)
|
|
18892
|
+
const { selector, name } = decodeQuantumRevert(e);
|
|
18893
|
+
if (!selector)
|
|
18830
18894
|
return null;
|
|
18831
|
-
|
|
18832
|
-
const map2 = {
|
|
18833
|
-
"0xbe4b82c1": "DeadZoneViolation()",
|
|
18834
|
-
"0x137f3b70": "InDeadZone()",
|
|
18835
|
-
"0x52ce5d58": "QuantumAlreadyUsed()",
|
|
18836
|
-
"0x3e76a3c9": "QuantumOutsideWindow()",
|
|
18837
|
-
"0x131d9a21": "QuantumExpired()",
|
|
18838
|
-
"0x8baa579f": "InvalidSignature()",
|
|
18839
|
-
"0x62278171": "InvalidValidatorSignature()",
|
|
18840
|
-
"0x3ee5aeb5": "OperationNotAuthorized()",
|
|
18841
|
-
"0x48f5c3ed": "Unauthorized()"
|
|
18842
|
-
};
|
|
18843
|
-
return map2[selector] ?? `Unknown error ${selector}`;
|
|
18895
|
+
return name ?? `Unknown error ${selector}`;
|
|
18844
18896
|
};
|
|
18845
18897
|
const MAX_DEADZONE_RESIMULATIONS = 3;
|
|
18846
18898
|
for (let sim = 1; ; sim++) {
|
|
@@ -19606,7 +19658,8 @@ Error data: ${errorData || "none"}`
|
|
|
19606
19658
|
tx = await positionManagerContract["withdrawBTC"](
|
|
19607
19659
|
withdrawalParams,
|
|
19608
19660
|
signatureBytes,
|
|
19609
|
-
btcSpendAuthBytes
|
|
19661
|
+
btcSpendAuthBytes,
|
|
19662
|
+
{ gasLimit: WITHDRAW_BTC_GAS_CEILING }
|
|
19610
19663
|
);
|
|
19611
19664
|
} catch (txError) {
|
|
19612
19665
|
const txErrorMsg = txError instanceof Error ? txError.message : String(txError);
|
|
@@ -19637,6 +19690,9 @@ Error data: ${errorData || "none"}`
|
|
|
19637
19690
|
WITHDRAW_BTC_GAS_CEILING
|
|
19638
19691
|
);
|
|
19639
19692
|
const gasLimit = estimatedGas ?? WITHDRAW_BTC_GAS_CEILING;
|
|
19693
|
+
await awaitSafeSubmissionWindow(
|
|
19694
|
+
Number(withdrawalParams.quantumTimestamp)
|
|
19695
|
+
);
|
|
19640
19696
|
tx = await signer.sendTransaction({
|
|
19641
19697
|
to: contractAddress,
|
|
19642
19698
|
data: calldata,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared decoder for custom-error reverts surfaced by quantum-signed operations
|
|
3
|
+
* (mintUCD / makePayment / withdrawBTC / extendPosition / liquidation).
|
|
4
|
+
*
|
|
5
|
+
* Consolidates what used to be three hand-rolled selector maps + ad-hoc error-data
|
|
6
|
+
* extraction scattered across diamond-hands-sdk.ts. The extraction probes EVERY
|
|
7
|
+
* nesting ethers v6 uses across provider types — notably `info.error.data`, which
|
|
8
|
+
* `BrowserProvider` (MetaMask) uses and the older per-site extractors missed, so a
|
|
9
|
+
* browser-provider DeadZoneViolation could slip through undetected and wrongly throw.
|
|
10
|
+
*/
|
|
11
|
+
/** `DeadZoneViolation()` selector — the stale-latest-block artifact we tolerate. */
|
|
12
|
+
export declare const DEAD_ZONE_VIOLATION_SELECTOR = "0xbe4b82c1";
|
|
13
|
+
/**
|
|
14
|
+
* Union of the custom-error selectors the mint/payment/quantum paths decode. Keep in
|
|
15
|
+
* sync with OperationAuthorizationRegistry / PositionManager / LoanOperationsManager.
|
|
16
|
+
*/
|
|
17
|
+
export declare const QUANTUM_REVERT_NAMES: Record<string, string>;
|
|
18
|
+
export interface DecodedRevert {
|
|
19
|
+
/** Raw revert data (`0x…`) if any provider nesting carried it, else null. */
|
|
20
|
+
data: string | null;
|
|
21
|
+
/** 4-byte custom-error selector (`0x…`) if the data is a valid custom error. */
|
|
22
|
+
selector: string | null;
|
|
23
|
+
/** Human-readable error name if the selector is known, else null. */
|
|
24
|
+
name: string | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract the revert data / custom-error selector / known name from an ethers error,
|
|
28
|
+
* probing every provider nesting (JsonRpc, Browser/MetaMask, wrapped `error.error`).
|
|
29
|
+
*/
|
|
30
|
+
export declare function decodeQuantumRevert(e: any): DecodedRevert;
|
|
31
|
+
/** True iff the error decodes to `DeadZoneViolation()` from any provider nesting. */
|
|
32
|
+
export declare function isDeadZoneViolation(e: any): boolean;
|
package/package.json
CHANGED