@atomiqlabs/base 12.0.4 → 13.1.2
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/btc/BitcoinNetwork.d.ts +5 -0
- package/dist/btc/BitcoinNetwork.js +5 -0
- package/dist/btc/lightning/LightningNetworkApi.d.ts +23 -0
- package/dist/btc/lightning/LightningNetworkApi.js +2 -0
- package/dist/btc/rpc/BitcoinRpc.d.ts +174 -7
- package/dist/btc/rpc/BitcoinRpcWithAddressIndex.d.ts +112 -0
- package/dist/btc/rpc/BitcoinRpcWithAddressIndex.js +2 -0
- package/dist/btcrelay/BtcRelay.d.ts +115 -6
- package/dist/btcrelay/synchronizer/RelaySynchronizer.d.ts +55 -14
- package/dist/btcrelay/types/BtcBlock.d.ts +32 -0
- package/dist/btcrelay/types/BtcHeader.d.ts +23 -0
- package/dist/btcrelay/types/BtcStoredHeader.d.ts +26 -0
- package/dist/btcrelay/utils/StatePredictorUtils.d.ts +5 -0
- package/dist/btcrelay/utils/StatePredictorUtils.js +5 -0
- package/dist/chains/ChainData.d.ts +41 -1
- package/dist/chains/ChainInterface.d.ts +44 -1
- package/dist/chains/ChainInterface.js +5 -0
- package/dist/chains/ChainType.d.ts +7 -1
- package/dist/errors/CannotInitializeATAError.d.ts +5 -0
- package/dist/errors/CannotInitializeATAError.js +5 -0
- package/dist/errors/SignatureVerificationError.d.ts +5 -0
- package/dist/errors/SignatureVerificationError.js +5 -0
- package/dist/errors/SwapDataVerificationError.d.ts +5 -0
- package/dist/errors/SwapDataVerificationError.js +5 -0
- package/dist/errors/TransactionRevertedError.d.ts +5 -0
- package/dist/errors/TransactionRevertedError.js +5 -0
- package/dist/events/ChainEvents.d.ts +40 -2
- package/dist/events/types/ChainEvent.d.ts +8 -0
- package/dist/events/types/ChainEvent.js +5 -0
- package/dist/events/types/spv_vault/SpvVaultClaimEvent.d.ts +29 -0
- package/dist/events/types/spv_vault/SpvVaultClaimEvent.js +5 -0
- package/dist/events/types/spv_vault/SpvVaultCloseEvent.d.ts +13 -0
- package/dist/events/types/spv_vault/SpvVaultCloseEvent.js +7 -0
- package/dist/events/types/spv_vault/SpvVaultDepositEvent.d.ts +12 -0
- package/dist/events/types/spv_vault/SpvVaultDepositEvent.js +5 -0
- package/dist/events/types/spv_vault/SpvVaultEvent.d.ts +18 -2
- package/dist/events/types/spv_vault/SpvVaultEvent.js +10 -0
- package/dist/events/types/spv_vault/SpvVaultFrontEvent.d.ts +22 -0
- package/dist/events/types/spv_vault/SpvVaultFrontEvent.js +5 -0
- package/dist/events/types/spv_vault/SpvVaultOpenEvent.d.ts +11 -0
- package/dist/events/types/spv_vault/SpvVaultOpenEvent.js +5 -0
- package/dist/events/types/swap/ClaimEvent.d.ts +8 -0
- package/dist/events/types/swap/ClaimEvent.js +6 -0
- package/dist/events/types/swap/InitializeEvent.d.ts +13 -2
- package/dist/events/types/swap/InitializeEvent.js +6 -0
- package/dist/events/types/swap/RefundEvent.d.ts +5 -0
- package/dist/events/types/swap/RefundEvent.js +9 -0
- package/dist/events/types/swap/SwapEvent.d.ts +15 -2
- package/dist/events/types/swap/SwapEvent.js +10 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/lockable/Lockable.d.ts +18 -0
- package/dist/lockable/Lockable.js +18 -0
- package/dist/messaging/Messenger.d.ts +32 -0
- package/dist/messaging/messages/Message.d.ts +24 -1
- package/dist/messaging/messages/Message.js +23 -0
- package/dist/messaging/messages/SwapClaimWitnessMessage.d.ts +22 -4
- package/dist/messaging/messages/SwapClaimWitnessMessage.js +12 -0
- package/dist/spv_swap/SpvVaultContract.d.ts +18 -10
- package/dist/spv_swap/SpvVaultData.d.ts +76 -0
- package/dist/spv_swap/SpvVaultData.js +19 -0
- package/dist/spv_swap/SpvWithdrawalState.d.ts +46 -0
- package/dist/spv_swap/SpvWithdrawalState.js +19 -0
- package/dist/spv_swap/SpvWithdrawalTransactionData.d.ts +94 -3
- package/dist/spv_swap/SpvWithdrawalTransactionData.js +81 -4
- package/dist/storage/IStorageManager.d.ts +37 -0
- package/dist/storage/StorageObject.d.ts +8 -0
- package/dist/swaps/ChainSwapType.d.ts +22 -0
- package/dist/swaps/ChainSwapType.js +22 -0
- package/dist/swaps/SwapCommitState.d.ts +50 -0
- package/dist/swaps/SwapCommitState.js +20 -0
- package/dist/swaps/SwapContract.d.ts +58 -2
- package/dist/swaps/SwapData.d.ts +147 -6
- package/dist/swaps/SwapData.js +20 -0
- package/dist/utils/BigIntBufferUtils.d.ts +5 -0
- package/dist/utils/BigIntBufferUtils.js +6 -1
- package/dist/utils/Logger.d.ts +17 -0
- package/dist/utils/Logger.js +17 -0
- package/dist/utils/RetryUtils.d.ts +23 -0
- package/dist/utils/RetryUtils.js +68 -0
- package/dist/utils/TimeoutUtils.d.ts +19 -0
- package/dist/utils/TimeoutUtils.js +57 -0
- package/package.json +5 -3
- package/src/btc/BitcoinNetwork.ts +5 -1
- package/src/btc/lightning/LightningNetworkApi.ts +27 -0
- package/src/btc/rpc/BitcoinRpc.ts +182 -8
- package/src/btc/rpc/BitcoinRpcWithAddressIndex.ts +138 -0
- package/src/btcrelay/BtcRelay.ts +121 -7
- package/src/btcrelay/synchronizer/RelaySynchronizer.ts +51 -10
- package/src/btcrelay/types/BtcBlock.ts +40 -0
- package/src/btcrelay/types/BtcHeader.ts +31 -3
- package/src/btcrelay/types/BtcStoredHeader.ts +31 -0
- package/src/btcrelay/utils/StatePredictorUtils.ts +5 -0
- package/src/chains/ChainData.ts +41 -1
- package/src/chains/ChainInterface.ts +47 -0
- package/src/chains/ChainType.ts +10 -3
- package/src/errors/CannotInitializeATAError.ts +5 -1
- package/src/errors/SignatureVerificationError.ts +5 -1
- package/src/errors/SwapDataVerificationError.ts +5 -1
- package/src/errors/TransactionRevertedError.ts +5 -1
- package/src/events/ChainEvents.ts +44 -2
- package/src/events/types/ChainEvent.ts +8 -0
- package/src/events/types/spv_vault/SpvVaultClaimEvent.ts +29 -0
- package/src/events/types/spv_vault/SpvVaultCloseEvent.ts +13 -0
- package/src/events/types/spv_vault/SpvVaultDepositEvent.ts +13 -0
- package/src/events/types/spv_vault/SpvVaultEvent.ts +18 -3
- package/src/events/types/spv_vault/SpvVaultFrontEvent.ts +22 -0
- package/src/events/types/spv_vault/SpvVaultOpenEvent.ts +11 -0
- package/src/events/types/swap/ClaimEvent.ts +9 -2
- package/src/events/types/swap/InitializeEvent.ts +14 -4
- package/src/events/types/swap/RefundEvent.ts +6 -1
- package/src/events/types/swap/SwapEvent.ts +15 -3
- package/src/index.ts +5 -0
- package/src/lockable/Lockable.ts +18 -2
- package/src/messaging/Messenger.ts +37 -0
- package/src/messaging/messages/Message.ts +24 -3
- package/src/messaging/messages/SwapClaimWitnessMessage.ts +23 -6
- package/src/spv_swap/SpvVaultContract.ts +19 -12
- package/src/spv_swap/SpvVaultData.ts +84 -0
- package/src/spv_swap/SpvWithdrawalState.ts +46 -1
- package/src/spv_swap/SpvWithdrawalTransactionData.ts +102 -7
- package/src/storage/IStorageManager.ts +41 -0
- package/src/storage/StorageObject.ts +8 -2
- package/src/swaps/ChainSwapType.ts +22 -0
- package/src/swaps/SwapCommitState.ts +50 -0
- package/src/swaps/SwapContract.ts +58 -2
- package/src/swaps/SwapData.ts +160 -7
- package/src/utils/BigIntBufferUtils.ts +6 -1
- package/src/utils/Logger.ts +25 -0
- package/src/utils/RetryUtils.ts +73 -0
- package/src/utils/TimeoutUtils.ts +52 -0
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BitcoinNetwork = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An enum for various bitcoin network types
|
|
6
|
+
*
|
|
7
|
+
* @category Bitcoin
|
|
8
|
+
*/
|
|
4
9
|
var BitcoinNetwork;
|
|
5
10
|
(function (BitcoinNetwork) {
|
|
6
11
|
BitcoinNetwork[BitcoinNetwork["MAINNET"] = 0] = "MAINNET";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type defining total capacity of a given lightning network node
|
|
3
|
+
*
|
|
4
|
+
* @category Bitcoin
|
|
5
|
+
*/
|
|
6
|
+
export type LNNodeLiquidity = {
|
|
7
|
+
publicKey: string;
|
|
8
|
+
capacity: bigint;
|
|
9
|
+
numChannels: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* An interface for Lightning API, provides view of the public lightning network data like channel graph
|
|
13
|
+
*
|
|
14
|
+
* @category Bitcoin
|
|
15
|
+
*/
|
|
16
|
+
export interface LightningNetworkApi {
|
|
17
|
+
/**
|
|
18
|
+
* Returns the lightning network's node liquidity as identified by an identity public key
|
|
19
|
+
*
|
|
20
|
+
* @param pubkey
|
|
21
|
+
*/
|
|
22
|
+
getLNNodeLiquidity(pubkey: string): Promise<LNNodeLiquidity | null>;
|
|
23
|
+
}
|
|
@@ -1,68 +1,235 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BtcBlock } from "../../btcrelay/types/BtcBlock";
|
|
3
3
|
import { Buffer } from "buffer";
|
|
4
|
+
/**
|
|
5
|
+
* A type defining a bitcoin transaction output
|
|
6
|
+
*
|
|
7
|
+
* @category Bitcoin
|
|
8
|
+
*/
|
|
4
9
|
export type BtcVout = {
|
|
10
|
+
/**
|
|
11
|
+
* Value of the output in satoshis
|
|
12
|
+
*/
|
|
5
13
|
value: number;
|
|
14
|
+
/**
|
|
15
|
+
* Position of the output in the transaction
|
|
16
|
+
*/
|
|
6
17
|
n: number;
|
|
18
|
+
/**
|
|
19
|
+
* Public key script defining spend conditions of the output
|
|
20
|
+
*/
|
|
7
21
|
scriptPubKey: {
|
|
8
22
|
asm?: string;
|
|
9
23
|
hex: string;
|
|
10
24
|
};
|
|
11
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* A type defining a bitcoin transaction input
|
|
28
|
+
*
|
|
29
|
+
* @category Bitcoin
|
|
30
|
+
*/
|
|
12
31
|
export type BtcVin = {
|
|
32
|
+
/**
|
|
33
|
+
* Spent UTXO's transaction id
|
|
34
|
+
*/
|
|
13
35
|
txid: string;
|
|
36
|
+
/**
|
|
37
|
+
* Spent UTXO's output position in the transaction
|
|
38
|
+
*/
|
|
14
39
|
vout: number;
|
|
40
|
+
/**
|
|
41
|
+
* Signature scripting satisfying the spend conditions
|
|
42
|
+
*/
|
|
15
43
|
scriptSig: {
|
|
16
44
|
asm?: string;
|
|
17
45
|
hex: string;
|
|
18
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Input nSequence value
|
|
49
|
+
*/
|
|
19
50
|
sequence: number;
|
|
51
|
+
/**
|
|
52
|
+
* Witness data pushes in hexadecimal format
|
|
53
|
+
*/
|
|
20
54
|
txinwitness: string[];
|
|
21
55
|
};
|
|
56
|
+
/**
|
|
57
|
+
* A type defining a bitcoin transaction
|
|
58
|
+
*
|
|
59
|
+
* @category Bitcoin
|
|
60
|
+
*/
|
|
22
61
|
export type BtcTx = {
|
|
23
|
-
|
|
24
|
-
|
|
62
|
+
/**
|
|
63
|
+
* A blockhash which includes this transaction, or undefined for unconfirmed txns
|
|
64
|
+
*/
|
|
65
|
+
blockhash?: string;
|
|
66
|
+
/**
|
|
67
|
+
* A number of confirmation that the block containing the transaction has, or undefined for unconfirmed txns
|
|
68
|
+
*/
|
|
69
|
+
confirmations?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Transaction size in vBytes (virtual bytes)
|
|
72
|
+
*/
|
|
25
73
|
vsize: number;
|
|
74
|
+
/**
|
|
75
|
+
* Transactions txId (reversed double sha256 hash of the transaction data excluding witness)
|
|
76
|
+
*/
|
|
26
77
|
txid: string;
|
|
78
|
+
/**
|
|
79
|
+
* Transaction encoded in hexadecimal format, without witness data (so the transaction is in legacy format)
|
|
80
|
+
*/
|
|
27
81
|
hex: string;
|
|
82
|
+
/**
|
|
83
|
+
* Full transaction encoded in hexadecimal format, with witness data
|
|
84
|
+
*/
|
|
28
85
|
raw: string;
|
|
86
|
+
/**
|
|
87
|
+
* Transaction's locktime field
|
|
88
|
+
*/
|
|
29
89
|
locktime: number;
|
|
90
|
+
/**
|
|
91
|
+
* Transaction's version
|
|
92
|
+
*/
|
|
30
93
|
version: number;
|
|
94
|
+
/**
|
|
95
|
+
* An array of outputs in the transactions
|
|
96
|
+
*/
|
|
31
97
|
outs: BtcVout[];
|
|
98
|
+
/**
|
|
99
|
+
* An array of inputs in the transaction
|
|
100
|
+
*/
|
|
32
101
|
ins: BtcVin[];
|
|
33
102
|
};
|
|
103
|
+
/**
|
|
104
|
+
* Representing a bitcoin block with all the transactions included
|
|
105
|
+
*
|
|
106
|
+
* @category Bitcoin
|
|
107
|
+
*/
|
|
34
108
|
export type BtcBlockWithTxs = {
|
|
35
109
|
height: number;
|
|
36
110
|
hash: string;
|
|
37
111
|
tx: BtcTx[];
|
|
38
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Information about the bitcoin RPCs synchronization status
|
|
115
|
+
*
|
|
116
|
+
* @category Bitcoin
|
|
117
|
+
*/
|
|
39
118
|
export type BtcSyncInfo = {
|
|
119
|
+
/**
|
|
120
|
+
* Whether the RPC is doing an IBD (initial block download)
|
|
121
|
+
*/
|
|
40
122
|
ibd: boolean;
|
|
123
|
+
/**
|
|
124
|
+
* How many blockheaders are available
|
|
125
|
+
*/
|
|
41
126
|
headers: number;
|
|
127
|
+
/**
|
|
128
|
+
* How many full bitcoin blocks are available
|
|
129
|
+
*/
|
|
42
130
|
blocks: number;
|
|
131
|
+
/**
|
|
132
|
+
* Progress of the full chain verification in percentages (0..100)
|
|
133
|
+
*/
|
|
43
134
|
verificationProgress: number;
|
|
44
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* An interface for Bitcoin RPC, providing access to Bitcoin on-chain data
|
|
138
|
+
*
|
|
139
|
+
* @category Bitcoin
|
|
140
|
+
*/
|
|
45
141
|
export interface BitcoinRpc<T extends BtcBlock> {
|
|
142
|
+
/**
|
|
143
|
+
* Checks whether a given blockhash is part of the canonical chain
|
|
144
|
+
*
|
|
145
|
+
* @param blockhash
|
|
146
|
+
*/
|
|
46
147
|
isInMainChain(blockhash: string): Promise<boolean>;
|
|
47
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Gets the bitcoin blockheader as identifier by the passed blockhash
|
|
150
|
+
*
|
|
151
|
+
* @param blockhash
|
|
152
|
+
*/
|
|
153
|
+
getBlockHeader(blockhash: string): Promise<T | null>;
|
|
154
|
+
/**
|
|
155
|
+
* Returns a merkle proof for a given transaction
|
|
156
|
+
*
|
|
157
|
+
* @param txId Identifies the transaction
|
|
158
|
+
* @param blockhash The blockhash in which the transaction was included
|
|
159
|
+
*/
|
|
48
160
|
getMerkleProof(txId: string, blockhash: string): Promise<{
|
|
49
161
|
reversedTxId: Buffer;
|
|
50
162
|
pos: number;
|
|
51
163
|
merkle: Buffer[];
|
|
52
164
|
blockheight: number;
|
|
53
|
-
}>;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
165
|
+
} | null>;
|
|
166
|
+
/**
|
|
167
|
+
* Returns the bitcoin transaction as identified by its txId
|
|
168
|
+
*
|
|
169
|
+
* @param txId
|
|
170
|
+
*/
|
|
171
|
+
getTransaction(txId: string): Promise<BtcTx | null>;
|
|
172
|
+
/**
|
|
173
|
+
* Returns blockhash of a block at a given block height
|
|
174
|
+
*
|
|
175
|
+
* @param height
|
|
176
|
+
*/
|
|
177
|
+
getBlockhash(height: number): Promise<string | null>;
|
|
178
|
+
/**
|
|
179
|
+
* Returns Bitcoin block with all the transactions based on blockhash
|
|
180
|
+
*
|
|
181
|
+
* @param blockhash
|
|
182
|
+
*/
|
|
183
|
+
getBlockWithTransactions(blockhash: string): Promise<BtcBlockWithTxs | null>;
|
|
184
|
+
/**
|
|
185
|
+
* Sends a single raw transaction
|
|
186
|
+
*
|
|
187
|
+
* @param rawTx A hexadecimal-encoded bitcoin transaction
|
|
188
|
+
*/
|
|
57
189
|
sendRawTransaction(rawTx: string): Promise<string>;
|
|
190
|
+
/**
|
|
191
|
+
* Sends a Bitcoin transaction package composed of multiple individual transactions at the same time
|
|
192
|
+
*
|
|
193
|
+
* @param rawTx An array of hexadecimal-encoded bitcoin transactions
|
|
194
|
+
*/
|
|
58
195
|
sendRawPackage(rawTx: string[]): Promise<string[]>;
|
|
196
|
+
/**
|
|
197
|
+
* Returns the current tip blockheight of bitcoin
|
|
198
|
+
*/
|
|
59
199
|
getTipHeight(): Promise<number>;
|
|
200
|
+
/**
|
|
201
|
+
* Returns the synchronization information of the underlying bitcoin RPC
|
|
202
|
+
*/
|
|
60
203
|
getSyncInfo(): Promise<BtcSyncInfo>;
|
|
204
|
+
/**
|
|
205
|
+
* Parses a raw bitcoin transaction
|
|
206
|
+
*
|
|
207
|
+
* @param rawTx Hexadecimal-encoded bitcoin transaction
|
|
208
|
+
*/
|
|
61
209
|
parseTransaction(rawTx: string): Promise<BtcTx>;
|
|
210
|
+
/**
|
|
211
|
+
* Returns whether a given UTXO is spent or not, returns `false` for non-existing UTXOs
|
|
212
|
+
*
|
|
213
|
+
* @param utxo The UTXO to check, should be in format [txId]:[vout]
|
|
214
|
+
* @param confirmed Whether the spent has to be confirmed or can also be in the mempool
|
|
215
|
+
*/
|
|
62
216
|
isSpent(utxo: string, confirmed?: boolean): Promise<boolean>;
|
|
217
|
+
/**
|
|
218
|
+
* Returns an effective fee rate of the provided bitcoin transaction, this takes into consideration
|
|
219
|
+
* the current fee rates of the potential unconfirmed inputs of the transaction that are already
|
|
220
|
+
* in the mempool
|
|
221
|
+
*
|
|
222
|
+
* @param btcTx
|
|
223
|
+
*/
|
|
63
224
|
getEffectiveFeeRate(btcTx: BtcTx): Promise<{
|
|
64
225
|
vsize: number;
|
|
65
226
|
fee: number;
|
|
66
227
|
feeRate: number;
|
|
67
228
|
}>;
|
|
229
|
+
/**
|
|
230
|
+
* Parses a bitcoin address from the passed output script in hexadecimal format
|
|
231
|
+
*
|
|
232
|
+
* @param outputScriptHex
|
|
233
|
+
*/
|
|
234
|
+
outputScriptToAddress?(outputScriptHex: string): Promise<string>;
|
|
68
235
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Buffer } from "buffer";
|
|
3
|
+
import { BitcoinRpc, BtcTx } from "./BitcoinRpc";
|
|
4
|
+
import { BtcBlock } from "../../btcrelay/types/BtcBlock";
|
|
5
|
+
/**
|
|
6
|
+
* A type defining a bitcoin transaction with its blockheight and optional input addresses populated
|
|
7
|
+
*
|
|
8
|
+
* @category Bitcoin
|
|
9
|
+
*/
|
|
10
|
+
export type BtcTxWithBlockheight = BtcTx & {
|
|
11
|
+
blockheight?: number;
|
|
12
|
+
inputAddresses?: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A type defining a single UTXO belonging to an address
|
|
16
|
+
*
|
|
17
|
+
* @category Bitcoin
|
|
18
|
+
*/
|
|
19
|
+
export type BtcAddressUtxo = {
|
|
20
|
+
txid: string;
|
|
21
|
+
vout: number;
|
|
22
|
+
confirmed: boolean;
|
|
23
|
+
block_height: number;
|
|
24
|
+
block_hash: string;
|
|
25
|
+
block_time: number;
|
|
26
|
+
value: bigint;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* An extended interface for Bitcoin, that allows querying balances and UTXOs of any address + other utilities
|
|
30
|
+
*
|
|
31
|
+
* @category Bitcoin
|
|
32
|
+
*/
|
|
33
|
+
export interface BitcoinRpcWithAddressIndex<T extends BtcBlock> extends BitcoinRpc<T> {
|
|
34
|
+
/**
|
|
35
|
+
* Returns the current fee rate required for submitted bitcoin transactions in sats/vB
|
|
36
|
+
*/
|
|
37
|
+
getFeeRate(): Promise<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns confirmed & unconfirmed balances for a given wallet address
|
|
40
|
+
*
|
|
41
|
+
* @param address
|
|
42
|
+
*/
|
|
43
|
+
getAddressBalances(address: string): Promise<{
|
|
44
|
+
confirmedBalance: bigint;
|
|
45
|
+
unconfirmedBalance: bigint;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns UTXOs owned by the given wallet address
|
|
49
|
+
* @param address
|
|
50
|
+
*/
|
|
51
|
+
getAddressUTXOs(address: string): Promise<BtcAddressUtxo[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Returns CPFP (children-pay-for-parent) data for a given transaction, or null if transaction is not found
|
|
54
|
+
* or already confirmed
|
|
55
|
+
*
|
|
56
|
+
* @param txId
|
|
57
|
+
*/
|
|
58
|
+
getCPFPData(txId: string): Promise<{
|
|
59
|
+
effectiveFeePerVsize: number;
|
|
60
|
+
adjustedVsize: number;
|
|
61
|
+
} | null>;
|
|
62
|
+
/**
|
|
63
|
+
* @inheritDoc
|
|
64
|
+
*/
|
|
65
|
+
getTransaction(txId: string): Promise<BtcTxWithBlockheight | null>;
|
|
66
|
+
/**
|
|
67
|
+
* Awaits till the given transaction gets confirmed
|
|
68
|
+
*
|
|
69
|
+
* @param txId Transaction ID to monitor
|
|
70
|
+
* @param requiredConfirmations Required number of confirmations
|
|
71
|
+
* @param stateUpdateCbk Optional update callback called with the current status of the bitcoin transaction
|
|
72
|
+
* @param abortSignal
|
|
73
|
+
* @param intervalSeconds How often to poll
|
|
74
|
+
*/
|
|
75
|
+
waitForTransaction(txId: string, requiredConfirmations: number, stateUpdateCbk?: (btcTx?: BtcTxWithBlockheight, txEtaMS?: number) => void, abortSignal?: AbortSignal, intervalSeconds?: number): Promise<BtcTxWithBlockheight>;
|
|
76
|
+
/**
|
|
77
|
+
* Returns an estimate after which time the tx will confirm with the required amount of confirmations,
|
|
78
|
+
* confirmationDelay of -1 means the transaction won't confirm in the near future
|
|
79
|
+
*
|
|
80
|
+
* @param tx
|
|
81
|
+
* @param requiredConfirmations
|
|
82
|
+
*
|
|
83
|
+
* @returns estimated confirmation delay, -1 if the transaction won't confirm in the near future, null if the
|
|
84
|
+
* transaction was replaced or was confirmed in the meantime
|
|
85
|
+
*/
|
|
86
|
+
getConfirmationDelay(tx: BtcTx, requiredConfirmations: number): Promise<number | null>;
|
|
87
|
+
/**
|
|
88
|
+
* Checks if an address received the transaction with the required txoHash, returns info about that
|
|
89
|
+
* specific transaction if found, or null if not found
|
|
90
|
+
*
|
|
91
|
+
* @param address Address that should receive the transaction
|
|
92
|
+
* @param txoHash Required output txoHash
|
|
93
|
+
*/
|
|
94
|
+
checkAddressTxos(address: string, txoHash: Buffer): Promise<{
|
|
95
|
+
tx: Omit<BtcTxWithBlockheight, "hex" | "raw">;
|
|
96
|
+
vout: number;
|
|
97
|
+
} | null>;
|
|
98
|
+
/**
|
|
99
|
+
* Waits till the address receives a transaction containing a specific txoHash
|
|
100
|
+
*
|
|
101
|
+
* @param address Address that should receive the transaction
|
|
102
|
+
* @param txoHash Required output txoHash
|
|
103
|
+
* @param requiredConfirmations Required confirmations of the transaction
|
|
104
|
+
* @param stateUpdateCbk Callback for transaction state updates
|
|
105
|
+
* @param abortSignal Abort signal
|
|
106
|
+
* @param intervalSeconds How often to check new transaction
|
|
107
|
+
*/
|
|
108
|
+
waitForAddressTxo(address: string, txoHash: Buffer, requiredConfirmations: number, stateUpdateCbk: (btcTx?: Omit<BtcTxWithBlockheight, "hex" | "raw">, vout?: number, txEtaMS?: number) => void, abortSignal?: AbortSignal, intervalSeconds?: number): Promise<{
|
|
109
|
+
tx: Omit<BtcTxWithBlockheight, "hex" | "raw">;
|
|
110
|
+
vout: number;
|
|
111
|
+
}>;
|
|
112
|
+
}
|
|
@@ -3,59 +3,168 @@ import { BtcStoredHeader } from "./types/BtcStoredHeader";
|
|
|
3
3
|
import { BtcBlock } from "./types/BtcBlock";
|
|
4
4
|
import { Buffer } from "buffer";
|
|
5
5
|
import { AbstractSigner } from "../chains/ChainInterface";
|
|
6
|
+
/**
|
|
7
|
+
* Represents a BTC relay bitcoin light client contract, which verifies the bitcoin blockheaders on smart chains
|
|
8
|
+
*
|
|
9
|
+
* @category BTC Relay
|
|
10
|
+
*/
|
|
6
11
|
export interface BtcRelay<V extends BtcStoredHeader<any>, T, B extends BtcBlock, Signer extends AbstractSigner = AbstractSigner> {
|
|
12
|
+
/**
|
|
13
|
+
* Maximum blockheaders that fit in a single transaction
|
|
14
|
+
*/
|
|
7
15
|
maxHeadersPerTx: number;
|
|
16
|
+
/**
|
|
17
|
+
* Maximum amount of fork headers that fit in a single transactions
|
|
18
|
+
*/
|
|
8
19
|
maxForkHeadersPerTx: number;
|
|
20
|
+
/**
|
|
21
|
+
* Maximum amount of fork headers that can be submitted at once using the short fork method
|
|
22
|
+
*/
|
|
9
23
|
maxShortForkHeadersPerTx?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Returns data about current main chain tip stored in the btc relay
|
|
26
|
+
*/
|
|
10
27
|
getTipData(): Promise<{
|
|
11
28
|
blockheight: number;
|
|
12
29
|
blockhash: string;
|
|
13
30
|
commitHash: string;
|
|
14
31
|
chainWork: Buffer;
|
|
15
|
-
}>;
|
|
32
|
+
} | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves blockheader with a specific blockhash, returns null if `requiredBlockheight` is provided and
|
|
35
|
+
* btc relay contract is not synced up to the desired blockheight
|
|
36
|
+
*
|
|
37
|
+
* @param blockData
|
|
38
|
+
* @param requiredBlockheight
|
|
39
|
+
*/
|
|
16
40
|
retrieveLogAndBlockheight(blockData: {
|
|
17
41
|
blockhash: string;
|
|
18
42
|
height: number;
|
|
19
43
|
}, requiredBlockheight?: number): Promise<{
|
|
20
44
|
header: V;
|
|
21
45
|
height: number;
|
|
22
|
-
}>;
|
|
46
|
+
} | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves stored bitcoin blockheader data by blockheader's commit hash and provided
|
|
49
|
+
* blockhash from `blockData`
|
|
50
|
+
*
|
|
51
|
+
* @param commitHash
|
|
52
|
+
* @param blockData
|
|
53
|
+
*/
|
|
23
54
|
retrieveLogByCommitHash(commitHash: string, blockData: {
|
|
24
55
|
blockhash: string;
|
|
25
56
|
height: number;
|
|
26
|
-
}): Promise<V>;
|
|
57
|
+
}): Promise<V | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieves latest known bitcoin blockheader stored in the BTC Relay and also known to the bitcoin RPC
|
|
60
|
+
*/
|
|
27
61
|
retrieveLatestKnownBlockLog(): Promise<{
|
|
28
62
|
resultStoredHeader: V;
|
|
29
63
|
resultBitcoinHeader: B;
|
|
30
|
-
}>;
|
|
64
|
+
} | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Initializes the underlying BTC Relay contract
|
|
67
|
+
*
|
|
68
|
+
* @param signer A signer's address to use for the transaction
|
|
69
|
+
* @param header Main chain blockheader to use as a genesis
|
|
70
|
+
* @param epochStart Timestamp of the first block in this difficulty epoch
|
|
71
|
+
* @param pastBlocksTimestamps Timestamps of the last 11 blockheaders, for median block time rule
|
|
72
|
+
* @param feeRate Optional fee rate for the transaction
|
|
73
|
+
*/
|
|
31
74
|
saveInitialHeader(signer: string, header: B, epochStart: number, pastBlocksTimestamps: number[], feeRate?: string): Promise<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns a transaction that submits bitcoin blockheaders as a bitcoin main chain to the btc relay
|
|
77
|
+
*
|
|
78
|
+
* @param signer A signer's address for the transaction
|
|
79
|
+
* @param mainHeaders New bitcoin blockheaders to submit
|
|
80
|
+
* @param storedHeader Latest committed and stored bitcoin blockheader in the BTC relay
|
|
81
|
+
* @param feeRate Optional fee rate for the transaction
|
|
82
|
+
*/
|
|
32
83
|
saveMainHeaders(signer: string, mainHeaders: B[], storedHeader: V, feeRate?: string): Promise<{
|
|
33
84
|
forkId: number;
|
|
34
85
|
lastStoredHeader: V;
|
|
35
86
|
tx: T;
|
|
36
87
|
computedCommitedHeaders: V[];
|
|
37
88
|
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Returns a transaction that submits a new long fork and submits the first headers to it
|
|
91
|
+
*
|
|
92
|
+
* @param signer A signer's address for the transaction
|
|
93
|
+
* @param forkHeaders New fork bitcoin blockheaders to submit
|
|
94
|
+
* @param storedHeader Committed and stored bitcoin blockheader in the BTC relay from which to fork
|
|
95
|
+
* @param tipWork Chainwork of the current BTC Relay main chain tip
|
|
96
|
+
* @param feeRate Optional fee rate for the transaction
|
|
97
|
+
*/
|
|
38
98
|
saveNewForkHeaders(signer: string, forkHeaders: B[], storedHeader: V, tipWork: Buffer, feeRate?: string): Promise<{
|
|
39
99
|
forkId: number;
|
|
40
100
|
lastStoredHeader: V;
|
|
41
101
|
tx: T;
|
|
42
102
|
computedCommitedHeaders: V[];
|
|
43
103
|
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns a transaction that continues submitting blockheaders to an existing long fork
|
|
106
|
+
*
|
|
107
|
+
* @param signer A signer's address for the transaction
|
|
108
|
+
* @param forkHeaders New fork bitcoin blockheaders to submit
|
|
109
|
+
* @param storedHeader Committed and stored bitcoin blockheader in the BTC relay from which to fork
|
|
110
|
+
* @param forkId Fork ID to submit the blockheaders to
|
|
111
|
+
* @param tipWork Chainwork of the current BTC Relay main chain tip
|
|
112
|
+
* @param feeRate Optional fee rate for the transaction
|
|
113
|
+
*/
|
|
44
114
|
saveForkHeaders(signer: string, forkHeaders: B[], storedHeader: V, forkId: number, tipWork: Buffer, feeRate?: string): Promise<{
|
|
45
115
|
forkId: number;
|
|
46
116
|
lastStoredHeader: V;
|
|
47
117
|
tx: T;
|
|
48
118
|
computedCommitedHeaders: V[];
|
|
49
119
|
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns a transaction that submits a short fork with the provided blockheaders
|
|
122
|
+
*
|
|
123
|
+
* @param signer A signer's address for the transaction
|
|
124
|
+
* @param forkHeaders New fork bitcoin blockheaders to submit
|
|
125
|
+
* @param storedHeader Committed and stored bitcoin blockheader in the BTC relay from which to fork
|
|
126
|
+
* @param tipWork Chainwork of the current BTC Relay main chain tip
|
|
127
|
+
* @param feeRate Optional fee rate for the transaction
|
|
128
|
+
*/
|
|
50
129
|
saveShortForkHeaders?(signer: string, forkHeaders: B[], storedHeader: V, tipWork: Buffer, feeRate?: string): Promise<{
|
|
51
130
|
forkId: number;
|
|
52
131
|
lastStoredHeader: V;
|
|
53
132
|
tx: T;
|
|
54
133
|
computedCommitedHeaders: V[];
|
|
55
134
|
}>;
|
|
56
|
-
|
|
57
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Gets fee rate required for submitting blockheaders to the main chain
|
|
137
|
+
*
|
|
138
|
+
* @param signer A signer's address to use for the estimation
|
|
139
|
+
*/
|
|
140
|
+
getMainFeeRate(signer: string): Promise<string>;
|
|
141
|
+
/**
|
|
142
|
+
* Gets fee rate required for submitting blockheaders to the specific fork
|
|
143
|
+
*
|
|
144
|
+
* @param signer A signer's address to use for the estimation
|
|
145
|
+
* @param forkId A fork ID to use for estimation
|
|
146
|
+
*/
|
|
147
|
+
getForkFeeRate(signer: string, forkId: number): Promise<string>;
|
|
148
|
+
/**
|
|
149
|
+
* Estimate required synchronization fee (worst case) to synchronize btc relay to the required blockheight
|
|
150
|
+
*
|
|
151
|
+
* @param requiredBlockheight Blockheight to which to synchronize
|
|
152
|
+
* @param feeRate Optional fee rate to use for the estimation
|
|
153
|
+
*/
|
|
58
154
|
estimateSynchronizeFee(requiredBlockheight: number, feeRate?: string): Promise<bigint>;
|
|
155
|
+
/**
|
|
156
|
+
* Returns required fee in native token to synchronize a single block to btc relay
|
|
157
|
+
*
|
|
158
|
+
* @param feeRate Optional fee rate to use for the estimation
|
|
159
|
+
*/
|
|
59
160
|
getFeePerBlock(feeRate?: any): Promise<bigint>;
|
|
161
|
+
/**
|
|
162
|
+
* Checks and sweeps data accounts which contain yet unused fork data (use for Solana's PDAs)
|
|
163
|
+
*
|
|
164
|
+
* @param signer A signer's address to check account for
|
|
165
|
+
* @param lastSweepTimestamp Timestamp of the last sweep
|
|
166
|
+
*
|
|
167
|
+
* @returns A number of data accounts swept
|
|
168
|
+
*/
|
|
60
169
|
sweepForkData?(signer: Signer, lastSweepTimestamp?: number): Promise<number | null>;
|
|
61
170
|
}
|
|
@@ -1,18 +1,59 @@
|
|
|
1
1
|
import { BtcStoredHeader } from "../types/BtcStoredHeader";
|
|
2
2
|
import { BtcBlock } from "../types/BtcBlock";
|
|
3
|
+
export type SynchronizationResponse<V extends BtcStoredHeader<any>, T, B extends BtcBlock> = {
|
|
4
|
+
/**
|
|
5
|
+
* Transactions required to synchronize the btc relay
|
|
6
|
+
*/
|
|
7
|
+
txs: T[];
|
|
8
|
+
/**
|
|
9
|
+
* Latest committed header after synchronization
|
|
10
|
+
*/
|
|
11
|
+
targetCommitedHeader: V;
|
|
12
|
+
/**
|
|
13
|
+
* Latest block header after synchronization
|
|
14
|
+
*/
|
|
15
|
+
latestBlockHeader: B;
|
|
16
|
+
/**
|
|
17
|
+
* Mapping of synchronized committed headers, based on blockheight
|
|
18
|
+
*/
|
|
19
|
+
computedHeaderMap: {
|
|
20
|
+
[blockheight: number]: V;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Mapping of synchronized block headers, based on blockheight
|
|
24
|
+
*/
|
|
25
|
+
blockHeaderMap: {
|
|
26
|
+
[blockheight: number]: B;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Tip committed header of the btc relay before synchronization
|
|
30
|
+
*/
|
|
31
|
+
btcRelayTipCommitedHeader: V;
|
|
32
|
+
/**
|
|
33
|
+
* Tip block header of the btc relay before synchronization
|
|
34
|
+
*/
|
|
35
|
+
btcRelayTipBlockHeader: B;
|
|
36
|
+
/**
|
|
37
|
+
* A fork ID that was used to re-org the chain to the current canonical chain
|
|
38
|
+
*/
|
|
39
|
+
startForkId?: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* An interface for a synchronizer of the BTC relay bitcoin light client contract, produces transactions
|
|
43
|
+
* necessary to synchronize the underlying relay contract to the current tip of the canonical chain,
|
|
44
|
+
* automatically handles forking if necessary
|
|
45
|
+
*
|
|
46
|
+
* @category BTC Relay
|
|
47
|
+
*/
|
|
3
48
|
export interface RelaySynchronizer<V extends BtcStoredHeader<any>, T, B extends BtcBlock> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
btcRelayTipCommitedHeader: V;
|
|
15
|
-
btcRelayTipBlockHeader: B;
|
|
16
|
-
startForkId?: number;
|
|
17
|
-
}>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the transactions necessary to synchronize the BTC relay contract to the
|
|
51
|
+
* tip of the canonical chain. Also returns the various bitcoin blockheaders that
|
|
52
|
+
* are to-be-synced to the relay, such that they can be used to already pre-create
|
|
53
|
+
* transactions, which require the stored blockheaders
|
|
54
|
+
*
|
|
55
|
+
* @param signer Transactions signer's address
|
|
56
|
+
* @param feeRate Optional fee rate to use for the transactions
|
|
57
|
+
*/
|
|
58
|
+
syncToLatestTxs(signer: string, feeRate?: string): Promise<SynchronizationResponse<V, T, B>>;
|
|
18
59
|
}
|