@atomiqlabs/lp-lib 14.0.0-dev.12 → 14.0.0-dev.13
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/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.js +46 -19
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +46 -20
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +1 -0
- package/package.json +2 -2
- package/src/swaps/escrow/frombtcln_abstract/FromBtcLnAbs.ts +52 -24
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +51 -24
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +1 -0
|
@@ -55,30 +55,57 @@ class FromBtcLnAbs extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
55
55
|
}
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
|
-
if (swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.RECEIVED) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
await
|
|
65
|
-
|
|
58
|
+
if (swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.RECEIVED || swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.COMMITED) {
|
|
59
|
+
const onchainStatus = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
60
|
+
const state = swap.state;
|
|
61
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.PAID) {
|
|
62
|
+
//Extract the swap secret
|
|
63
|
+
if (state !== FromBtcLnSwapAbs_1.FromBtcLnSwapState.CLAIMED && state !== FromBtcLnSwapAbs_1.FromBtcLnSwapState.SETTLED) {
|
|
64
|
+
const secretHex = await onchainStatus.getClaimResult();
|
|
65
|
+
const secret = Buffer.from(secretHex, "hex");
|
|
66
|
+
const paymentHash = (0, crypto_1.createHash)("sha256").update(secret).digest();
|
|
67
|
+
const paymentHashHex = paymentHash.toString("hex");
|
|
68
|
+
if (swap.lnPaymentHash !== paymentHashHex) {
|
|
69
|
+
//TODO: Possibly fatal failure
|
|
70
|
+
this.swapLogger.error(swap, "processPastSwap(state=RECEIVED|COMMITED): onchainStatus=PAID, Invalid swap secret specified: " + secretHex + " for paymentHash: " + paymentHashHex);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
swap.secret = secretHex;
|
|
74
|
+
await swap.setState(FromBtcLnSwapAbs_1.FromBtcLnSwapState.CLAIMED);
|
|
75
|
+
await this.saveSwapData(swap);
|
|
76
|
+
this.swapLogger.warn(swap, "processPastSwap(state=RECEIVED|COMMITED): swap settled (detected from processPastSwap), invoice: " + swap.pr);
|
|
77
|
+
return "SETTLE";
|
|
66
78
|
}
|
|
67
|
-
|
|
68
|
-
await swap.setState(FromBtcLnSwapAbs_1.FromBtcLnSwapState.COMMITED);
|
|
69
|
-
await this.saveSwapData(swap);
|
|
79
|
+
return null;
|
|
70
80
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.COMMITED) {
|
|
82
|
+
if (state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.RECEIVED) {
|
|
83
|
+
await swap.setState(FromBtcLnSwapAbs_1.FromBtcLnSwapState.COMMITED);
|
|
84
|
+
await this.saveSwapData(swap);
|
|
85
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap committed (detected from processPastSwap), invoice: " + swap.pr);
|
|
86
|
+
}
|
|
74
87
|
return null;
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
88
|
+
}
|
|
89
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.NOT_COMMITED || onchainStatus.type === base_1.SwapCommitStateType.EXPIRED) {
|
|
90
|
+
if (swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.RECEIVED) {
|
|
91
|
+
const isAuthorizationExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap);
|
|
92
|
+
if (isAuthorizationExpired) {
|
|
93
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap not committed before authorization expiry, cancelling the LN invoice, invoice: " + swap.pr);
|
|
94
|
+
await swap.setState(FromBtcLnSwapAbs_1.FromBtcLnSwapState.CANCELED);
|
|
95
|
+
return "CANCEL";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
if (await swapContract.isExpired(signer.getAddress(), swap.data)) {
|
|
100
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap timed out, refunding to self, invoice: " + swap.pr);
|
|
101
|
+
return "REFUND";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.REFUNDABLE) {
|
|
106
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap timed out, refunding to self, invoice: " + swap.pr);
|
|
78
107
|
return "REFUND";
|
|
79
108
|
}
|
|
80
|
-
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED): swap timed out, cancelling the LN invoice, invoice: " + swap.pr);
|
|
81
|
-
return "CANCEL";
|
|
82
109
|
}
|
|
83
110
|
if (swap.state === FromBtcLnSwapAbs_1.FromBtcLnSwapState.CLAIMED)
|
|
84
111
|
return "SETTLE";
|
|
@@ -65,31 +65,57 @@ class FromBtcLnAuto extends FromBtcBaseSwapHandler_1.FromBtcBaseSwapHandler {
|
|
|
65
65
|
}
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
|
-
if (swap.state === FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.TXS_SENT) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
await
|
|
75
|
-
|
|
68
|
+
if (swap.state === FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.TXS_SENT || swap.state === FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.COMMITED) {
|
|
69
|
+
const onchainStatus = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
70
|
+
const state = swap.state;
|
|
71
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.PAID) {
|
|
72
|
+
//Extract the swap secret
|
|
73
|
+
if (state !== FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.CLAIMED && state !== FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.SETTLED) {
|
|
74
|
+
const secretHex = await onchainStatus.getClaimResult();
|
|
75
|
+
const secret = Buffer.from(secretHex, "hex");
|
|
76
|
+
const paymentHash = (0, crypto_1.createHash)("sha256").update(secret).digest();
|
|
77
|
+
const paymentHashHex = paymentHash.toString("hex");
|
|
78
|
+
if (swap.lnPaymentHash !== paymentHashHex) {
|
|
79
|
+
//TODO: Possibly fatal failure
|
|
80
|
+
this.swapLogger.error(swap, "processPastSwap(state=TXS_SENT|COMMITED): onchainStatus=PAID, Invalid swap secret specified: " + secretHex + " for paymentHash: " + paymentHashHex);
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
swap.secret = secretHex;
|
|
84
|
+
await swap.setState(FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.CLAIMED);
|
|
85
|
+
await this.saveSwapData(swap);
|
|
86
|
+
this.swapLogger.warn(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap settled (detected from processPastSwap), invoice: " + swap.pr);
|
|
87
|
+
return "SETTLE";
|
|
76
88
|
}
|
|
77
|
-
|
|
78
|
-
await swap.setState(FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.COMMITED);
|
|
79
|
-
await this.saveSwapData(swap);
|
|
89
|
+
return null;
|
|
80
90
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.COMMITED) {
|
|
92
|
+
if (state === FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.TXS_SENT) {
|
|
93
|
+
await swap.setState(FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.COMMITED);
|
|
94
|
+
await this.saveSwapData(swap);
|
|
95
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap committed (detected from processPastSwap), invoice: " + swap.pr);
|
|
96
|
+
}
|
|
84
97
|
return null;
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
98
|
+
}
|
|
99
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.NOT_COMMITED || onchainStatus.type === base_1.SwapCommitStateType.EXPIRED) {
|
|
100
|
+
if (swap.state === FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.TXS_SENT) {
|
|
101
|
+
const isAuthorizationExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap);
|
|
102
|
+
if (isAuthorizationExpired) {
|
|
103
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap not committed before authorization expiry, cancelling the LN invoice, invoice: " + swap.pr);
|
|
104
|
+
await this.cancelSwapAndInvoice(swap);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (await swapContract.isExpired(signer.getAddress(), swap.data)) {
|
|
110
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap timed out, refunding to self, invoice: " + swap.pr);
|
|
111
|
+
return "REFUND";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (onchainStatus.type === base_1.SwapCommitStateType.REFUNDABLE) {
|
|
116
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap timed out, refunding to self, invoice: " + swap.pr);
|
|
88
117
|
return "REFUND";
|
|
89
118
|
}
|
|
90
|
-
this.swapLogger.info(swap, "processPastSwap(state=COMMITED): swap timed out, cancelling the LN invoice, invoice: " + swap.pr);
|
|
91
|
-
await this.cancelSwapAndInvoice(swap);
|
|
92
|
-
return null;
|
|
93
119
|
}
|
|
94
120
|
if (swap.state === FromBtcLnAutoSwap_1.FromBtcLnAutoSwapState.CLAIMED)
|
|
95
121
|
return "SETTLE";
|
|
@@ -372,6 +372,7 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
372
372
|
data.executionFeeRate !== swap.executionFeeShare ||
|
|
373
373
|
data.rawAmounts[0] !== swap.rawAmountToken ||
|
|
374
374
|
data.rawAmounts[1] !== swap.rawAmountGasToken ||
|
|
375
|
+
data.getExecutionData() != null ||
|
|
375
376
|
data.getSpentVaultUtxo() !== swap.vaultUtxo ||
|
|
376
377
|
data.btcTx.outs[0].value !== SpvVaults_1.VAULT_DUST_AMOUNT ||
|
|
377
378
|
!Buffer.from(data.btcTx.outs[0].scriptPubKey.hex, "hex").equals(this.bitcoin.toOutputScript(swap.vaultAddress)) ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomiqlabs/lp-lib",
|
|
3
|
-
"version": "14.0.0-dev.
|
|
3
|
+
"version": "14.0.0-dev.13",
|
|
4
4
|
"description": "Main functionality implementation for atomiq LP node",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types:": "./dist/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"author": "adambor",
|
|
23
23
|
"license": "ISC",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@atomiqlabs/base": "^10.0.0-dev.
|
|
25
|
+
"@atomiqlabs/base": "^10.0.0-dev.9",
|
|
26
26
|
"@atomiqlabs/server-base": "2.0.0",
|
|
27
27
|
"@scure/btc-signer": "1.6.0",
|
|
28
28
|
"express": "4.21.1",
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ClaimEvent,
|
|
10
10
|
InitializeEvent,
|
|
11
11
|
RefundEvent,
|
|
12
|
+
SwapCommitStateType,
|
|
12
13
|
SwapData
|
|
13
14
|
} from "@atomiqlabs/base";
|
|
14
15
|
import {expressHandlerWrapper, getAbortController, HEX_REGEX, isDefinedRuntimeError} from "../../../utils/Utils";
|
|
@@ -25,7 +26,7 @@ import {
|
|
|
25
26
|
LightningNetworkChannel,
|
|
26
27
|
LightningNetworkInvoice
|
|
27
28
|
} from "../../../wallets/ILightningWallet";
|
|
28
|
-
import {
|
|
29
|
+
import {LightningAssertions} from "../../assertions/LightningAssertions";
|
|
29
30
|
|
|
30
31
|
export type FromBtcLnConfig = FromBtcBaseConfig & {
|
|
31
32
|
invoiceTimeoutSeconds?: number,
|
|
@@ -103,34 +104,61 @@ export class FromBtcLnAbs extends FromBtcBaseSwapHandler<FromBtcLnSwapAbs, FromB
|
|
|
103
104
|
return null;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
if(swap.state===FromBtcLnSwapState.RECEIVED) {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
if(swap.state===FromBtcLnSwapState.RECEIVED || swap.state===FromBtcLnSwapState.COMMITED) {
|
|
108
|
+
const onchainStatus = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
109
|
+
const state: FromBtcLnSwapState = swap.state as FromBtcLnSwapState;
|
|
110
|
+
if(onchainStatus.type===SwapCommitStateType.PAID) {
|
|
111
|
+
//Extract the swap secret
|
|
112
|
+
if(state!==FromBtcLnSwapState.CLAIMED && state!==FromBtcLnSwapState.SETTLED) {
|
|
113
|
+
const secretHex = await onchainStatus.getClaimResult();
|
|
114
|
+
const secret: Buffer = Buffer.from(secretHex, "hex");
|
|
115
|
+
const paymentHash: Buffer = createHash("sha256").update(secret).digest();
|
|
116
|
+
const paymentHashHex = paymentHash.toString("hex");
|
|
117
|
+
|
|
118
|
+
if (swap.lnPaymentHash!==paymentHashHex) {
|
|
119
|
+
//TODO: Possibly fatal failure
|
|
120
|
+
this.swapLogger.error(swap, "processPastSwap(state=RECEIVED|COMMITED): onchainStatus=PAID, Invalid swap secret specified: "+secretHex+" for paymentHash: "+paymentHashHex);
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
swap.secret = secretHex;
|
|
125
|
+
await swap.setState(FromBtcLnSwapState.CLAIMED);
|
|
126
|
+
await this.saveSwapData(swap);
|
|
127
|
+
|
|
128
|
+
this.swapLogger.warn(swap, "processPastSwap(state=RECEIVED|COMMITED): swap settled (detected from processPastSwap), invoice: "+swap.pr);
|
|
129
|
+
|
|
130
|
+
return "SETTLE";
|
|
115
131
|
}
|
|
116
|
-
|
|
117
|
-
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED): swap committed (detected from processPastSwap), invoice: "+swap.pr);
|
|
118
|
-
await swap.setState(FromBtcLnSwapState.COMMITED);
|
|
119
|
-
await this.saveSwapData(swap);
|
|
132
|
+
return null;
|
|
120
133
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
134
|
+
if(onchainStatus.type===SwapCommitStateType.COMMITED) {
|
|
135
|
+
if(state===FromBtcLnSwapState.RECEIVED) {
|
|
136
|
+
await swap.setState(FromBtcLnSwapState.COMMITED);
|
|
137
|
+
await this.saveSwapData(swap);
|
|
125
138
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap committed (detected from processPastSwap), invoice: "+swap.pr);
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
if(onchainStatus.type===SwapCommitStateType.NOT_COMMITED || onchainStatus.type===SwapCommitStateType.EXPIRED) {
|
|
144
|
+
if(swap.state===FromBtcLnSwapState.RECEIVED) {
|
|
145
|
+
const isAuthorizationExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap);
|
|
146
|
+
if(isAuthorizationExpired) {
|
|
147
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap not committed before authorization expiry, cancelling the LN invoice, invoice: "+swap.pr);
|
|
148
|
+
await swap.setState(FromBtcLnSwapState.CANCELED);
|
|
149
|
+
return "CANCEL";
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
if(await swapContract.isExpired(signer.getAddress(), swap.data)) {
|
|
153
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap timed out, refunding to self, invoice: "+swap.pr);
|
|
154
|
+
return "REFUND";
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if(onchainStatus.type===SwapCommitStateType.REFUNDABLE) {
|
|
159
|
+
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED|COMMITED): swap timed out, refunding to self, invoice: "+swap.pr);
|
|
129
160
|
return "REFUND";
|
|
130
161
|
}
|
|
131
|
-
|
|
132
|
-
this.swapLogger.info(swap, "processPastSwap(state=RECEIVED): swap timed out, cancelling the LN invoice, invoice: "+swap.pr);
|
|
133
|
-
return "CANCEL";
|
|
134
162
|
}
|
|
135
163
|
|
|
136
164
|
if(swap.state===FromBtcLnSwapState.CLAIMED) return "SETTLE";
|
|
@@ -3,7 +3,7 @@ import {createHash} from "crypto";
|
|
|
3
3
|
import {FromBtcLnAutoSwap, FromBtcLnAutoSwapState} from "./FromBtcLnAutoSwap";
|
|
4
4
|
import {MultichainData, SwapHandlerType} from "../../SwapHandler";
|
|
5
5
|
import {ISwapPrice} from "../../../prices/ISwapPrice";
|
|
6
|
-
import {ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapData} from "@atomiqlabs/base";
|
|
6
|
+
import {ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapCommitStateType, SwapData} from "@atomiqlabs/base";
|
|
7
7
|
import {expressHandlerWrapper, getAbortController, HEX_REGEX} from "../../../utils/Utils";
|
|
8
8
|
import {PluginManager} from "../../../plugins/PluginManager";
|
|
9
9
|
import {IIntermediaryStorage} from "../../../storage/IIntermediaryStorage";
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
LightningNetworkInvoice
|
|
20
20
|
} from "../../../wallets/ILightningWallet";
|
|
21
21
|
import {LightningAssertions} from "../../assertions/LightningAssertions";
|
|
22
|
+
import {FromBtcLnSwapState} from "../frombtcln_abstract/FromBtcLnSwapAbs";
|
|
22
23
|
|
|
23
24
|
export type FromBtcLnAutoConfig = FromBtcBaseConfig & {
|
|
24
25
|
invoiceTimeoutSeconds?: number,
|
|
@@ -110,35 +111,61 @@ export class FromBtcLnAuto extends FromBtcBaseSwapHandler<FromBtcLnAutoSwap, Fro
|
|
|
110
111
|
return null;
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
if(swap.state===FromBtcLnAutoSwapState.TXS_SENT) {
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
114
|
+
if(swap.state===FromBtcLnAutoSwapState.TXS_SENT || swap.state===FromBtcLnAutoSwapState.COMMITED) {
|
|
115
|
+
const onchainStatus = await swapContract.getCommitStatus(signer.getAddress(), swap.data);
|
|
116
|
+
const state: FromBtcLnAutoSwapState = swap.state as FromBtcLnAutoSwapState;
|
|
117
|
+
if(onchainStatus.type===SwapCommitStateType.PAID) {
|
|
118
|
+
//Extract the swap secret
|
|
119
|
+
if(state!==FromBtcLnAutoSwapState.CLAIMED && state!==FromBtcLnAutoSwapState.SETTLED) {
|
|
120
|
+
const secretHex = await onchainStatus.getClaimResult();
|
|
121
|
+
const secret: Buffer = Buffer.from(secretHex, "hex");
|
|
122
|
+
const paymentHash: Buffer = createHash("sha256").update(secret).digest();
|
|
123
|
+
const paymentHashHex = paymentHash.toString("hex");
|
|
124
|
+
|
|
125
|
+
if (swap.lnPaymentHash!==paymentHashHex) {
|
|
126
|
+
//TODO: Possibly fatal failure
|
|
127
|
+
this.swapLogger.error(swap, "processPastSwap(state=TXS_SENT|COMMITED): onchainStatus=PAID, Invalid swap secret specified: "+secretHex+" for paymentHash: "+paymentHashHex);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
117
130
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
await this.
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
131
|
+
swap.secret = secretHex;
|
|
132
|
+
await swap.setState(FromBtcLnAutoSwapState.CLAIMED);
|
|
133
|
+
await this.saveSwapData(swap);
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
await swap.setState(FromBtcLnAutoSwapState.COMMITED);
|
|
126
|
-
await this.saveSwapData(swap);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
135
|
+
this.swapLogger.warn(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap settled (detected from processPastSwap), invoice: "+swap.pr);
|
|
129
136
|
|
|
130
|
-
|
|
131
|
-
|
|
137
|
+
return "SETTLE";
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if(onchainStatus.type===SwapCommitStateType.COMMITED) {
|
|
142
|
+
if(state===FromBtcLnAutoSwapState.TXS_SENT) {
|
|
143
|
+
await swap.setState(FromBtcLnAutoSwapState.COMMITED);
|
|
144
|
+
await this.saveSwapData(swap);
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
146
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap committed (detected from processPastSwap), invoice: "+swap.pr);
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
if(onchainStatus.type===SwapCommitStateType.NOT_COMMITED || onchainStatus.type===SwapCommitStateType.EXPIRED) {
|
|
151
|
+
if(swap.state===FromBtcLnAutoSwapState.TXS_SENT) {
|
|
152
|
+
const isAuthorizationExpired = await swapContract.isInitAuthorizationExpired(swap.data, swap);
|
|
153
|
+
if(isAuthorizationExpired) {
|
|
154
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap not committed before authorization expiry, cancelling the LN invoice, invoice: "+swap.pr);
|
|
155
|
+
await this.cancelSwapAndInvoice(swap);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
if(await swapContract.isExpired(signer.getAddress(), swap.data)) {
|
|
160
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap timed out, refunding to self, invoice: "+swap.pr);
|
|
161
|
+
return "REFUND";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if(onchainStatus.type===SwapCommitStateType.REFUNDABLE) {
|
|
166
|
+
this.swapLogger.info(swap, "processPastSwap(state=TXS_SENT|COMMITED): swap timed out, refunding to self, invoice: "+swap.pr);
|
|
136
167
|
return "REFUND";
|
|
137
168
|
}
|
|
138
|
-
|
|
139
|
-
this.swapLogger.info(swap, "processPastSwap(state=COMMITED): swap timed out, cancelling the LN invoice, invoice: "+swap.pr);
|
|
140
|
-
await this.cancelSwapAndInvoice(swap);
|
|
141
|
-
return null;
|
|
142
169
|
}
|
|
143
170
|
|
|
144
171
|
if(swap.state===FromBtcLnAutoSwapState.CLAIMED) return "SETTLE";
|
|
@@ -502,6 +502,7 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
502
502
|
data.executionFeeRate!==swap.executionFeeShare ||
|
|
503
503
|
data.rawAmounts[0]!==swap.rawAmountToken ||
|
|
504
504
|
data.rawAmounts[1]!==swap.rawAmountGasToken ||
|
|
505
|
+
data.getExecutionData()!=null ||
|
|
505
506
|
data.getSpentVaultUtxo()!==swap.vaultUtxo ||
|
|
506
507
|
data.btcTx.outs[0].value!==VAULT_DUST_AMOUNT ||
|
|
507
508
|
!Buffer.from(data.btcTx.outs[0].scriptPubKey.hex, "hex").equals(this.bitcoin.toOutputScript(swap.vaultAddress)) ||
|