@atomiqlabs/base 12.0.4 → 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 +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/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 +58 -2
- package/src/swaps/SwapData.ts +160 -7
- package/src/utils/BigIntBufferUtils.ts +6 -1
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { SwapEvent, SwapEventType } from "./SwapEvent";
|
|
2
2
|
import { SwapData } from "../../../swaps/SwapData";
|
|
3
3
|
import { ChainSwapType } from "../../../swaps/ChainSwapType";
|
|
4
|
+
/**
|
|
5
|
+
* Escrow swap Initialization event representation, emitted when an escrow is created
|
|
6
|
+
*
|
|
7
|
+
* @category Events
|
|
8
|
+
*/
|
|
4
9
|
export declare class InitializeEvent<T extends SwapData> extends SwapEvent<T, SwapEventType.INITIALIZE> {
|
|
5
10
|
readonly eventType: SwapEventType.INITIALIZE;
|
|
11
|
+
/**
|
|
12
|
+
* Type of the escrow swap that was created (depends on the claim handler)
|
|
13
|
+
*/
|
|
6
14
|
swapType: ChainSwapType;
|
|
7
|
-
|
|
8
|
-
|
|
15
|
+
/**
|
|
16
|
+
* A getter for the actual full swap data that was used to initialize the escrow swap
|
|
17
|
+
*/
|
|
18
|
+
swapData: () => Promise<T | null>;
|
|
19
|
+
constructor(escrowHash: string, swapType: ChainSwapType, swapData: () => Promise<T | null>);
|
|
9
20
|
}
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InitializeEvent = void 0;
|
|
4
4
|
const SwapEvent_1 = require("./SwapEvent");
|
|
5
|
+
/**
|
|
6
|
+
* Escrow swap Initialization event representation, emitted when an escrow is created
|
|
7
|
+
*
|
|
8
|
+
* @category Events
|
|
9
|
+
*/
|
|
5
10
|
class InitializeEvent extends SwapEvent_1.SwapEvent {
|
|
6
11
|
constructor(escrowHash, swapType, swapData) {
|
|
7
12
|
super(escrowHash);
|
|
13
|
+
this.eventType = SwapEvent_1.SwapEventType.INITIALIZE;
|
|
8
14
|
this.swapType = swapType;
|
|
9
15
|
this.swapData = swapData;
|
|
10
16
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { SwapEvent, SwapEventType } from "./SwapEvent";
|
|
2
2
|
import { SwapData } from "../../../swaps/SwapData";
|
|
3
|
+
/**
|
|
4
|
+
* Escrow swap Refund event representation, offerer refunded funds from the escrow
|
|
5
|
+
*
|
|
6
|
+
* @category Events
|
|
7
|
+
*/
|
|
3
8
|
export declare class RefundEvent<T extends SwapData> extends SwapEvent<T, SwapEventType.REFUND> {
|
|
4
9
|
readonly eventType: SwapEventType.REFUND;
|
|
5
10
|
}
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RefundEvent = void 0;
|
|
4
4
|
const SwapEvent_1 = require("./SwapEvent");
|
|
5
|
+
/**
|
|
6
|
+
* Escrow swap Refund event representation, offerer refunded funds from the escrow
|
|
7
|
+
*
|
|
8
|
+
* @category Events
|
|
9
|
+
*/
|
|
5
10
|
class RefundEvent extends SwapEvent_1.SwapEvent {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.eventType = SwapEvent_1.SwapEventType.REFUND;
|
|
14
|
+
}
|
|
6
15
|
}
|
|
7
16
|
exports.RefundEvent = RefundEvent;
|
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { SwapData } from "../../../swaps/SwapData";
|
|
2
2
|
import { ChainEvent } from "../ChainEvent";
|
|
3
|
+
/**
|
|
4
|
+
* Enum of the different types of escrow-swap specific events
|
|
5
|
+
*
|
|
6
|
+
* @category Events
|
|
7
|
+
*/
|
|
3
8
|
export declare enum SwapEventType {
|
|
4
9
|
INITIALIZE = 0,
|
|
5
10
|
REFUND = 1,
|
|
6
11
|
CLAIM = 2
|
|
7
12
|
}
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Represents an escrow-specific event
|
|
15
|
+
*
|
|
16
|
+
* @category Events
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class SwapEvent<T extends SwapData, C extends SwapEventType = SwapEventType> extends ChainEvent<T> {
|
|
19
|
+
abstract readonly eventType: C;
|
|
20
|
+
/**
|
|
21
|
+
* Identifier of the escrow, usually a hash of the full escrow swap data
|
|
22
|
+
*/
|
|
10
23
|
escrowHash: string;
|
|
11
24
|
constructor(escrowHash: string);
|
|
12
25
|
}
|
|
@@ -2,12 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SwapEvent = exports.SwapEventType = void 0;
|
|
4
4
|
const ChainEvent_1 = require("../ChainEvent");
|
|
5
|
+
/**
|
|
6
|
+
* Enum of the different types of escrow-swap specific events
|
|
7
|
+
*
|
|
8
|
+
* @category Events
|
|
9
|
+
*/
|
|
5
10
|
var SwapEventType;
|
|
6
11
|
(function (SwapEventType) {
|
|
7
12
|
SwapEventType[SwapEventType["INITIALIZE"] = 0] = "INITIALIZE";
|
|
8
13
|
SwapEventType[SwapEventType["REFUND"] = 1] = "REFUND";
|
|
9
14
|
SwapEventType[SwapEventType["CLAIM"] = 2] = "CLAIM";
|
|
10
15
|
})(SwapEventType = exports.SwapEventType || (exports.SwapEventType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Represents an escrow-specific event
|
|
18
|
+
*
|
|
19
|
+
* @category Events
|
|
20
|
+
*/
|
|
11
21
|
class SwapEvent extends ChainEvent_1.ChainEvent {
|
|
12
22
|
constructor(escrowHash) {
|
|
13
23
|
super();
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper class for create an object based lock, ensuring only one lock on the object
|
|
3
|
+
* can be acquired along with a given timeout
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
* @category Utils
|
|
7
|
+
*/
|
|
1
8
|
export declare class Lockable {
|
|
2
9
|
private lockedTill;
|
|
3
10
|
private lockNonce;
|
|
11
|
+
/**
|
|
12
|
+
* Attempts to lock an object with a given timeout, returns null if the object is already locked and an unlock
|
|
13
|
+
* callback function that unlocks this object.
|
|
14
|
+
*
|
|
15
|
+
* @param timeoutSeconds A timeout in seconds after which this object should be unlocked even if the unlock
|
|
16
|
+
* function isn't called sooner
|
|
17
|
+
* @returns A callback, which shall be called to unlock an object, or `null` if the object is locked
|
|
18
|
+
*/
|
|
4
19
|
lock(timeoutSeconds: number): (() => boolean) | null;
|
|
20
|
+
/**
|
|
21
|
+
* Checks whether the object is currently locked
|
|
22
|
+
*/
|
|
5
23
|
isLocked(): boolean;
|
|
6
24
|
}
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Lockable = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A helper class for create an object based lock, ensuring only one lock on the object
|
|
6
|
+
* can be acquired along with a given timeout
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
* @category Utils
|
|
10
|
+
*/
|
|
4
11
|
class Lockable {
|
|
5
12
|
constructor() {
|
|
6
13
|
this.lockedTill = 0;
|
|
7
14
|
this.lockNonce = 0;
|
|
8
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Attempts to lock an object with a given timeout, returns null if the object is already locked and an unlock
|
|
18
|
+
* callback function that unlocks this object.
|
|
19
|
+
*
|
|
20
|
+
* @param timeoutSeconds A timeout in seconds after which this object should be unlocked even if the unlock
|
|
21
|
+
* function isn't called sooner
|
|
22
|
+
* @returns A callback, which shall be called to unlock an object, or `null` if the object is locked
|
|
23
|
+
*/
|
|
9
24
|
lock(timeoutSeconds) {
|
|
10
25
|
if (this.isLocked()) {
|
|
11
26
|
return null;
|
|
@@ -21,6 +36,9 @@ class Lockable {
|
|
|
21
36
|
return true;
|
|
22
37
|
};
|
|
23
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks whether the object is currently locked
|
|
41
|
+
*/
|
|
24
42
|
isLocked() {
|
|
25
43
|
return this.lockedTill > Date.now();
|
|
26
44
|
}
|
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
import { Message } from "./messages/Message";
|
|
2
|
+
/**
|
|
3
|
+
* An interface of a messenger, this is a generic data propagation layer, where parties can broadcast messages
|
|
4
|
+
* and others can listen to these broadcasted messages
|
|
5
|
+
*
|
|
6
|
+
* @category Messenger
|
|
7
|
+
*/
|
|
2
8
|
export interface Messenger {
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the messenger instance
|
|
11
|
+
*/
|
|
3
12
|
init(): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* The messenger implementation can expose a warmup function that warms up the connection before
|
|
15
|
+
* an actual broadcast takes place (this is useful for browsers environments where you might
|
|
16
|
+
* want to warmup the connection before the tab is backgrounded)
|
|
17
|
+
*/
|
|
4
18
|
warmup?(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Broadcast a message to the data propagation layer
|
|
21
|
+
*
|
|
22
|
+
* @param msg
|
|
23
|
+
*/
|
|
5
24
|
broadcast(msg: Message): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Adds a listener to listen to broadcasted messages
|
|
27
|
+
*
|
|
28
|
+
* @param callback
|
|
29
|
+
*/
|
|
6
30
|
subscribe(callback: (msg: Message) => void): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Removes a listener
|
|
33
|
+
*
|
|
34
|
+
* @param callback
|
|
35
|
+
*/
|
|
7
36
|
unsubscribe(callback: (msg: Message) => void): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Stops the instance, releasing any resources used by it
|
|
39
|
+
*/
|
|
8
40
|
stop(): Promise<void>;
|
|
9
41
|
}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currently defined types of the data propagation messages
|
|
3
|
+
*
|
|
4
|
+
* @category Messenger
|
|
5
|
+
*/
|
|
1
6
|
export declare enum MessageType {
|
|
2
7
|
SWAP_CLAIM_WITNESS = 0
|
|
3
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Representation of an abstract message in a data propagation layer
|
|
11
|
+
*
|
|
12
|
+
* @category Messenger
|
|
13
|
+
*/
|
|
4
14
|
export declare abstract class Message {
|
|
5
|
-
abstract type: MessageType;
|
|
15
|
+
abstract readonly type: MessageType;
|
|
16
|
+
/**
|
|
17
|
+
* A mapping of deserializers for different message types
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
6
21
|
static deserializers: {
|
|
7
22
|
[type: number]: (obj: any) => Message;
|
|
8
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Serializes the message to a format that can be JSON serialized (i.e. no bigints, functions, etc.)
|
|
26
|
+
*/
|
|
9
27
|
serialize(): any;
|
|
28
|
+
/**
|
|
29
|
+
* Deserializer that parses the message from it's JSON compatible representation
|
|
30
|
+
*
|
|
31
|
+
* @param message
|
|
32
|
+
*/
|
|
10
33
|
static deserialize(message: any): Message;
|
|
11
34
|
}
|
|
@@ -1,16 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Message = exports.MessageType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Currently defined types of the data propagation messages
|
|
6
|
+
*
|
|
7
|
+
* @category Messenger
|
|
8
|
+
*/
|
|
4
9
|
var MessageType;
|
|
5
10
|
(function (MessageType) {
|
|
6
11
|
MessageType[MessageType["SWAP_CLAIM_WITNESS"] = 0] = "SWAP_CLAIM_WITNESS";
|
|
7
12
|
})(MessageType = exports.MessageType || (exports.MessageType = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Representation of an abstract message in a data propagation layer
|
|
15
|
+
*
|
|
16
|
+
* @category Messenger
|
|
17
|
+
*/
|
|
8
18
|
class Message {
|
|
19
|
+
/**
|
|
20
|
+
* Serializes the message to a format that can be JSON serialized (i.e. no bigints, functions, etc.)
|
|
21
|
+
*/
|
|
9
22
|
serialize() {
|
|
10
23
|
return {
|
|
11
24
|
type: this.type
|
|
12
25
|
};
|
|
13
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Deserializer that parses the message from it's JSON compatible representation
|
|
29
|
+
*
|
|
30
|
+
* @param message
|
|
31
|
+
*/
|
|
14
32
|
static deserialize(message) {
|
|
15
33
|
const deserializer = Message.deserializers[message.type];
|
|
16
34
|
if (deserializer == null)
|
|
@@ -19,4 +37,9 @@ class Message {
|
|
|
19
37
|
}
|
|
20
38
|
}
|
|
21
39
|
exports.Message = Message;
|
|
40
|
+
/**
|
|
41
|
+
* A mapping of deserializers for different message types
|
|
42
|
+
*
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
22
45
|
Message.deserializers = {};
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import { SwapData } from "../../swaps/SwapData";
|
|
2
2
|
import { Message, MessageType } from "./Message";
|
|
3
|
+
/**
|
|
4
|
+
* Representation of an HTLC claim message, providing a swap pre-image in the `witness` field for a specific
|
|
5
|
+
* escrow {@link SwapData}
|
|
6
|
+
*
|
|
7
|
+
* @category Messenger
|
|
8
|
+
*/
|
|
3
9
|
export declare class SwapClaimWitnessMessage<T extends SwapData> extends Message {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
readonly type = MessageType.SWAP_CLAIM_WITNESS;
|
|
11
|
+
/**
|
|
12
|
+
* Swap data of the escrow to claim
|
|
13
|
+
*/
|
|
14
|
+
readonly swapData: T;
|
|
15
|
+
/**
|
|
16
|
+
* A witness allowing the claim of the escrow (i.e. a hash pre-image)
|
|
17
|
+
*/
|
|
18
|
+
readonly witness: string;
|
|
7
19
|
constructor(swapData: T, witness: string);
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
8
23
|
serialize(): any;
|
|
9
|
-
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
static deserialize<T extends SwapData>(obj: any): SwapClaimWitnessMessage<T>;
|
|
10
28
|
}
|
|
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SwapClaimWitnessMessage = void 0;
|
|
4
4
|
const SwapData_1 = require("../../swaps/SwapData");
|
|
5
5
|
const Message_1 = require("./Message");
|
|
6
|
+
/**
|
|
7
|
+
* Representation of an HTLC claim message, providing a swap pre-image in the `witness` field for a specific
|
|
8
|
+
* escrow {@link SwapData}
|
|
9
|
+
*
|
|
10
|
+
* @category Messenger
|
|
11
|
+
*/
|
|
6
12
|
class SwapClaimWitnessMessage extends Message_1.Message {
|
|
7
13
|
constructor(swapData, witness) {
|
|
8
14
|
super();
|
|
@@ -10,6 +16,9 @@ class SwapClaimWitnessMessage extends Message_1.Message {
|
|
|
10
16
|
this.swapData = swapData;
|
|
11
17
|
this.witness = witness;
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
13
22
|
serialize() {
|
|
14
23
|
return {
|
|
15
24
|
...super.serialize(),
|
|
@@ -17,6 +26,9 @@ class SwapClaimWitnessMessage extends Message_1.Message {
|
|
|
17
26
|
witness: this.witness
|
|
18
27
|
};
|
|
19
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
20
32
|
static deserialize(obj) {
|
|
21
33
|
if (obj == null || typeof (obj.witness) !== "string" || typeof (obj.swapData) !== "object") {
|
|
22
34
|
throw new Error("Invalid format!");
|
|
@@ -7,7 +7,15 @@ import { RelaySynchronizer } from "../btcrelay/synchronizer/RelaySynchronizer";
|
|
|
7
7
|
import { SpvWithdrawalState } from "./SpvWithdrawalState";
|
|
8
8
|
import { Buffer } from "buffer";
|
|
9
9
|
import { BtcTx } from "../btc/rpc/BitcoinRpc";
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Represents an SPV vault (UTXO-controlled vault) contract, exposes operations on the vaults
|
|
12
|
+
*
|
|
13
|
+
* @category Swaps
|
|
14
|
+
*/
|
|
15
|
+
export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = AbstractSigner, ChainId extends string = string, WithdrawalTX extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData, Data extends SpvVaultData<WithdrawalTX> = SpvVaultData<WithdrawalTX>> {
|
|
16
|
+
/**
|
|
17
|
+
* Chain identifier string
|
|
18
|
+
*/
|
|
11
19
|
readonly chainId: ChainId;
|
|
12
20
|
/**
|
|
13
21
|
* Signs & sends transactions for opening a specific spv vault
|
|
@@ -129,7 +137,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
129
137
|
* @param owner Owner of the vault
|
|
130
138
|
* @param vaultId Vault ID
|
|
131
139
|
*/
|
|
132
|
-
getVaultData(owner: string, vaultId: bigint): Promise<Data>;
|
|
140
|
+
getVaultData(owner: string, vaultId: bigint): Promise<Data | null>;
|
|
133
141
|
/**
|
|
134
142
|
* Returns current vault data for multiple vaults
|
|
135
143
|
*
|
|
@@ -140,7 +148,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
140
148
|
vaultId: bigint;
|
|
141
149
|
}[]): Promise<{
|
|
142
150
|
[owner: string]: {
|
|
143
|
-
[vaultId: string]: Data;
|
|
151
|
+
[vaultId: string]: Data | null;
|
|
144
152
|
};
|
|
145
153
|
}>;
|
|
146
154
|
/**
|
|
@@ -175,7 +183,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
175
183
|
* @param withdrawalTx
|
|
176
184
|
* @param scStartBlockheight
|
|
177
185
|
*/
|
|
178
|
-
getWithdrawalState(withdrawalTx: WithdrawalTX, scStartBlockheight?: number): Promise<SpvWithdrawalState>;
|
|
186
|
+
getWithdrawalState(withdrawalTx: WithdrawalTX, scStartBlockheight?: number): Promise<SpvWithdrawalState | null>;
|
|
179
187
|
/**
|
|
180
188
|
* Returns current state of the withdrawals, optionally
|
|
181
189
|
* only check withdrawals from the provided block height
|
|
@@ -186,7 +194,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
186
194
|
withdrawal: WithdrawalTX;
|
|
187
195
|
scStartBlockheight?: number;
|
|
188
196
|
}[]): Promise<{
|
|
189
|
-
[btcTxId: string]: SpvWithdrawalState;
|
|
197
|
+
[btcTxId: string]: SpvWithdrawalState | null;
|
|
190
198
|
}>;
|
|
191
199
|
/**
|
|
192
200
|
* Parses withdrawal data from the parsed bitcoin transaction
|
|
@@ -217,7 +225,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
217
225
|
fromOpReturnData(data: Buffer): {
|
|
218
226
|
recipient: string;
|
|
219
227
|
rawAmounts: bigint[];
|
|
220
|
-
executionHash
|
|
228
|
+
executionHash?: string;
|
|
221
229
|
};
|
|
222
230
|
/**
|
|
223
231
|
* Returns the fee in native token base units to claim the swap
|
|
@@ -227,7 +235,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
227
235
|
* @param withdrawalData Withdrawal to claim
|
|
228
236
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
229
237
|
*/
|
|
230
|
-
getClaimFee(signer: string, vault
|
|
238
|
+
getClaimFee(signer: string, vault?: Data, withdrawalData?: WithdrawalTX, feeRate?: string): Promise<bigint>;
|
|
231
239
|
/**
|
|
232
240
|
* Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
|
|
233
241
|
*
|
|
@@ -236,7 +244,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
236
244
|
* @param withdrawalData Withdrawal to claim
|
|
237
245
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
238
246
|
*/
|
|
239
|
-
getRawClaimFee?(signer: string, vault
|
|
247
|
+
getRawClaimFee?(signer: string, vault?: Data, withdrawalData?: WithdrawalTX, feeRate?: string): Promise<bigint>;
|
|
240
248
|
/**
|
|
241
249
|
* Returns the fee in native token base units to claim the swap
|
|
242
250
|
*
|
|
@@ -245,7 +253,7 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
245
253
|
* @param withdrawalData Withdrawal to claim
|
|
246
254
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
247
255
|
*/
|
|
248
|
-
getFrontFee(signer: string, vault
|
|
256
|
+
getFrontFee(signer: string, vault?: Data, withdrawalData?: WithdrawalTX, feeRate?: string): Promise<bigint>;
|
|
249
257
|
/**
|
|
250
258
|
* Returns raw fee (not including any refunds we might get that would make the getClaimFee negative) for claiming the swap
|
|
251
259
|
*
|
|
@@ -254,5 +262,5 @@ export interface SpvVaultContract<TX = any, Signer extends AbstractSigner = Abst
|
|
|
254
262
|
* @param withdrawalData Withdrawal to claim
|
|
255
263
|
* @param feeRate Optional fee rate (fetched on-demand if not provided)
|
|
256
264
|
*/
|
|
257
|
-
getRawFrontFee?(signer: string, vault
|
|
265
|
+
getRawFrontFee?(signer: string, vault?: Data, withdrawalData?: WithdrawalTX, feeRate?: string): Promise<bigint>;
|
|
258
266
|
}
|
|
@@ -4,30 +4,106 @@ import { SpvVaultClaimEvent } from "../events/types/spv_vault/SpvVaultClaimEvent
|
|
|
4
4
|
import { SpvVaultCloseEvent } from "../events/types/spv_vault/SpvVaultCloseEvent";
|
|
5
5
|
import { SpvVaultOpenEvent } from "../events/types/spv_vault/SpvVaultOpenEvent";
|
|
6
6
|
import { SpvVaultDepositEvent } from "../events/types/spv_vault/SpvVaultDepositEvent";
|
|
7
|
+
/**
|
|
8
|
+
* Balance for a specific token inside a vault
|
|
9
|
+
*
|
|
10
|
+
* @category Swaps
|
|
11
|
+
*/
|
|
7
12
|
export type SpvVaultTokenBalance = SpvVaultTokenData & {
|
|
13
|
+
/**
|
|
14
|
+
* A raw amount of the token, exactly as specified in the vault state
|
|
15
|
+
*/
|
|
8
16
|
rawAmount: bigint;
|
|
17
|
+
/**
|
|
18
|
+
* An actual amount of funds in the vault, calculated as `rawAmount` * `multiplier`
|
|
19
|
+
*/
|
|
9
20
|
scaledAmount: bigint;
|
|
10
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for a specific token inside an SPV vault (UTXO-controlled vault)
|
|
24
|
+
*
|
|
25
|
+
* @category Swaps
|
|
26
|
+
*/
|
|
11
27
|
export type SpvVaultTokenData = {
|
|
28
|
+
/**
|
|
29
|
+
* Address of the token used
|
|
30
|
+
*/
|
|
12
31
|
token: string;
|
|
32
|
+
/**
|
|
33
|
+
* A multiplier to scale the token value with
|
|
34
|
+
*/
|
|
13
35
|
multiplier: bigint;
|
|
14
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Represents the state of a single SPV vault (UTXO-controlled vault)
|
|
39
|
+
*
|
|
40
|
+
* @category Swaps
|
|
41
|
+
*/
|
|
15
42
|
export declare abstract class SpvVaultData<T extends SpvWithdrawalTransactionData = SpvWithdrawalTransactionData> implements StorageObject {
|
|
43
|
+
/**
|
|
44
|
+
* A mapping of deserializers for different spv vault data types coming from different smart chain implementations
|
|
45
|
+
*/
|
|
16
46
|
static deserializers: {
|
|
17
47
|
[type: string]: new (serialized: any) => any;
|
|
18
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Deserializer parsing the chain-specific spv vault data from a JSON-compatible object representation
|
|
51
|
+
*
|
|
52
|
+
* @param data
|
|
53
|
+
*/
|
|
19
54
|
static deserialize<T extends SpvVaultData>(data: any): T;
|
|
55
|
+
/**
|
|
56
|
+
* @inheritDoc
|
|
57
|
+
*/
|
|
20
58
|
abstract serialize(): any;
|
|
59
|
+
/**
|
|
60
|
+
* Gets the owner of the vault
|
|
61
|
+
*/
|
|
21
62
|
abstract getOwner(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the vault ID, this along with the owner uniquely identifies a vault
|
|
65
|
+
*/
|
|
22
66
|
abstract getVaultId(): bigint;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the configuration of the tokens supported by the vault
|
|
69
|
+
*/
|
|
23
70
|
abstract getTokenData(): SpvVaultTokenData[];
|
|
71
|
+
/**
|
|
72
|
+
* Returns the token balance currently available in the vault
|
|
73
|
+
*/
|
|
24
74
|
abstract getBalances(): SpvVaultTokenBalance[];
|
|
75
|
+
/**
|
|
76
|
+
* Returns the UTXO in [txId]:[vout] format which currently controls the vault
|
|
77
|
+
*/
|
|
25
78
|
abstract getUtxo(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the required number of confirmations that a bitcoin transaction has to get in order for the
|
|
81
|
+
* vault claim (withdrawal) to be authorized
|
|
82
|
+
*/
|
|
26
83
|
abstract getConfirmations(): number;
|
|
84
|
+
/**
|
|
85
|
+
* Returns the current number of claims (withdrawals) processed by the vault
|
|
86
|
+
*/
|
|
27
87
|
abstract getWithdrawalCount(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Returns the current number of deposits deposited into the vault
|
|
90
|
+
*/
|
|
28
91
|
abstract getDepositCount(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Checks whether a vault is opened and available to process claims (withdrawals)
|
|
94
|
+
*/
|
|
29
95
|
abstract isOpened(): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Updates the state of the spv vault data from either an on-chain event or a {@link SpvWithdrawalTransactionData}
|
|
98
|
+
*
|
|
99
|
+
* @param withdrawalTxOrEvent
|
|
100
|
+
*/
|
|
30
101
|
abstract updateState(withdrawalTxOrEvent: T | SpvVaultClaimEvent | SpvVaultCloseEvent | SpvVaultOpenEvent | SpvVaultDepositEvent): void;
|
|
102
|
+
/**
|
|
103
|
+
* A helper function which calculates the vault balances after processing an array of claims (withdrawals)
|
|
104
|
+
*
|
|
105
|
+
* @param priorWithdrawalTxs
|
|
106
|
+
*/
|
|
31
107
|
calculateStateAfter(priorWithdrawalTxs: T[]): {
|
|
32
108
|
withdrawalCount: number;
|
|
33
109
|
balances: SpvVaultTokenBalance[];
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SpvVaultData = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents the state of a single SPV vault (UTXO-controlled vault)
|
|
6
|
+
*
|
|
7
|
+
* @category Swaps
|
|
8
|
+
*/
|
|
4
9
|
class SpvVaultData {
|
|
10
|
+
/**
|
|
11
|
+
* Deserializer parsing the chain-specific spv vault data from a JSON-compatible object representation
|
|
12
|
+
*
|
|
13
|
+
* @param data
|
|
14
|
+
*/
|
|
5
15
|
static deserialize(data) {
|
|
6
16
|
if (SpvVaultData.deserializers[data.type] != null) {
|
|
7
17
|
return new SpvVaultData.deserializers[data.type](data);
|
|
8
18
|
}
|
|
19
|
+
throw new Error(`No deserializer found for spv vault data type: ${data.type}`);
|
|
9
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A helper function which calculates the vault balances after processing an array of claims (withdrawals)
|
|
23
|
+
*
|
|
24
|
+
* @param priorWithdrawalTxs
|
|
25
|
+
*/
|
|
10
26
|
calculateStateAfter(priorWithdrawalTxs) {
|
|
11
27
|
const balances = [...this.getBalances()];
|
|
12
28
|
let withdrawalCount = this.getWithdrawalCount();
|
|
@@ -34,4 +50,7 @@ class SpvVaultData {
|
|
|
34
50
|
}
|
|
35
51
|
}
|
|
36
52
|
exports.SpvVaultData = SpvVaultData;
|
|
53
|
+
/**
|
|
54
|
+
* A mapping of deserializers for different spv vault data types coming from different smart chain implementations
|
|
55
|
+
*/
|
|
37
56
|
SpvVaultData.deserializers = {};
|