@atomiqlabs/base 12.0.3 → 13.0.4
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/rpc/BitcoinRpc.d.ts +168 -7
- 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/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 +66 -3
- 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/package.json +5 -3
- package/src/btc/BitcoinNetwork.ts +5 -1
- package/src/btc/rpc/BitcoinRpc.ts +175 -8
- 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/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 +71 -3
- package/src/swaps/SwapData.ts +160 -7
- package/src/utils/BigIntBufferUtils.ts +6 -1
|
@@ -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";
|
|
@@ -1,65 +1,226 @@
|
|
|
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;
|
|
@@ -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
|
}
|
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a bitcoin block header as fetched from the RPC
|
|
5
|
+
*
|
|
6
|
+
* @category Bitcoin
|
|
7
|
+
*/
|
|
3
8
|
export interface BtcBlock {
|
|
9
|
+
/**
|
|
10
|
+
* Block's version field
|
|
11
|
+
*/
|
|
4
12
|
getVersion(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Previous block hash
|
|
15
|
+
*/
|
|
5
16
|
getPrevBlockhash(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Merkle root of the transactions tree
|
|
19
|
+
*/
|
|
6
20
|
getMerkleRoot(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Timestamp of the block
|
|
23
|
+
*/
|
|
7
24
|
getTimestamp(): number;
|
|
25
|
+
/**
|
|
26
|
+
* nBits field of the block
|
|
27
|
+
*/
|
|
8
28
|
getNbits(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Nonce of the block
|
|
31
|
+
*/
|
|
9
32
|
getNonce(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Block hash of this block
|
|
35
|
+
*/
|
|
10
36
|
getHash(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Height at which this block was mined
|
|
39
|
+
*/
|
|
11
40
|
getHeight(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Total accumulated chainwork at this block
|
|
43
|
+
*/
|
|
12
44
|
getChainWork(): Buffer;
|
|
13
45
|
}
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
|
+
/**
|
|
4
|
+
* Represents a raw bitcoin header (80-bytes) that can be synchronized to the underlying BTC relay light client contract
|
|
5
|
+
*
|
|
6
|
+
* @category BTC Relay
|
|
7
|
+
*/
|
|
3
8
|
export interface BtcHeader {
|
|
9
|
+
/**
|
|
10
|
+
* Version of the block
|
|
11
|
+
*/
|
|
4
12
|
getVersion(): number;
|
|
13
|
+
/**
|
|
14
|
+
* Hash of the previous block in little-endian representation
|
|
15
|
+
*/
|
|
5
16
|
getReversedPrevBlockhash(): Buffer;
|
|
17
|
+
/**
|
|
18
|
+
* Merkle root of the transactions tree
|
|
19
|
+
*/
|
|
6
20
|
getMerkleRoot(): Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* Timestamp of the block
|
|
23
|
+
*/
|
|
7
24
|
getTimestamp(): number;
|
|
25
|
+
/**
|
|
26
|
+
* nBits field of the block
|
|
27
|
+
*/
|
|
8
28
|
getNbits(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Nonce of the block
|
|
31
|
+
*/
|
|
9
32
|
getNonce(): number;
|
|
10
33
|
}
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BtcHeader } from "./BtcHeader";
|
|
3
3
|
import { Buffer } from "buffer";
|
|
4
|
+
/**
|
|
5
|
+
* Represents a bitcoin blockheader that has already been synchronized and saved (committed) in the BTC relay
|
|
6
|
+
* contract
|
|
7
|
+
*
|
|
8
|
+
* @category BTC Relay
|
|
9
|
+
*/
|
|
4
10
|
export interface BtcStoredHeader<T extends BtcHeader> {
|
|
11
|
+
/**
|
|
12
|
+
* Total accumulated chainwork at this block
|
|
13
|
+
*/
|
|
5
14
|
getChainWork(): Buffer;
|
|
15
|
+
/**
|
|
16
|
+
* The actual blockheader that was saved
|
|
17
|
+
*/
|
|
6
18
|
getHeader(): T;
|
|
19
|
+
/**
|
|
20
|
+
* UNIX seconds timestamp of the last difficulty adjustment
|
|
21
|
+
*/
|
|
7
22
|
getLastDiffAdjustment(): number;
|
|
23
|
+
/**
|
|
24
|
+
* Blockheight of the current block
|
|
25
|
+
*/
|
|
8
26
|
getBlockheight(): number;
|
|
27
|
+
/**
|
|
28
|
+
* UNIX seconds timestamps of the last 11 blocks, used for checking the median block time rule
|
|
29
|
+
*/
|
|
9
30
|
getPrevBlockTimestamps(): number[];
|
|
31
|
+
/**
|
|
32
|
+
* Computes and returns a new stored blockheader after adding a new blockheader on top of it
|
|
33
|
+
*
|
|
34
|
+
* @param header The new blockheader to append to the chain
|
|
35
|
+
*/
|
|
10
36
|
computeNext(header: T): BtcStoredHeader<T>;
|
|
11
37
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
|
+
/**
|
|
4
|
+
* Big integer arithmetic helpers for block difficulty calculations
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
3
8
|
export declare class StatePredictorUtils {
|
|
4
9
|
static readonly DIFF_ADJUSTMENT_PERIOD = 2016;
|
|
5
10
|
static gtBuffer(a: Buffer, b: Buffer): boolean;
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StatePredictorUtils = void 0;
|
|
4
4
|
const buffer_1 = require("buffer");
|
|
5
5
|
const BigIntBufferUtils_1 = require("../../utils/BigIntBufferUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Big integer arithmetic helpers for block difficulty calculations
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
6
11
|
class StatePredictorUtils {
|
|
7
12
|
static gtBuffer(a, b) {
|
|
8
13
|
for (let i = 0; i < a.length; i++) {
|