@gvnrdao/dh-sdk 0.0.235 → 0.0.243

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.
Files changed (30) hide show
  1. package/dist/constants/chunks/deployment-addresses.d.ts +2 -0
  2. package/dist/constants/chunks/network-configs.d.ts +2 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +20474 -31322
  5. package/dist/index.mjs +20305 -31155
  6. package/dist/interfaces/chunks/config.i.d.ts +20 -10
  7. package/dist/interfaces/chunks/contract-interactions.i.d.ts +2 -2
  8. package/dist/interfaces/chunks/contract-types.i.d.ts +95 -91
  9. package/dist/interfaces/chunks/loan-operations.i.d.ts +2 -3
  10. package/dist/modules/bitcoin/bitcoin-operations.module.d.ts +37 -0
  11. package/dist/modules/cache/cache-manager.module.d.ts +8 -0
  12. package/dist/modules/contract/contract-manager.module.d.ts +5 -5
  13. package/dist/modules/diamond-hands-sdk.d.ts +103 -7
  14. package/dist/modules/loan/loan-creator.module.d.ts +1 -1
  15. package/dist/modules/loan/loan-query.module.d.ts +3 -3
  16. package/dist/modules/pkp/pkp-manager.module.d.ts +6 -2
  17. package/dist/protocol/protocol-pause.d.ts +2 -2
  18. package/dist/utils/address-conversion.utils.d.ts +39 -0
  19. package/dist/utils/bitcoin-provider.utils.d.ts +36 -0
  20. package/dist/utils/btc-withdrawal-message.d.ts +60 -0
  21. package/dist/utils/chunks/bitcoin-utils.d.ts +10 -0
  22. package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +8 -9
  23. package/dist/utils/eip712-login.d.ts +27 -0
  24. package/dist/utils/extend-authorization.utils.d.ts +2 -2
  25. package/dist/utils/mint-authorization.utils.d.ts +9 -8
  26. package/dist/utils/position-delegate.utils.d.ts +41 -0
  27. package/dist/utils/server-session.d.ts +44 -0
  28. package/dist/utils/signature-tempering.utils.d.ts +6 -3
  29. package/package.json +6 -7
  30. package/dist/utils/bitcoin-signature.d.ts +0 -20
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * SDK Configuration Interfaces
3
3
  */
4
- import { ethers as ethers5 } from "ethers";
4
+ import type { Wallet, Signer, Provider } from "ethers";
5
5
  import { LitNetwork } from "@gvnrdao/dh-lit-ops";
6
6
  export type SDKMode = "standalone" | "service";
7
7
  /**
@@ -28,6 +28,10 @@ export interface ContractAddresses {
28
28
  btcSpendAuthorizer?: string;
29
29
  /** BitcoinProviderRegistry proxy; required on non-hardhat chains when chain policy disallows arbitrary providers. */
30
30
  bitcoinProviderRegistry?: string;
31
+ /** ContractVersionRegistry proxy; used for cross-contract version pinning. */
32
+ contractVersionRegistry?: string;
33
+ /** PositionDelegateRegistry proxy; consumed by LIT Action authorization verifier as the third recovery arm for Safe-as-borrower flows. */
34
+ positionDelegateRegistry?: string;
31
35
  mockUsdcToken?: string;
32
36
  mockUsdcOwner?: string;
33
37
  mockUsdtToken?: string;
@@ -38,21 +42,26 @@ export interface ContractAddresses {
38
42
  */
39
43
  interface BaseSDKConfig {
40
44
  litNetwork?: LitNetwork;
41
- contractSigner?: ethers5.Wallet | ethers5.Signer;
45
+ contractSigner?: Wallet | Signer;
46
+ /**
47
+ * Optional signer used exclusively for EIP-712 server-session login.
48
+ * When provided, `ServerSession` uses this instead of `contractSigner` so
49
+ * the two concerns (auth identity vs on-chain msg.sender) can differ. In
50
+ * Safe mode the CLI passes the raw agent EOA here while `contractSigner`
51
+ * is a SafeModuleSignerAdapter that routes transactions through the module.
52
+ */
53
+ authSigner?: Wallet | Signer;
42
54
  ethRpcUrl?: string;
43
55
  chainId?: number;
44
56
  networkOverride?: {
45
57
  chainId: number;
46
58
  name: string;
47
59
  };
48
- provider?: ethers5.providers.Provider;
60
+ provider?: Provider;
49
61
  chain?: string;
50
62
  litActionCid?: string;
51
63
  litNodeConnectTimeoutMs?: number;
52
64
  subgraphUrl?: string;
53
- bitcoinRpcUrl?: string;
54
- bitcoinProviders?: BitcoinProviderConfig[];
55
- bitcoinConsensusMode?: "single" | "majority";
56
65
  priceProviders?: PriceProviderConfig[];
57
66
  /** PKP Ethereum address for signed price oracle (Lit jsParams pkpId); optional */
58
67
  priceOraclePkpId?: string;
@@ -79,6 +88,8 @@ interface BaseSDKConfig {
79
88
  transactionTimeoutMs?: number;
80
89
  retryAttempts?: number;
81
90
  debug?: boolean;
91
+ /** Notification label for server Telegram notifications. Default: "DH SDK". Set "DH APP" in the web app. */
92
+ callerLabel?: string;
82
93
  /**
83
94
  * Optional: Override quantum timing buffer (in seconds)
84
95
  * Default: Auto-detected based on network (10s for local, 50s for Sepolia, 35s for mainnet)
@@ -159,7 +170,6 @@ interface BaseSDKConfig {
159
170
  export interface ServiceModeConfig extends BaseSDKConfig {
160
171
  mode: "service";
161
172
  serviceEndpoint: string;
162
- serviceAuthToken?: string;
163
173
  litOpsSigner?: never;
164
174
  }
165
175
  /**
@@ -168,9 +178,8 @@ export interface ServiceModeConfig extends BaseSDKConfig {
168
178
  */
169
179
  export interface StandaloneModeConfig extends BaseSDKConfig {
170
180
  mode: "standalone";
171
- litOpsSigner: ethers5.Wallet;
181
+ litOpsSigner: Wallet;
172
182
  serviceEndpoint?: never;
173
- serviceAuthToken?: never;
174
183
  }
175
184
  /**
176
185
  * Main SDK Configuration - Discriminated Union
@@ -222,7 +231,7 @@ export declare function validateSDKConfig(config: DiamondHandsSDKConfig): string
222
231
  */
223
232
  export interface SDKInitOptions {
224
233
  overrideDefaults?: boolean;
225
- customProvider?: ethers5.providers.Provider;
234
+ customProvider?: Provider;
226
235
  skipNetworkCheck?: boolean;
227
236
  }
228
237
  /**
@@ -252,6 +261,7 @@ export interface BitcoinProviderConfig {
252
261
  */
253
262
  export interface PriceProviderConfig {
254
263
  name: string;
264
+ pkpId?: string;
255
265
  apiKey?: string;
256
266
  apiSecret?: string;
257
267
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Smart Contract Interaction Interfaces
3
3
  */
4
- import { ethers as ethers5 } from "ethers";
4
+ import type { TransactionReceipt } from "ethers";
5
5
  /**
6
6
  * Contract Call Options Interface
7
7
  */
@@ -18,7 +18,7 @@ export interface ContractTransactionResult {
18
18
  success: boolean;
19
19
  error?: string;
20
20
  transactionHash?: string;
21
- receipt?: ethers5.providers.TransactionReceipt;
21
+ receipt?: TransactionReceipt;
22
22
  gasUsed?: string;
23
23
  events?: any[];
24
24
  }
@@ -5,20 +5,19 @@
5
5
  * They are independent definitions - NOT imported from the contracts package.
6
6
  * Based on Solidity interfaces from contracts/src/interfaces/
7
7
  */
8
- import { ethers as ethers5 } from "ethers";
9
- import type { BigNumber } from "ethers";
8
+ import type { BaseContract, ContractTransactionResponse } from "ethers";
10
9
  /**
11
10
  * Position Manager Contract Interface
12
11
  * Based on contracts/src/interfaces/IPositionManager.sol
13
12
  */
14
- export interface PositionManager extends ethers5.Contract {
15
- createPosition(pkpId: string, validatorSignature: string, mainnetVaultAddress: string, regtestVaultAddress: string, selectedTermMonths: number | BigNumber, validatorVersion: number | BigNumber, pkpPublicKey: string): Promise<ethers5.ContractTransaction>;
16
- mintUCD(positionId: string, mintAmount: BigNumber, mintFee: BigNumber, newDebt: BigNumber, newCollateral: BigNumber, btcPrice: BigNumber, authorizedSpendsHash: string, ucdDebtHash: string, contractHash: string, quantumTimestamp: BigNumber, mintValidatorSignature: string): Promise<ethers5.ContractTransaction>;
17
- liquidatePosition(positionId: string, btcPrice: BigNumber, quantumTimestamp: BigNumber, liquidationValidatorSignature: string): Promise<ethers5.ContractTransaction>;
13
+ export interface PositionManager extends BaseContract {
14
+ createPosition(pkpId: string, validatorSignature: string, mainnetVaultAddress: string, regtestVaultAddress: string, selectedTermMonths: number | bigint, validatorVersion: number | bigint, pkpPublicKey: string): Promise<ContractTransactionResponse>;
15
+ mintUCD(positionId: string, mintAmount: bigint, mintFee: bigint, newDebt: bigint, newCollateral: bigint, btcPrice: bigint, authorizedSpendsHash: string, ucdDebtHash: string, contractHash: string, quantumTimestamp: bigint, mintValidatorSignature: string): Promise<ContractTransactionResponse>;
16
+ liquidatePosition(positionId: string, btcPrice: bigint, quantumTimestamp: bigint, liquidationValidatorSignature: string): Promise<ContractTransactionResponse>;
18
17
  getPosition(positionId: string): Promise<{
19
18
  positionId: string;
20
19
  pkpId: string;
21
- ucdDebt: BigNumber;
20
+ ucdDebt: bigint;
22
21
  borrower: string;
23
22
  createdAt: number;
24
23
  lastUpdated: number;
@@ -26,67 +25,71 @@ export interface PositionManager extends ethers5.Contract {
26
25
  expiryAt: number;
27
26
  status: number;
28
27
  }>;
28
+ extendPosition(positionId: string, selectedTerm: bigint, quantumTimestamp: bigint, btcPrice: bigint, availableBTCBalance: bigint, proRataRenewalFee: bigint, extensionValidatorSignature: string): Promise<ContractTransactionResponse>;
29
+ commitLiquidation(positionId: string, quantumTimestamp: bigint, btcPrice: bigint, btcVaultBalance: bigint, liquidationValidatorSignature: string, overrides?: object): Promise<ContractTransactionResponse>;
30
+ revealAndLiquidate(positionId: string, quantumTimestamp: bigint, btcPrice: bigint, btcVaultBalance: bigint, liquidationValidatorSignature: string, deadline: bigint, overrides?: object): Promise<ContractTransactionResponse>;
31
+ makePayment(positionId: string, paymentAmount: bigint | string, quantumTimestamp: bigint | string, btcPrice: bigint | string, paymentValidatorSignature: string): Promise<ContractTransactionResponse>;
29
32
  pkpValidationRegistry(): Promise<string>;
30
- updateBalance(positionId: string, newBtcBalance: string | number | BigNumber, btcPrice: string | number | BigNumber, quantumTimestamp: string | number | BigNumber, signature: string): Promise<ethers5.ContractTransaction>;
33
+ updateBalance(positionId: string, newBtcBalance: string | number | bigint, btcPrice: string | number | bigint, quantumTimestamp: string | number | bigint, signature: string): Promise<ContractTransactionResponse>;
31
34
  }
32
35
  /**
33
36
  * Loan Operations Manager Contract Interface
34
37
  * Based on contracts/src/interfaces/ILoanOperationsManager.sol
35
38
  */
36
- export interface ILoanOperationsManager extends ethers5.Contract {
37
- mintUCD(positionId: string, mintAmount: BigNumber, mintFee: BigNumber, newDebt: BigNumber, newCollateral: BigNumber, btcPrice: BigNumber, authorizedSpendsHash: string, ucdDebtHash: string, quantumTimestamp: BigNumber): Promise<ethers5.ContractTransaction>;
38
- processPayment(positionId: string, paymentAmount: BigNumber, quantumTimestamp: BigNumber, btcPrice: BigNumber): Promise<ethers5.ContractTransaction>;
39
- updatePosition(positionId: string, newDebt: BigNumber, quantumTimestamp: BigNumber, btcPrice: BigNumber, updateValidatorSignature: string): Promise<ethers5.ContractTransaction>;
40
- transferOriginationFee(recipient: string, amount: BigNumber): Promise<ethers5.ContractTransaction>;
41
- mintExtensionFee(amount: BigNumber): Promise<ethers5.ContractTransaction>;
42
- getOriginationFeeBalance(): Promise<BigNumber>;
43
- authorizeBTCSpend(positionId: string, txid: string, vout: number, satoshis: BigNumber, targetAddress: string, targetAmount: BigNumber, litSignature: string): Promise<ethers5.ContractTransaction>;
44
- liquidationThreshold(): Promise<BigNumber>;
45
- minimumLoanValueWei(): Promise<BigNumber>;
39
+ export interface ILoanOperationsManager extends BaseContract {
40
+ mintUCD(positionId: string, mintAmount: bigint, mintFee: bigint, newDebt: bigint, newCollateral: bigint, btcPrice: bigint, authorizedSpendsHash: string, ucdDebtHash: string, quantumTimestamp: bigint): Promise<ContractTransactionResponse>;
41
+ processPayment(positionId: string, paymentAmount: bigint, quantumTimestamp: bigint, btcPrice: bigint): Promise<ContractTransactionResponse>;
42
+ updatePosition(positionId: string, newDebt: bigint, quantumTimestamp: bigint, btcPrice: bigint, updateValidatorSignature: string): Promise<ContractTransactionResponse>;
43
+ transferOriginationFee(recipient: string, amount: bigint): Promise<ContractTransactionResponse>;
44
+ mintExtensionFee(amount: bigint): Promise<ContractTransactionResponse>;
45
+ getOriginationFeeBalance(): Promise<bigint>;
46
+ authorizeBTCSpend(positionId: string, txid: string, vout: number, satoshis: bigint, targetAddress: string, targetAmount: bigint, litSignature: string): Promise<ContractTransactionResponse>;
47
+ liquidationThreshold(): Promise<bigint>;
48
+ minimumLoanValueWei(): Promise<bigint>;
46
49
  ucdToken(): Promise<string>;
47
50
  getUcdController(): Promise<string>;
48
- getPKPActualCollateral(pkpId: string): Promise<BigNumber>;
51
+ getPKPActualCollateral(pkpId: string): Promise<bigint>;
49
52
  isPriceFeedStale(): Promise<boolean>;
50
- calculateCollateralRatio(positionId: string, btcPrice: BigNumber): Promise<BigNumber>;
51
- getTotalAuthorizedSats(positionId: string): Promise<BigNumber>;
52
- extendPosition(positionId: string, newTermMonths: BigNumber, extensionFee: BigNumber, quantumTimestamp: BigNumber, btcPrice: BigNumber, extendValidatorSignature: string): Promise<ethers5.ContractTransaction>;
53
- withdrawBTC(positionId: string, btcTxid: string, btcVout: number, satoshis: BigNumber, destinationAddress: string, quantumTimestamp: BigNumber, btcPrice: BigNumber, btcWithdrawalSignature: string): Promise<ethers5.ContractTransaction>;
53
+ calculateCollateralRatio(positionId: string, btcPrice: bigint): Promise<bigint>;
54
+ getTotalAuthorizedSats(positionId: string): Promise<bigint>;
55
+ extendPosition(positionId: string, newTermMonths: bigint, extensionFee: bigint, quantumTimestamp: bigint, btcPrice: bigint, extendValidatorSignature: string): Promise<ContractTransactionResponse>;
56
+ withdrawBTC(positionId: string, btcTxid: string, btcVout: number, satoshis: bigint, destinationAddress: string, quantumTimestamp: bigint, btcPrice: bigint, btcWithdrawalSignature: string): Promise<ContractTransactionResponse>;
54
57
  }
55
58
  /**
56
59
  * UCD Controller Contract Interface
57
60
  * Based on contracts/src/interfaces/IUCDController.sol
58
61
  */
59
- export interface IUCDController extends ethers5.Contract {
60
- mintFromLoanOps(to: string, amount: BigNumber, positionId: string, debtAfterMint: BigNumber): Promise<ethers5.ContractTransaction>;
61
- mintFromPsm(to: string, amount: BigNumber, stablecoin: string, amountIn: BigNumber): Promise<ethers5.ContractTransaction>;
62
- burnTokens(from: string, amount: BigNumber): Promise<ethers5.ContractTransaction>;
63
- setAdminModule(_adminModule: string): Promise<ethers5.ContractTransaction>;
64
- setAuthorizedMinter(minter: string, authorized: boolean): Promise<ethers5.ContractTransaction>;
65
- setAuthorizedBurner(burner: string, authorized: boolean): Promise<ethers5.ContractTransaction>;
66
- setMaxSupply(newMaxSupply: BigNumber): Promise<ethers5.ContractTransaction>;
67
- setDailyMintLimit(newLimit: BigNumber): Promise<ethers5.ContractTransaction>;
68
- setDailyBurnLimit(newLimit: BigNumber): Promise<ethers5.ContractTransaction>;
69
- setUCDToken(newToken: string): Promise<ethers5.ContractTransaction>;
70
- getCurrentSupply(): Promise<BigNumber>;
71
- getRemainingMintCapacity(): Promise<BigNumber>;
72
- getRemainingBurnCapacity(): Promise<BigNumber>;
73
- getRemainingPsmMintCapacity(): Promise<BigNumber>;
62
+ export interface IUCDController extends BaseContract {
63
+ mintFromLoanOps(to: string, amount: bigint, positionId: string, debtAfterMint: bigint): Promise<ContractTransactionResponse>;
64
+ mintFromPsm(to: string, amount: bigint, stablecoin: string, amountIn: bigint): Promise<ContractTransactionResponse>;
65
+ burnTokens(from: string, amount: bigint): Promise<ContractTransactionResponse>;
66
+ setAdminModule(_adminModule: string): Promise<ContractTransactionResponse>;
67
+ setAuthorizedMinter(minter: string, authorized: boolean): Promise<ContractTransactionResponse>;
68
+ setAuthorizedBurner(burner: string, authorized: boolean): Promise<ContractTransactionResponse>;
69
+ setMaxSupply(newMaxSupply: bigint): Promise<ContractTransactionResponse>;
70
+ setDailyMintLimit(newLimit: bigint): Promise<ContractTransactionResponse>;
71
+ setDailyBurnLimit(newLimit: bigint): Promise<ContractTransactionResponse>;
72
+ setUCDToken(newToken: string): Promise<ContractTransactionResponse>;
73
+ getCurrentSupply(): Promise<bigint>;
74
+ getRemainingMintCapacity(): Promise<bigint>;
75
+ getRemainingBurnCapacity(): Promise<bigint>;
76
+ getRemainingPsmMintCapacity(): Promise<bigint>;
74
77
  isAuthorizedMinter(account: string): Promise<boolean>;
75
78
  isAuthorizedBurner(account: string): Promise<boolean>;
76
79
  authorizedMinters(account: string): Promise<boolean>;
77
80
  authorizedBurners(account: string): Promise<boolean>;
78
- burnedPerAddress(account: string): Promise<BigNumber>;
79
- totalMinted(): Promise<BigNumber>;
80
- totalBurned(): Promise<BigNumber>;
81
- maxSupply(): Promise<BigNumber>;
82
- dailyMintLimit(): Promise<BigNumber>;
83
- dailyBurnLimit(): Promise<BigNumber>;
84
- lastMintReset(): Promise<BigNumber>;
85
- lastBurnReset(): Promise<BigNumber>;
86
- dailyMinted(): Promise<BigNumber>;
87
- dailyBurned(): Promise<BigNumber>;
88
- dailyPsmMinted(): Promise<BigNumber>;
89
- psmDailyMintLimit(): Promise<BigNumber>;
81
+ burnedPerAddress(account: string): Promise<bigint>;
82
+ totalMinted(): Promise<bigint>;
83
+ totalBurned(): Promise<bigint>;
84
+ maxSupply(): Promise<bigint>;
85
+ dailyMintLimit(): Promise<bigint>;
86
+ dailyBurnLimit(): Promise<bigint>;
87
+ lastMintReset(): Promise<bigint>;
88
+ lastBurnReset(): Promise<bigint>;
89
+ dailyMinted(): Promise<bigint>;
90
+ dailyBurned(): Promise<bigint>;
91
+ dailyPsmMinted(): Promise<bigint>;
92
+ psmDailyMintLimit(): Promise<bigint>;
90
93
  circuitBreaker(): Promise<string>;
91
94
  ucdToken(): Promise<string>;
92
95
  adminModule(): Promise<string>;
@@ -94,72 +97,73 @@ export interface IUCDController extends ethers5.Contract {
94
97
  /**
95
98
  * Price Feed Consumer Contract Interface
96
99
  */
97
- export interface IPriceFeedConsumer extends ethers5.Contract {
98
- updatePrice(): Promise<ethers5.ContractTransaction>;
99
- getCurrentPrice(): Promise<BigNumber>;
100
- getPriceAge(): Promise<BigNumber>;
100
+ export interface IPriceFeedConsumer extends BaseContract {
101
+ updatePrice(): Promise<ContractTransactionResponse>;
102
+ getCurrentPrice(): Promise<bigint>;
103
+ getPriceAge(): Promise<bigint>;
101
104
  isPriceStale(): Promise<boolean>;
102
105
  validatePriceFeed(): Promise<boolean>;
103
- getLatestBTCPrice(): Promise<BigNumber>;
106
+ getLatestBTCPrice(): Promise<bigint>;
104
107
  decimals(): Promise<number>;
105
108
  }
106
109
  /**
107
110
  * Term Manager Contract Interface
108
111
  * Based on contracts/src/interfaces/ITermManager.sol
109
112
  */
110
- export interface ITermManager extends ethers5.Contract {
111
- addTerm(termMonths: BigNumber, originationFee: BigNumber, extensionFee: BigNumber): Promise<ethers5.ContractTransaction>;
112
- removeTerm(termMonths: BigNumber): Promise<ethers5.ContractTransaction>;
113
- updateTermFees(termMonths: BigNumber, originationFee: BigNumber, extensionFee: BigNumber): Promise<ethers5.ContractTransaction>;
114
- getTermFees(termMonths: BigNumber): Promise<{
115
- originationFee: BigNumber;
116
- extensionFee: BigNumber;
113
+ export interface ITermManager extends BaseContract {
114
+ addTerm(termMonths: bigint, originationFee: bigint, extensionFee: bigint): Promise<ContractTransactionResponse>;
115
+ removeTerm(termMonths: bigint): Promise<ContractTransactionResponse>;
116
+ updateTermFees(termMonths: bigint, originationFee: bigint, extensionFee: bigint): Promise<ContractTransactionResponse>;
117
+ getTermFees(termMonths: bigint): Promise<{
118
+ originationFee: bigint;
119
+ extensionFee: bigint;
117
120
  }>;
118
- isValidTerm(termMonths: BigNumber): Promise<boolean>;
121
+ isValidTerm(termMonths: bigint): Promise<boolean>;
119
122
  getValidTermsWithFees(): Promise<{
120
- terms: BigNumber[];
121
- originationFees: BigNumber[];
122
- extensionFees: BigNumber[];
123
+ terms: bigint[];
124
+ originationFees: bigint[];
125
+ extensionFees: bigint[];
123
126
  }>;
124
- getTermDataById(termId: BigNumber): Promise<{
125
- termMonths: BigNumber;
126
- originationFee: BigNumber;
127
- extensionFee: BigNumber;
127
+ getTermDataById(termId: bigint): Promise<{
128
+ termMonths: bigint;
129
+ originationFee: bigint;
130
+ extensionFee: bigint;
128
131
  isActive: boolean;
129
132
  }>;
130
- getAllTerms(): Promise<BigNumber[]>;
131
- updateDependencies(newCore: string, newUcdController: string): Promise<ethers5.ContractTransaction>;
133
+ getAllTerms(): Promise<bigint[]>;
134
+ updateDependencies(newCore: string, newUcdController: string): Promise<ContractTransactionResponse>;
132
135
  supportsInterface(interfaceId: string): Promise<boolean>;
133
136
  }
134
137
  /**
135
138
  * Circuit Breaker Module Contract Interface
136
139
  * Based on contracts/src/interfaces/ICircuitBreakerModule.sol
137
140
  */
138
- export interface CircuitBreakerModule extends ethers5.Contract {
139
- circuitBreakerCheck(ucdAmount: BigNumber, btcAmount: BigNumber): Promise<ethers5.ContractTransaction>;
140
- proposeLimitUpdate(newMaxLoanValue: BigNumber, newMaxBtcPerPosition: BigNumber, newDailyLimit: BigNumber): Promise<ethers5.ContractTransaction>;
141
- signLimitUpdate(proposalHash: string): Promise<ethers5.ContractTransaction>;
142
- executeLimitUpdate(proposalHash: string, newMaxLoanValue: BigNumber, newMaxBtcPerPosition: BigNumber, newDailyLimit: BigNumber): Promise<ethers5.ContractTransaction>;
143
- activateCircuitBreaker(): Promise<ethers5.ContractTransaction>;
144
- deactivateCircuitBreaker(): Promise<ethers5.ContractTransaction>;
145
- signCircuitBreakerDeactivation(): Promise<ethers5.ContractTransaction>;
146
- maxSingleLoanValue(): Promise<BigNumber>;
147
- maxBtcPerPosition(): Promise<BigNumber>;
148
- dailyVolumeLimit(): Promise<BigNumber>;
141
+ export interface CircuitBreakerModule extends BaseContract {
142
+ circuitBreakerCheck(ucdAmount: bigint, btcAmount: bigint): Promise<ContractTransactionResponse>;
143
+ proposeLimitUpdate(newMaxLoanValue: bigint, newMaxBtcPerPosition: bigint, newDailyLimit: bigint): Promise<ContractTransactionResponse>;
144
+ signLimitUpdate(proposalHash: string): Promise<ContractTransactionResponse>;
145
+ executeLimitUpdate(proposalHash: string, newMaxLoanValue: bigint, newMaxBtcPerPosition: bigint, newDailyLimit: bigint): Promise<ContractTransactionResponse>;
146
+ activateCircuitBreaker(): Promise<ContractTransactionResponse>;
147
+ deactivateCircuitBreaker(): Promise<ContractTransactionResponse>;
148
+ signCircuitBreakerDeactivation(): Promise<ContractTransactionResponse>;
149
+ maxSingleLoanValue(): Promise<bigint>;
150
+ maxBtcPerPosition(): Promise<bigint>;
151
+ dailyVolumeLimit(): Promise<bigint>;
149
152
  circuitBreakerActive(): Promise<boolean>;
150
- circuitBreakerActivatedAt(): Promise<BigNumber>;
151
- dailyUcdVolume(day: BigNumber): Promise<BigNumber>;
152
- dailyBtcVolume(day: BigNumber): Promise<BigNumber>;
153
+ circuitBreakerActivatedAt(): Promise<bigint>;
154
+ dailyUcdVolume(day: bigint): Promise<bigint>;
155
+ dailyBtcVolume(day: bigint): Promise<bigint>;
153
156
  supportsInterface(interfaceId: string): Promise<boolean>;
154
157
  }
155
158
  /**
156
159
  * Liquidation Manager Contract Interface
157
160
  * Based on contracts/src/interfaces/ILiquidationManager.sol
158
161
  */
159
- export interface ILiquidationManager extends ethers5.Contract {
160
- liquidatePosition(positionId: string, btcPrice: BigNumber, quantumTimestamp: BigNumber): Promise<ethers5.ContractTransaction>;
161
- commitLiquidation(positionId: string, quantumTimestamp: BigNumber, btcPrice: BigNumber): Promise<ethers5.ContractTransaction>;
162
- revealAndLiquidate(positionId: string, quantumTimestamp: BigNumber, btcPrice: BigNumber, liquidationValidatorSignature: string, deadline: BigNumber): Promise<ethers5.ContractTransaction>;
163
- isLiquidatable(positionId: string, btcPrice: BigNumber, quantumTimestamp: BigNumber, liquidationValidatorSignature: string): Promise<boolean>;
162
+ export interface ILiquidationManager extends BaseContract {
163
+ liquidatePosition(positionId: string, btcPrice: bigint, quantumTimestamp: bigint): Promise<ContractTransactionResponse>;
164
+ commitLiquidation(positionId: string, quantumTimestamp: bigint, btcPrice: bigint): Promise<ContractTransactionResponse>;
165
+ revealAndLiquidate(positionId: string, quantumTimestamp: bigint, btcPrice: bigint, liquidationValidatorSignature: string, deadline: bigint): Promise<ContractTransactionResponse>;
166
+ isLiquidatable(positionId: string, btcPrice: bigint, quantumTimestamp: bigint, liquidationValidatorSignature: string): Promise<boolean>;
167
+ vrfSeeds(positionId: string): Promise<bigint>;
164
168
  supportsInterface(interfaceId: string): Promise<boolean>;
165
169
  }
@@ -169,7 +169,6 @@ export interface UCDMintRequest {
169
169
  selectedTerm?: number;
170
170
  skipValidation?: boolean;
171
171
  rpcUrl?: string;
172
- customBitcoinRpcUrl?: string;
173
172
  testBtcPrice?: number;
174
173
  debugOverrides?: {
175
174
  useStubbedBtcData?: boolean;
@@ -232,6 +231,8 @@ export interface BTCWithdrawalResult {
232
231
  bitcoinTransactionHash?: string;
233
232
  utxoTxid?: string;
234
233
  utxoVout?: number;
234
+ /** Full satoshi value of the authorized UTXO; needed by Phase 2 broadcast. */
235
+ utxoSatoshis?: string;
235
236
  error?: string;
236
237
  }
237
238
  /**
@@ -247,7 +248,6 @@ export interface LiquidationRequest {
247
248
  */
248
249
  skipUcdApproval?: boolean;
249
250
  rpcUrl?: string;
250
- customBitcoinRpcUrl?: string;
251
251
  }
252
252
  /**
253
253
  * Liquidation Result Interface
@@ -272,7 +272,6 @@ export interface PartialPaymentRequest {
272
272
  positionId: string;
273
273
  paymentAmount: number;
274
274
  rpcUrl?: string;
275
- customBitcoinRpcUrl?: string;
276
275
  }
277
276
  /**
278
277
  * Confirm Balance Result Interface
@@ -197,6 +197,43 @@ export declare class BitcoinOperations {
197
197
  * Check if consensus mode is enabled
198
198
  */
199
199
  isConsensusEnabled(): boolean;
200
+ /**
201
+ * Audit CRIT-2: verify a Phase-2 BTC withdrawal that the lit-ops-server
202
+ * claimed broadcast actually exists on chain and matches the user's
203
+ * authorization.
204
+ *
205
+ * Behavior:
206
+ * - If we successfully fetch the tx AND it disagrees with what the user
207
+ * authorized → throws (hard fail; server lied).
208
+ * - If we fetch the tx and it matches → returns `{ verified: true }`.
209
+ * - If no provider has the tx after `maxAttempts` retries → returns
210
+ * `{ verified: false, reason: "not yet visible" }`. The caller decides
211
+ * whether to log a warning and proceed (e.g., regtest without an
212
+ * Esplora indexer, or extreme propagation delay) or to escalate.
213
+ * - If no Bitcoin providers are configured → returns `{ verified: false,
214
+ * reason: "no providers" }` immediately.
215
+ *
216
+ * The expected `value` is `targetAmount - networkFee` (what reaches the
217
+ * recipient after the fee), matching the Lit Action's
218
+ * `userReceivesAmount` computation.
219
+ */
220
+ verifyBroadcastTx(args: {
221
+ txid: string;
222
+ expectedInput: {
223
+ txid: string;
224
+ vout: number;
225
+ };
226
+ expectedOutput: {
227
+ address: string;
228
+ value: number;
229
+ };
230
+ maxAttempts?: number;
231
+ delayMs?: number;
232
+ }): Promise<{
233
+ verified: boolean;
234
+ reason?: string;
235
+ confirmed?: boolean;
236
+ }>;
200
237
  /**
201
238
  * Get current BTC price using LIT Protocol price oracle
202
239
  *
@@ -86,6 +86,14 @@ export interface CacheConfig {
86
86
  */
87
87
  export declare class LRUCache<K, V> {
88
88
  private cache;
89
+ /**
90
+ * Audit M-J: singleflight registry for `getOrCompute` / `getOrComputeResult`.
91
+ * Concurrent cache-miss callers for the same key share one inflight promise
92
+ * instead of each running `compute()` independently — important when the
93
+ * compute spends a paid LIT capacity credit or hits a rate-limited upstream.
94
+ */
95
+ private inflight;
96
+ private inflightResult;
89
97
  private readonly maxSize;
90
98
  private readonly ttlMs;
91
99
  private readonly debug;
@@ -10,19 +10,19 @@
10
10
  * This module centralizes all contract interaction setup and provides
11
11
  * a clean interface for other modules to access contracts.
12
12
  */
13
- import { ethers as ethers5 } from "ethers";
13
+ import { type Provider, type Signer } from "ethers";
14
14
  import type { ContractAddresses } from "../../interfaces/chunks/config.i";
15
15
  import { Result } from "../../types/result";
16
16
  import { SDKError } from "../../utils/error-handler";
17
17
  import type { PositionManager, ILoanOperationsManager, IUCDController, IPriceFeedConsumer, ITermManager, CircuitBreakerModule, ILiquidationManager } from "../../interfaces/chunks/contract-types.i";
18
18
  /**
19
- * Type alias for ethers v5 provider (used throughout SDK)
19
+ * Type alias for ethers v6 provider (used throughout SDK)
20
20
  */
21
- export type Provider = ethers5.providers.Provider;
21
+ export type { Provider };
22
22
  /**
23
- * Type alias for ethers v5 signer
23
+ * Type alias for ethers v6 signer
24
24
  */
25
- export type Signer = ethers5.Signer;
25
+ export type { Signer };
26
26
  /**
27
27
  * Type alias for contract runner (provider or signer)
28
28
  */