@gvnrdao/dh-sdk 0.0.125 → 0.0.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.js +131 -70
- package/dist/index.mjs +131 -70
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -602,6 +602,7 @@ interface BaseSDKConfig {
|
|
|
602
602
|
bitcoinRpcUrl?: string;
|
|
603
603
|
bitcoinProviders?: BitcoinProviderConfig[];
|
|
604
604
|
bitcoinConsensusMode?: "single" | "majority";
|
|
605
|
+
priceProviders?: PriceProviderConfig[];
|
|
605
606
|
bitcoinFaucetUrl?: string;
|
|
606
607
|
contractAddresses?: ContractAddresses;
|
|
607
608
|
subgraphs?: {
|
|
@@ -766,6 +767,13 @@ interface BitcoinProviderConfig {
|
|
|
766
767
|
name?: string;
|
|
767
768
|
priority?: number;
|
|
768
769
|
}
|
|
770
|
+
/**
|
|
771
|
+
* Price Provider Configuration
|
|
772
|
+
*/
|
|
773
|
+
interface PriceProviderConfig {
|
|
774
|
+
name: string;
|
|
775
|
+
apiKey?: string;
|
|
776
|
+
}
|
|
769
777
|
|
|
770
778
|
interface TypedDeferredTopicFilter<_TCEvent extends TypedContractEvent> extends DeferredTopicFilter {
|
|
771
779
|
}
|
|
@@ -5045,10 +5053,10 @@ declare class DiamondHandsSDK {
|
|
|
5045
5053
|
* Goal: Start LIT Action execution early in a quantum window to maximize
|
|
5046
5054
|
* the chance that contract submission happens within safe window.
|
|
5047
5055
|
*
|
|
5048
|
-
* Optimal window: 10-15 seconds into quantum (
|
|
5056
|
+
* Optimal window: 10-15 seconds into quantum (100s window)
|
|
5049
5057
|
* - Narrower window for more predictable timing
|
|
5050
5058
|
* - Avoids start dead zone (0-7s)
|
|
5051
|
-
* - Leaves maximum time for LIT Action + submission (up to
|
|
5059
|
+
* - Leaves maximum time for LIT Action + submission (up to 85s with 100s window)
|
|
5052
5060
|
*
|
|
5053
5061
|
* MAX WAIT: 50 seconds to cover full quantum transition without landing in dead zone
|
|
5054
5062
|
*/
|
|
@@ -5073,7 +5081,7 @@ declare class DiamondHandsSDK {
|
|
|
5073
5081
|
* This forces the caller to retry with a fresh signature rather than risk hitting dead zone
|
|
5074
5082
|
* during transaction submission.
|
|
5075
5083
|
*
|
|
5076
|
-
* Safe submission window: 10-
|
|
5084
|
+
* Safe submission window: 10-91 seconds into quantum (81s window with 100s quantum)
|
|
5077
5085
|
* - Avoids start dead zone: 0-9s (extra buffer for clock drift)
|
|
5078
5086
|
* - Avoids end dead zone: 192-199s
|
|
5079
5087
|
* - 42s buffer before end dead zone accounts for:
|
|
@@ -6794,4 +6802,4 @@ declare const DEFAULT_BITCOIN_CONSENSUS_MODE: "majority";
|
|
|
6794
6802
|
*/
|
|
6795
6803
|
declare const MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS = 2;
|
|
6796
6804
|
|
|
6797
|
-
export { AuditTrail, AuthParamsValidation, AuthorizationParams, AuthorizationRequest, AuthorizationResult, BPS, BPSConversions, BTCDepositRequest, BTCDepositResult, BTCProof, BTCTransaction, BTCWithdrawalResult, BasicNetworkConfig, BitcoinAddresses, BitcoinBalanceResult, BitcoinNetwork, BitcoinOperations, BitcoinOperationsConfig, BitcoinProviderConfig, BitcoinUTXO, BlockNumber, CacheConfig, CacheManager, CacheStats, ClosePositionAuthParams, ConfirmationResult, ContractAddresses, ContractCallOptions, ContractManager, ContractManagerConfig, ContractQueryOptions, ContractTransactionResult, CreateLoanAuthParams, CreateLoanRequest, CreateLoanResult, DEFAULT_BALANCE_CACHE_SIZE, DEFAULT_BALANCE_CACHE_TTL_MS, DEFAULT_BITCOIN_CONSENSUS_MODE, DEFAULT_CACHE_CLEANUP_INTERVAL_MS, DEFAULT_CONCURRENCY_LIMIT, DEFAULT_LIT_NETWORKS, DEFAULT_MAX_RETRIES, DEFAULT_NETWORKS, DEFAULT_NETWORK_CONFIG, DEFAULT_OPERATION_TIMEOUT_MS, DEFAULT_PAGINATION_ROWS, DEFAULT_PKP_CACHE_SIZE, DEFAULT_PKP_CACHE_TTL_MS, DebugInfo, DiamondHandsSDK, DiamondHandsSDKConfig, EnrichedBitcoinBalance, EnvironmentName, ErrorCategory, ErrorSeverity, EventFilter, EventHelpers, EventLog, ExtendTermAuthParams, Failure, FeeDistributionEvent, IBTCProof, ILitAction, IPKPManager, IUCDMinting, LRUCache, LiquidationEvent, LiquidationRequest, LitActionAuth, LitActionParams, LitActionResult, LitActionValidationResult, LoanCreationAudit, LoanCreator, LoanCreatorConfig, LoanData, LoanDataDetail, LoanEvents, LoanEventsFilter, LoanManagerConfig, LoanQuery, LoanQueryConfig, LoanQueryFilters, LoanStatus, LoansQuery, MAX_PAGINATION_ROWS, MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS, ManagedContracts, MintUCDAuthParams, MintingParams, MintingResult, MockTokenManager, MockTokenManagerConfig, MockTokenTransactionResult, MonitoringOptions, NETWORK_CONFIGS, NetworkConfig, PKPCreationRequest, PKPCreationResult, PKPData, PKPIssuanceRequest, PKPManager, PKPManagerConfig, PKPSigningRequest, PKPSigningResult, PKPValidationData, PKPValidationRequest, PKPValidationResult, POSITION_MANAGER_ABI, PRICE_FEED_CONSUMER_ABI, PSM_ABI, PSM_MAX_OPERATIONS_PER_WINDOW, PSM_RATE_LIMIT_RESET_BLOCKS, PaginatedLoansResponse, PaginatedResult, Pagination, PaginationParams, PartialPaymentRequest, PartialPaymentResult, PaymentEvent, PaymentType, Position, PositionDetails, PositionQueryOptions, PositionQueryResult, PositionStatus, PositionWithBTCStatus, RepayDebtAuthParams, Result$1 as Result, RetryConfig, RewardDistribution, SDKConfig, SDKError, SDKInitOptions, SDKMode, SDK_DEFAULTS, SDK_ERROR_MESSAGES, Satoshis, SatoshisConversions, ServiceModeConfig, StandaloneModeConfig, StatusUpdateEvent, Success, THE_GRAPH_MAX_BATCH_SIZE, UCD, UCDConversions, UCDMintEvent, UCDMintRequest, UCDMintResult, UCD_TOKEN_ABI, UnixTimestamp, ValidationRequest, Wei, WeiConversions, WithdrawBTCAuthParams, andThen, collectFailures, collectSuccesses, combine, createBitcoinOperations, createCacheManager, createContractManager, createLoanCreator, createLoanQuery, createMockTokenManager, createPKPManager, DiamondHandsSDK as default, envLog, failure, firstSuccess, fromPromise, getAllNetworkConfigs, getCurrentEnvironment, getLitNetworkConfig, getNetworkConfig, getNetworkConfigByName, isClosePositionAuth, isCreateLoanAuth, isExtendTermAuth, isFailure, isMintUCDAuth, isNetworkSupported, isRepayDebtAuth, isServiceModeConfig, isStandaloneModeConfig, isSuccess, isValidPaymentType, isValidPositionStatus, isWithdrawBTCAuth, loadSDKConfig, map, mapError, match, numericToPositionStatus, success, toPromise, tryCatch, tryCatchAsync, unwrap, unwrapOr, validateSDKConfig, validateSDKEnvironment, validateServiceModeConfig, validateStandaloneModeConfig };
|
|
6805
|
+
export { AuditTrail, AuthParamsValidation, AuthorizationParams, AuthorizationRequest, AuthorizationResult, BPS, BPSConversions, BTCDepositRequest, BTCDepositResult, BTCProof, BTCTransaction, BTCWithdrawalResult, BasicNetworkConfig, BitcoinAddresses, BitcoinBalanceResult, BitcoinNetwork, BitcoinOperations, BitcoinOperationsConfig, BitcoinProviderConfig, BitcoinUTXO, BlockNumber, CacheConfig, CacheManager, CacheStats, ClosePositionAuthParams, ConfirmationResult, ContractAddresses, ContractCallOptions, ContractManager, ContractManagerConfig, ContractQueryOptions, ContractTransactionResult, CreateLoanAuthParams, CreateLoanRequest, CreateLoanResult, DEFAULT_BALANCE_CACHE_SIZE, DEFAULT_BALANCE_CACHE_TTL_MS, DEFAULT_BITCOIN_CONSENSUS_MODE, DEFAULT_CACHE_CLEANUP_INTERVAL_MS, DEFAULT_CONCURRENCY_LIMIT, DEFAULT_LIT_NETWORKS, DEFAULT_MAX_RETRIES, DEFAULT_NETWORKS, DEFAULT_NETWORK_CONFIG, DEFAULT_OPERATION_TIMEOUT_MS, DEFAULT_PAGINATION_ROWS, DEFAULT_PKP_CACHE_SIZE, DEFAULT_PKP_CACHE_TTL_MS, DebugInfo, DiamondHandsSDK, DiamondHandsSDKConfig, EnrichedBitcoinBalance, EnvironmentName, ErrorCategory, ErrorSeverity, EventFilter, EventHelpers, EventLog, ExtendTermAuthParams, Failure, FeeDistributionEvent, IBTCProof, ILitAction, IPKPManager, IUCDMinting, LRUCache, LiquidationEvent, LiquidationRequest, LitActionAuth, LitActionParams, LitActionResult, LitActionValidationResult, LoanCreationAudit, LoanCreator, LoanCreatorConfig, LoanData, LoanDataDetail, LoanEvents, LoanEventsFilter, LoanManagerConfig, LoanQuery, LoanQueryConfig, LoanQueryFilters, LoanStatus, LoansQuery, MAX_PAGINATION_ROWS, MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS, ManagedContracts, MintUCDAuthParams, MintingParams, MintingResult, MockTokenManager, MockTokenManagerConfig, MockTokenTransactionResult, MonitoringOptions, NETWORK_CONFIGS, NetworkConfig, PKPCreationRequest, PKPCreationResult, PKPData, PKPIssuanceRequest, PKPManager, PKPManagerConfig, PKPSigningRequest, PKPSigningResult, PKPValidationData, PKPValidationRequest, PKPValidationResult, POSITION_MANAGER_ABI, PRICE_FEED_CONSUMER_ABI, PSM_ABI, PSM_MAX_OPERATIONS_PER_WINDOW, PSM_RATE_LIMIT_RESET_BLOCKS, PaginatedLoansResponse, PaginatedResult, Pagination, PaginationParams, PartialPaymentRequest, PartialPaymentResult, PaymentEvent, PaymentType, Position, PositionDetails, PositionQueryOptions, PositionQueryResult, PositionStatus, PositionWithBTCStatus, PriceProviderConfig, RepayDebtAuthParams, Result$1 as Result, RetryConfig, RewardDistribution, SDKConfig, SDKError, SDKInitOptions, SDKMode, SDK_DEFAULTS, SDK_ERROR_MESSAGES, Satoshis, SatoshisConversions, ServiceModeConfig, StandaloneModeConfig, StatusUpdateEvent, Success, THE_GRAPH_MAX_BATCH_SIZE, UCD, UCDConversions, UCDMintEvent, UCDMintRequest, UCDMintResult, UCD_TOKEN_ABI, UnixTimestamp, ValidationRequest, Wei, WeiConversions, WithdrawBTCAuthParams, andThen, collectFailures, collectSuccesses, combine, createBitcoinOperations, createCacheManager, createContractManager, createLoanCreator, createLoanQuery, createMockTokenManager, createPKPManager, DiamondHandsSDK as default, envLog, failure, firstSuccess, fromPromise, getAllNetworkConfigs, getCurrentEnvironment, getLitNetworkConfig, getNetworkConfig, getNetworkConfigByName, isClosePositionAuth, isCreateLoanAuth, isExtendTermAuth, isFailure, isMintUCDAuth, isNetworkSupported, isRepayDebtAuth, isServiceModeConfig, isStandaloneModeConfig, isSuccess, isValidPaymentType, isValidPositionStatus, isWithdrawBTCAuth, loadSDKConfig, map, mapError, match, numericToPositionStatus, success, toPromise, tryCatch, tryCatchAsync, unwrap, unwrapOr, validateSDKConfig, validateSDKEnvironment, validateServiceModeConfig, validateStandaloneModeConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -602,6 +602,7 @@ interface BaseSDKConfig {
|
|
|
602
602
|
bitcoinRpcUrl?: string;
|
|
603
603
|
bitcoinProviders?: BitcoinProviderConfig[];
|
|
604
604
|
bitcoinConsensusMode?: "single" | "majority";
|
|
605
|
+
priceProviders?: PriceProviderConfig[];
|
|
605
606
|
bitcoinFaucetUrl?: string;
|
|
606
607
|
contractAddresses?: ContractAddresses;
|
|
607
608
|
subgraphs?: {
|
|
@@ -766,6 +767,13 @@ interface BitcoinProviderConfig {
|
|
|
766
767
|
name?: string;
|
|
767
768
|
priority?: number;
|
|
768
769
|
}
|
|
770
|
+
/**
|
|
771
|
+
* Price Provider Configuration
|
|
772
|
+
*/
|
|
773
|
+
interface PriceProviderConfig {
|
|
774
|
+
name: string;
|
|
775
|
+
apiKey?: string;
|
|
776
|
+
}
|
|
769
777
|
|
|
770
778
|
interface TypedDeferredTopicFilter<_TCEvent extends TypedContractEvent> extends DeferredTopicFilter {
|
|
771
779
|
}
|
|
@@ -5045,10 +5053,10 @@ declare class DiamondHandsSDK {
|
|
|
5045
5053
|
* Goal: Start LIT Action execution early in a quantum window to maximize
|
|
5046
5054
|
* the chance that contract submission happens within safe window.
|
|
5047
5055
|
*
|
|
5048
|
-
* Optimal window: 10-15 seconds into quantum (
|
|
5056
|
+
* Optimal window: 10-15 seconds into quantum (100s window)
|
|
5049
5057
|
* - Narrower window for more predictable timing
|
|
5050
5058
|
* - Avoids start dead zone (0-7s)
|
|
5051
|
-
* - Leaves maximum time for LIT Action + submission (up to
|
|
5059
|
+
* - Leaves maximum time for LIT Action + submission (up to 85s with 100s window)
|
|
5052
5060
|
*
|
|
5053
5061
|
* MAX WAIT: 50 seconds to cover full quantum transition without landing in dead zone
|
|
5054
5062
|
*/
|
|
@@ -5073,7 +5081,7 @@ declare class DiamondHandsSDK {
|
|
|
5073
5081
|
* This forces the caller to retry with a fresh signature rather than risk hitting dead zone
|
|
5074
5082
|
* during transaction submission.
|
|
5075
5083
|
*
|
|
5076
|
-
* Safe submission window: 10-
|
|
5084
|
+
* Safe submission window: 10-91 seconds into quantum (81s window with 100s quantum)
|
|
5077
5085
|
* - Avoids start dead zone: 0-9s (extra buffer for clock drift)
|
|
5078
5086
|
* - Avoids end dead zone: 192-199s
|
|
5079
5087
|
* - 42s buffer before end dead zone accounts for:
|
|
@@ -6794,4 +6802,4 @@ declare const DEFAULT_BITCOIN_CONSENSUS_MODE: "majority";
|
|
|
6794
6802
|
*/
|
|
6795
6803
|
declare const MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS = 2;
|
|
6796
6804
|
|
|
6797
|
-
export { AuditTrail, AuthParamsValidation, AuthorizationParams, AuthorizationRequest, AuthorizationResult, BPS, BPSConversions, BTCDepositRequest, BTCDepositResult, BTCProof, BTCTransaction, BTCWithdrawalResult, BasicNetworkConfig, BitcoinAddresses, BitcoinBalanceResult, BitcoinNetwork, BitcoinOperations, BitcoinOperationsConfig, BitcoinProviderConfig, BitcoinUTXO, BlockNumber, CacheConfig, CacheManager, CacheStats, ClosePositionAuthParams, ConfirmationResult, ContractAddresses, ContractCallOptions, ContractManager, ContractManagerConfig, ContractQueryOptions, ContractTransactionResult, CreateLoanAuthParams, CreateLoanRequest, CreateLoanResult, DEFAULT_BALANCE_CACHE_SIZE, DEFAULT_BALANCE_CACHE_TTL_MS, DEFAULT_BITCOIN_CONSENSUS_MODE, DEFAULT_CACHE_CLEANUP_INTERVAL_MS, DEFAULT_CONCURRENCY_LIMIT, DEFAULT_LIT_NETWORKS, DEFAULT_MAX_RETRIES, DEFAULT_NETWORKS, DEFAULT_NETWORK_CONFIG, DEFAULT_OPERATION_TIMEOUT_MS, DEFAULT_PAGINATION_ROWS, DEFAULT_PKP_CACHE_SIZE, DEFAULT_PKP_CACHE_TTL_MS, DebugInfo, DiamondHandsSDK, DiamondHandsSDKConfig, EnrichedBitcoinBalance, EnvironmentName, ErrorCategory, ErrorSeverity, EventFilter, EventHelpers, EventLog, ExtendTermAuthParams, Failure, FeeDistributionEvent, IBTCProof, ILitAction, IPKPManager, IUCDMinting, LRUCache, LiquidationEvent, LiquidationRequest, LitActionAuth, LitActionParams, LitActionResult, LitActionValidationResult, LoanCreationAudit, LoanCreator, LoanCreatorConfig, LoanData, LoanDataDetail, LoanEvents, LoanEventsFilter, LoanManagerConfig, LoanQuery, LoanQueryConfig, LoanQueryFilters, LoanStatus, LoansQuery, MAX_PAGINATION_ROWS, MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS, ManagedContracts, MintUCDAuthParams, MintingParams, MintingResult, MockTokenManager, MockTokenManagerConfig, MockTokenTransactionResult, MonitoringOptions, NETWORK_CONFIGS, NetworkConfig, PKPCreationRequest, PKPCreationResult, PKPData, PKPIssuanceRequest, PKPManager, PKPManagerConfig, PKPSigningRequest, PKPSigningResult, PKPValidationData, PKPValidationRequest, PKPValidationResult, POSITION_MANAGER_ABI, PRICE_FEED_CONSUMER_ABI, PSM_ABI, PSM_MAX_OPERATIONS_PER_WINDOW, PSM_RATE_LIMIT_RESET_BLOCKS, PaginatedLoansResponse, PaginatedResult, Pagination, PaginationParams, PartialPaymentRequest, PartialPaymentResult, PaymentEvent, PaymentType, Position, PositionDetails, PositionQueryOptions, PositionQueryResult, PositionStatus, PositionWithBTCStatus, RepayDebtAuthParams, Result$1 as Result, RetryConfig, RewardDistribution, SDKConfig, SDKError, SDKInitOptions, SDKMode, SDK_DEFAULTS, SDK_ERROR_MESSAGES, Satoshis, SatoshisConversions, ServiceModeConfig, StandaloneModeConfig, StatusUpdateEvent, Success, THE_GRAPH_MAX_BATCH_SIZE, UCD, UCDConversions, UCDMintEvent, UCDMintRequest, UCDMintResult, UCD_TOKEN_ABI, UnixTimestamp, ValidationRequest, Wei, WeiConversions, WithdrawBTCAuthParams, andThen, collectFailures, collectSuccesses, combine, createBitcoinOperations, createCacheManager, createContractManager, createLoanCreator, createLoanQuery, createMockTokenManager, createPKPManager, DiamondHandsSDK as default, envLog, failure, firstSuccess, fromPromise, getAllNetworkConfigs, getCurrentEnvironment, getLitNetworkConfig, getNetworkConfig, getNetworkConfigByName, isClosePositionAuth, isCreateLoanAuth, isExtendTermAuth, isFailure, isMintUCDAuth, isNetworkSupported, isRepayDebtAuth, isServiceModeConfig, isStandaloneModeConfig, isSuccess, isValidPaymentType, isValidPositionStatus, isWithdrawBTCAuth, loadSDKConfig, map, mapError, match, numericToPositionStatus, success, toPromise, tryCatch, tryCatchAsync, unwrap, unwrapOr, validateSDKConfig, validateSDKEnvironment, validateServiceModeConfig, validateStandaloneModeConfig };
|
|
6805
|
+
export { AuditTrail, AuthParamsValidation, AuthorizationParams, AuthorizationRequest, AuthorizationResult, BPS, BPSConversions, BTCDepositRequest, BTCDepositResult, BTCProof, BTCTransaction, BTCWithdrawalResult, BasicNetworkConfig, BitcoinAddresses, BitcoinBalanceResult, BitcoinNetwork, BitcoinOperations, BitcoinOperationsConfig, BitcoinProviderConfig, BitcoinUTXO, BlockNumber, CacheConfig, CacheManager, CacheStats, ClosePositionAuthParams, ConfirmationResult, ContractAddresses, ContractCallOptions, ContractManager, ContractManagerConfig, ContractQueryOptions, ContractTransactionResult, CreateLoanAuthParams, CreateLoanRequest, CreateLoanResult, DEFAULT_BALANCE_CACHE_SIZE, DEFAULT_BALANCE_CACHE_TTL_MS, DEFAULT_BITCOIN_CONSENSUS_MODE, DEFAULT_CACHE_CLEANUP_INTERVAL_MS, DEFAULT_CONCURRENCY_LIMIT, DEFAULT_LIT_NETWORKS, DEFAULT_MAX_RETRIES, DEFAULT_NETWORKS, DEFAULT_NETWORK_CONFIG, DEFAULT_OPERATION_TIMEOUT_MS, DEFAULT_PAGINATION_ROWS, DEFAULT_PKP_CACHE_SIZE, DEFAULT_PKP_CACHE_TTL_MS, DebugInfo, DiamondHandsSDK, DiamondHandsSDKConfig, EnrichedBitcoinBalance, EnvironmentName, ErrorCategory, ErrorSeverity, EventFilter, EventHelpers, EventLog, ExtendTermAuthParams, Failure, FeeDistributionEvent, IBTCProof, ILitAction, IPKPManager, IUCDMinting, LRUCache, LiquidationEvent, LiquidationRequest, LitActionAuth, LitActionParams, LitActionResult, LitActionValidationResult, LoanCreationAudit, LoanCreator, LoanCreatorConfig, LoanData, LoanDataDetail, LoanEvents, LoanEventsFilter, LoanManagerConfig, LoanQuery, LoanQueryConfig, LoanQueryFilters, LoanStatus, LoansQuery, MAX_PAGINATION_ROWS, MIN_BITCOIN_PROVIDERS_FOR_CONSENSUS, ManagedContracts, MintUCDAuthParams, MintingParams, MintingResult, MockTokenManager, MockTokenManagerConfig, MockTokenTransactionResult, MonitoringOptions, NETWORK_CONFIGS, NetworkConfig, PKPCreationRequest, PKPCreationResult, PKPData, PKPIssuanceRequest, PKPManager, PKPManagerConfig, PKPSigningRequest, PKPSigningResult, PKPValidationData, PKPValidationRequest, PKPValidationResult, POSITION_MANAGER_ABI, PRICE_FEED_CONSUMER_ABI, PSM_ABI, PSM_MAX_OPERATIONS_PER_WINDOW, PSM_RATE_LIMIT_RESET_BLOCKS, PaginatedLoansResponse, PaginatedResult, Pagination, PaginationParams, PartialPaymentRequest, PartialPaymentResult, PaymentEvent, PaymentType, Position, PositionDetails, PositionQueryOptions, PositionQueryResult, PositionStatus, PositionWithBTCStatus, PriceProviderConfig, RepayDebtAuthParams, Result$1 as Result, RetryConfig, RewardDistribution, SDKConfig, SDKError, SDKInitOptions, SDKMode, SDK_DEFAULTS, SDK_ERROR_MESSAGES, Satoshis, SatoshisConversions, ServiceModeConfig, StandaloneModeConfig, StatusUpdateEvent, Success, THE_GRAPH_MAX_BATCH_SIZE, UCD, UCDConversions, UCDMintEvent, UCDMintRequest, UCDMintResult, UCD_TOKEN_ABI, UnixTimestamp, ValidationRequest, Wei, WeiConversions, WithdrawBTCAuthParams, andThen, collectFailures, collectSuccesses, combine, createBitcoinOperations, createCacheManager, createContractManager, createLoanCreator, createLoanQuery, createMockTokenManager, createPKPManager, DiamondHandsSDK as default, envLog, failure, firstSuccess, fromPromise, getAllNetworkConfigs, getCurrentEnvironment, getLitNetworkConfig, getNetworkConfig, getNetworkConfigByName, isClosePositionAuth, isCreateLoanAuth, isExtendTermAuth, isFailure, isMintUCDAuth, isNetworkSupported, isRepayDebtAuth, isServiceModeConfig, isStandaloneModeConfig, isSuccess, isValidPaymentType, isValidPositionStatus, isWithdrawBTCAuth, loadSDKConfig, map, mapError, match, numericToPositionStatus, success, toPromise, tryCatch, tryCatchAsync, unwrap, unwrapOr, validateSDKConfig, validateSDKEnvironment, validateServiceModeConfig, validateStandaloneModeConfig };
|
package/dist/index.js
CHANGED
|
@@ -42330,7 +42330,7 @@ async function executeLitAction(litNodeClient, executionConfig, config = {}) {
|
|
|
42330
42330
|
}
|
|
42331
42331
|
|
|
42332
42332
|
// src/utils/quantum-timing.ts
|
|
42333
|
-
var QUANTUM_WINDOW_SECONDS =
|
|
42333
|
+
var QUANTUM_WINDOW_SECONDS = 100;
|
|
42334
42334
|
var DEAD_ZONE_SECONDS = 8;
|
|
42335
42335
|
function getCurrentQuantum() {
|
|
42336
42336
|
const now2 = Math.floor(Date.now() / 1e3);
|
|
@@ -42675,13 +42675,29 @@ var PKPAuthorization = class {
|
|
|
42675
42675
|
})
|
|
42676
42676
|
);
|
|
42677
42677
|
}
|
|
42678
|
-
const
|
|
42679
|
-
|
|
42680
|
-
|
|
42681
|
-
|
|
42682
|
-
|
|
42683
|
-
|
|
42684
|
-
|
|
42678
|
+
const QUANTUM_WINDOW = 100;
|
|
42679
|
+
const QUANTUM_OFFSET = 10;
|
|
42680
|
+
const DEAD_ZONE_SECONDS2 = 8;
|
|
42681
|
+
const now2 = Math.floor(Date.now() / 1e3);
|
|
42682
|
+
const currentQuantum = Math.floor(now2 / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
42683
|
+
const progress = now2 % QUANTUM_WINDOW;
|
|
42684
|
+
const endDeadZoneStart = QUANTUM_WINDOW - DEAD_ZONE_SECONDS2;
|
|
42685
|
+
const targetQuantum = progress >= endDeadZoneStart ? currentQuantum + QUANTUM_WINDOW : currentQuantum;
|
|
42686
|
+
if (this.config.debug) {
|
|
42687
|
+
if (progress >= endDeadZoneStart) {
|
|
42688
|
+
log.info("\u26A0\uFE0F In end dead zone - using next quantum (LIT Action will wait for next quantum)", {
|
|
42689
|
+
currentQuantum,
|
|
42690
|
+
targetQuantum,
|
|
42691
|
+
progress,
|
|
42692
|
+
note: "LIT Action will wait until next quantum safe zone, so timestamp must match next quantum"
|
|
42693
|
+
});
|
|
42694
|
+
} else if (progress < DEAD_ZONE_SECONDS2) {
|
|
42695
|
+
log.info("\u26A0\uFE0F In start dead zone - using current quantum (LIT Action will wait)", {
|
|
42696
|
+
currentQuantum: targetQuantum,
|
|
42697
|
+
progress,
|
|
42698
|
+
note: "LIT Action will wait for safe zone in current quantum"
|
|
42699
|
+
});
|
|
42700
|
+
}
|
|
42685
42701
|
}
|
|
42686
42702
|
const regeneratedAuth = await generateMintAuthorization(
|
|
42687
42703
|
params.positionId,
|
|
@@ -42690,10 +42706,10 @@ var PKPAuthorization = class {
|
|
|
42690
42706
|
mode,
|
|
42691
42707
|
signer
|
|
42692
42708
|
);
|
|
42693
|
-
const QUANTUM_WINDOW = 200;
|
|
42694
|
-
const QUANTUM_OFFSET = 10;
|
|
42695
42709
|
const targetTimestamp = targetQuantum + QUANTUM_OFFSET;
|
|
42696
|
-
|
|
42710
|
+
const currentAuthQuantum = Math.floor(regeneratedAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
42711
|
+
const oldTimestamp = regeneratedAuth.timestamp;
|
|
42712
|
+
if (currentAuthQuantum !== targetQuantum || regeneratedAuth.timestamp !== targetTimestamp) {
|
|
42697
42713
|
regeneratedAuth.timestamp = targetTimestamp;
|
|
42698
42714
|
const actionHash = ethers_exports.utils.keccak256(ethers_exports.utils.toUtf8Bytes("mint-ucd"));
|
|
42699
42715
|
const messageHash = ethers_exports.utils.solidityKeccak256(
|
|
@@ -42709,35 +42725,24 @@ var PKPAuthorization = class {
|
|
|
42709
42725
|
);
|
|
42710
42726
|
const messageHashBytes = ethers_exports.utils.arrayify(messageHash);
|
|
42711
42727
|
regeneratedAuth.signature = await signer.signMessage(messageHashBytes);
|
|
42712
|
-
|
|
42713
|
-
|
|
42714
|
-
|
|
42715
|
-
|
|
42716
|
-
|
|
42717
|
-
|
|
42718
|
-
|
|
42719
|
-
["bytes32", "uint256", "uint256", "uint256", "bytes32"],
|
|
42720
|
-
[
|
|
42721
|
-
params.positionId,
|
|
42722
|
-
regeneratedAuth.timestamp,
|
|
42723
|
-
chainId,
|
|
42724
|
-
params.amount.toString(),
|
|
42725
|
-
actionHash
|
|
42726
|
-
]
|
|
42727
|
-
);
|
|
42728
|
-
const messageHashBytes = ethers_exports.utils.arrayify(messageHash);
|
|
42729
|
-
regeneratedAuth.signature = await signer.signMessage(messageHashBytes);
|
|
42728
|
+
if (this.config.debug) {
|
|
42729
|
+
log.info("\u{1F504} Regenerated authorization signature with target quantum timestamp", {
|
|
42730
|
+
oldTimestamp,
|
|
42731
|
+
newTimestamp: targetTimestamp,
|
|
42732
|
+
targetQuantum,
|
|
42733
|
+
currentAuthQuantum
|
|
42734
|
+
});
|
|
42730
42735
|
}
|
|
42731
42736
|
}
|
|
42732
42737
|
if (this.config.debug) {
|
|
42733
|
-
const
|
|
42738
|
+
const currentQuantum2 = getCurrentQuantum();
|
|
42734
42739
|
const authQuantum = Math.floor(regeneratedAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
42735
42740
|
log.info("\u2705 Authorization regenerated", {
|
|
42736
42741
|
oldTimestamp: mintAuth.timestamp,
|
|
42737
42742
|
newTimestamp: regeneratedAuth.timestamp,
|
|
42738
42743
|
oldQuantum: Math.floor(mintAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW,
|
|
42739
42744
|
newQuantum: authQuantum,
|
|
42740
|
-
currentQuantum,
|
|
42745
|
+
currentQuantum: currentQuantum2,
|
|
42741
42746
|
nextQuantum: getNextQuantum(),
|
|
42742
42747
|
inDeadZone: isInDeadZone(),
|
|
42743
42748
|
quantumMatch: authQuantum === targetQuantum
|
|
@@ -42812,15 +42817,31 @@ var PKPAuthorization = class {
|
|
|
42812
42817
|
}
|
|
42813
42818
|
log.error("\u26A0\uFE0F No contract addresses provided - Lit Action will fail with toLowerCase error");
|
|
42814
42819
|
}
|
|
42820
|
+
const requiredContractsForLIT = ["PositionManager", "LoanOperationsManagerModule", "TermManagerModule", "UCDController"];
|
|
42821
|
+
const hasRequiredContracts = contractAddresses && requiredContractsForLIT.every(
|
|
42822
|
+
(contract) => contractAddresses[contract] && contractAddresses[contract].trim() !== ""
|
|
42823
|
+
);
|
|
42824
|
+
const authWithContracts = { ...auth };
|
|
42825
|
+
if (hasRequiredContracts && contractAddresses) {
|
|
42826
|
+
authWithContracts.contracts = contractAddresses;
|
|
42827
|
+
if (this.config.debug) {
|
|
42828
|
+
log.info("\u2705 Added contracts to auth object for main branch CID compatibility", {
|
|
42829
|
+
contracts: Object.keys(contractAddresses)
|
|
42830
|
+
});
|
|
42831
|
+
}
|
|
42832
|
+
}
|
|
42815
42833
|
const jsParams = {
|
|
42816
42834
|
chain: chainStr,
|
|
42817
42835
|
bitcoinProviderUrl: this.config.bitcoinProviderUrl || "",
|
|
42818
|
-
auth,
|
|
42836
|
+
auth: authWithContracts,
|
|
42837
|
+
// Use auth with contracts added
|
|
42819
42838
|
amount: params.amount.toString(),
|
|
42820
42839
|
publicKey: pkpPublicKey,
|
|
42821
42840
|
ipfsId: this.config.litActionCid,
|
|
42822
42841
|
// Include pkpTokenId for burned PKPs (required for scope [1] authorization)
|
|
42823
|
-
...pkpTokenId ? { pkpTokenId } : {}
|
|
42842
|
+
...pkpTokenId ? { pkpTokenId } : {},
|
|
42843
|
+
// Include price providers if configured
|
|
42844
|
+
...this.config.priceProviders ? { priceProviders: this.config.priceProviders } : {}
|
|
42824
42845
|
};
|
|
42825
42846
|
if (this.config.ethRpcUrl) {
|
|
42826
42847
|
jsParams["rpcUrl"] = this.config.ethRpcUrl;
|
|
@@ -42845,10 +42866,6 @@ var PKPAuthorization = class {
|
|
|
42845
42866
|
note: "PKP must be authorized for Lit Action CID with scope [1] (SignAnything)"
|
|
42846
42867
|
});
|
|
42847
42868
|
}
|
|
42848
|
-
const requiredContractsForLIT = ["PositionManager", "LoanOperationsManagerModule", "TermManagerModule", "UCDController"];
|
|
42849
|
-
const hasRequiredContracts = contractAddresses && requiredContractsForLIT.every(
|
|
42850
|
-
(contract) => contractAddresses[contract] && contractAddresses[contract].trim() !== ""
|
|
42851
|
-
);
|
|
42852
42869
|
if (hasRequiredContracts) {
|
|
42853
42870
|
jsParams["contracts"] = contractAddresses;
|
|
42854
42871
|
jsParams["contractAddresses"] = contractAddresses;
|
|
@@ -43170,16 +43187,23 @@ var PKPAuthorization = class {
|
|
|
43170
43187
|
}
|
|
43171
43188
|
return response;
|
|
43172
43189
|
},
|
|
43173
|
-
(error) =>
|
|
43174
|
-
|
|
43175
|
-
|
|
43176
|
-
|
|
43177
|
-
|
|
43178
|
-
context: {
|
|
43179
|
-
rawResponse: litResult.value.response,
|
|
43180
|
-
responseType: typeof litResult.value.response
|
|
43190
|
+
(error) => {
|
|
43191
|
+
if (error instanceof SDKError) {
|
|
43192
|
+
if (error.message.includes("declined") || error.message.includes("authorization") || error.message.includes("not authorized")) {
|
|
43193
|
+
return error;
|
|
43194
|
+
}
|
|
43181
43195
|
}
|
|
43182
|
-
|
|
43196
|
+
return new SDKError({
|
|
43197
|
+
message: "Failed to parse mint authorization response",
|
|
43198
|
+
category: "PKP" /* PKP */,
|
|
43199
|
+
severity: "HIGH" /* HIGH */,
|
|
43200
|
+
originalError: error instanceof Error ? error : new Error(String(error)),
|
|
43201
|
+
context: {
|
|
43202
|
+
rawResponse: litResult.value.response,
|
|
43203
|
+
responseType: typeof litResult.value.response
|
|
43204
|
+
}
|
|
43205
|
+
});
|
|
43206
|
+
}
|
|
43183
43207
|
);
|
|
43184
43208
|
}
|
|
43185
43209
|
/**
|
|
@@ -43244,7 +43268,7 @@ var PKPAuthorization = class {
|
|
|
43244
43268
|
mode,
|
|
43245
43269
|
signer
|
|
43246
43270
|
);
|
|
43247
|
-
const QUANTUM_WINDOW =
|
|
43271
|
+
const QUANTUM_WINDOW = 100;
|
|
43248
43272
|
const QUANTUM_OFFSET = 10;
|
|
43249
43273
|
const targetTimestamp = targetQuantum + QUANTUM_OFFSET;
|
|
43250
43274
|
if (Math.floor(regeneratedAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW !== targetQuantum) {
|
|
@@ -44028,13 +44052,18 @@ var PKPAuthorization = class {
|
|
|
44028
44052
|
const finalJsParams = {
|
|
44029
44053
|
...jsParams,
|
|
44030
44054
|
publicKey: formattedPkpPublicKey,
|
|
44031
|
-
ipfsId: cid
|
|
44055
|
+
ipfsId: cid,
|
|
44056
|
+
// CRITICAL: Include pkpTokenId for burned PKP signing
|
|
44057
|
+
// Without this, LIT nodes cannot authorize signing and will timeout
|
|
44058
|
+
...pkpTokenId ? { pkpTokenId } : {}
|
|
44032
44059
|
};
|
|
44033
44060
|
if (this.config.debug) {
|
|
44034
44061
|
log.info("\u{1F680} Final jsParams being sent to LIT Protocol (IPFS execution):", {
|
|
44035
44062
|
ipfsId: cid,
|
|
44036
44063
|
jsParamsKeys: Object.keys(finalJsParams),
|
|
44037
44064
|
jsParamsCount: Object.keys(finalJsParams).length,
|
|
44065
|
+
hasPkpTokenId: !!finalJsParams["pkpTokenId"],
|
|
44066
|
+
pkpTokenId: finalJsParams["pkpTokenId"] || "NOT PROVIDED",
|
|
44038
44067
|
contracts: finalJsParams["contracts"] ? {
|
|
44039
44068
|
keys: Object.keys(finalJsParams["contracts"]),
|
|
44040
44069
|
PositionManager: finalJsParams["contracts"]?.PositionManager || "MISSING",
|
|
@@ -45494,7 +45523,9 @@ var BitcoinDataProvider = class {
|
|
|
45494
45523
|
/**
|
|
45495
45524
|
* Parse Esplora/Blockstream/Mempool.space UTXO response
|
|
45496
45525
|
*
|
|
45497
|
-
*
|
|
45526
|
+
* Supports multiple formats:
|
|
45527
|
+
* - Esplora format: {txid, vout, value, status: {confirmed, block_height}}
|
|
45528
|
+
* - Blockstream format: {txid, vout, value, confirmations}
|
|
45498
45529
|
*
|
|
45499
45530
|
* @param data Raw response from provider API
|
|
45500
45531
|
* @returns Array of normalized UTXOs
|
|
@@ -45503,12 +45534,26 @@ var BitcoinDataProvider = class {
|
|
|
45503
45534
|
if (!Array.isArray(data)) {
|
|
45504
45535
|
throw new Error("Invalid Blockstream response format: expected an array");
|
|
45505
45536
|
}
|
|
45506
|
-
const utxos = data.map((utxo) =>
|
|
45507
|
-
|
|
45508
|
-
|
|
45509
|
-
|
|
45510
|
-
|
|
45511
|
-
|
|
45537
|
+
const utxos = data.map((utxo) => {
|
|
45538
|
+
let confirmations = 0;
|
|
45539
|
+
if (utxo.status && typeof utxo.status === "object") {
|
|
45540
|
+
if (utxo.status.confirmed) {
|
|
45541
|
+
if (utxo.status.block_height !== void 0 && utxo.status.block_height > 0) {
|
|
45542
|
+
confirmations = utxo.status.block_height;
|
|
45543
|
+
} else {
|
|
45544
|
+
confirmations = 1;
|
|
45545
|
+
}
|
|
45546
|
+
}
|
|
45547
|
+
} else if (utxo.confirmations !== void 0) {
|
|
45548
|
+
confirmations = utxo.confirmations;
|
|
45549
|
+
}
|
|
45550
|
+
return {
|
|
45551
|
+
txid: utxo.txid,
|
|
45552
|
+
vout: utxo.vout !== void 0 ? utxo.vout : utxo.n,
|
|
45553
|
+
satoshis: BigInt(utxo.value !== void 0 ? utxo.value : utxo.satoshis),
|
|
45554
|
+
confirmations
|
|
45555
|
+
};
|
|
45556
|
+
});
|
|
45512
45557
|
return utxos;
|
|
45513
45558
|
}
|
|
45514
45559
|
/**
|
|
@@ -47984,8 +48029,9 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
47984
48029
|
contractAddresses: config.contractAddresses,
|
|
47985
48030
|
ethRpcUrl: config.ethRpcUrl,
|
|
47986
48031
|
debug: config.debug,
|
|
47987
|
-
timeoutMs: config.pkpServiceTimeoutMs || 48e4
|
|
48032
|
+
timeoutMs: config.pkpServiceTimeoutMs || 48e4,
|
|
47988
48033
|
// Use PKP service timeout (default 8 minutes)
|
|
48034
|
+
priceProviders: config.priceProviders
|
|
47989
48035
|
});
|
|
47990
48036
|
console.log("[SDK] Passing contractAddresses to createPKPAuthorization", {
|
|
47991
48037
|
keys: Object.keys(config.contractAddresses || {}),
|
|
@@ -48423,7 +48469,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48423
48469
|
contractAddresses.operationAuthorizationRegistry,
|
|
48424
48470
|
provider
|
|
48425
48471
|
);
|
|
48426
|
-
const QUANTUM_WINDOW =
|
|
48472
|
+
const QUANTUM_WINDOW = 100;
|
|
48427
48473
|
const lastUsedQuantum = await registryContract.lastOperationQuantum(positionIdBytes32);
|
|
48428
48474
|
const lastUsedQuantumNumber = Number(lastUsedQuantum.toString());
|
|
48429
48475
|
const quantumFromLastUsed = Math.floor(lastUsedQuantumNumber / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
@@ -48479,15 +48525,15 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48479
48525
|
* Goal: Start LIT Action execution early in a quantum window to maximize
|
|
48480
48526
|
* the chance that contract submission happens within safe window.
|
|
48481
48527
|
*
|
|
48482
|
-
* Optimal window: 10-15 seconds into quantum (
|
|
48528
|
+
* Optimal window: 10-15 seconds into quantum (100s window)
|
|
48483
48529
|
* - Narrower window for more predictable timing
|
|
48484
48530
|
* - Avoids start dead zone (0-7s)
|
|
48485
|
-
* - Leaves maximum time for LIT Action + submission (up to
|
|
48531
|
+
* - Leaves maximum time for LIT Action + submission (up to 85s with 100s window)
|
|
48486
48532
|
*
|
|
48487
48533
|
* MAX WAIT: 50 seconds to cover full quantum transition without landing in dead zone
|
|
48488
48534
|
*/
|
|
48489
48535
|
async waitForOptimalQuantumTiming() {
|
|
48490
|
-
const QUANTUM_WINDOW =
|
|
48536
|
+
const QUANTUM_WINDOW = 100;
|
|
48491
48537
|
const OPTIMAL_START = 10;
|
|
48492
48538
|
const OPTIMAL_END = 15;
|
|
48493
48539
|
const MAX_WAIT_SECONDS = 50;
|
|
@@ -48545,7 +48591,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48545
48591
|
contractAddresses.operationAuthorizationRegistry,
|
|
48546
48592
|
provider
|
|
48547
48593
|
);
|
|
48548
|
-
const QUANTUM_WINDOW =
|
|
48594
|
+
const QUANTUM_WINDOW = 100;
|
|
48549
48595
|
const quantumFromTimestamp = Math.floor(quantumTimestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
48550
48596
|
const lastUsedQuantum = await registryContract.lastOperationQuantum(positionIdBytes32);
|
|
48551
48597
|
const lastUsedQuantumNumber = Number(lastUsedQuantum.toString());
|
|
@@ -48599,7 +48645,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48599
48645
|
* This forces the caller to retry with a fresh signature rather than risk hitting dead zone
|
|
48600
48646
|
* during transaction submission.
|
|
48601
48647
|
*
|
|
48602
|
-
* Safe submission window: 10-
|
|
48648
|
+
* Safe submission window: 10-91 seconds into quantum (81s window with 100s quantum)
|
|
48603
48649
|
* - Avoids start dead zone: 0-9s (extra buffer for clock drift)
|
|
48604
48650
|
* - Avoids end dead zone: 192-199s
|
|
48605
48651
|
* - 42s buffer before end dead zone accounts for:
|
|
@@ -48611,7 +48657,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48611
48657
|
* @param targetTimestamp - Target timestamp (may have offset, e.g., quantum + 10)
|
|
48612
48658
|
*/
|
|
48613
48659
|
async ensureSafeQuantum(targetTimestamp) {
|
|
48614
|
-
const QUANTUM_WINDOW =
|
|
48660
|
+
const QUANTUM_WINDOW = 100;
|
|
48615
48661
|
const currentTime = Math.floor(Date.now() / 1e3);
|
|
48616
48662
|
const currentQuantum = Math.floor(currentTime / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
48617
48663
|
const progress = currentTime % QUANTUM_WINDOW;
|
|
@@ -49218,10 +49264,6 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
49218
49264
|
note: "Capacity credits delegated to signing PKP (validator), not loan PKP"
|
|
49219
49265
|
});
|
|
49220
49266
|
}
|
|
49221
|
-
mintAuthParams.timestamp = Math.floor(Date.now() / 1e3);
|
|
49222
|
-
if (this.config.debug) {
|
|
49223
|
-
log.info(`\u{1F550} Using fresh timestamp for authorization: ${mintAuthParams.timestamp}`);
|
|
49224
|
-
}
|
|
49225
49267
|
console.log("[SDK] About to call authorizeMintUCD", {
|
|
49226
49268
|
hasPkpAuth: !!this.pkpAuthorization,
|
|
49227
49269
|
configContractAddresses: Object.keys(this.config.contractAddresses || {}),
|
|
@@ -49413,7 +49455,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
49413
49455
|
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
49414
49456
|
}
|
|
49415
49457
|
if (quantumValidationResult.reason?.includes("dead zone")) {
|
|
49416
|
-
const QUANTUM_WINDOW =
|
|
49458
|
+
const QUANTUM_WINDOW = 100;
|
|
49417
49459
|
const DEAD_ZONE = 8;
|
|
49418
49460
|
const QUANTUM_OFFSET = 10;
|
|
49419
49461
|
const currentTime = Math.floor(Date.now() / 1e3);
|
|
@@ -49586,11 +49628,30 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
49586
49628
|
console.log(" \u26A0\uFE0F SIGNATURE MISMATCH DETECTED!");
|
|
49587
49629
|
console.log(" Signature was signed by:", recovered);
|
|
49588
49630
|
console.log(" But contract expects:", expectedValidatorPkp);
|
|
49631
|
+
console.log(" This will cause InvalidValidatorSignature() error");
|
|
49632
|
+
const sigBytes = ethers_exports.utils.arrayify(finalSignatureBytes);
|
|
49633
|
+
if (sigBytes.length === 65) {
|
|
49634
|
+
const v = sigBytes[64];
|
|
49635
|
+
if (v !== void 0) {
|
|
49636
|
+
const normalizedV = v < 27 ? v + 27 : v;
|
|
49637
|
+
console.log(" Signature v value:", v, "(normalized:", normalizedV, ")");
|
|
49638
|
+
console.log(" v should be 27 or 28 for valid signature");
|
|
49639
|
+
}
|
|
49640
|
+
}
|
|
49589
49641
|
}
|
|
49590
49642
|
} catch (err) {
|
|
49591
49643
|
console.error(" \u274C Signature recovery failed:", err.message);
|
|
49592
49644
|
console.error(" Error details:", err);
|
|
49593
|
-
|
|
49645
|
+
console.error(" This indicates the signature format is invalid");
|
|
49646
|
+
}
|
|
49647
|
+
console.log("\n\u{1F50D} CONTRACT VERIFICATION PREVIEW:");
|
|
49648
|
+
console.log(" Contract will call: authorizationRegistry.verifyAuthorization(");
|
|
49649
|
+
console.log(" selector: 0x2bf4de41 (mintUCD)");
|
|
49650
|
+
console.log(" messageHash:", contractMessageHash);
|
|
49651
|
+
console.log(" signature length:", finalSignatureBytes.length, "chars");
|
|
49652
|
+
console.log(" )");
|
|
49653
|
+
console.log(" Contract expects validator PKP:", ucdMintValidatorPkpEthAddress || ethers_exports.utils.computeAddress(ucdMintValidatorPkp));
|
|
49654
|
+
console.log(" Registered validator PKP in registry:", ucdMintValidatorPkpEthAddress || ethers_exports.utils.computeAddress(ucdMintValidatorPkp));
|
|
49594
49655
|
console.log("=".repeat(80) + "\n");
|
|
49595
49656
|
tx = await loanOpsContract.mintUCD(
|
|
49596
49657
|
positionIdBytes32,
|
|
@@ -50186,7 +50247,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
50186
50247
|
const isDeadZone = quantumValidationResult.reason?.includes("dead zone");
|
|
50187
50248
|
const isExpired = quantumValidationResult.reason?.includes("does not match current quantum");
|
|
50188
50249
|
if (isDeadZone || isExpired) {
|
|
50189
|
-
const QUANTUM_WINDOW =
|
|
50250
|
+
const QUANTUM_WINDOW = 100;
|
|
50190
50251
|
const DEAD_ZONE = 8;
|
|
50191
50252
|
const QUANTUM_OFFSET = 10;
|
|
50192
50253
|
const currentTime = Math.floor(Date.now() / 1e3);
|
package/dist/index.mjs
CHANGED
|
@@ -42235,7 +42235,7 @@ async function executeLitAction(litNodeClient, executionConfig, config = {}) {
|
|
|
42235
42235
|
}
|
|
42236
42236
|
|
|
42237
42237
|
// src/utils/quantum-timing.ts
|
|
42238
|
-
var QUANTUM_WINDOW_SECONDS =
|
|
42238
|
+
var QUANTUM_WINDOW_SECONDS = 100;
|
|
42239
42239
|
var DEAD_ZONE_SECONDS = 8;
|
|
42240
42240
|
function getCurrentQuantum() {
|
|
42241
42241
|
const now2 = Math.floor(Date.now() / 1e3);
|
|
@@ -42580,13 +42580,29 @@ var PKPAuthorization = class {
|
|
|
42580
42580
|
})
|
|
42581
42581
|
);
|
|
42582
42582
|
}
|
|
42583
|
-
const
|
|
42584
|
-
|
|
42585
|
-
|
|
42586
|
-
|
|
42587
|
-
|
|
42588
|
-
|
|
42589
|
-
|
|
42583
|
+
const QUANTUM_WINDOW = 100;
|
|
42584
|
+
const QUANTUM_OFFSET = 10;
|
|
42585
|
+
const DEAD_ZONE_SECONDS2 = 8;
|
|
42586
|
+
const now2 = Math.floor(Date.now() / 1e3);
|
|
42587
|
+
const currentQuantum = Math.floor(now2 / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
42588
|
+
const progress = now2 % QUANTUM_WINDOW;
|
|
42589
|
+
const endDeadZoneStart = QUANTUM_WINDOW - DEAD_ZONE_SECONDS2;
|
|
42590
|
+
const targetQuantum = progress >= endDeadZoneStart ? currentQuantum + QUANTUM_WINDOW : currentQuantum;
|
|
42591
|
+
if (this.config.debug) {
|
|
42592
|
+
if (progress >= endDeadZoneStart) {
|
|
42593
|
+
log.info("\u26A0\uFE0F In end dead zone - using next quantum (LIT Action will wait for next quantum)", {
|
|
42594
|
+
currentQuantum,
|
|
42595
|
+
targetQuantum,
|
|
42596
|
+
progress,
|
|
42597
|
+
note: "LIT Action will wait until next quantum safe zone, so timestamp must match next quantum"
|
|
42598
|
+
});
|
|
42599
|
+
} else if (progress < DEAD_ZONE_SECONDS2) {
|
|
42600
|
+
log.info("\u26A0\uFE0F In start dead zone - using current quantum (LIT Action will wait)", {
|
|
42601
|
+
currentQuantum: targetQuantum,
|
|
42602
|
+
progress,
|
|
42603
|
+
note: "LIT Action will wait for safe zone in current quantum"
|
|
42604
|
+
});
|
|
42605
|
+
}
|
|
42590
42606
|
}
|
|
42591
42607
|
const regeneratedAuth = await generateMintAuthorization(
|
|
42592
42608
|
params.positionId,
|
|
@@ -42595,10 +42611,10 @@ var PKPAuthorization = class {
|
|
|
42595
42611
|
mode,
|
|
42596
42612
|
signer
|
|
42597
42613
|
);
|
|
42598
|
-
const QUANTUM_WINDOW = 200;
|
|
42599
|
-
const QUANTUM_OFFSET = 10;
|
|
42600
42614
|
const targetTimestamp = targetQuantum + QUANTUM_OFFSET;
|
|
42601
|
-
|
|
42615
|
+
const currentAuthQuantum = Math.floor(regeneratedAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
42616
|
+
const oldTimestamp = regeneratedAuth.timestamp;
|
|
42617
|
+
if (currentAuthQuantum !== targetQuantum || regeneratedAuth.timestamp !== targetTimestamp) {
|
|
42602
42618
|
regeneratedAuth.timestamp = targetTimestamp;
|
|
42603
42619
|
const actionHash = ethers_exports.utils.keccak256(ethers_exports.utils.toUtf8Bytes("mint-ucd"));
|
|
42604
42620
|
const messageHash = ethers_exports.utils.solidityKeccak256(
|
|
@@ -42614,35 +42630,24 @@ var PKPAuthorization = class {
|
|
|
42614
42630
|
);
|
|
42615
42631
|
const messageHashBytes = ethers_exports.utils.arrayify(messageHash);
|
|
42616
42632
|
regeneratedAuth.signature = await signer.signMessage(messageHashBytes);
|
|
42617
|
-
|
|
42618
|
-
|
|
42619
|
-
|
|
42620
|
-
|
|
42621
|
-
|
|
42622
|
-
|
|
42623
|
-
|
|
42624
|
-
["bytes32", "uint256", "uint256", "uint256", "bytes32"],
|
|
42625
|
-
[
|
|
42626
|
-
params.positionId,
|
|
42627
|
-
regeneratedAuth.timestamp,
|
|
42628
|
-
chainId,
|
|
42629
|
-
params.amount.toString(),
|
|
42630
|
-
actionHash
|
|
42631
|
-
]
|
|
42632
|
-
);
|
|
42633
|
-
const messageHashBytes = ethers_exports.utils.arrayify(messageHash);
|
|
42634
|
-
regeneratedAuth.signature = await signer.signMessage(messageHashBytes);
|
|
42633
|
+
if (this.config.debug) {
|
|
42634
|
+
log.info("\u{1F504} Regenerated authorization signature with target quantum timestamp", {
|
|
42635
|
+
oldTimestamp,
|
|
42636
|
+
newTimestamp: targetTimestamp,
|
|
42637
|
+
targetQuantum,
|
|
42638
|
+
currentAuthQuantum
|
|
42639
|
+
});
|
|
42635
42640
|
}
|
|
42636
42641
|
}
|
|
42637
42642
|
if (this.config.debug) {
|
|
42638
|
-
const
|
|
42643
|
+
const currentQuantum2 = getCurrentQuantum();
|
|
42639
42644
|
const authQuantum = Math.floor(regeneratedAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
42640
42645
|
log.info("\u2705 Authorization regenerated", {
|
|
42641
42646
|
oldTimestamp: mintAuth.timestamp,
|
|
42642
42647
|
newTimestamp: regeneratedAuth.timestamp,
|
|
42643
42648
|
oldQuantum: Math.floor(mintAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW,
|
|
42644
42649
|
newQuantum: authQuantum,
|
|
42645
|
-
currentQuantum,
|
|
42650
|
+
currentQuantum: currentQuantum2,
|
|
42646
42651
|
nextQuantum: getNextQuantum(),
|
|
42647
42652
|
inDeadZone: isInDeadZone(),
|
|
42648
42653
|
quantumMatch: authQuantum === targetQuantum
|
|
@@ -42717,15 +42722,31 @@ var PKPAuthorization = class {
|
|
|
42717
42722
|
}
|
|
42718
42723
|
log.error("\u26A0\uFE0F No contract addresses provided - Lit Action will fail with toLowerCase error");
|
|
42719
42724
|
}
|
|
42725
|
+
const requiredContractsForLIT = ["PositionManager", "LoanOperationsManagerModule", "TermManagerModule", "UCDController"];
|
|
42726
|
+
const hasRequiredContracts = contractAddresses && requiredContractsForLIT.every(
|
|
42727
|
+
(contract) => contractAddresses[contract] && contractAddresses[contract].trim() !== ""
|
|
42728
|
+
);
|
|
42729
|
+
const authWithContracts = { ...auth };
|
|
42730
|
+
if (hasRequiredContracts && contractAddresses) {
|
|
42731
|
+
authWithContracts.contracts = contractAddresses;
|
|
42732
|
+
if (this.config.debug) {
|
|
42733
|
+
log.info("\u2705 Added contracts to auth object for main branch CID compatibility", {
|
|
42734
|
+
contracts: Object.keys(contractAddresses)
|
|
42735
|
+
});
|
|
42736
|
+
}
|
|
42737
|
+
}
|
|
42720
42738
|
const jsParams = {
|
|
42721
42739
|
chain: chainStr,
|
|
42722
42740
|
bitcoinProviderUrl: this.config.bitcoinProviderUrl || "",
|
|
42723
|
-
auth,
|
|
42741
|
+
auth: authWithContracts,
|
|
42742
|
+
// Use auth with contracts added
|
|
42724
42743
|
amount: params.amount.toString(),
|
|
42725
42744
|
publicKey: pkpPublicKey,
|
|
42726
42745
|
ipfsId: this.config.litActionCid,
|
|
42727
42746
|
// Include pkpTokenId for burned PKPs (required for scope [1] authorization)
|
|
42728
|
-
...pkpTokenId ? { pkpTokenId } : {}
|
|
42747
|
+
...pkpTokenId ? { pkpTokenId } : {},
|
|
42748
|
+
// Include price providers if configured
|
|
42749
|
+
...this.config.priceProviders ? { priceProviders: this.config.priceProviders } : {}
|
|
42729
42750
|
};
|
|
42730
42751
|
if (this.config.ethRpcUrl) {
|
|
42731
42752
|
jsParams["rpcUrl"] = this.config.ethRpcUrl;
|
|
@@ -42750,10 +42771,6 @@ var PKPAuthorization = class {
|
|
|
42750
42771
|
note: "PKP must be authorized for Lit Action CID with scope [1] (SignAnything)"
|
|
42751
42772
|
});
|
|
42752
42773
|
}
|
|
42753
|
-
const requiredContractsForLIT = ["PositionManager", "LoanOperationsManagerModule", "TermManagerModule", "UCDController"];
|
|
42754
|
-
const hasRequiredContracts = contractAddresses && requiredContractsForLIT.every(
|
|
42755
|
-
(contract) => contractAddresses[contract] && contractAddresses[contract].trim() !== ""
|
|
42756
|
-
);
|
|
42757
42774
|
if (hasRequiredContracts) {
|
|
42758
42775
|
jsParams["contracts"] = contractAddresses;
|
|
42759
42776
|
jsParams["contractAddresses"] = contractAddresses;
|
|
@@ -43075,16 +43092,23 @@ var PKPAuthorization = class {
|
|
|
43075
43092
|
}
|
|
43076
43093
|
return response;
|
|
43077
43094
|
},
|
|
43078
|
-
(error) =>
|
|
43079
|
-
|
|
43080
|
-
|
|
43081
|
-
|
|
43082
|
-
|
|
43083
|
-
context: {
|
|
43084
|
-
rawResponse: litResult.value.response,
|
|
43085
|
-
responseType: typeof litResult.value.response
|
|
43095
|
+
(error) => {
|
|
43096
|
+
if (error instanceof SDKError) {
|
|
43097
|
+
if (error.message.includes("declined") || error.message.includes("authorization") || error.message.includes("not authorized")) {
|
|
43098
|
+
return error;
|
|
43099
|
+
}
|
|
43086
43100
|
}
|
|
43087
|
-
|
|
43101
|
+
return new SDKError({
|
|
43102
|
+
message: "Failed to parse mint authorization response",
|
|
43103
|
+
category: "PKP" /* PKP */,
|
|
43104
|
+
severity: "HIGH" /* HIGH */,
|
|
43105
|
+
originalError: error instanceof Error ? error : new Error(String(error)),
|
|
43106
|
+
context: {
|
|
43107
|
+
rawResponse: litResult.value.response,
|
|
43108
|
+
responseType: typeof litResult.value.response
|
|
43109
|
+
}
|
|
43110
|
+
});
|
|
43111
|
+
}
|
|
43088
43112
|
);
|
|
43089
43113
|
}
|
|
43090
43114
|
/**
|
|
@@ -43149,7 +43173,7 @@ var PKPAuthorization = class {
|
|
|
43149
43173
|
mode,
|
|
43150
43174
|
signer
|
|
43151
43175
|
);
|
|
43152
|
-
const QUANTUM_WINDOW =
|
|
43176
|
+
const QUANTUM_WINDOW = 100;
|
|
43153
43177
|
const QUANTUM_OFFSET = 10;
|
|
43154
43178
|
const targetTimestamp = targetQuantum + QUANTUM_OFFSET;
|
|
43155
43179
|
if (Math.floor(regeneratedAuth.timestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW !== targetQuantum) {
|
|
@@ -43933,13 +43957,18 @@ var PKPAuthorization = class {
|
|
|
43933
43957
|
const finalJsParams = {
|
|
43934
43958
|
...jsParams,
|
|
43935
43959
|
publicKey: formattedPkpPublicKey,
|
|
43936
|
-
ipfsId: cid
|
|
43960
|
+
ipfsId: cid,
|
|
43961
|
+
// CRITICAL: Include pkpTokenId for burned PKP signing
|
|
43962
|
+
// Without this, LIT nodes cannot authorize signing and will timeout
|
|
43963
|
+
...pkpTokenId ? { pkpTokenId } : {}
|
|
43937
43964
|
};
|
|
43938
43965
|
if (this.config.debug) {
|
|
43939
43966
|
log.info("\u{1F680} Final jsParams being sent to LIT Protocol (IPFS execution):", {
|
|
43940
43967
|
ipfsId: cid,
|
|
43941
43968
|
jsParamsKeys: Object.keys(finalJsParams),
|
|
43942
43969
|
jsParamsCount: Object.keys(finalJsParams).length,
|
|
43970
|
+
hasPkpTokenId: !!finalJsParams["pkpTokenId"],
|
|
43971
|
+
pkpTokenId: finalJsParams["pkpTokenId"] || "NOT PROVIDED",
|
|
43943
43972
|
contracts: finalJsParams["contracts"] ? {
|
|
43944
43973
|
keys: Object.keys(finalJsParams["contracts"]),
|
|
43945
43974
|
PositionManager: finalJsParams["contracts"]?.PositionManager || "MISSING",
|
|
@@ -45399,7 +45428,9 @@ var BitcoinDataProvider = class {
|
|
|
45399
45428
|
/**
|
|
45400
45429
|
* Parse Esplora/Blockstream/Mempool.space UTXO response
|
|
45401
45430
|
*
|
|
45402
|
-
*
|
|
45431
|
+
* Supports multiple formats:
|
|
45432
|
+
* - Esplora format: {txid, vout, value, status: {confirmed, block_height}}
|
|
45433
|
+
* - Blockstream format: {txid, vout, value, confirmations}
|
|
45403
45434
|
*
|
|
45404
45435
|
* @param data Raw response from provider API
|
|
45405
45436
|
* @returns Array of normalized UTXOs
|
|
@@ -45408,12 +45439,26 @@ var BitcoinDataProvider = class {
|
|
|
45408
45439
|
if (!Array.isArray(data)) {
|
|
45409
45440
|
throw new Error("Invalid Blockstream response format: expected an array");
|
|
45410
45441
|
}
|
|
45411
|
-
const utxos = data.map((utxo) =>
|
|
45412
|
-
|
|
45413
|
-
|
|
45414
|
-
|
|
45415
|
-
|
|
45416
|
-
|
|
45442
|
+
const utxos = data.map((utxo) => {
|
|
45443
|
+
let confirmations = 0;
|
|
45444
|
+
if (utxo.status && typeof utxo.status === "object") {
|
|
45445
|
+
if (utxo.status.confirmed) {
|
|
45446
|
+
if (utxo.status.block_height !== void 0 && utxo.status.block_height > 0) {
|
|
45447
|
+
confirmations = utxo.status.block_height;
|
|
45448
|
+
} else {
|
|
45449
|
+
confirmations = 1;
|
|
45450
|
+
}
|
|
45451
|
+
}
|
|
45452
|
+
} else if (utxo.confirmations !== void 0) {
|
|
45453
|
+
confirmations = utxo.confirmations;
|
|
45454
|
+
}
|
|
45455
|
+
return {
|
|
45456
|
+
txid: utxo.txid,
|
|
45457
|
+
vout: utxo.vout !== void 0 ? utxo.vout : utxo.n,
|
|
45458
|
+
satoshis: BigInt(utxo.value !== void 0 ? utxo.value : utxo.satoshis),
|
|
45459
|
+
confirmations
|
|
45460
|
+
};
|
|
45461
|
+
});
|
|
45417
45462
|
return utxos;
|
|
45418
45463
|
}
|
|
45419
45464
|
/**
|
|
@@ -47889,8 +47934,9 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
47889
47934
|
contractAddresses: config.contractAddresses,
|
|
47890
47935
|
ethRpcUrl: config.ethRpcUrl,
|
|
47891
47936
|
debug: config.debug,
|
|
47892
|
-
timeoutMs: config.pkpServiceTimeoutMs || 48e4
|
|
47937
|
+
timeoutMs: config.pkpServiceTimeoutMs || 48e4,
|
|
47893
47938
|
// Use PKP service timeout (default 8 minutes)
|
|
47939
|
+
priceProviders: config.priceProviders
|
|
47894
47940
|
});
|
|
47895
47941
|
console.log("[SDK] Passing contractAddresses to createPKPAuthorization", {
|
|
47896
47942
|
keys: Object.keys(config.contractAddresses || {}),
|
|
@@ -48328,7 +48374,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48328
48374
|
contractAddresses.operationAuthorizationRegistry,
|
|
48329
48375
|
provider
|
|
48330
48376
|
);
|
|
48331
|
-
const QUANTUM_WINDOW =
|
|
48377
|
+
const QUANTUM_WINDOW = 100;
|
|
48332
48378
|
const lastUsedQuantum = await registryContract.lastOperationQuantum(positionIdBytes32);
|
|
48333
48379
|
const lastUsedQuantumNumber = Number(lastUsedQuantum.toString());
|
|
48334
48380
|
const quantumFromLastUsed = Math.floor(lastUsedQuantumNumber / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
@@ -48384,15 +48430,15 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48384
48430
|
* Goal: Start LIT Action execution early in a quantum window to maximize
|
|
48385
48431
|
* the chance that contract submission happens within safe window.
|
|
48386
48432
|
*
|
|
48387
|
-
* Optimal window: 10-15 seconds into quantum (
|
|
48433
|
+
* Optimal window: 10-15 seconds into quantum (100s window)
|
|
48388
48434
|
* - Narrower window for more predictable timing
|
|
48389
48435
|
* - Avoids start dead zone (0-7s)
|
|
48390
|
-
* - Leaves maximum time for LIT Action + submission (up to
|
|
48436
|
+
* - Leaves maximum time for LIT Action + submission (up to 85s with 100s window)
|
|
48391
48437
|
*
|
|
48392
48438
|
* MAX WAIT: 50 seconds to cover full quantum transition without landing in dead zone
|
|
48393
48439
|
*/
|
|
48394
48440
|
async waitForOptimalQuantumTiming() {
|
|
48395
|
-
const QUANTUM_WINDOW =
|
|
48441
|
+
const QUANTUM_WINDOW = 100;
|
|
48396
48442
|
const OPTIMAL_START = 10;
|
|
48397
48443
|
const OPTIMAL_END = 15;
|
|
48398
48444
|
const MAX_WAIT_SECONDS = 50;
|
|
@@ -48450,7 +48496,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48450
48496
|
contractAddresses.operationAuthorizationRegistry,
|
|
48451
48497
|
provider
|
|
48452
48498
|
);
|
|
48453
|
-
const QUANTUM_WINDOW =
|
|
48499
|
+
const QUANTUM_WINDOW = 100;
|
|
48454
48500
|
const quantumFromTimestamp = Math.floor(quantumTimestamp / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
48455
48501
|
const lastUsedQuantum = await registryContract.lastOperationQuantum(positionIdBytes32);
|
|
48456
48502
|
const lastUsedQuantumNumber = Number(lastUsedQuantum.toString());
|
|
@@ -48504,7 +48550,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48504
48550
|
* This forces the caller to retry with a fresh signature rather than risk hitting dead zone
|
|
48505
48551
|
* during transaction submission.
|
|
48506
48552
|
*
|
|
48507
|
-
* Safe submission window: 10-
|
|
48553
|
+
* Safe submission window: 10-91 seconds into quantum (81s window with 100s quantum)
|
|
48508
48554
|
* - Avoids start dead zone: 0-9s (extra buffer for clock drift)
|
|
48509
48555
|
* - Avoids end dead zone: 192-199s
|
|
48510
48556
|
* - 42s buffer before end dead zone accounts for:
|
|
@@ -48516,7 +48562,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
48516
48562
|
* @param targetTimestamp - Target timestamp (may have offset, e.g., quantum + 10)
|
|
48517
48563
|
*/
|
|
48518
48564
|
async ensureSafeQuantum(targetTimestamp) {
|
|
48519
|
-
const QUANTUM_WINDOW =
|
|
48565
|
+
const QUANTUM_WINDOW = 100;
|
|
48520
48566
|
const currentTime = Math.floor(Date.now() / 1e3);
|
|
48521
48567
|
const currentQuantum = Math.floor(currentTime / QUANTUM_WINDOW) * QUANTUM_WINDOW;
|
|
48522
48568
|
const progress = currentTime % QUANTUM_WINDOW;
|
|
@@ -49123,10 +49169,6 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
49123
49169
|
note: "Capacity credits delegated to signing PKP (validator), not loan PKP"
|
|
49124
49170
|
});
|
|
49125
49171
|
}
|
|
49126
|
-
mintAuthParams.timestamp = Math.floor(Date.now() / 1e3);
|
|
49127
|
-
if (this.config.debug) {
|
|
49128
|
-
log.info(`\u{1F550} Using fresh timestamp for authorization: ${mintAuthParams.timestamp}`);
|
|
49129
|
-
}
|
|
49130
49172
|
console.log("[SDK] About to call authorizeMintUCD", {
|
|
49131
49173
|
hasPkpAuth: !!this.pkpAuthorization,
|
|
49132
49174
|
configContractAddresses: Object.keys(this.config.contractAddresses || {}),
|
|
@@ -49318,7 +49360,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
49318
49360
|
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
49319
49361
|
}
|
|
49320
49362
|
if (quantumValidationResult.reason?.includes("dead zone")) {
|
|
49321
|
-
const QUANTUM_WINDOW =
|
|
49363
|
+
const QUANTUM_WINDOW = 100;
|
|
49322
49364
|
const DEAD_ZONE = 8;
|
|
49323
49365
|
const QUANTUM_OFFSET = 10;
|
|
49324
49366
|
const currentTime = Math.floor(Date.now() / 1e3);
|
|
@@ -49491,11 +49533,30 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
49491
49533
|
console.log(" \u26A0\uFE0F SIGNATURE MISMATCH DETECTED!");
|
|
49492
49534
|
console.log(" Signature was signed by:", recovered);
|
|
49493
49535
|
console.log(" But contract expects:", expectedValidatorPkp);
|
|
49536
|
+
console.log(" This will cause InvalidValidatorSignature() error");
|
|
49537
|
+
const sigBytes = ethers_exports.utils.arrayify(finalSignatureBytes);
|
|
49538
|
+
if (sigBytes.length === 65) {
|
|
49539
|
+
const v = sigBytes[64];
|
|
49540
|
+
if (v !== void 0) {
|
|
49541
|
+
const normalizedV = v < 27 ? v + 27 : v;
|
|
49542
|
+
console.log(" Signature v value:", v, "(normalized:", normalizedV, ")");
|
|
49543
|
+
console.log(" v should be 27 or 28 for valid signature");
|
|
49544
|
+
}
|
|
49545
|
+
}
|
|
49494
49546
|
}
|
|
49495
49547
|
} catch (err) {
|
|
49496
49548
|
console.error(" \u274C Signature recovery failed:", err.message);
|
|
49497
49549
|
console.error(" Error details:", err);
|
|
49498
|
-
|
|
49550
|
+
console.error(" This indicates the signature format is invalid");
|
|
49551
|
+
}
|
|
49552
|
+
console.log("\n\u{1F50D} CONTRACT VERIFICATION PREVIEW:");
|
|
49553
|
+
console.log(" Contract will call: authorizationRegistry.verifyAuthorization(");
|
|
49554
|
+
console.log(" selector: 0x2bf4de41 (mintUCD)");
|
|
49555
|
+
console.log(" messageHash:", contractMessageHash);
|
|
49556
|
+
console.log(" signature length:", finalSignatureBytes.length, "chars");
|
|
49557
|
+
console.log(" )");
|
|
49558
|
+
console.log(" Contract expects validator PKP:", ucdMintValidatorPkpEthAddress || ethers_exports.utils.computeAddress(ucdMintValidatorPkp));
|
|
49559
|
+
console.log(" Registered validator PKP in registry:", ucdMintValidatorPkpEthAddress || ethers_exports.utils.computeAddress(ucdMintValidatorPkp));
|
|
49499
49560
|
console.log("=".repeat(80) + "\n");
|
|
49500
49561
|
tx = await loanOpsContract.mintUCD(
|
|
49501
49562
|
positionIdBytes32,
|
|
@@ -50091,7 +50152,7 @@ var DiamondHandsSDK = class _DiamondHandsSDK {
|
|
|
50091
50152
|
const isDeadZone = quantumValidationResult.reason?.includes("dead zone");
|
|
50092
50153
|
const isExpired = quantumValidationResult.reason?.includes("does not match current quantum");
|
|
50093
50154
|
if (isDeadZone || isExpired) {
|
|
50094
|
-
const QUANTUM_WINDOW =
|
|
50155
|
+
const QUANTUM_WINDOW = 100;
|
|
50095
50156
|
const DEAD_ZONE = 8;
|
|
50096
50157
|
const QUANTUM_OFFSET = 10;
|
|
50097
50158
|
const currentTime = Math.floor(Date.now() / 1e3);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gvnrdao/dh-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.126",
|
|
4
4
|
"description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"author": "Diamond Hands Protocol",
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@gvnrdao/dh-lit-actions": "^0.0.
|
|
53
|
-
"@gvnrdao/dh-lit-ops": "^0.0.
|
|
52
|
+
"@gvnrdao/dh-lit-actions": "^0.0.81",
|
|
53
|
+
"@gvnrdao/dh-lit-ops": "^0.0.73",
|
|
54
54
|
"@lit-protocol/lit-node-client": "^7.3.1",
|
|
55
55
|
"@noble/hashes": "^1.5.0",
|
|
56
56
|
"axios": "^1.5.0",
|