@gvnrdao/dh-lit-actions 0.0.60 → 0.0.63
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/package.json +3 -3
- package/pkg-dist/pkg-src/constants/chunks/contract-deployments.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/contract-deployments.js.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/lit-actions-registry.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/lit-actions-registry.js.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/package-registry.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/chunks/package-registry.js.map +1 -0
- package/pkg-dist/pkg-src/constants/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/constants/index.js.map +1 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.d.ts +40 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.d.ts.map +1 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.js +102 -0
- package/pkg-dist/pkg-src/executors/chunks/vault-snapshot-executor.js.map +1 -0
- package/pkg-dist/pkg-src/executors/index.d.ts +43 -0
- package/pkg-dist/pkg-src/executors/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/executors/index.js +48 -0
- package/pkg-dist/pkg-src/executors/index.js.map +1 -0
- package/pkg-dist/pkg-src/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/index.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/diamond-hands-lit-actions.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/diamond-hands-lit-actions.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-config.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-config.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-name.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-name.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-registry.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/lit-action-registry.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/pkp-info.i.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/chunks/pkp-info.i.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/deployments.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/deployments.js.map +1 -0
- package/pkg-dist/pkg-src/interfaces/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/interfaces/index.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/cid-utils.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/cid-utils.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/connection-helpers.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/connection-helpers.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/debug-logger.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/debug-logger.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/error-classification.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/error-classification.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/lit-action-helpers.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/lit-action-helpers.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/pkp-setup.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/pkp-setup.js.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/session-signature-cache.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/chunks/session-signature-cache.js.map +1 -0
- package/pkg-dist/pkg-src/utils/index.d.ts.map +1 -0
- package/pkg-dist/pkg-src/utils/index.js.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.d.ts +130 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.js +244 -0
- package/pkg-dist/src/constants/chunks/bitcoin-network-config.js.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin.d.ts +42 -0
- package/pkg-dist/src/constants/chunks/bitcoin.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/bitcoin.js +45 -0
- package/pkg-dist/src/constants/chunks/bitcoin.js.map +1 -0
- package/pkg-dist/src/constants/chunks/decimals.d.ts +44 -0
- package/pkg-dist/src/constants/chunks/decimals.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/decimals.js +47 -0
- package/pkg-dist/src/constants/chunks/decimals.js.map +1 -0
- package/pkg-dist/src/constants/chunks/liquidation.d.ts +51 -0
- package/pkg-dist/src/constants/chunks/liquidation.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/liquidation.js +54 -0
- package/pkg-dist/src/constants/chunks/liquidation.js.map +1 -0
- package/pkg-dist/src/constants/chunks/loan-status.d.ts +57 -0
- package/pkg-dist/src/constants/chunks/loan-status.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/loan-status.js +95 -0
- package/pkg-dist/src/constants/chunks/loan-status.js.map +1 -0
- package/pkg-dist/src/constants/chunks/price-oracle.d.ts +46 -0
- package/pkg-dist/src/constants/chunks/price-oracle.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/price-oracle.js +49 -0
- package/pkg-dist/src/constants/chunks/price-oracle.js.map +1 -0
- package/pkg-dist/src/constants/chunks/quantum-time.d.ts +63 -0
- package/pkg-dist/src/constants/chunks/quantum-time.d.ts.map +1 -0
- package/pkg-dist/src/constants/chunks/quantum-time.js +66 -0
- package/pkg-dist/src/constants/chunks/quantum-time.js.map +1 -0
- package/pkg-dist/src/constants/index.d.ts +16 -0
- package/pkg-dist/src/constants/index.d.ts.map +1 -0
- package/pkg-dist/src/constants/index.js +57 -0
- package/pkg-dist/src/constants/index.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.d.ts +19 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/authorization.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.d.ts +60 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/bitcoin-data-provider.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.d.ts +18 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.js +8 -0
- package/pkg-dist/src/interfaces/chunks/circuit-breaker.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.d.ts +24 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.js +5 -0
- package/pkg-dist/src/interfaces/chunks/mint-authorization.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.d.ts +60 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.js +8 -0
- package/pkg-dist/src/interfaces/chunks/owner-authorization.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.d.ts +26 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/price-oracle.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.d.ts +23 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance-module.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.d.ts +63 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/vault-balance.i.js.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.d.ts +51 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.js +3 -0
- package/pkg-dist/src/interfaces/chunks/vault-snapshot.i.js.map +1 -0
- package/pkg-dist/src/interfaces/index.d.ts +15 -0
- package/pkg-dist/src/interfaces/index.d.ts.map +1 -0
- package/pkg-dist/src/interfaces/index.js +30 -0
- package/pkg-dist/src/interfaces/index.js.map +1 -0
- package/pkg-dist/src/modules/authorization.module.d.ts +160 -0
- package/pkg-dist/src/modules/authorization.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/authorization.module.js +317 -0
- package/pkg-dist/src/modules/authorization.module.js.map +1 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.d.ts +91 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.js +261 -0
- package/pkg-dist/src/modules/bitcoin-data-provider.module.js.map +1 -0
- package/pkg-dist/src/modules/business-rules-math.module.d.ts +155 -0
- package/pkg-dist/src/modules/business-rules-math.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/business-rules-math.module.js +309 -0
- package/pkg-dist/src/modules/business-rules-math.module.js.map +1 -0
- package/pkg-dist/src/modules/price-oracle.module.d.ts +29 -0
- package/pkg-dist/src/modules/price-oracle.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/price-oracle.module.js +223 -0
- package/pkg-dist/src/modules/price-oracle.module.js.map +1 -0
- package/pkg-dist/src/modules/protocol-parameters.module.d.ts +58 -0
- package/pkg-dist/src/modules/protocol-parameters.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/protocol-parameters.module.js +125 -0
- package/pkg-dist/src/modules/protocol-parameters.module.js.map +1 -0
- package/pkg-dist/src/modules/quantum-time.module.d.ts +149 -0
- package/pkg-dist/src/modules/quantum-time.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/quantum-time.module.js +240 -0
- package/pkg-dist/src/modules/quantum-time.module.js.map +1 -0
- package/pkg-dist/src/modules/vault-balance.module.d.ts +172 -0
- package/pkg-dist/src/modules/vault-balance.module.d.ts.map +1 -0
- package/pkg-dist/src/modules/vault-balance.module.js +318 -0
- package/pkg-dist/src/modules/vault-balance.module.js.map +1 -0
- package/pkg-dist/src/modules/vault-snapshot.d.ts +168 -0
- package/pkg-dist/src/modules/vault-snapshot.d.ts.map +1 -0
- package/pkg-dist/src/modules/vault-snapshot.js +370 -0
- package/pkg-dist/src/modules/vault-snapshot.js.map +1 -0
- package/pkg-dist/constants/chunks/contract-deployments.d.ts.map +0 -1
- package/pkg-dist/constants/chunks/contract-deployments.js.map +0 -1
- package/pkg-dist/constants/chunks/lit-actions-registry.d.ts.map +0 -1
- package/pkg-dist/constants/chunks/lit-actions-registry.js.map +0 -1
- package/pkg-dist/constants/chunks/package-registry.d.ts.map +0 -1
- package/pkg-dist/constants/chunks/package-registry.js.map +0 -1
- package/pkg-dist/constants/index.d.ts.map +0 -1
- package/pkg-dist/constants/index.js.map +0 -1
- package/pkg-dist/index.d.ts.map +0 -1
- package/pkg-dist/index.js.map +0 -1
- package/pkg-dist/interfaces/chunks/diamond-hands-lit-actions.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/diamond-hands-lit-actions.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-config.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-config.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-name.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-name.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-registry.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/lit-action-registry.i.js.map +0 -1
- package/pkg-dist/interfaces/chunks/pkp-info.i.d.ts.map +0 -1
- package/pkg-dist/interfaces/chunks/pkp-info.i.js.map +0 -1
- package/pkg-dist/interfaces/deployments.d.ts.map +0 -1
- package/pkg-dist/interfaces/deployments.js.map +0 -1
- package/pkg-dist/interfaces/index.d.ts.map +0 -1
- package/pkg-dist/interfaces/index.js.map +0 -1
- package/pkg-dist/utils/chunks/cid-utils.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/cid-utils.js.map +0 -1
- package/pkg-dist/utils/chunks/connection-helpers.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/connection-helpers.js.map +0 -1
- package/pkg-dist/utils/chunks/debug-logger.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/debug-logger.js.map +0 -1
- package/pkg-dist/utils/chunks/error-classification.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/error-classification.js.map +0 -1
- package/pkg-dist/utils/chunks/lit-action-helpers.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/lit-action-helpers.js.map +0 -1
- package/pkg-dist/utils/chunks/pkp-setup.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/pkp-setup.js.map +0 -1
- package/pkg-dist/utils/chunks/session-signature-cache.d.ts.map +0 -1
- package/pkg-dist/utils/chunks/session-signature-cache.js.map +0 -1
- package/pkg-dist/utils/index.d.ts.map +0 -1
- package/pkg-dist/utils/index.js.map +0 -1
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/contract-deployments.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/contract-deployments.js +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/lit-actions-registry.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/lit-actions-registry.js +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/package-registry.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/chunks/package-registry.js +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/index.d.ts +0 -0
- /package/pkg-dist/{constants → pkg-src/constants}/index.js +0 -0
- /package/pkg-dist/{index.d.ts → pkg-src/index.d.ts} +0 -0
- /package/pkg-dist/{index.js → pkg-src/index.js} +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/diamond-hands-lit-actions.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/diamond-hands-lit-actions.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-config.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-config.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-name.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-name.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-registry.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/lit-action-registry.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/pkp-info.i.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/chunks/pkp-info.i.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/deployments.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/deployments.js +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/index.d.ts +0 -0
- /package/pkg-dist/{interfaces → pkg-src/interfaces}/index.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/cid-utils.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/cid-utils.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/connection-helpers.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/connection-helpers.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/debug-logger.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/debug-logger.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/error-classification.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/error-classification.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/lit-action-helpers.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/lit-action-helpers.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/pkp-setup.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/pkp-setup.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/session-signature-cache.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/chunks/session-signature-cache.js +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/index.d.ts +0 -0
- /package/pkg-dist/{utils → pkg-src/utils}/index.js +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Protocol Parameters Module
|
|
4
|
+
*
|
|
5
|
+
* Fetches protocol parameters directly from smart contracts.
|
|
6
|
+
* This ensures LIT actions always use current values set by protocol governance.
|
|
7
|
+
*
|
|
8
|
+
* Parameters fetched:
|
|
9
|
+
* - Liquidation threshold (from LoanOperationsManager)
|
|
10
|
+
* - Term-specific fees (from TermManager)
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ProtocolParametersModule = void 0;
|
|
14
|
+
exports.createProtocolParametersModule = createProtocolParametersModule;
|
|
15
|
+
/**
|
|
16
|
+
* Protocol Parameters Module
|
|
17
|
+
*
|
|
18
|
+
* Fetches governance-controlled parameters from smart contracts
|
|
19
|
+
*/
|
|
20
|
+
class ProtocolParametersModule {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.termManagerAddress = config.termManagerAddress;
|
|
23
|
+
this.loanOpsManagerAddress = config.loanOpsManagerAddress;
|
|
24
|
+
this.chain = config.chain;
|
|
25
|
+
this.chainId = config.chainId;
|
|
26
|
+
this.rpcUrl = config.rpcUrl;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get liquidation threshold from LoanOperationsManager
|
|
30
|
+
*
|
|
31
|
+
* @returns Liquidation threshold in basis points
|
|
32
|
+
*/
|
|
33
|
+
async getLiquidationThreshold() {
|
|
34
|
+
try {
|
|
35
|
+
// Get RPC URL - either from config (for local testing) or from Lit runtime
|
|
36
|
+
let rpcUrl;
|
|
37
|
+
if (this.rpcUrl) {
|
|
38
|
+
rpcUrl = this.rpcUrl;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// @ts-ignore - Lit.Actions available in LIT runtime
|
|
42
|
+
rpcUrl = await Lit.Actions.getRpcUrl({ chain: this.chain });
|
|
43
|
+
}
|
|
44
|
+
// @ts-ignore - ethers available in LIT runtime
|
|
45
|
+
// StaticJsonRpcProvider with explicit network bypasses auto-detection (required for ngrok URLs)
|
|
46
|
+
const provider = new ethers.providers.StaticJsonRpcProvider(rpcUrl, { name: 'any', chainId: 1337 });
|
|
47
|
+
const abi = [
|
|
48
|
+
{
|
|
49
|
+
inputs: [],
|
|
50
|
+
name: "liquidationThreshold",
|
|
51
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
52
|
+
stateMutability: "view",
|
|
53
|
+
type: "function",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
// @ts-ignore - ethers available in LIT runtime
|
|
57
|
+
const contract = new ethers.Contract(this.loanOpsManagerAddress, abi, provider);
|
|
58
|
+
const result = await contract.liquidationThreshold();
|
|
59
|
+
return Number(result.toString());
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error("[ProtocolParameters] Error fetching liquidation threshold:", error.message);
|
|
63
|
+
throw new Error(`Failed to fetch liquidation threshold: ${error.message}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get term-specific fees from TermManager
|
|
68
|
+
*
|
|
69
|
+
* @param termMonths Loan term in months
|
|
70
|
+
* @returns Term fees (origination and extension) in basis points
|
|
71
|
+
*/
|
|
72
|
+
async getTermFees(termMonths) {
|
|
73
|
+
try {
|
|
74
|
+
// Get RPC URL - either from config (for local testing) or from Lit runtime
|
|
75
|
+
let rpcUrl;
|
|
76
|
+
if (this.rpcUrl) {
|
|
77
|
+
rpcUrl = this.rpcUrl;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// @ts-ignore - Lit.Actions available in LIT runtime
|
|
81
|
+
rpcUrl = await Lit.Actions.getRpcUrl({ chain: this.chain });
|
|
82
|
+
}
|
|
83
|
+
// @ts-ignore - ethers available in LIT runtime
|
|
84
|
+
// StaticJsonRpcProvider with explicit network bypasses auto-detection (required for ngrok URLs)
|
|
85
|
+
const provider = new ethers.providers.StaticJsonRpcProvider(rpcUrl, { name: 'any', chainId: 1337 });
|
|
86
|
+
const abi = [
|
|
87
|
+
{
|
|
88
|
+
inputs: [
|
|
89
|
+
{ internalType: "uint256", name: "_termMonths", type: "uint256" },
|
|
90
|
+
],
|
|
91
|
+
name: "getTermFees",
|
|
92
|
+
outputs: [
|
|
93
|
+
{ internalType: "uint88", name: "originationFee", type: "uint88" },
|
|
94
|
+
{ internalType: "uint88", name: "extensionFee", type: "uint88" },
|
|
95
|
+
],
|
|
96
|
+
stateMutability: "view",
|
|
97
|
+
type: "function",
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
// @ts-ignore - ethers available in LIT runtime
|
|
101
|
+
const contract = new ethers.Contract(this.termManagerAddress, abi, provider);
|
|
102
|
+
const result = await contract.getTermFees(termMonths);
|
|
103
|
+
return {
|
|
104
|
+
originationFeeBps: Number(result.originationFee?.toString?.() ??
|
|
105
|
+
result[0]?.toString?.() ??
|
|
106
|
+
result[0]),
|
|
107
|
+
extensionFeeBps: Number(result.extensionFee?.toString?.() ??
|
|
108
|
+
result[1]?.toString?.() ??
|
|
109
|
+
result[1]),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error("[ProtocolParameters] Error fetching term fees:", error.message);
|
|
114
|
+
throw new Error(`Failed to fetch term fees: ${error.message}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.ProtocolParametersModule = ProtocolParametersModule;
|
|
119
|
+
/**
|
|
120
|
+
* Factory function to create protocol parameters module
|
|
121
|
+
*/
|
|
122
|
+
function createProtocolParametersModule(config) {
|
|
123
|
+
return new ProtocolParametersModule(config);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=protocol-parameters.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-parameters.module.js","sourceRoot":"","sources":["../../../src/modules/protocol-parameters.module.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAwJH,wEAIC;AAvID;;;;GAIG;AACH,MAAa,wBAAwB;IAOnC,YAAY,MAAgC;QAC1C,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACpD,IAAI,CAAC,qBAAqB,GAAG,MAAM,CAAC,qBAAqB,CAAC;QAC1D,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,uBAAuB;QAC3B,IAAI,CAAC;YACL,2EAA2E;YAC3E,IAAI,MAAc,CAAC;YACnB,IAAI,IAAI,CAAC,MAAM,EAAE,C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CACZ;gBACD,eAAe,EAAE,MAAM,CACrB,MAAM,CAAC,YAAY,EAAE,QAAQ,EAAE,EAAE;oBAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE;oBACvB,MAAM,CAAC,CAAC,CAAC,CACZ;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO,CAAC,KAAK,CACX,gDAAgD,EAChD,KAAK,CAAC,OAAO,CACd,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,8BAA8B,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CACF;AAzHD,4DAyHC;AAED;;GAEG;AACH,SAAgB,8BAA8B,CAC5C,MAAgC;IAEhC,OAAO,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quantum Time Window Utilities for LIT Actions
|
|
3
|
+
*
|
|
4
|
+
* PRIMARY WORKFLOW FOR LIT ACTIONS:
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // 1. Wait for safe quantum moment (waits if in dead zone)
|
|
8
|
+
* await waitForSafeQuantumMoment();
|
|
9
|
+
*
|
|
10
|
+
* // 2. Validate signature timestamp (throws if invalid)
|
|
11
|
+
* validateQuantumTimestamp(timestampOnSignature);
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* The macro validateQuantumTimestamp() combines waiting + validation:
|
|
15
|
+
* - Ensures LIT Action only validates when NOT in dead zone
|
|
16
|
+
* - Ensures signature is from current quantum (prevents replay attacks)
|
|
17
|
+
* - Throws error if validation fails
|
|
18
|
+
*
|
|
19
|
+
* Dead Zone Protection (16 seconds: 8+8):
|
|
20
|
+
* - Protects against clock desynchronization
|
|
21
|
+
* - Protects against Ethereum miner timestamp manipulation (±15s)
|
|
22
|
+
* - Ensures deterministic validation across all validators
|
|
23
|
+
*
|
|
24
|
+
* See QUANTUM_TIME_WINDOW.md for full documentation.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Calculate quantum window start for given timestamp
|
|
28
|
+
*
|
|
29
|
+
* @param timestamp - Unix timestamp in seconds
|
|
30
|
+
* @returns Quantum window start timestamp
|
|
31
|
+
*/
|
|
32
|
+
export declare function getQuantumStart(timestamp: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Calculate quantum window end for given timestamp
|
|
35
|
+
*
|
|
36
|
+
* @param timestamp - Unix timestamp in seconds
|
|
37
|
+
* @returns Quantum window end timestamp
|
|
38
|
+
*/
|
|
39
|
+
export declare function getQuantumEnd(timestamp: number): number;
|
|
40
|
+
/**
|
|
41
|
+
* Get current quantum timestamp (start of current quantum)
|
|
42
|
+
*
|
|
43
|
+
* Use this for signing operations.
|
|
44
|
+
*
|
|
45
|
+
* @returns Current quantum start timestamp
|
|
46
|
+
*/
|
|
47
|
+
export declare function getCurrentQuantumTimestamp(): number;
|
|
48
|
+
/**
|
|
49
|
+
* Check if currently in dead zone (last 8s before boundary + first 8s after boundary)
|
|
50
|
+
*
|
|
51
|
+
* Dead zone = seconds 92-99 OR 0-7 of each quantum
|
|
52
|
+
*
|
|
53
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
54
|
+
* @returns True if in dead zone
|
|
55
|
+
*/
|
|
56
|
+
export declare function isInDeadZone(now?: number): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Get seconds remaining in current quantum
|
|
59
|
+
*
|
|
60
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
61
|
+
* @returns Seconds until quantum expires
|
|
62
|
+
*/
|
|
63
|
+
export declare function getSecondsRemainingInQuantum(now?: number): number;
|
|
64
|
+
/**
|
|
65
|
+
* Wait for safe quantum moment (LIT Actions use)
|
|
66
|
+
*
|
|
67
|
+
* LIT Actions must wait during dead zone to ensure deterministic validation.
|
|
68
|
+
* Waits until second 8 of next quantum (first safe second).
|
|
69
|
+
*
|
|
70
|
+
* Decision logic:
|
|
71
|
+
* - If in dead zone: Wait until second 8 of next quantum
|
|
72
|
+
* - Otherwise: Proceed immediately
|
|
73
|
+
*
|
|
74
|
+
* @returns Promise that resolves when safe to operate
|
|
75
|
+
*/
|
|
76
|
+
export declare function waitForSafeQuantumMoment(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Validate timestamp is from current quantum (throws on invalid)
|
|
79
|
+
*
|
|
80
|
+
* This is the PRIMARY macro for LIT Actions validation.
|
|
81
|
+
*
|
|
82
|
+
* Usage:
|
|
83
|
+
* 1. Wait for safe moment: await waitForSafeQuantumMoment()
|
|
84
|
+
* 2. Validate signature: validateQuantumTimestamp(signatureTimestamp)
|
|
85
|
+
*
|
|
86
|
+
* @param timestampOnSignature - Timestamp from signed message
|
|
87
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
88
|
+
* @throws Error if timestamp is not from current quantum
|
|
89
|
+
*/
|
|
90
|
+
export declare function validateQuantumTimestamp(timestampOnSignature: number, now?: number): void;
|
|
91
|
+
/**
|
|
92
|
+
* Check if timestamp is valid (boolean version - does not throw)
|
|
93
|
+
*
|
|
94
|
+
* Rules:
|
|
95
|
+
* 1. Must be current quantum (not previous, not future)
|
|
96
|
+
*
|
|
97
|
+
* NOTE: Dead zone doesn't invalidate timestamps - only affects WHEN we validate.
|
|
98
|
+
* LIT Actions should WAIT during dead zone, but can validate any timestamp from current quantum.
|
|
99
|
+
*
|
|
100
|
+
* @param signatureTimestamp - Timestamp from signed message
|
|
101
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
102
|
+
* @returns True if valid
|
|
103
|
+
*/
|
|
104
|
+
export declare function isTimestampValid(signatureTimestamp: number, now?: number): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Get next quantum timestamp
|
|
107
|
+
*
|
|
108
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
109
|
+
* @returns Next quantum timestamp
|
|
110
|
+
*/
|
|
111
|
+
export declare function getNextQuantumTimestamp(now?: number): number;
|
|
112
|
+
/**
|
|
113
|
+
* Get quantum info for debugging
|
|
114
|
+
*
|
|
115
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
116
|
+
* @returns Quantum information object
|
|
117
|
+
*/
|
|
118
|
+
export declare function getQuantumInfo(now?: number): {
|
|
119
|
+
currentTime: number;
|
|
120
|
+
currentQuantum: number;
|
|
121
|
+
timeInQuantum: number;
|
|
122
|
+
secondsRemaining: number;
|
|
123
|
+
isInDeadZone: boolean;
|
|
124
|
+
nextQuantum: number;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Get safe quantum info (async - waits if needed)
|
|
128
|
+
*
|
|
129
|
+
* This is useful for debugging but not typically needed in LIT Actions.
|
|
130
|
+
* LIT Actions should use waitForSafeQuantumMoment() + validateQuantumTimestamp().
|
|
131
|
+
*
|
|
132
|
+
* @returns Promise resolving to quantum information for safe operation
|
|
133
|
+
*/
|
|
134
|
+
export declare function getSafeQuantumInfo(): Promise<{
|
|
135
|
+
currentTime: number;
|
|
136
|
+
currentQuantum: number;
|
|
137
|
+
timeInQuantum: number;
|
|
138
|
+
secondsRemaining: number;
|
|
139
|
+
isInDeadZone: boolean;
|
|
140
|
+
nextQuantum: number;
|
|
141
|
+
}>;
|
|
142
|
+
/**
|
|
143
|
+
* Format quantum info for debugging
|
|
144
|
+
*
|
|
145
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
146
|
+
* @returns Human-readable quantum info
|
|
147
|
+
*/
|
|
148
|
+
export declare function formatQuantumInfo(now?: number): string;
|
|
149
|
+
//# sourceMappingURL=quantum-time.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantum-time.module.d.ts","sourceRoot":"","sources":["../../../src/modules/quantum-time.module.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAOH;;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AM,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAMD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAgBtD"}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Quantum Time Window Utilities for LIT Actions
|
|
4
|
+
*
|
|
5
|
+
* PRIMARY WORKFLOW FOR LIT ACTIONS:
|
|
6
|
+
*
|
|
7
|
+
* ```typescript
|
|
8
|
+
* // 1. Wait for safe quantum moment (waits if in dead zone)
|
|
9
|
+
* await waitForSafeQuantumMoment();
|
|
10
|
+
*
|
|
11
|
+
* // 2. Validate signature timestamp (throws if invalid)
|
|
12
|
+
* validateQuantumTimestamp(timestampOnSignature);
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The macro validateQuantumTimestamp() combines waiting + validation:
|
|
16
|
+
* - Ensures LIT Action only validates when NOT in dead zone
|
|
17
|
+
* - Ensures signature is from current quantum (prevents replay attacks)
|
|
18
|
+
* - Throws error if validation fails
|
|
19
|
+
*
|
|
20
|
+
* Dead Zone Protection (16 seconds: 8+8):
|
|
21
|
+
* - Protects against clock desynchronization
|
|
22
|
+
* - Protects against Ethereum miner timestamp manipulation (±15s)
|
|
23
|
+
* - Ensures deterministic validation across all validators
|
|
24
|
+
*
|
|
25
|
+
* See QUANTUM_TIME_WINDOW.md for full documentation.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.getQuantumStart = getQuantumStart;
|
|
29
|
+
exports.getQuantumEnd = getQuantumEnd;
|
|
30
|
+
exports.getCurrentQuantumTimestamp = getCurrentQuantumTimestamp;
|
|
31
|
+
exports.isInDeadZone = isInDeadZone;
|
|
32
|
+
exports.getSecondsRemainingInQuantum = getSecondsRemainingInQuantum;
|
|
33
|
+
exports.waitForSafeQuantumMoment = waitForSafeQuantumMoment;
|
|
34
|
+
exports.validateQuantumTimestamp = validateQuantumTimestamp;
|
|
35
|
+
exports.isTimestampValid = isTimestampValid;
|
|
36
|
+
exports.getNextQuantumTimestamp = getNextQuantumTimestamp;
|
|
37
|
+
exports.getQuantumInfo = getQuantumInfo;
|
|
38
|
+
exports.getSafeQuantumInfo = getSafeQuantumInfo;
|
|
39
|
+
exports.formatQuantumInfo = formatQuantumInfo;
|
|
40
|
+
const constants_1 = require("../constants");
|
|
41
|
+
/**
|
|
42
|
+
* Calculate quantum window start for given timestamp
|
|
43
|
+
*
|
|
44
|
+
* @param timestamp - Unix timestamp in seconds
|
|
45
|
+
* @returns Quantum window start timestamp
|
|
46
|
+
*/
|
|
47
|
+
function getQuantumStart(timestamp) {
|
|
48
|
+
return (Math.floor(timestamp / constants_1.QUANTUM_WINDOW_SECONDS) * constants_1.QUANTUM_WINDOW_SECONDS);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Calculate quantum window end for given timestamp
|
|
52
|
+
*
|
|
53
|
+
* @param timestamp - Unix timestamp in seconds
|
|
54
|
+
* @returns Quantum window end timestamp
|
|
55
|
+
*/
|
|
56
|
+
function getQuantumEnd(timestamp) {
|
|
57
|
+
return getQuantumStart(timestamp) + constants_1.QUANTUM_WINDOW_SECONDS;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get current quantum timestamp (start of current quantum)
|
|
61
|
+
*
|
|
62
|
+
* Use this for signing operations.
|
|
63
|
+
*
|
|
64
|
+
* @returns Current quantum start timestamp
|
|
65
|
+
*/
|
|
66
|
+
function getCurrentQuantumTimestamp() {
|
|
67
|
+
const now = Math.floor(Date.now() / 1000);
|
|
68
|
+
return getQuantumStart(now);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if currently in dead zone (last 8s before boundary + first 8s after boundary)
|
|
72
|
+
*
|
|
73
|
+
* Dead zone = seconds 92-99 OR 0-7 of each quantum
|
|
74
|
+
*
|
|
75
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
76
|
+
* @returns True if in dead zone
|
|
77
|
+
*/
|
|
78
|
+
function isInDeadZone(now) {
|
|
79
|
+
const currentTime = now ?? Math.floor(Date.now() / 1000);
|
|
80
|
+
const timeInQuantum = currentTime % constants_1.QUANTUM_WINDOW_SECONDS;
|
|
81
|
+
// Last 8 seconds OR first 8 seconds
|
|
82
|
+
return timeInQuantum >= 92 || timeInQuantum < 8;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get seconds remaining in current quantum
|
|
86
|
+
*
|
|
87
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
88
|
+
* @returns Seconds until quantum expires
|
|
89
|
+
*/
|
|
90
|
+
function getSecondsRemainingInQuantum(now) {
|
|
91
|
+
const currentTime = now ?? Math.floor(Date.now() / 1000);
|
|
92
|
+
const timeInQuantum = currentTime % constants_1.QUANTUM_WINDOW_SECONDS;
|
|
93
|
+
return constants_1.QUANTUM_WINDOW_SECONDS - timeInQuantum;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Wait for safe quantum moment (LIT Actions use)
|
|
97
|
+
*
|
|
98
|
+
* LIT Actions must wait during dead zone to ensure deterministic validation.
|
|
99
|
+
* Waits until second 8 of next quantum (first safe second).
|
|
100
|
+
*
|
|
101
|
+
* Decision logic:
|
|
102
|
+
* - If in dead zone: Wait until second 8 of next quantum
|
|
103
|
+
* - Otherwise: Proceed immediately
|
|
104
|
+
*
|
|
105
|
+
* @returns Promise that resolves when safe to operate
|
|
106
|
+
*/
|
|
107
|
+
async function waitForSafeQuantumMoment() {
|
|
108
|
+
const now = Math.floor(Date.now() / 1000);
|
|
109
|
+
const timeInQuantum = now % constants_1.QUANTUM_WINDOW_SECONDS;
|
|
110
|
+
if (!isInDeadZone(now)) {
|
|
111
|
+
return; // Safe to proceed immediately
|
|
112
|
+
}
|
|
113
|
+
// Calculate wait time to reach second 8 of next quantum
|
|
114
|
+
let waitSeconds;
|
|
115
|
+
if (timeInQuantum >= 92) {
|
|
116
|
+
// In dead zone before boundary (seconds 92-99)
|
|
117
|
+
// Wait to second 8 of next quantum
|
|
118
|
+
waitSeconds = 100 - timeInQuantum + 8;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// In dead zone after boundary (seconds 0-7)
|
|
122
|
+
// Wait until second 8
|
|
123
|
+
waitSeconds = 8 - timeInQuantum;
|
|
124
|
+
}
|
|
125
|
+
console.log(`[Quantum] Waiting ${waitSeconds}s for safe moment (current time in quantum: ${timeInQuantum}s)`);
|
|
126
|
+
await new Promise((resolve) => setTimeout(resolve, waitSeconds * 1000));
|
|
127
|
+
console.log(`[Quantum] Safe quantum ready: ${getCurrentQuantumTimestamp()}`);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Validate timestamp is from current quantum (throws on invalid)
|
|
131
|
+
*
|
|
132
|
+
* This is the PRIMARY macro for LIT Actions validation.
|
|
133
|
+
*
|
|
134
|
+
* Usage:
|
|
135
|
+
* 1. Wait for safe moment: await waitForSafeQuantumMoment()
|
|
136
|
+
* 2. Validate signature: validateQuantumTimestamp(signatureTimestamp)
|
|
137
|
+
*
|
|
138
|
+
* @param timestampOnSignature - Timestamp from signed message
|
|
139
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
140
|
+
* @throws Error if timestamp is not from current quantum
|
|
141
|
+
*/
|
|
142
|
+
function validateQuantumTimestamp(timestampOnSignature, now) {
|
|
143
|
+
const currentTime = now ?? Math.floor(Date.now() / 1000);
|
|
144
|
+
const currentQuantum = getQuantumStart(currentTime);
|
|
145
|
+
const signatureQuantum = getQuantumStart(timestampOnSignature);
|
|
146
|
+
// Must be current quantum
|
|
147
|
+
if (signatureQuantum !== currentQuantum) {
|
|
148
|
+
throw new Error(`[Quantum] Invalid timestamp: signature from quantum ${signatureQuantum}, current quantum is ${currentQuantum}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Check if timestamp is valid (boolean version - does not throw)
|
|
153
|
+
*
|
|
154
|
+
* Rules:
|
|
155
|
+
* 1. Must be current quantum (not previous, not future)
|
|
156
|
+
*
|
|
157
|
+
* NOTE: Dead zone doesn't invalidate timestamps - only affects WHEN we validate.
|
|
158
|
+
* LIT Actions should WAIT during dead zone, but can validate any timestamp from current quantum.
|
|
159
|
+
*
|
|
160
|
+
* @param signatureTimestamp - Timestamp from signed message
|
|
161
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
162
|
+
* @returns True if valid
|
|
163
|
+
*/
|
|
164
|
+
function isTimestampValid(signatureTimestamp, now) {
|
|
165
|
+
const currentTime = now ?? Math.floor(Date.now() / 1000);
|
|
166
|
+
const currentQuantum = getQuantumStart(currentTime);
|
|
167
|
+
const signatureQuantum = getQuantumStart(signatureTimestamp);
|
|
168
|
+
// Must be current quantum
|
|
169
|
+
if (signatureQuantum !== currentQuantum) {
|
|
170
|
+
console.error(`[Quantum] Signature not from current quantum:`, `\n Current: ${currentQuantum}`, `\n Signature: ${signatureQuantum}`);
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get next quantum timestamp
|
|
177
|
+
*
|
|
178
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
179
|
+
* @returns Next quantum timestamp
|
|
180
|
+
*/
|
|
181
|
+
function getNextQuantumTimestamp(now) {
|
|
182
|
+
const currentTime = now ?? Math.floor(Date.now() / 1000);
|
|
183
|
+
const currentQuantum = getQuantumStart(currentTime);
|
|
184
|
+
return currentQuantum + constants_1.QUANTUM_WINDOW_SECONDS;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get quantum info for debugging
|
|
188
|
+
*
|
|
189
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
190
|
+
* @returns Quantum information object
|
|
191
|
+
*/
|
|
192
|
+
function getQuantumInfo(now) {
|
|
193
|
+
const currentTime = now ?? Math.floor(Date.now() / 1000);
|
|
194
|
+
const currentQuantum = getQuantumStart(currentTime);
|
|
195
|
+
const timeInQuantum = currentTime % constants_1.QUANTUM_WINDOW_SECONDS;
|
|
196
|
+
const secondsRemaining = constants_1.QUANTUM_WINDOW_SECONDS - timeInQuantum;
|
|
197
|
+
return {
|
|
198
|
+
currentTime,
|
|
199
|
+
currentQuantum,
|
|
200
|
+
timeInQuantum,
|
|
201
|
+
secondsRemaining,
|
|
202
|
+
isInDeadZone: isInDeadZone(currentTime),
|
|
203
|
+
nextQuantum: getNextQuantumTimestamp(currentTime),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get safe quantum info (async - waits if needed)
|
|
208
|
+
*
|
|
209
|
+
* This is useful for debugging but not typically needed in LIT Actions.
|
|
210
|
+
* LIT Actions should use waitForSafeQuantumMoment() + validateQuantumTimestamp().
|
|
211
|
+
*
|
|
212
|
+
* @returns Promise resolving to quantum information for safe operation
|
|
213
|
+
*/
|
|
214
|
+
async function getSafeQuantumInfo() {
|
|
215
|
+
// Wait for safe moment if needed
|
|
216
|
+
await waitForSafeQuantumMoment();
|
|
217
|
+
// Now get info (guaranteed to be outside dead zone)
|
|
218
|
+
return getQuantumInfo();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Format quantum info for debugging
|
|
222
|
+
*
|
|
223
|
+
* @param now - Current Unix timestamp (defaults to Date.now()/1000)
|
|
224
|
+
* @returns Human-readable quantum info
|
|
225
|
+
*/
|
|
226
|
+
function formatQuantumInfo(now) {
|
|
227
|
+
const info = getQuantumInfo(now);
|
|
228
|
+
const startDate = new Date(info.currentQuantum * 1000).toISOString();
|
|
229
|
+
const endDate = new Date((info.currentQuantum + constants_1.QUANTUM_WINDOW_SECONDS) * 1000).toISOString();
|
|
230
|
+
return [
|
|
231
|
+
`Quantum Window:`,
|
|
232
|
+
` Start: ${startDate} (${info.currentQuantum})`,
|
|
233
|
+
` End: ${endDate} (${info.currentQuantum + constants_1.QUANTUM_WINDOW_SECONDS})`,
|
|
234
|
+
` Duration: ${constants_1.QUANTUM_WINDOW_SECONDS}s`,
|
|
235
|
+
` Time in quantum: ${info.timeInQuantum}s`,
|
|
236
|
+
` Remaining: ${info.secondsRemaining}s`,
|
|
237
|
+
` In Dead Zone: ${info.isInDeadZone}`,
|
|
238
|
+
].join("\n");
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=quantum-time.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantum-time.module.js","sourceRoot":"","sources":["../../../src/modules/quantum-time.module.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;AAaH,0CAIC;AAQD,sCAEC;AASD,gEAGC;AAUD,oCAKC;AAQD,oEAIC;AAaD,4DA4BC;AAeD,4DAcC;AAeD,4CAmBC;AAQD,0DAIC;AAQD,wCAqBC;AAUD,gDAaC;AAQD,8CAgBC;AAhQD,4CAIsB;AACtB;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,SAAiB;IAC/C,OAAO,CACL,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,kCAAsB,CAAC,GAAG,kCAAsB,CACxE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,SAAiB;IAC7C,OAAO,eAAe,CAAC,SAAS,CAAC,GAAG,kCAAsB,CAAC;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,0BAA0B;IACxC,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,YAAY,CAAC,GAAY;IACvC,MAAM,WAAW,GAAG,GA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