@gvnrdao/dh-sdk 0.0.166 → 0.0.205

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -5
  3. package/browser/dist/397.browser.js +1 -1
  4. package/browser/dist/833.browser.js +1 -1
  5. package/browser/dist/browser.js +1 -13
  6. package/browser/dist/browser.js.LICENSE.txt +1 -70
  7. package/browser/dist/index.d.ts +3 -4
  8. package/browser/dist/index.d.ts.map +1 -1
  9. package/browser/dist/index.js +4 -3
  10. package/dist/constants/chunks/contract-abis.d.ts +7 -0
  11. package/dist/constants/chunks/deployment-addresses.d.ts +68 -0
  12. package/dist/constants/chunks/encrypted-provider-params.d.ts +21 -0
  13. package/dist/constants/chunks/environment.browser.d.ts +45 -0
  14. package/dist/constants/chunks/environment.d.ts +57 -0
  15. package/dist/constants/chunks/network-configs.d.ts +65 -0
  16. package/dist/constants/chunks/sdk-config.d.ts +33 -0
  17. package/dist/constants/chunks/sdk-limits.d.ts +66 -0
  18. package/dist/constants/index.d.ts +15 -0
  19. package/dist/graphs/client.d.ts +19 -0
  20. package/dist/graphs/diamond-hands.d.ts +248 -0
  21. package/dist/index.d.ts +47 -7391
  22. package/dist/index.js +4525 -16860
  23. package/dist/index.mjs +4489 -16801
  24. package/dist/interfaces/chunks/btc.i.d.ts +36 -0
  25. package/dist/interfaces/chunks/config.i.d.ts +250 -0
  26. package/dist/interfaces/chunks/contract-interactions.i.d.ts +64 -0
  27. package/dist/interfaces/chunks/contract-types.i.d.ts +165 -0
  28. package/dist/interfaces/chunks/lit-actions-results.i.d.ts +165 -0
  29. package/dist/interfaces/chunks/lit-actions.i.d.ts +98 -0
  30. package/dist/interfaces/chunks/loan-operations.i.d.ts +332 -0
  31. package/dist/interfaces/chunks/pkp-integration.i.d.ts +87 -0
  32. package/dist/interfaces/chunks/position-query.i.d.ts +76 -0
  33. package/dist/interfaces/chunks/requests.i.d.ts +55 -0
  34. package/dist/interfaces/chunks/ucd-minting.i.d.ts +34 -0
  35. package/dist/interfaces/chunks/utility.i.d.ts +64 -0
  36. package/dist/interfaces/index.d.ts +17 -0
  37. package/dist/modules/bitcoin/bitcoin-operations.module.d.ts +223 -0
  38. package/dist/modules/cache/cache-manager.module.d.ts +92 -0
  39. package/dist/modules/contract/contract-manager.module.d.ts +136 -0
  40. package/dist/modules/diamond-hands-sdk.d.ts +669 -0
  41. package/dist/modules/loan/loan-creator.module.d.ts +143 -0
  42. package/dist/modules/loan/loan-query.module.d.ts +206 -0
  43. package/dist/modules/mock/mock-token-manager.module.d.ts +83 -0
  44. package/dist/modules/pkp/pkp-manager.module.d.ts +136 -0
  45. package/dist/protocol/protocol-pause.d.ts +19 -0
  46. package/dist/server.d.ts +17 -0
  47. package/dist/server.js +285 -0
  48. package/dist/server.mjs +242 -0
  49. package/dist/types/authorization-params.d.ts +160 -0
  50. package/dist/types/branded/domain-values.d.ts +138 -0
  51. package/dist/types/branded/ids.d.ts +23 -0
  52. package/dist/types/event-types.d.ts +235 -0
  53. package/dist/types/graph-dtos.d.ts +228 -0
  54. package/dist/types/loanStatus.d.ts +10 -0
  55. package/dist/types/result.d.ts +120 -0
  56. package/dist/utils/bitcoin-address-cache.utils.d.ts +87 -0
  57. package/dist/utils/bitcoin-provider.utils.d.ts +48 -0
  58. package/dist/utils/bitcoin-signature.d.ts +20 -0
  59. package/dist/utils/chunks/bitcoin-utils.d.ts +75 -0
  60. package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +24 -0
  61. package/dist/utils/error-handler.d.ts +106 -0
  62. package/dist/utils/ethers-interop.utils.d.ts +146 -0
  63. package/dist/utils/extend-authorization.utils.d.ts +61 -0
  64. package/dist/utils/lit-signature.utils.d.ts +6 -0
  65. package/dist/utils/logger.utils.d.ts +142 -0
  66. package/dist/utils/mint-authorization.utils.d.ts +224 -0
  67. package/dist/utils/quantum-timing.d.ts +75 -0
  68. package/dist/utils/signature-tempering.utils.d.ts +31 -0
  69. package/dist/utils/telegram-messaging.utils.d.ts +188 -0
  70. package/package.json +43 -22
  71. package/dist/index.d.mts +0 -7392
@@ -0,0 +1,6 @@
1
+ export declare function extractLitSignature(raw: unknown, key: string): {
2
+ signature: string;
3
+ envelope?: Record<string, unknown>;
4
+ };
5
+ export declare function extractOptionalLitSignatureFromEnvelope(envelope: Record<string, unknown> | undefined, key: string): string;
6
+ export declare function extractOptionalLitSignature(raw: unknown): string;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Minimal Logger Utility
3
+ * Provides structured logging with levels and context to keep production output clean
4
+ */
5
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
6
+ export interface LogContext {
7
+ operation?: string;
8
+ id?: string;
9
+ userId?: string;
10
+ positionId?: string;
11
+ pkpId?: string;
12
+ address?: string;
13
+ network?: string;
14
+ provider?: string;
15
+ attempt?: number;
16
+ maxAttempts?: number;
17
+ duration?: number;
18
+ [key: string]: any;
19
+ }
20
+ export interface LoggerConfig {
21
+ enabled: boolean;
22
+ level: LogLevel;
23
+ includeTimestamp: boolean;
24
+ includeContext: boolean;
25
+ maxContextKeys: number;
26
+ verboseInProduction: boolean;
27
+ isProduction: boolean;
28
+ }
29
+ export declare class Logger {
30
+ private config;
31
+ private static instance;
32
+ constructor(config?: Partial<LoggerConfig>);
33
+ /**
34
+ * Get or create singleton logger instance
35
+ */
36
+ static getInstance(config?: Partial<LoggerConfig>): Logger;
37
+ /**
38
+ * Update logger configuration
39
+ */
40
+ updateConfig(config: Partial<LoggerConfig>): void;
41
+ /**
42
+ * Check if a log level should be output
43
+ */
44
+ private shouldLog;
45
+ /**
46
+ * Format context object for output
47
+ */
48
+ private formatContext;
49
+ /**
50
+ * Format timestamp for output
51
+ */
52
+ private formatTimestamp;
53
+ /**
54
+ * Core logging method
55
+ */
56
+ private log;
57
+ /**
58
+ * Get prefix for log level
59
+ */
60
+ private getLevelPrefix;
61
+ /**
62
+ * Debug level logging
63
+ */
64
+ debug(message: string, context?: LogContext): void;
65
+ /**
66
+ * Info level logging
67
+ */
68
+ info(message: string, context?: LogContext): void;
69
+ /**
70
+ * Warning level logging
71
+ */
72
+ warn(message: string, context?: LogContext): void;
73
+ /**
74
+ * Error level logging
75
+ */
76
+ error(message: string, context?: LogContext): void;
77
+ /**
78
+ * Log operation start
79
+ */
80
+ startOperation(operation: string, context?: LogContext): void;
81
+ /**
82
+ * Log operation completion
83
+ */
84
+ completeOperation(operation: string, context?: LogContext): void;
85
+ /**
86
+ * Log operation failure
87
+ */
88
+ failOperation(operation: string, error: Error | string, context?: LogContext): void;
89
+ /**
90
+ * Log retry attempt
91
+ */
92
+ retry(operation: string, attempt: number, maxAttempts: number, error?: Error, context?: LogContext): void;
93
+ /**
94
+ * Log cache operations
95
+ */
96
+ cacheHit(key: string, context?: LogContext): void;
97
+ cacheMiss(key: string, context?: LogContext): void;
98
+ /**
99
+ * Log network operations
100
+ */
101
+ networkRequest(url: string, method: string, context?: LogContext): void;
102
+ networkResponse(url: string, status: number, duration?: number, context?: LogContext): void;
103
+ /**
104
+ * Log Bitcoin operations
105
+ */
106
+ bitcoinOperation(operation: string, address?: string, context?: LogContext): void;
107
+ /**
108
+ * Log contract operations
109
+ */
110
+ contractOperation(operation: string, contract?: string, context?: LogContext): void;
111
+ }
112
+ /**
113
+ * Get the global logger instance
114
+ */
115
+ export declare function getLogger(): Logger;
116
+ /**
117
+ * Create a logger with specific configuration
118
+ */
119
+ export declare function createLogger(config: Partial<LoggerConfig>): Logger;
120
+ /**
121
+ * Quick logging functions for common use cases
122
+ */
123
+ export declare const log: {
124
+ debug: (message: string, context?: LogContext) => void;
125
+ info: (message: string, context?: LogContext) => void;
126
+ warn: (message: string, context?: LogContext) => void;
127
+ error: (message: string, context?: LogContext) => void;
128
+ start: (operation: string, context?: LogContext) => void;
129
+ complete: (operation: string, context?: LogContext) => void;
130
+ fail: (operation: string, error: Error | string, context?: LogContext) => void;
131
+ retry: (operation: string, attempt: number, maxAttempts: number, error?: Error, context?: LogContext) => void;
132
+ cache: {
133
+ hit: (key: string, context?: LogContext) => void;
134
+ miss: (key: string, context?: LogContext) => void;
135
+ };
136
+ network: {
137
+ request: (url: string, method: string, context?: LogContext) => void;
138
+ response: (url: string, status: number, duration?: number, context?: LogContext) => void;
139
+ };
140
+ bitcoin: (operation: string, address?: string, context?: LogContext) => void;
141
+ contract: (operation: string, contract?: string, context?: LogContext) => void;
142
+ };
@@ -0,0 +1,224 @@
1
+ /**
2
+ * UCD Mint Authorization Utilities
3
+ *
4
+ * Generates authorization signatures for UCD mint requests
5
+ * that can be verified by the ucd-mint-validator LIT Action.
6
+ * Also includes withdrawal authorization utilities.
7
+ */
8
+ import { ethers as ethers5 } from "ethers";
9
+ /**
10
+ * Owner Authorization Interface (matches lit-actions)
11
+ */
12
+ export interface MintOwnerAuthorization {
13
+ positionId: string;
14
+ timestamp: number;
15
+ chainId: number;
16
+ amount: string;
17
+ action: string;
18
+ signature: string;
19
+ }
20
+ /**
21
+ * Build the mint authorization message hash without signing.
22
+ *
23
+ * Use this when signing with a smart contract wallet (e.g. Safe) that
24
+ * needs to wrap the hash in its own domain before signing.
25
+ *
26
+ * Returns the raw hash AND the timestamp so both can be passed to
27
+ * generateMintAuthorization via the pre-computed signature overload.
28
+ *
29
+ * @param positionId - Position identifier
30
+ * @param amount - Amount to mint in wei (bigint)
31
+ * @param chainId - Chain ID for cross-chain replay protection
32
+ * @returns { hash, timestamp } — pass these to Safe for signing
33
+ */
34
+ export declare function buildMintAuthorizationHash(positionId: string, amount: bigint, chainId: number): {
35
+ hash: string;
36
+ timestamp: number;
37
+ };
38
+ /**
39
+ * Generate mint authorization signature
40
+ *
41
+ * Creates a signature that matches the format expected by
42
+ * AuthorizationModule.verifyMintAuthorization in lit-actions.
43
+ *
44
+ * Message structure:
45
+ * solidityKeccak256(
46
+ * ["bytes32", "uint256", "uint256", "uint256", "bytes32"],
47
+ * [positionId, timestamp, chainId, amount, actionHash]
48
+ * )
49
+ *
50
+ * Where:
51
+ * - actionHash = keccak256("mint-ucd")
52
+ * - Signer address is recovered from signature by LIT Action
53
+ * - LIT Action validates recovered address === position owner
54
+ *
55
+ * @param positionId - Position identifier
56
+ * @param amount - Amount to mint in wei (bigint)
57
+ * @param chainId - Chain ID for cross-chain replay protection
58
+ * @param signerOrPrecomputed - Either an ethers Signer (EOA) or { timestamp, signature } for smart contract wallets
59
+ * @returns Authorization object with signature
60
+ */
61
+ export declare function generateMintAuthorization(positionId: string, amount: bigint, chainId: number, signerOrPrecomputed: ethers5.Signer | {
62
+ timestamp: number;
63
+ signature: string;
64
+ }): Promise<MintOwnerAuthorization>;
65
+ /**
66
+ * Payment Authorization Interface (matches lit-actions)
67
+ */
68
+ export interface PaymentOwnerAuthorization {
69
+ positionId: string;
70
+ timestamp: number;
71
+ chainId: number;
72
+ amount: string;
73
+ action: string;
74
+ signature: string;
75
+ }
76
+ /**
77
+ * Extend Position Authorization Interface (matches lit-actions)
78
+ */
79
+ export interface ExtendOwnerAuthorization {
80
+ positionId: string;
81
+ timestamp: number;
82
+ chainId: number;
83
+ selectedTerm: number;
84
+ action: string;
85
+ signature: string;
86
+ }
87
+ /**
88
+ * Balance Confirmation Authorization Interface
89
+ * For permissionless balance confirmation with quantum security
90
+ */
91
+ export interface BalanceConfirmationAuthorization {
92
+ positionId: string;
93
+ timestamp: number;
94
+ chainId: number;
95
+ caller: string;
96
+ action: string;
97
+ signature: string;
98
+ }
99
+ /**
100
+ * Generate payment authorization signature
101
+ *
102
+ * Creates a signature that matches the format expected by
103
+ * process-payment-validator LIT Action.
104
+ *
105
+ * Message structure:
106
+ * solidityKeccak256(
107
+ * ["bytes32", "uint256", "uint256", "uint256", "bytes32"],
108
+ * [positionId, timestamp, chainId, amount, actionHash]
109
+ * )
110
+ *
111
+ * Where:
112
+ * - actionHash = keccak256("make-payment")
113
+ * - Signer address is recovered from signature by LIT Action
114
+ * - LIT Action validates recovered address === position owner
115
+ */
116
+ export declare function generatePaymentAuthorization(positionId: string, amount: bigint, chainId: number, signer: ethers5.Signer): Promise<PaymentOwnerAuthorization>;
117
+ /**
118
+ * Generate extend position authorization signature
119
+ *
120
+ * Creates a signature that matches the format expected by
121
+ * extend-position-validator LIT Action.
122
+ *
123
+ * Message structure:
124
+ * solidityKeccak256(
125
+ * ["bytes32", "uint256", "uint256", "uint256", "bytes32"],
126
+ * [positionId, timestamp, chainId, selectedTerm, actionHash]
127
+ * )
128
+ *
129
+ * Where:
130
+ * - actionHash = keccak256("extend-position")
131
+ * - Signer address is recovered from signature by LIT Action
132
+ * - LIT Action validates recovered address === position owner
133
+ */
134
+ export declare function generateExtendAuthorization(positionId: string, selectedTerm: number, chainId: number, signer: ethers5.Signer): Promise<ExtendOwnerAuthorization>;
135
+ /**
136
+ * Get PKP public key from PKP token ID
137
+ *
138
+ * Queries the PKP NFT contract on the Chipotle LIT chain (Chronicle Yellowstone, chainId 175188).
139
+ *
140
+ * @param pkpTokenId - PKP token ID (bytes32 hex string)
141
+ * @param provider - Ethereum provider (optional; reused if already on the correct LIT chain)
142
+ * @param pkpNftContractAddress - PKP NFT contract address (required)
143
+ * @returns PKP public key as hex string with '0x' prefix
144
+ */
145
+ export declare function getPKPPublicKeyFromTokenId(pkpTokenId: string, provider?: ethers5.providers.Provider, pkpNftContractAddress?: string): Promise<string>;
146
+ /**
147
+ * Withdraw Owner Authorization Interface (matches lit-actions)
148
+ */
149
+ export interface WithdrawOwnerAuthorization {
150
+ positionId: string;
151
+ timestamp: number;
152
+ chainId: number;
153
+ amount: string;
154
+ action: string;
155
+ signature: string;
156
+ }
157
+ /**
158
+ * Build the withdraw authorization message hash without signing.
159
+ *
160
+ * Use this when signing with a smart contract wallet (e.g. Safe) that
161
+ * needs to wrap the hash in its own domain before signing.
162
+ *
163
+ * @param positionId - Position identifier
164
+ * @param amount - Amount to withdraw in satoshis (bigint)
165
+ * @param chainId - Chain ID for cross-chain replay protection
166
+ * @param destinationAddress - Bitcoin destination address
167
+ * @returns { hash, timestamp } — pass these to Safe for signing
168
+ */
169
+ export declare function buildWithdrawAuthorizationHash(positionId: string, amount: bigint, chainId: number, destinationAddress: string): {
170
+ hash: string;
171
+ timestamp: number;
172
+ };
173
+ /**
174
+ * Generate withdrawal authorization signature
175
+ *
176
+ * Creates a signature that matches the format expected by
177
+ * AuthorizationModule.verifyWithdrawAuthorization in lit-actions.
178
+ *
179
+ * Message structure:
180
+ * solidityKeccak256(
181
+ * ["bytes32", "uint256", "uint256", "uint256", "string", "bytes32"],
182
+ * [positionId, timestamp, chainId, amount, destinationAddress, actionHash]
183
+ * )
184
+ *
185
+ * Where:
186
+ * - actionHash = keccak256("withdraw-btc")
187
+ * - Signer address is recovered from signature by LIT Action
188
+ * - LIT Action validates recovered address === position owner
189
+ *
190
+ * @param positionId - Position identifier
191
+ * @param amount - Amount to withdraw in satoshis (bigint)
192
+ * @param chainId - Chain ID for cross-chain replay protection
193
+ * @param signerOrPrecomputed - Either an ethers Signer (EOA) or { timestamp, signature } for smart contract wallets
194
+ * @param destinationAddress - Bitcoin address for withdrawal
195
+ * @returns Authorization object with signature
196
+ */
197
+ export declare function generateWithdrawAuthorization(positionId: string, amount: bigint, // satoshis
198
+ chainId: number, signerOrPrecomputed: ethers5.Signer | {
199
+ timestamp: number;
200
+ signature: string;
201
+ }, destinationAddress: string): Promise<WithdrawOwnerAuthorization>;
202
+ /**
203
+ * Generate balance confirmation authorization signature
204
+ *
205
+ * Creates a signature for permissionless balance confirmation with quantum security.
206
+ * Unlike mint/payment (owner-signed), this is signed by the caller (anyone).
207
+ *
208
+ * Message structure:
209
+ * solidityKeccak256(
210
+ * ["bytes32", "uint256", "uint256", "address", "bytes32"],
211
+ * [positionId, timestamp, chainId, caller, actionHash]
212
+ * )
213
+ *
214
+ * Where:
215
+ * - actionHash = keccak256("confirm-balance")
216
+ * - Signer is the caller (anyone can call permissionlessly)
217
+ * - Quantum timestamp validates timing security
218
+ *
219
+ * @param positionId - Position identifier
220
+ * @param chainId - Chain ID for cross-chain replay protection
221
+ * @param signer - Ethereum signer to sign with (the caller)
222
+ * @returns Authorization object with signature
223
+ */
224
+ export declare function generateBalanceConfirmationAuthorization(positionId: string, chainId: number, signer: ethers5.Signer): Promise<BalanceConfirmationAuthorization>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Quantum Timing Utility
3
+ *
4
+ * Shared utility for calculating valid quantum timestamps across SDK, tests, and lit-ops.
5
+ *
6
+ * NEW QUANTUM PROTOCOL (60-second 3-window system):
7
+ * - SDK signs for NEXT quantum immediately (no waiting)
8
+ * - 60-second quantum windows
9
+ * - 3-quantum validation (past, current, next) = 180s total validity
10
+ * - Dead zones: first 8s and last 8s of each quantum
11
+ * - Users can operate once per 60 seconds per position
12
+ *
13
+ * Architecture:
14
+ * - SDK uses this to calculate NEXT quantum immediately
15
+ * - Tests use this to generate valid timestamps
16
+ * - LIT Actions validate 3-quantum window with dead zone protection
17
+ */
18
+ /**
19
+ * Calculate a valid quantum timestamp for NEXT quantum (NO WAITING)
20
+ *
21
+ * NEW 60-second quantum system:
22
+ * - Returns NEXT quantum boundary immediately
23
+ * - No waiting for optimal moment
24
+ * - Signature valid for 180 seconds (3 quantums: PAST, CURRENT, NEXT)
25
+ * - User can sign immediately, operation executes within 3-quantum window
26
+ *
27
+ * @returns Promise<number> - Next quantum boundary timestamp
28
+ */
29
+ export declare function calculateValidQuantumTimestamp(): Promise<number>;
30
+ /**
31
+ * Check if a timestamp is in the safe work zone (outside dead zones)
32
+ *
33
+ * @param timestamp - Unix timestamp to check
34
+ * @returns boolean - True if in safe zone (8-52s of any quantum)
35
+ */
36
+ export declare function isInSafeWorkZone(timestamp: number): boolean;
37
+ /**
38
+ * Get current quantum without waiting
39
+ *
40
+ * @returns number - Current quantum timestamp
41
+ */
42
+ export declare function getCurrentQuantum(): number;
43
+ /**
44
+ * Get seconds remaining in current quantum
45
+ *
46
+ * @returns number - Seconds until quantum expires
47
+ */
48
+ export declare function getSecondsUntilQuantumExpiry(): number;
49
+ /**
50
+ * Calculate next quantum timestamp WITHOUT waiting (60-second system)
51
+ *
52
+ * Returns NEXT quantum boundary immediately.
53
+ * No waiting, no optimal moment calculation.
54
+ * Signature valid for 180 seconds (3 quantums).
55
+ *
56
+ * @returns number - Next quantum boundary timestamp
57
+ */
58
+ export declare function calculateNextQuantumTimestamp(): number;
59
+ /**
60
+ * Wait until specific timestamp is reached
61
+ *
62
+ * @param targetTimestamp - Unix timestamp to wait for
63
+ */
64
+ export declare function waitUntilTimestamp(targetTimestamp: number): Promise<void>;
65
+ /**
66
+ * Validate quantum timing (60-second 3-quantum system)
67
+ *
68
+ * Validates that a signed timestamp falls within valid 3-quantum window.
69
+ * With 60-second quantums, signatures are valid for 180 seconds (PAST, CURRENT, NEXT).
70
+ *
71
+ * @param signedTimestamp - Timestamp that was signed by user
72
+ * @param bufferSeconds - Unused in new system (kept for API compatibility)
73
+ * @throws Error if timestamp is invalid
74
+ */
75
+ export declare function validateQuantumTiming(signedTimestamp: number, _bufferSeconds?: number): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Signature Tempering Utility
3
+ *
4
+ * Security testing tool to intentionally corrupt signatures
5
+ * to prove that smart contracts properly validate and reject invalid signatures.
6
+ *
7
+ * WARNING: This is for TESTING ONLY. Tempered signatures will cause transactions to FAIL.
8
+ */
9
+ /**
10
+ * Tempers a signature by modifying the 3rd character with a random valid hex character
11
+ * that differs from the original.
12
+ *
13
+ * @param signature - Original signature (0x prefixed hex string)
14
+ * @returns Tempered signature with 3rd character modified
15
+ *
16
+ * @example
17
+ * const original = "0x1234567890abcdef...";
18
+ * const tempered = temperSignature(original);
19
+ * // tempered = "0x12X4567890abcdef..." where X != 3
20
+ */
21
+ export declare function temperSignature(signature: string): string;
22
+ /**
23
+ * Conditionally tempers a signature based on config flag.
24
+ * Returns original signature if tempering is disabled.
25
+ *
26
+ * @param signature - Original signature
27
+ * @param shouldTemper - Whether to apply tempering
28
+ * @param operationName - Name of operation for logging (optional)
29
+ * @returns Original or tempered signature
30
+ */
31
+ export declare function maybeTemperSignature(signature: string, shouldTemper: boolean | undefined, operationName?: string): string;
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Telegram Messaging Utilities
3
+ *
4
+ * Provides functionality to send messages to Telegram chats using the node-telegram-bot-api package
5
+ */
6
+ /**
7
+ * Send a message to a Telegram chat
8
+ *
9
+ * @param chatId - Telegram chat ID
10
+ * @param chatToken - Telegram bot token
11
+ * @param message - Message to send
12
+ * @param threadId - Optional thread ID for message threads in groups
13
+ * @returns Promise that resolves when message is sent, or rejects on error
14
+ */
15
+ export declare function sendTelegramMessage(chatId: string, chatToken: string, message: string, threadId?: number): Promise<void>;
16
+ /**
17
+ * Format a mint notification message
18
+ *
19
+ * @param mintAmount - Amount minted in UCD
20
+ * @param loanId - Position/loan ID
21
+ * @param txHash - Transaction hash
22
+ * @returns Formatted message string
23
+ */
24
+ export declare function formatMintMessage(mintAmount: number | string, loanId: string, txHash: string): string;
25
+ /**
26
+ * Format a partial payment notification message
27
+ *
28
+ * @param paymentAmount - Amount repaid in UCD
29
+ * @param loanId - Position/loan ID
30
+ * @param txHash - Transaction hash
31
+ * @returns Formatted message string
32
+ */
33
+ export declare function formatPartialPaymentMessage(paymentAmount: number | string, loanId: string, txHash: string): string;
34
+ /**
35
+ * Format a BTC withdrawal notification message
36
+ *
37
+ * @param withdrawalAmount - Amount withdrawn in BTC
38
+ * @param vaultAddress - Bitcoin vault address
39
+ * @param loanId - Position/loan ID
40
+ * @param destinationAddress - Bitcoin destination address
41
+ * @returns Formatted message string
42
+ */
43
+ export declare function formatWithdrawalMessage(withdrawalAmount: number | string, vaultAddress: string, loanId: string, destinationAddress: string): string;
44
+ /**
45
+ * Format a mint failure notification message
46
+ *
47
+ * @param mintAmount - Amount that failed to be minted in UCD
48
+ * @param loanId - Position/loan ID
49
+ * @returns Formatted message string
50
+ */
51
+ export declare function formatMintFailureMessage(mintAmount: number | string, loanId: string): string;
52
+ /**
53
+ * Format a partial payment failure notification message
54
+ *
55
+ * @param paymentAmount - Amount that failed to be repaid in UCD
56
+ * @param loanId - Position/loan ID
57
+ * @param txHash - Optional transaction hash if available
58
+ * @returns Formatted message string
59
+ */
60
+ export declare function formatPartialPaymentFailureMessage(paymentAmount: number | string, loanId: string, txHash?: string): string;
61
+ /**
62
+ * Format a loan creation notification message
63
+ *
64
+ * @param positionId - Position/loan ID
65
+ * @param pkpId - PKP token ID
66
+ * @param vaultAddress - Regtest BTC vault address
67
+ * @returns Formatted message string
68
+ */
69
+ export declare function formatLoanCreationMessage(positionId: string, pkpId: string, vaultAddress?: string): string;
70
+ /**
71
+ * Format a loan creation failure notification message
72
+ *
73
+ * @param error - Error description
74
+ * @returns Formatted message string
75
+ */
76
+ export declare function formatLoanCreationFailureMessage(error: string): string;
77
+ /**
78
+ * Format a BTC withdrawal notification message
79
+ *
80
+ * @param withdrawalAmount - Amount withdrawn in BTC
81
+ * @param loanId - Position/loan ID
82
+ * @param btcTxHash - Bitcoin transaction hash
83
+ * @returns Formatted message string
84
+ */
85
+ export declare function formatBTCWithdrawalMessage(withdrawalAmount: number | string, loanId: string, btcTxHash: string): string;
86
+ /**
87
+ * Format a BTC withdrawal failure notification message
88
+ *
89
+ * @param withdrawalAmount - Amount that failed to be withdrawn in BTC
90
+ * @param btcVault - Bitcoin vault address
91
+ * @param btcDestinationAddress - Bitcoin destination address
92
+ * @param loanId - Position/loan ID
93
+ * @returns Formatted message string
94
+ */
95
+ export declare function formatBTCWithdrawalFailureMessage(withdrawalAmount: number | string, btcVault: string, btcDestinationAddress: string, loanId: string): string;
96
+ /**
97
+ * Format a loan renewal success notification message
98
+ *
99
+ * @param positionId - Position/loan ID
100
+ * @param txHash - Transaction hash
101
+ * @returns Formatted message string
102
+ */
103
+ export declare function formatLoanRenewalMessage(positionId: string, txHash: string): string;
104
+ /**
105
+ * Format a loan renewal failure notification message
106
+ *
107
+ * @param loanId - Position/loan ID
108
+ * @param error - Error description
109
+ * @returns Formatted message string
110
+ */
111
+ export declare function formatLoanRenewalFailureMessage(loanId: string, error: string): string;
112
+ /**
113
+ * Format a balance confirmation success notification message
114
+ *
115
+ * @param loanId - Position/loan ID
116
+ * @returns Formatted message string
117
+ */
118
+ export declare function formatBalanceConfirmationMessage(loanId: string): string;
119
+ /**
120
+ * Format a balance confirmation failure notification message
121
+ *
122
+ * @param loanId - Position/loan ID
123
+ * @returns Formatted message string
124
+ */
125
+ export declare function formatBalanceConfirmationFailureMessage(loanId: string): string;
126
+ /**
127
+ * Format a BTC withdrawal success notification message
128
+ *
129
+ * @param withdrawalAmount - Amount withdrawn in BTC
130
+ * @param btcVault - Bitcoin vault address
131
+ * @param btcDestinationAddress - Bitcoin destination address
132
+ * @param loanId - Position/loan ID
133
+ * @returns Formatted message string
134
+ */
135
+ export declare function formatBTCWithdrawalSuccessMessage(withdrawalAmount: number | string, btcVault: string, btcDestinationAddress: string, loanId: string): string;
136
+ /**
137
+ * Format a liquidation skipped notification message
138
+ *
139
+ * @param loanId - Position/loan ID
140
+ * @param ratio - Current collateral ratio (as percentage)
141
+ * @param threshold - Liquidation threshold (as percentage)
142
+ * @param btcVault - Bitcoin vault address
143
+ * @param btcVaultBalance - BTC vault balance
144
+ * @param ucdDebt - UCD debt amount
145
+ * @param btcPrice - Current BTC price
146
+ * @returns Formatted message string
147
+ */
148
+ export declare function formatLiquidationSkippedMessage(loanId: string, ratio: number | string, threshold: number | string, btcVault: string, btcVaultBalance: string, ucdDebt: string, btcPrice: string): string;
149
+ /**
150
+ * Format a liquidation success notification message
151
+ *
152
+ * @param loanId - Position/loan ID
153
+ * @param ratio - Current collateral ratio (as percentage)
154
+ * @param threshold - Liquidation threshold (as percentage)
155
+ * @param btcVault - Bitcoin vault address
156
+ * @param btcVaultBalance - BTC vault balance
157
+ * @param ucdDebt - UCD debt amount
158
+ * @param btcPrice - Current BTC price
159
+ * @returns Formatted message string
160
+ */
161
+ export declare function formatLiquidationSuccessMessage(loanId: string, ratio: number | string, threshold: number | string, btcVault: string, btcVaultBalance: string, ucdDebt: string, btcPrice: string): string;
162
+ /**
163
+ * Format BTC price from satoshi value to readable USD format
164
+ *
165
+ * @param btcPriceSats - BTC price in satoshis (8 decimals)
166
+ * @returns Formatted BTC price string
167
+ */
168
+ export declare function formatBTCPrice(btcPriceSats: string | number): string;
169
+ /**
170
+ * Format BTC amount to readable BTC format
171
+ * Accepts either satoshi values (converts to BTC) or already formatted BTC values
172
+ *
173
+ * @param btcAmount - BTC amount in satoshis or already in BTC format
174
+ * @returns Formatted BTC amount string
175
+ */
176
+ export declare function formatBTCAmount(btcAmount: string | number): string;
177
+ /**
178
+ * Format a liquidation failure notification message
179
+ *
180
+ * @param loanId - Position/loan ID
181
+ * @param errorMessage - Error message describing the failure
182
+ * @param btcVault - Bitcoin vault address
183
+ * @param btcVaultBalance - BTC vault balance
184
+ * @param ucdDebt - UCD debt amount
185
+ * @param btcPrice - Current BTC price
186
+ * @returns Formatted message string
187
+ */
188
+ export declare function formatLiquidationFailureMessage(loanId: string, errorMessage: string, btcVault: string, btcVaultBalance: string, ucdDebt: string, btcPrice: string): string;