@atomiqlabs/lp-lib 14.0.0-dev.21 → 14.0.0-dev.24
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/LICENSE +201 -201
- package/dist/fees/IBtcFeeEstimator.d.ts +3 -3
- package/dist/fees/IBtcFeeEstimator.js +2 -2
- package/dist/index.d.ts +42 -42
- package/dist/index.js +58 -58
- package/dist/info/InfoHandler.d.ts +17 -17
- package/dist/info/InfoHandler.js +61 -61
- package/dist/plugins/IPlugin.d.ts +143 -143
- package/dist/plugins/IPlugin.js +34 -34
- package/dist/plugins/PluginManager.d.ts +112 -112
- package/dist/plugins/PluginManager.js +259 -259
- package/dist/prices/BinanceSwapPrice.d.ts +26 -26
- package/dist/prices/BinanceSwapPrice.js +92 -92
- package/dist/prices/CoinGeckoSwapPrice.d.ts +30 -30
- package/dist/prices/CoinGeckoSwapPrice.js +64 -64
- package/dist/prices/ISwapPrice.d.ts +43 -43
- package/dist/prices/ISwapPrice.js +55 -55
- package/dist/prices/OKXSwapPrice.d.ts +26 -26
- package/dist/prices/OKXSwapPrice.js +92 -92
- package/dist/storage/IIntermediaryStorage.d.ts +18 -18
- package/dist/storage/IIntermediaryStorage.js +2 -2
- package/dist/storagemanager/IntermediaryStorageManager.d.ts +19 -19
- package/dist/storagemanager/IntermediaryStorageManager.js +111 -111
- package/dist/storagemanager/StorageManager.d.ts +13 -13
- package/dist/storagemanager/StorageManager.js +64 -64
- package/dist/swaps/SwapHandler.d.ts +153 -153
- package/dist/swaps/SwapHandler.js +160 -160
- package/dist/swaps/SwapHandlerSwap.d.ts +79 -79
- package/dist/swaps/SwapHandlerSwap.js +78 -78
- package/dist/swaps/assertions/AmountAssertions.d.ts +28 -28
- package/dist/swaps/assertions/AmountAssertions.js +72 -72
- package/dist/swaps/assertions/FromBtcAmountAssertions.d.ts +76 -76
- package/dist/swaps/assertions/FromBtcAmountAssertions.js +180 -180
- package/dist/swaps/assertions/LightningAssertions.d.ts +44 -44
- package/dist/swaps/assertions/LightningAssertions.js +86 -86
- package/dist/swaps/assertions/ToBtcAmountAssertions.d.ts +53 -53
- package/dist/swaps/assertions/ToBtcAmountAssertions.js +150 -150
- package/dist/swaps/escrow/EscrowHandler.d.ts +51 -51
- package/dist/swaps/escrow/EscrowHandler.js +158 -158
- package/dist/swaps/escrow/EscrowHandlerSwap.d.ts +35 -35
- package/dist/swaps/escrow/EscrowHandlerSwap.js +69 -69
- package/dist/swaps/escrow/FromBtcBaseSwap.d.ts +14 -14
- package/dist/swaps/escrow/FromBtcBaseSwap.js +32 -32
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.d.ts +102 -102
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.js +210 -210
- package/dist/swaps/escrow/ToBtcBaseSwap.d.ts +36 -36
- package/dist/swaps/escrow/ToBtcBaseSwap.js +67 -67
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.d.ts +53 -53
- package/dist/swaps/escrow/ToBtcBaseSwapHandler.js +81 -81
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.d.ts +83 -83
- package/dist/swaps/escrow/frombtc_abstract/FromBtcAbs.js +318 -318
- package/dist/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.d.ts +21 -21
- package/dist/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.js +50 -50
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.d.ts +107 -107
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +675 -675
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.d.ts +33 -33
- package/dist/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.js +91 -91
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.d.ts +111 -111
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +684 -684
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.d.ts +55 -55
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.js +120 -120
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.d.ts +171 -171
- package/dist/swaps/escrow/tobtc_abstract/ToBtcAbs.js +706 -706
- package/dist/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.d.ts +26 -26
- package/dist/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.js +62 -62
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.d.ts +177 -177
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.js +863 -863
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.d.ts +24 -24
- package/dist/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.js +58 -58
- package/dist/swaps/spv_vault_swap/SpvVault.d.ts +40 -41
- package/dist/swaps/spv_vault_swap/SpvVault.js +111 -111
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.d.ts +67 -67
- package/dist/swaps/spv_vault_swap/SpvVaultSwap.js +158 -158
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.d.ts +68 -68
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +492 -492
- package/dist/swaps/spv_vault_swap/SpvVaults.d.ts +52 -52
- package/dist/swaps/spv_vault_swap/SpvVaults.js +394 -364
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.d.ts +51 -51
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrusted.js +650 -650
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.d.ts +52 -52
- package/dist/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.js +118 -118
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.d.ts +76 -76
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.js +494 -494
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.d.ts +34 -34
- package/dist/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.js +81 -81
- package/dist/utils/BitcoinUtils.d.ts +2 -2
- package/dist/utils/BitcoinUtils.js +45 -45
- package/dist/utils/Utils.d.ts +29 -29
- package/dist/utils/Utils.js +89 -89
- package/dist/utils/paramcoders/IParamReader.d.ts +5 -5
- package/dist/utils/paramcoders/IParamReader.js +2 -2
- package/dist/utils/paramcoders/IParamWriter.d.ts +4 -4
- package/dist/utils/paramcoders/IParamWriter.js +2 -2
- package/dist/utils/paramcoders/LegacyParamEncoder.d.ts +10 -10
- package/dist/utils/paramcoders/LegacyParamEncoder.js +22 -22
- package/dist/utils/paramcoders/ParamDecoder.d.ts +25 -25
- package/dist/utils/paramcoders/ParamDecoder.js +222 -222
- package/dist/utils/paramcoders/ParamEncoder.d.ts +9 -9
- package/dist/utils/paramcoders/ParamEncoder.js +22 -22
- package/dist/utils/paramcoders/SchemaVerifier.d.ts +21 -21
- package/dist/utils/paramcoders/SchemaVerifier.js +84 -84
- package/dist/utils/paramcoders/server/ServerParamDecoder.d.ts +8 -8
- package/dist/utils/paramcoders/server/ServerParamDecoder.js +107 -107
- package/dist/utils/paramcoders/server/ServerParamEncoder.d.ts +11 -11
- package/dist/utils/paramcoders/server/ServerParamEncoder.js +65 -65
- package/dist/wallets/IBitcoinWallet.d.ts +67 -67
- package/dist/wallets/IBitcoinWallet.js +2 -2
- package/dist/wallets/ILightningWallet.d.ts +117 -117
- package/dist/wallets/ILightningWallet.js +37 -37
- package/dist/wallets/ISpvVaultSigner.d.ts +7 -7
- package/dist/wallets/ISpvVaultSigner.js +2 -2
- package/package.json +36 -36
- package/src/fees/IBtcFeeEstimator.ts +6 -6
- package/src/index.ts +53 -53
- package/src/info/InfoHandler.ts +106 -106
- package/src/plugins/IPlugin.ts +168 -168
- package/src/plugins/PluginManager.ts +336 -336
- package/src/prices/BinanceSwapPrice.ts +113 -113
- package/src/prices/CoinGeckoSwapPrice.ts +87 -87
- package/src/prices/ISwapPrice.ts +88 -88
- package/src/prices/OKXSwapPrice.ts +113 -113
- package/src/storage/IIntermediaryStorage.ts +19 -19
- package/src/storagemanager/IntermediaryStorageManager.ts +118 -118
- package/src/storagemanager/StorageManager.ts +78 -78
- package/src/swaps/SwapHandler.ts +277 -277
- package/src/swaps/SwapHandlerSwap.ts +141 -141
- package/src/swaps/assertions/AmountAssertions.ts +76 -76
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +246 -246
- package/src/swaps/assertions/LightningAssertions.ts +103 -103
- package/src/swaps/assertions/ToBtcAmountAssertions.ts +203 -203
- package/src/swaps/escrow/EscrowHandler.ts +179 -179
- package/src/swaps/escrow/EscrowHandlerSwap.ts +86 -86
- package/src/swaps/escrow/FromBtcBaseSwap.ts +38 -38
- package/src/swaps/escrow/FromBtcBaseSwapHandler.ts +286 -286
- package/src/swaps/escrow/ToBtcBaseSwap.ts +85 -85
- package/src/swaps/escrow/ToBtcBaseSwapHandler.ts +129 -129
- package/src/swaps/escrow/frombtc_abstract/FromBtcAbs.ts +452 -452
- package/src/swaps/escrow/frombtc_abstract/FromBtcSwapAbs.ts +61 -61
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +856 -856
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs.ts +141 -141
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +850 -850
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.ts +196 -196
- package/src/swaps/escrow/tobtc_abstract/ToBtcAbs.ts +879 -879
- package/src/swaps/escrow/tobtc_abstract/ToBtcSwapAbs.ts +102 -102
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnAbs.ts +1112 -1112
- package/src/swaps/escrow/tobtcln_abstract/ToBtcLnSwapAbs.ts +80 -80
- package/src/swaps/spv_vault_swap/SpvVault.ts +143 -143
- package/src/swaps/spv_vault_swap/SpvVaultSwap.ts +225 -225
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +628 -628
- package/src/swaps/spv_vault_swap/SpvVaults.ts +469 -435
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrusted.ts +747 -747
- package/src/swaps/trusted/frombtc_trusted/FromBtcTrustedSwap.ts +185 -185
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrusted.ts +590 -590
- package/src/swaps/trusted/frombtcln_trusted/FromBtcLnTrustedSwap.ts +121 -121
- package/src/utils/BitcoinUtils.ts +42 -42
- package/src/utils/Utils.ts +104 -104
- package/src/utils/paramcoders/IParamReader.ts +7 -7
- package/src/utils/paramcoders/IParamWriter.ts +8 -8
- package/src/utils/paramcoders/LegacyParamEncoder.ts +27 -27
- package/src/utils/paramcoders/ParamDecoder.ts +218 -218
- package/src/utils/paramcoders/ParamEncoder.ts +29 -29
- package/src/utils/paramcoders/SchemaVerifier.ts +96 -96
- package/src/utils/paramcoders/server/ServerParamDecoder.ts +118 -118
- package/src/utils/paramcoders/server/ServerParamEncoder.ts +75 -75
- package/src/wallets/IBitcoinWallet.ts +68 -68
- package/src/wallets/ILightningWallet.ts +178 -178
- package/src/wallets/ISpvVaultSigner.ts +10 -10
|
@@ -1,186 +1,186 @@
|
|
|
1
|
-
import {BigIntBufferUtils, BtcTx, SwapData} from "@atomiqlabs/base";
|
|
2
|
-
import {deserializeBN, serializeBN} from "../../../utils/Utils";
|
|
3
|
-
import {createHash, randomBytes} from "crypto";
|
|
4
|
-
import {SwapHandlerSwap} from "../../SwapHandlerSwap";
|
|
5
|
-
import {SwapHandlerType} from "../../SwapHandler";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export enum FromBtcTrustedSwapState {
|
|
9
|
-
DOUBLE_SPENT = -4,
|
|
10
|
-
REFUNDED = -3,
|
|
11
|
-
REFUNDABLE = -2,
|
|
12
|
-
EXPIRED = -1,
|
|
13
|
-
CREATED = 0,
|
|
14
|
-
RECEIVED = 1,
|
|
15
|
-
BTC_CONFIRMED = 2,
|
|
16
|
-
SENT = 3,
|
|
17
|
-
CONFIRMED = 4,
|
|
18
|
-
FINISHED = 5
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class FromBtcTrustedSwap extends SwapHandlerSwap<FromBtcTrustedSwapState> {
|
|
22
|
-
|
|
23
|
-
readonly amount: bigint;
|
|
24
|
-
readonly sequence: bigint;
|
|
25
|
-
readonly btcAddress: string;
|
|
26
|
-
|
|
27
|
-
readonly dstAddress: string;
|
|
28
|
-
readonly outputTokens: bigint;
|
|
29
|
-
|
|
30
|
-
readonly createdHeight: number;
|
|
31
|
-
readonly expiresAt: number;
|
|
32
|
-
readonly recommendedFee: number;
|
|
33
|
-
|
|
34
|
-
readonly token: string;
|
|
35
|
-
|
|
36
|
-
refundAddress: string;
|
|
37
|
-
|
|
38
|
-
adjustedInput: bigint;
|
|
39
|
-
adjustedOutput: bigint;
|
|
40
|
-
|
|
41
|
-
doubleSpent: boolean;
|
|
42
|
-
scRawTx: string;
|
|
43
|
-
|
|
44
|
-
btcTx: BtcTx;
|
|
45
|
-
txFee: number;
|
|
46
|
-
txSize: number;
|
|
47
|
-
txId: string;
|
|
48
|
-
vout: number;
|
|
49
|
-
|
|
50
|
-
burnTxId: string;
|
|
51
|
-
refundTxId: string;
|
|
52
|
-
|
|
53
|
-
constructor(
|
|
54
|
-
chainIdentifier: string,
|
|
55
|
-
swapFee: bigint,
|
|
56
|
-
swapFeeInToken: bigint,
|
|
57
|
-
btcAddress: string,
|
|
58
|
-
inputSats: bigint,
|
|
59
|
-
dstAddress: string,
|
|
60
|
-
outputTokens: bigint,
|
|
61
|
-
createdHeight: number,
|
|
62
|
-
expiresAt: number,
|
|
63
|
-
recommendedFee: number,
|
|
64
|
-
refundAddress: string,
|
|
65
|
-
token: string
|
|
66
|
-
);
|
|
67
|
-
constructor(obj: any);
|
|
68
|
-
|
|
69
|
-
constructor(
|
|
70
|
-
objOrChainIdentifier: any | string,
|
|
71
|
-
swapFee?: bigint,
|
|
72
|
-
swapFeeInToken?: bigint,
|
|
73
|
-
btcAddress?: string,
|
|
74
|
-
inputSats?: bigint,
|
|
75
|
-
dstAddress?: string,
|
|
76
|
-
outputTokens?: bigint,
|
|
77
|
-
createdHeight?: number,
|
|
78
|
-
expiresAt?: number,
|
|
79
|
-
recommendedFee?: number,
|
|
80
|
-
refundAddress?: string,
|
|
81
|
-
token?: string
|
|
82
|
-
) {
|
|
83
|
-
if(typeof(objOrChainIdentifier)==="string") {
|
|
84
|
-
super(objOrChainIdentifier, swapFee, swapFeeInToken);
|
|
85
|
-
this.state = FromBtcTrustedSwapState.CREATED;
|
|
86
|
-
this.doubleSpent = false;
|
|
87
|
-
this.amount = inputSats;
|
|
88
|
-
this.sequence = BigIntBufferUtils.fromBuffer(randomBytes(8));
|
|
89
|
-
this.btcAddress = btcAddress;
|
|
90
|
-
this.dstAddress = dstAddress;
|
|
91
|
-
this.outputTokens = outputTokens;
|
|
92
|
-
this.createdHeight = createdHeight;
|
|
93
|
-
this.expiresAt = expiresAt;
|
|
94
|
-
this.recommendedFee = recommendedFee;
|
|
95
|
-
this.refundAddress = refundAddress;
|
|
96
|
-
this.token = token;
|
|
97
|
-
} else {
|
|
98
|
-
super(objOrChainIdentifier);
|
|
99
|
-
this.btcAddress = objOrChainIdentifier.btcAddress;
|
|
100
|
-
this.amount = deserializeBN(objOrChainIdentifier.amount);
|
|
101
|
-
this.sequence = deserializeBN(objOrChainIdentifier.sequence);
|
|
102
|
-
this.dstAddress = objOrChainIdentifier.dstAddress;
|
|
103
|
-
this.outputTokens = deserializeBN(objOrChainIdentifier.outputTokens);
|
|
104
|
-
this.adjustedInput = deserializeBN(objOrChainIdentifier.adjustedInput);
|
|
105
|
-
this.adjustedOutput = deserializeBN(objOrChainIdentifier.adjustedOutput);
|
|
106
|
-
this.createdHeight = objOrChainIdentifier.createdHeight;
|
|
107
|
-
this.expiresAt = objOrChainIdentifier.expiresAt;
|
|
108
|
-
this.recommendedFee = objOrChainIdentifier.recommendedFee;
|
|
109
|
-
this.refundAddress = objOrChainIdentifier.refundAddress;
|
|
110
|
-
this.doubleSpent = objOrChainIdentifier.doubleSpent;
|
|
111
|
-
this.scRawTx = objOrChainIdentifier.scRawTx;
|
|
112
|
-
this.btcTx = objOrChainIdentifier.btcTx;
|
|
113
|
-
this.txFee = objOrChainIdentifier.txFee;
|
|
114
|
-
this.txSize = objOrChainIdentifier.txSize;
|
|
115
|
-
this.txId = objOrChainIdentifier.txId;
|
|
116
|
-
this.vout = objOrChainIdentifier.vout;
|
|
117
|
-
this.burnTxId = objOrChainIdentifier.burnTxId;
|
|
118
|
-
this.refundTxId = objOrChainIdentifier.refundTxId;
|
|
119
|
-
this.token = objOrChainIdentifier.token;
|
|
120
|
-
}
|
|
121
|
-
this.type = SwapHandlerType.FROM_BTC_TRUSTED;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
serialize(): any {
|
|
125
|
-
const partialSerialized = super.serialize();
|
|
126
|
-
partialSerialized.btcAddress = this.btcAddress;
|
|
127
|
-
partialSerialized.amount = serializeBN(this.amount);
|
|
128
|
-
partialSerialized.sequence = serializeBN(this.sequence);
|
|
129
|
-
partialSerialized.dstAddress = this.dstAddress;
|
|
130
|
-
partialSerialized.outputTokens = serializeBN(this.outputTokens);
|
|
131
|
-
partialSerialized.adjustedInput = serializeBN(this.adjustedInput);
|
|
132
|
-
partialSerialized.adjustedOutput = serializeBN(this.adjustedOutput);
|
|
133
|
-
partialSerialized.createdHeight = this.createdHeight;
|
|
134
|
-
partialSerialized.expiresAt = this.expiresAt;
|
|
135
|
-
partialSerialized.recommendedFee = this.recommendedFee;
|
|
136
|
-
partialSerialized.refundAddress = this.refundAddress;
|
|
137
|
-
partialSerialized.doubleSpent = this.doubleSpent;
|
|
138
|
-
partialSerialized.scRawTx = this.scRawTx;
|
|
139
|
-
partialSerialized.btcTx = this.btcTx;
|
|
140
|
-
partialSerialized.txFee = this.txFee;
|
|
141
|
-
partialSerialized.txSize = this.txSize;
|
|
142
|
-
partialSerialized.txId = this.txId;
|
|
143
|
-
partialSerialized.vout = this.vout;
|
|
144
|
-
partialSerialized.burnTxId = this.burnTxId;
|
|
145
|
-
partialSerialized.refundTxId = this.refundTxId;
|
|
146
|
-
partialSerialized.token = this.token;
|
|
147
|
-
return partialSerialized;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
getSequence(): bigint {
|
|
151
|
-
return this.sequence;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getToken(): string {
|
|
155
|
-
return this.token;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
getOutputAmount(): bigint {
|
|
159
|
-
return this.adjustedOutput || this.outputTokens;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
getTotalInputAmount(): bigint {
|
|
163
|
-
return this.adjustedInput || this.amount;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
getSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
|
|
167
|
-
return {inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken};
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
isFailed(): boolean {
|
|
171
|
-
return this.state===FromBtcTrustedSwapState.EXPIRED || this.state===FromBtcTrustedSwapState.REFUNDED || this.state===FromBtcTrustedSwapState.DOUBLE_SPENT;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
isInitiated(): boolean {
|
|
175
|
-
return this.state!==FromBtcTrustedSwapState.CREATED;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
isSuccess(): boolean {
|
|
179
|
-
return this.state===FromBtcTrustedSwapState.CONFIRMED;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getIdentifierHash(): string {
|
|
183
|
-
return createHash("sha256").update(this.btcAddress).digest().toString("hex");
|
|
184
|
-
}
|
|
185
|
-
|
|
1
|
+
import {BigIntBufferUtils, BtcTx, SwapData} from "@atomiqlabs/base";
|
|
2
|
+
import {deserializeBN, serializeBN} from "../../../utils/Utils";
|
|
3
|
+
import {createHash, randomBytes} from "crypto";
|
|
4
|
+
import {SwapHandlerSwap} from "../../SwapHandlerSwap";
|
|
5
|
+
import {SwapHandlerType} from "../../SwapHandler";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export enum FromBtcTrustedSwapState {
|
|
9
|
+
DOUBLE_SPENT = -4,
|
|
10
|
+
REFUNDED = -3,
|
|
11
|
+
REFUNDABLE = -2,
|
|
12
|
+
EXPIRED = -1,
|
|
13
|
+
CREATED = 0,
|
|
14
|
+
RECEIVED = 1,
|
|
15
|
+
BTC_CONFIRMED = 2,
|
|
16
|
+
SENT = 3,
|
|
17
|
+
CONFIRMED = 4,
|
|
18
|
+
FINISHED = 5
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class FromBtcTrustedSwap extends SwapHandlerSwap<FromBtcTrustedSwapState> {
|
|
22
|
+
|
|
23
|
+
readonly amount: bigint;
|
|
24
|
+
readonly sequence: bigint;
|
|
25
|
+
readonly btcAddress: string;
|
|
26
|
+
|
|
27
|
+
readonly dstAddress: string;
|
|
28
|
+
readonly outputTokens: bigint;
|
|
29
|
+
|
|
30
|
+
readonly createdHeight: number;
|
|
31
|
+
readonly expiresAt: number;
|
|
32
|
+
readonly recommendedFee: number;
|
|
33
|
+
|
|
34
|
+
readonly token: string;
|
|
35
|
+
|
|
36
|
+
refundAddress: string;
|
|
37
|
+
|
|
38
|
+
adjustedInput: bigint;
|
|
39
|
+
adjustedOutput: bigint;
|
|
40
|
+
|
|
41
|
+
doubleSpent: boolean;
|
|
42
|
+
scRawTx: string;
|
|
43
|
+
|
|
44
|
+
btcTx: BtcTx;
|
|
45
|
+
txFee: number;
|
|
46
|
+
txSize: number;
|
|
47
|
+
txId: string;
|
|
48
|
+
vout: number;
|
|
49
|
+
|
|
50
|
+
burnTxId: string;
|
|
51
|
+
refundTxId: string;
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
chainIdentifier: string,
|
|
55
|
+
swapFee: bigint,
|
|
56
|
+
swapFeeInToken: bigint,
|
|
57
|
+
btcAddress: string,
|
|
58
|
+
inputSats: bigint,
|
|
59
|
+
dstAddress: string,
|
|
60
|
+
outputTokens: bigint,
|
|
61
|
+
createdHeight: number,
|
|
62
|
+
expiresAt: number,
|
|
63
|
+
recommendedFee: number,
|
|
64
|
+
refundAddress: string,
|
|
65
|
+
token: string
|
|
66
|
+
);
|
|
67
|
+
constructor(obj: any);
|
|
68
|
+
|
|
69
|
+
constructor(
|
|
70
|
+
objOrChainIdentifier: any | string,
|
|
71
|
+
swapFee?: bigint,
|
|
72
|
+
swapFeeInToken?: bigint,
|
|
73
|
+
btcAddress?: string,
|
|
74
|
+
inputSats?: bigint,
|
|
75
|
+
dstAddress?: string,
|
|
76
|
+
outputTokens?: bigint,
|
|
77
|
+
createdHeight?: number,
|
|
78
|
+
expiresAt?: number,
|
|
79
|
+
recommendedFee?: number,
|
|
80
|
+
refundAddress?: string,
|
|
81
|
+
token?: string
|
|
82
|
+
) {
|
|
83
|
+
if(typeof(objOrChainIdentifier)==="string") {
|
|
84
|
+
super(objOrChainIdentifier, swapFee, swapFeeInToken);
|
|
85
|
+
this.state = FromBtcTrustedSwapState.CREATED;
|
|
86
|
+
this.doubleSpent = false;
|
|
87
|
+
this.amount = inputSats;
|
|
88
|
+
this.sequence = BigIntBufferUtils.fromBuffer(randomBytes(8));
|
|
89
|
+
this.btcAddress = btcAddress;
|
|
90
|
+
this.dstAddress = dstAddress;
|
|
91
|
+
this.outputTokens = outputTokens;
|
|
92
|
+
this.createdHeight = createdHeight;
|
|
93
|
+
this.expiresAt = expiresAt;
|
|
94
|
+
this.recommendedFee = recommendedFee;
|
|
95
|
+
this.refundAddress = refundAddress;
|
|
96
|
+
this.token = token;
|
|
97
|
+
} else {
|
|
98
|
+
super(objOrChainIdentifier);
|
|
99
|
+
this.btcAddress = objOrChainIdentifier.btcAddress;
|
|
100
|
+
this.amount = deserializeBN(objOrChainIdentifier.amount);
|
|
101
|
+
this.sequence = deserializeBN(objOrChainIdentifier.sequence);
|
|
102
|
+
this.dstAddress = objOrChainIdentifier.dstAddress;
|
|
103
|
+
this.outputTokens = deserializeBN(objOrChainIdentifier.outputTokens);
|
|
104
|
+
this.adjustedInput = deserializeBN(objOrChainIdentifier.adjustedInput);
|
|
105
|
+
this.adjustedOutput = deserializeBN(objOrChainIdentifier.adjustedOutput);
|
|
106
|
+
this.createdHeight = objOrChainIdentifier.createdHeight;
|
|
107
|
+
this.expiresAt = objOrChainIdentifier.expiresAt;
|
|
108
|
+
this.recommendedFee = objOrChainIdentifier.recommendedFee;
|
|
109
|
+
this.refundAddress = objOrChainIdentifier.refundAddress;
|
|
110
|
+
this.doubleSpent = objOrChainIdentifier.doubleSpent;
|
|
111
|
+
this.scRawTx = objOrChainIdentifier.scRawTx;
|
|
112
|
+
this.btcTx = objOrChainIdentifier.btcTx;
|
|
113
|
+
this.txFee = objOrChainIdentifier.txFee;
|
|
114
|
+
this.txSize = objOrChainIdentifier.txSize;
|
|
115
|
+
this.txId = objOrChainIdentifier.txId;
|
|
116
|
+
this.vout = objOrChainIdentifier.vout;
|
|
117
|
+
this.burnTxId = objOrChainIdentifier.burnTxId;
|
|
118
|
+
this.refundTxId = objOrChainIdentifier.refundTxId;
|
|
119
|
+
this.token = objOrChainIdentifier.token;
|
|
120
|
+
}
|
|
121
|
+
this.type = SwapHandlerType.FROM_BTC_TRUSTED;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
serialize(): any {
|
|
125
|
+
const partialSerialized = super.serialize();
|
|
126
|
+
partialSerialized.btcAddress = this.btcAddress;
|
|
127
|
+
partialSerialized.amount = serializeBN(this.amount);
|
|
128
|
+
partialSerialized.sequence = serializeBN(this.sequence);
|
|
129
|
+
partialSerialized.dstAddress = this.dstAddress;
|
|
130
|
+
partialSerialized.outputTokens = serializeBN(this.outputTokens);
|
|
131
|
+
partialSerialized.adjustedInput = serializeBN(this.adjustedInput);
|
|
132
|
+
partialSerialized.adjustedOutput = serializeBN(this.adjustedOutput);
|
|
133
|
+
partialSerialized.createdHeight = this.createdHeight;
|
|
134
|
+
partialSerialized.expiresAt = this.expiresAt;
|
|
135
|
+
partialSerialized.recommendedFee = this.recommendedFee;
|
|
136
|
+
partialSerialized.refundAddress = this.refundAddress;
|
|
137
|
+
partialSerialized.doubleSpent = this.doubleSpent;
|
|
138
|
+
partialSerialized.scRawTx = this.scRawTx;
|
|
139
|
+
partialSerialized.btcTx = this.btcTx;
|
|
140
|
+
partialSerialized.txFee = this.txFee;
|
|
141
|
+
partialSerialized.txSize = this.txSize;
|
|
142
|
+
partialSerialized.txId = this.txId;
|
|
143
|
+
partialSerialized.vout = this.vout;
|
|
144
|
+
partialSerialized.burnTxId = this.burnTxId;
|
|
145
|
+
partialSerialized.refundTxId = this.refundTxId;
|
|
146
|
+
partialSerialized.token = this.token;
|
|
147
|
+
return partialSerialized;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
getSequence(): bigint {
|
|
151
|
+
return this.sequence;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
getToken(): string {
|
|
155
|
+
return this.token;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getOutputAmount(): bigint {
|
|
159
|
+
return this.adjustedOutput || this.outputTokens;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getTotalInputAmount(): bigint {
|
|
163
|
+
return this.adjustedInput || this.amount;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
getSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
|
|
167
|
+
return {inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
isFailed(): boolean {
|
|
171
|
+
return this.state===FromBtcTrustedSwapState.EXPIRED || this.state===FromBtcTrustedSwapState.REFUNDED || this.state===FromBtcTrustedSwapState.DOUBLE_SPENT;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
isInitiated(): boolean {
|
|
175
|
+
return this.state!==FromBtcTrustedSwapState.CREATED;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
isSuccess(): boolean {
|
|
179
|
+
return this.state===FromBtcTrustedSwapState.CONFIRMED;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getIdentifierHash(): string {
|
|
183
|
+
return createHash("sha256").update(this.btcAddress).digest().toString("hex");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
186
|
}
|