@atomiqlabs/lp-lib 14.0.0-dev.6 → 14.0.0-dev.7
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/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugins/IPlugin.d.ts +2 -2
- package/dist/plugins/PluginManager.d.ts +2 -2
- package/dist/swaps/SwapHandler.d.ts +2 -1
- package/dist/swaps/SwapHandler.js +1 -0
- package/dist/swaps/assertions/FromBtcAmountAssertions.d.ts +2 -2
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.d.ts +2 -1
- package/dist/swaps/escrow/FromBtcBaseSwapHandler.js +5 -2
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.d.ts +101 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.js +621 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoInit.d.ts +101 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoInit.js +601 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoInitSwap.d.ts +54 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoInitSwap.js +117 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.d.ts +54 -0
- package/dist/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.js +117 -0
- package/package.json +2 -2
- package/src/index.ts +2 -0
- package/src/plugins/IPlugin.ts +2 -2
- package/src/plugins/PluginManager.ts +2 -2
- package/src/swaps/SwapHandler.ts +2 -1
- package/src/swaps/assertions/FromBtcAmountAssertions.ts +3 -3
- package/src/swaps/escrow/FromBtcBaseSwapHandler.ts +5 -2
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAuto.ts +780 -0
- package/src/swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap.ts +192 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromBtcLnAutoInitSwap = exports.FromBtcLnAutoInitSwapState = void 0;
|
|
4
|
+
const index_1 = require("../../../index");
|
|
5
|
+
const FromBtcBaseSwap_1 = require("../FromBtcBaseSwap");
|
|
6
|
+
const Utils_1 = require("../../../utils/Utils");
|
|
7
|
+
var FromBtcLnAutoInitSwapState;
|
|
8
|
+
(function (FromBtcLnAutoInitSwapState) {
|
|
9
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["REFUNDED"] = -2] = "REFUNDED";
|
|
10
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["CANCELED"] = -1] = "CANCELED";
|
|
11
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["CREATED"] = 0] = "CREATED";
|
|
12
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["RECEIVED"] = 1] = "RECEIVED";
|
|
13
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["TXS_SENT"] = 2] = "TXS_SENT";
|
|
14
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["COMMITED"] = 3] = "COMMITED";
|
|
15
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["CLAIMED"] = 4] = "CLAIMED";
|
|
16
|
+
FromBtcLnAutoInitSwapState[FromBtcLnAutoInitSwapState["SETTLED"] = 5] = "SETTLED";
|
|
17
|
+
})(FromBtcLnAutoInitSwapState = exports.FromBtcLnAutoInitSwapState || (exports.FromBtcLnAutoInitSwapState = {}));
|
|
18
|
+
class FromBtcLnAutoInitSwap extends FromBtcBaseSwap_1.FromBtcBaseSwap {
|
|
19
|
+
constructor(chainIdOrObj, pr, lnPaymentHash, claimHash, amountMtokens, claimer, token, gasToken, amountToken, amountGasToken, tokenSwapFee, tokenSwapFeeInToken, gasSwapFee, gasSwapFeeInToken, claimerBounty) {
|
|
20
|
+
if (typeof (chainIdOrObj) === "string") {
|
|
21
|
+
super(chainIdOrObj, (amountMtokens + 999n) / 1000n, tokenSwapFee + gasSwapFee, tokenSwapFeeInToken);
|
|
22
|
+
this.state = FromBtcLnAutoInitSwapState.CREATED;
|
|
23
|
+
this.pr = pr;
|
|
24
|
+
this.lnPaymentHash = lnPaymentHash;
|
|
25
|
+
this.claimHash = claimHash;
|
|
26
|
+
this.claimer = claimer;
|
|
27
|
+
this.token = token;
|
|
28
|
+
this.gasToken = gasToken;
|
|
29
|
+
this.amountToken = amountToken;
|
|
30
|
+
this.amountGasToken = amountGasToken;
|
|
31
|
+
this.tokenSwapFee = tokenSwapFee;
|
|
32
|
+
this.tokenSwapFeeInToken = tokenSwapFeeInToken;
|
|
33
|
+
this.gasSwapFee = gasSwapFee;
|
|
34
|
+
this.gasSwapFeeInToken = gasSwapFeeInToken;
|
|
35
|
+
this.claimerBounty = claimerBounty;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
super(chainIdOrObj);
|
|
39
|
+
this.pr = chainIdOrObj.pr;
|
|
40
|
+
this.lnPaymentHash = chainIdOrObj.lnPaymentHash;
|
|
41
|
+
this.claimHash = chainIdOrObj.claimHash;
|
|
42
|
+
this.claimer = chainIdOrObj.claimer;
|
|
43
|
+
this.token = chainIdOrObj.token;
|
|
44
|
+
this.gasToken = chainIdOrObj.gasToken;
|
|
45
|
+
this.amountToken = (0, Utils_1.deserializeBN)(chainIdOrObj.amountToken);
|
|
46
|
+
this.amountGasToken = (0, Utils_1.deserializeBN)(chainIdOrObj.amountGasToken);
|
|
47
|
+
this.tokenSwapFee = (0, Utils_1.deserializeBN)(chainIdOrObj.tokenSwapFee);
|
|
48
|
+
this.tokenSwapFeeInToken = (0, Utils_1.deserializeBN)(chainIdOrObj.tokenSwapFeeInToken);
|
|
49
|
+
this.gasSwapFee = (0, Utils_1.deserializeBN)(chainIdOrObj.gasSwapFee);
|
|
50
|
+
this.gasSwapFeeInToken = (0, Utils_1.deserializeBN)(chainIdOrObj.gasSwapFeeInToken);
|
|
51
|
+
this.claimerBounty = (0, Utils_1.deserializeBN)(chainIdOrObj.claimerBounty);
|
|
52
|
+
this.secret = chainIdOrObj.secret;
|
|
53
|
+
}
|
|
54
|
+
this.type = index_1.SwapHandlerType.FROM_BTCLN;
|
|
55
|
+
}
|
|
56
|
+
serialize() {
|
|
57
|
+
const partialSerialized = super.serialize();
|
|
58
|
+
partialSerialized.pr = this.pr;
|
|
59
|
+
partialSerialized.secret = this.secret;
|
|
60
|
+
partialSerialized.lnPaymentHash = this.lnPaymentHash;
|
|
61
|
+
partialSerialized.claimHash = this.claimHash;
|
|
62
|
+
partialSerialized.claimer = this.claimer;
|
|
63
|
+
partialSerialized.token = this.token;
|
|
64
|
+
partialSerialized.gasToken = this.gasToken;
|
|
65
|
+
partialSerialized.amountToken = (0, Utils_1.serializeBN)(this.amountToken);
|
|
66
|
+
partialSerialized.amountGasToken = (0, Utils_1.serializeBN)(this.amountGasToken);
|
|
67
|
+
partialSerialized.tokenSwapFee = (0, Utils_1.serializeBN)(this.tokenSwapFee);
|
|
68
|
+
partialSerialized.tokenSwapFeeInToken = (0, Utils_1.serializeBN)(this.tokenSwapFeeInToken);
|
|
69
|
+
partialSerialized.gasSwapFee = (0, Utils_1.serializeBN)(this.gasSwapFee);
|
|
70
|
+
partialSerialized.gasSwapFeeInToken = (0, Utils_1.serializeBN)(this.gasSwapFeeInToken);
|
|
71
|
+
partialSerialized.claimerBounty = (0, Utils_1.serializeBN)(this.claimerBounty);
|
|
72
|
+
return partialSerialized;
|
|
73
|
+
}
|
|
74
|
+
getIdentifierHash() {
|
|
75
|
+
return this.lnPaymentHash;
|
|
76
|
+
}
|
|
77
|
+
getOutputGasAmount() {
|
|
78
|
+
return this.amountGasToken;
|
|
79
|
+
}
|
|
80
|
+
getOutputAmount() {
|
|
81
|
+
return this.amountToken;
|
|
82
|
+
}
|
|
83
|
+
getTotalOutputAmount() {
|
|
84
|
+
return this.amountToken;
|
|
85
|
+
}
|
|
86
|
+
getTotalOutputGasAmount() {
|
|
87
|
+
return this.amountGasToken + this.claimerBounty;
|
|
88
|
+
}
|
|
89
|
+
getSequence() {
|
|
90
|
+
return 0n;
|
|
91
|
+
}
|
|
92
|
+
getSwapFee() {
|
|
93
|
+
return { inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken };
|
|
94
|
+
}
|
|
95
|
+
getTokenSwapFee() {
|
|
96
|
+
return { inInputToken: this.tokenSwapFee, inOutputToken: this.tokenSwapFeeInToken };
|
|
97
|
+
}
|
|
98
|
+
getGasSwapFee() {
|
|
99
|
+
return { inInputToken: this.gasSwapFee, inOutputToken: this.gasSwapFeeInToken };
|
|
100
|
+
}
|
|
101
|
+
getToken() {
|
|
102
|
+
return this.token;
|
|
103
|
+
}
|
|
104
|
+
getGasToken() {
|
|
105
|
+
return this.gasToken;
|
|
106
|
+
}
|
|
107
|
+
isInitiated() {
|
|
108
|
+
return this.state !== FromBtcLnAutoInitSwapState.CREATED;
|
|
109
|
+
}
|
|
110
|
+
isFailed() {
|
|
111
|
+
return this.state === FromBtcLnAutoInitSwapState.CANCELED || this.state === FromBtcLnAutoInitSwapState.REFUNDED;
|
|
112
|
+
}
|
|
113
|
+
isSuccess() {
|
|
114
|
+
return this.state === FromBtcLnAutoInitSwapState.SETTLED;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.FromBtcLnAutoInitSwap = FromBtcLnAutoInitSwap;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { SwapData } from "@atomiqlabs/base";
|
|
2
|
+
import { FromBtcBaseSwap } from "../FromBtcBaseSwap";
|
|
3
|
+
export declare enum FromBtcLnAutoSwapState {
|
|
4
|
+
REFUNDED = -2,
|
|
5
|
+
CANCELED = -1,
|
|
6
|
+
CREATED = 0,
|
|
7
|
+
RECEIVED = 1,
|
|
8
|
+
TXS_SENT = 2,
|
|
9
|
+
COMMITED = 3,
|
|
10
|
+
CLAIMED = 4,
|
|
11
|
+
SETTLED = 5
|
|
12
|
+
}
|
|
13
|
+
export declare class FromBtcLnAutoSwap<T extends SwapData = SwapData> extends FromBtcBaseSwap<T, FromBtcLnAutoSwapState> {
|
|
14
|
+
readonly pr: string;
|
|
15
|
+
readonly lnPaymentHash: string;
|
|
16
|
+
readonly claimHash: string;
|
|
17
|
+
readonly claimer: string;
|
|
18
|
+
readonly token: string;
|
|
19
|
+
readonly gasToken: string;
|
|
20
|
+
readonly amountToken: bigint;
|
|
21
|
+
readonly amountGasToken: bigint;
|
|
22
|
+
readonly tokenSwapFee: bigint;
|
|
23
|
+
readonly tokenSwapFeeInToken: bigint;
|
|
24
|
+
readonly gasSwapFee: bigint;
|
|
25
|
+
readonly gasSwapFeeInToken: bigint;
|
|
26
|
+
readonly claimerBounty: bigint;
|
|
27
|
+
secret: string;
|
|
28
|
+
constructor(chainIdentifier: string, pr: string, lnPaymentHash: string, claimHash: string, amountMtokens: bigint, claimer: string, token: string, gasToken: string, amountToken: bigint, amountGasToken: bigint, tokenSwapFee: bigint, tokenSwapFeeInToken: bigint, gasSwapFee: bigint, gasSwapFeeInToken: bigint, claimerBounty: bigint);
|
|
29
|
+
constructor(obj: any);
|
|
30
|
+
serialize(): any;
|
|
31
|
+
getIdentifierHash(): string;
|
|
32
|
+
getOutputGasAmount(): bigint;
|
|
33
|
+
getOutputAmount(): bigint;
|
|
34
|
+
getTotalOutputAmount(): bigint;
|
|
35
|
+
getTotalOutputGasAmount(): bigint;
|
|
36
|
+
getSequence(): bigint;
|
|
37
|
+
getSwapFee(): {
|
|
38
|
+
inInputToken: bigint;
|
|
39
|
+
inOutputToken: bigint;
|
|
40
|
+
};
|
|
41
|
+
getTokenSwapFee(): {
|
|
42
|
+
inInputToken: bigint;
|
|
43
|
+
inOutputToken: bigint;
|
|
44
|
+
};
|
|
45
|
+
getGasSwapFee(): {
|
|
46
|
+
inInputToken: bigint;
|
|
47
|
+
inOutputToken: bigint;
|
|
48
|
+
};
|
|
49
|
+
getToken(): string;
|
|
50
|
+
getGasToken(): string;
|
|
51
|
+
isInitiated(): boolean;
|
|
52
|
+
isFailed(): boolean;
|
|
53
|
+
isSuccess(): boolean;
|
|
54
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FromBtcLnAutoSwap = exports.FromBtcLnAutoSwapState = void 0;
|
|
4
|
+
const index_1 = require("../../../index");
|
|
5
|
+
const FromBtcBaseSwap_1 = require("../FromBtcBaseSwap");
|
|
6
|
+
const Utils_1 = require("../../../utils/Utils");
|
|
7
|
+
var FromBtcLnAutoSwapState;
|
|
8
|
+
(function (FromBtcLnAutoSwapState) {
|
|
9
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["REFUNDED"] = -2] = "REFUNDED";
|
|
10
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["CANCELED"] = -1] = "CANCELED";
|
|
11
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["CREATED"] = 0] = "CREATED";
|
|
12
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["RECEIVED"] = 1] = "RECEIVED";
|
|
13
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["TXS_SENT"] = 2] = "TXS_SENT";
|
|
14
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["COMMITED"] = 3] = "COMMITED";
|
|
15
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["CLAIMED"] = 4] = "CLAIMED";
|
|
16
|
+
FromBtcLnAutoSwapState[FromBtcLnAutoSwapState["SETTLED"] = 5] = "SETTLED";
|
|
17
|
+
})(FromBtcLnAutoSwapState = exports.FromBtcLnAutoSwapState || (exports.FromBtcLnAutoSwapState = {}));
|
|
18
|
+
class FromBtcLnAutoSwap extends FromBtcBaseSwap_1.FromBtcBaseSwap {
|
|
19
|
+
constructor(chainIdOrObj, pr, lnPaymentHash, claimHash, amountMtokens, claimer, token, gasToken, amountToken, amountGasToken, tokenSwapFee, tokenSwapFeeInToken, gasSwapFee, gasSwapFeeInToken, claimerBounty) {
|
|
20
|
+
if (typeof (chainIdOrObj) === "string") {
|
|
21
|
+
super(chainIdOrObj, (amountMtokens + 999n) / 1000n, tokenSwapFee + gasSwapFee, tokenSwapFeeInToken);
|
|
22
|
+
this.state = FromBtcLnAutoSwapState.CREATED;
|
|
23
|
+
this.pr = pr;
|
|
24
|
+
this.lnPaymentHash = lnPaymentHash;
|
|
25
|
+
this.claimHash = claimHash;
|
|
26
|
+
this.claimer = claimer;
|
|
27
|
+
this.token = token;
|
|
28
|
+
this.gasToken = gasToken;
|
|
29
|
+
this.amountToken = amountToken;
|
|
30
|
+
this.amountGasToken = amountGasToken;
|
|
31
|
+
this.tokenSwapFee = tokenSwapFee;
|
|
32
|
+
this.tokenSwapFeeInToken = tokenSwapFeeInToken;
|
|
33
|
+
this.gasSwapFee = gasSwapFee;
|
|
34
|
+
this.gasSwapFeeInToken = gasSwapFeeInToken;
|
|
35
|
+
this.claimerBounty = claimerBounty;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
super(chainIdOrObj);
|
|
39
|
+
this.pr = chainIdOrObj.pr;
|
|
40
|
+
this.lnPaymentHash = chainIdOrObj.lnPaymentHash;
|
|
41
|
+
this.claimHash = chainIdOrObj.claimHash;
|
|
42
|
+
this.claimer = chainIdOrObj.claimer;
|
|
43
|
+
this.token = chainIdOrObj.token;
|
|
44
|
+
this.gasToken = chainIdOrObj.gasToken;
|
|
45
|
+
this.amountToken = (0, Utils_1.deserializeBN)(chainIdOrObj.amountToken);
|
|
46
|
+
this.amountGasToken = (0, Utils_1.deserializeBN)(chainIdOrObj.amountGasToken);
|
|
47
|
+
this.tokenSwapFee = (0, Utils_1.deserializeBN)(chainIdOrObj.tokenSwapFee);
|
|
48
|
+
this.tokenSwapFeeInToken = (0, Utils_1.deserializeBN)(chainIdOrObj.tokenSwapFeeInToken);
|
|
49
|
+
this.gasSwapFee = (0, Utils_1.deserializeBN)(chainIdOrObj.gasSwapFee);
|
|
50
|
+
this.gasSwapFeeInToken = (0, Utils_1.deserializeBN)(chainIdOrObj.gasSwapFeeInToken);
|
|
51
|
+
this.claimerBounty = (0, Utils_1.deserializeBN)(chainIdOrObj.claimerBounty);
|
|
52
|
+
this.secret = chainIdOrObj.secret;
|
|
53
|
+
}
|
|
54
|
+
this.type = index_1.SwapHandlerType.FROM_BTCLN;
|
|
55
|
+
}
|
|
56
|
+
serialize() {
|
|
57
|
+
const partialSerialized = super.serialize();
|
|
58
|
+
partialSerialized.pr = this.pr;
|
|
59
|
+
partialSerialized.secret = this.secret;
|
|
60
|
+
partialSerialized.lnPaymentHash = this.lnPaymentHash;
|
|
61
|
+
partialSerialized.claimHash = this.claimHash;
|
|
62
|
+
partialSerialized.claimer = this.claimer;
|
|
63
|
+
partialSerialized.token = this.token;
|
|
64
|
+
partialSerialized.gasToken = this.gasToken;
|
|
65
|
+
partialSerialized.amountToken = (0, Utils_1.serializeBN)(this.amountToken);
|
|
66
|
+
partialSerialized.amountGasToken = (0, Utils_1.serializeBN)(this.amountGasToken);
|
|
67
|
+
partialSerialized.tokenSwapFee = (0, Utils_1.serializeBN)(this.tokenSwapFee);
|
|
68
|
+
partialSerialized.tokenSwapFeeInToken = (0, Utils_1.serializeBN)(this.tokenSwapFeeInToken);
|
|
69
|
+
partialSerialized.gasSwapFee = (0, Utils_1.serializeBN)(this.gasSwapFee);
|
|
70
|
+
partialSerialized.gasSwapFeeInToken = (0, Utils_1.serializeBN)(this.gasSwapFeeInToken);
|
|
71
|
+
partialSerialized.claimerBounty = (0, Utils_1.serializeBN)(this.claimerBounty);
|
|
72
|
+
return partialSerialized;
|
|
73
|
+
}
|
|
74
|
+
getIdentifierHash() {
|
|
75
|
+
return this.lnPaymentHash;
|
|
76
|
+
}
|
|
77
|
+
getOutputGasAmount() {
|
|
78
|
+
return this.amountGasToken;
|
|
79
|
+
}
|
|
80
|
+
getOutputAmount() {
|
|
81
|
+
return this.amountToken;
|
|
82
|
+
}
|
|
83
|
+
getTotalOutputAmount() {
|
|
84
|
+
return this.amountToken;
|
|
85
|
+
}
|
|
86
|
+
getTotalOutputGasAmount() {
|
|
87
|
+
return this.amountGasToken + this.claimerBounty;
|
|
88
|
+
}
|
|
89
|
+
getSequence() {
|
|
90
|
+
return 0n;
|
|
91
|
+
}
|
|
92
|
+
getSwapFee() {
|
|
93
|
+
return { inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken };
|
|
94
|
+
}
|
|
95
|
+
getTokenSwapFee() {
|
|
96
|
+
return { inInputToken: this.tokenSwapFee, inOutputToken: this.tokenSwapFeeInToken };
|
|
97
|
+
}
|
|
98
|
+
getGasSwapFee() {
|
|
99
|
+
return { inInputToken: this.gasSwapFee, inOutputToken: this.gasSwapFeeInToken };
|
|
100
|
+
}
|
|
101
|
+
getToken() {
|
|
102
|
+
return this.token;
|
|
103
|
+
}
|
|
104
|
+
getGasToken() {
|
|
105
|
+
return this.gasToken;
|
|
106
|
+
}
|
|
107
|
+
isInitiated() {
|
|
108
|
+
return this.state !== FromBtcLnAutoSwapState.CREATED;
|
|
109
|
+
}
|
|
110
|
+
isFailed() {
|
|
111
|
+
return this.state === FromBtcLnAutoSwapState.CANCELED || this.state === FromBtcLnAutoSwapState.REFUNDED;
|
|
112
|
+
}
|
|
113
|
+
isSuccess() {
|
|
114
|
+
return this.state === FromBtcLnAutoSwapState.SETTLED;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.FromBtcLnAutoSwap = FromBtcLnAutoSwap;
|
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.7",
|
|
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.7",
|
|
26
26
|
"@atomiqlabs/server-base": "2.0.0",
|
|
27
27
|
"@scure/btc-signer": "1.6.0",
|
|
28
28
|
"express": "4.21.1",
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,8 @@ export * from "./swaps/escrow/frombtc_abstract/FromBtcAbs";
|
|
|
13
13
|
export * from "./swaps/escrow/frombtc_abstract/FromBtcSwapAbs";
|
|
14
14
|
export * from "./swaps/escrow/frombtcln_abstract/FromBtcLnAbs";
|
|
15
15
|
export * from "./swaps/escrow/frombtcln_abstract/FromBtcLnSwapAbs";
|
|
16
|
+
export * from "./swaps/escrow/frombtcln_autoinit/FromBtcLnAuto";
|
|
17
|
+
export * from "./swaps/escrow/frombtcln_autoinit/FromBtcLnAutoSwap";
|
|
16
18
|
export * from "./swaps/escrow/tobtc_abstract/ToBtcAbs";
|
|
17
19
|
export * from "./swaps/escrow/tobtc_abstract/ToBtcSwapAbs";
|
|
18
20
|
export * from "./swaps/escrow/tobtcln_abstract/ToBtcLnAbs";
|
package/src/plugins/IPlugin.ts
CHANGED
|
@@ -116,7 +116,7 @@ export interface IPlugin {
|
|
|
116
116
|
onSwapRemove?(swap: SwapHandlerSwap): Promise<void>;
|
|
117
117
|
|
|
118
118
|
onHandlePreFromBtcQuote?(
|
|
119
|
-
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV,
|
|
119
|
+
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO,
|
|
120
120
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>,
|
|
121
121
|
requestedAmount: {input: boolean, amount: bigint, token: string},
|
|
122
122
|
chainIdentifier: string,
|
|
@@ -125,7 +125,7 @@ export interface IPlugin {
|
|
|
125
125
|
gasTokenAmount?: {input: false, amount: bigint, token: string}
|
|
126
126
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
127
127
|
onHandlePostFromBtcQuote?(
|
|
128
|
-
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV,
|
|
128
|
+
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO,
|
|
129
129
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>,
|
|
130
130
|
requestedAmount: {input: boolean, amount: bigint, token: string, pricePrefetch?: Promise<bigint>},
|
|
131
131
|
chainIdentifier: string,
|
|
@@ -167,7 +167,7 @@ export class PluginManager {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
static async onHandlePostFromBtcQuote(
|
|
170
|
-
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV,
|
|
170
|
+
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO,
|
|
171
171
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>,
|
|
172
172
|
requestedAmount: {input: boolean, amount: bigint, token: string, pricePrefetch?: Promise<bigint>},
|
|
173
173
|
chainIdentifier: string,
|
|
@@ -198,7 +198,7 @@ export class PluginManager {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
static async onHandlePreFromBtcQuote(
|
|
201
|
-
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV,
|
|
201
|
+
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO,
|
|
202
202
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>,
|
|
203
203
|
requestedAmount: {input: boolean, amount: bigint, token: string},
|
|
204
204
|
chainIdentifier: string,
|
package/src/swaps/SwapHandler.ts
CHANGED
|
@@ -17,7 +17,8 @@ export enum SwapHandlerType {
|
|
|
17
17
|
FROM_BTCLN = "FROM_BTCLN",
|
|
18
18
|
FROM_BTCLN_TRUSTED = "FROM_BTCLN_TRUSTED",
|
|
19
19
|
FROM_BTC_TRUSTED = "FROM_BTC_TRUSTED",
|
|
20
|
-
FROM_BTC_SPV = "FROM_BTC_SPV"
|
|
20
|
+
FROM_BTC_SPV = "FROM_BTC_SPV",
|
|
21
|
+
FROM_BTCLN_AUTO = "FROM_BTCLN_AUTO"
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export type SwapHandlerInfoType = {
|
|
@@ -3,7 +3,7 @@ import {FromBtcRequestType} from "../escrow/frombtc_abstract/FromBtcAbs";
|
|
|
3
3
|
import {FromBtcLnTrustedRequestType} from "../trusted/frombtcln_trusted/FromBtcLnTrusted";
|
|
4
4
|
import {PluginManager} from "../../plugins/PluginManager";
|
|
5
5
|
import {isPluginQuote, isQuoteSetFees} from "../../plugins/IPlugin";
|
|
6
|
-
import {RequestData, SwapHandlerType} from "../SwapHandler";
|
|
6
|
+
import {RequestData, SwapHandler, SwapHandlerType} from "../SwapHandler";
|
|
7
7
|
import {AmountAssertions, AmountAssertionsConfig} from "./AmountAssertions";
|
|
8
8
|
import {ISwapPrice} from "../../prices/ISwapPrice";
|
|
9
9
|
import {FromBtcTrustedRequestType} from "../trusted/frombtc_trusted/FromBtcTrusted";
|
|
@@ -32,7 +32,7 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
32
32
|
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
33
33
|
*/
|
|
34
34
|
async preCheckFromBtcAmounts(
|
|
35
|
-
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV,
|
|
35
|
+
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO,
|
|
36
36
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>,
|
|
37
37
|
requestedAmount: {input: boolean, amount: bigint, token: string},
|
|
38
38
|
gasAmount?: {input: false, amount: bigint, token: string}
|
|
@@ -94,7 +94,7 @@ export class FromBtcAmountAssertions extends AmountAssertions {
|
|
|
94
94
|
* @throws {DefinedRuntimeError} will throw an error if the amount is outside minimum/maximum bounds
|
|
95
95
|
*/
|
|
96
96
|
async checkFromBtcAmount(
|
|
97
|
-
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV,
|
|
97
|
+
swapType: SwapHandlerType.FROM_BTCLN | SwapHandlerType.FROM_BTC | SwapHandlerType.FROM_BTCLN_TRUSTED | SwapHandlerType.FROM_BTC_TRUSTED | SwapHandlerType.FROM_BTC_SPV | SwapHandlerType.FROM_BTCLN_AUTO,
|
|
98
98
|
request: RequestData<FromBtcLnRequestType | FromBtcRequestType | FromBtcLnTrustedRequestType | FromBtcTrustedRequestType | SpvVaultSwapRequestType>,
|
|
99
99
|
requestedAmount: {input: boolean, amount: bigint, token: string, pricePrefetch?: Promise<bigint>},
|
|
100
100
|
fees: {baseFee: bigint, feePPM: bigint},
|
|
@@ -116,11 +116,12 @@ export abstract class FromBtcBaseSwapHandler<V extends FromBtcBaseSwap<SwapData,
|
|
|
116
116
|
* @param chainIdentifier
|
|
117
117
|
* @param useToken
|
|
118
118
|
* @param abortController
|
|
119
|
+
* @param inContract
|
|
119
120
|
*/
|
|
120
|
-
protected async getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController): Promise<bigint> {
|
|
121
|
+
protected async getBalancePrefetch(chainIdentifier: string, useToken: string, abortController: AbortController, inContract: boolean = true): Promise<bigint> {
|
|
121
122
|
const {swapContract, signer} = this.getChain(chainIdentifier);
|
|
122
123
|
try {
|
|
123
|
-
return await swapContract.getBalance(signer.getAddress(), useToken,
|
|
124
|
+
return await swapContract.getBalance(signer.getAddress(), useToken, inContract);
|
|
124
125
|
} catch (e) {
|
|
125
126
|
this.logger.error("getBalancePrefetch(): balancePrefetch error: ", e);
|
|
126
127
|
abortController.abort(e);
|
|
@@ -137,6 +138,8 @@ export abstract class FromBtcBaseSwapHandler<V extends FromBtcBaseSwap<SwapData,
|
|
|
137
138
|
* @throws {DefinedRuntimeError} will throw an error if there are not enough funds in the vault
|
|
138
139
|
*/
|
|
139
140
|
protected async checkBalance(totalInToken: bigint, balancePrefetch: Promise<bigint>, signal: AbortSignal | null): Promise<void> {
|
|
141
|
+
if(totalInToken===0n) return;
|
|
142
|
+
|
|
140
143
|
const balance = await balancePrefetch;
|
|
141
144
|
if(signal!=null) signal.throwIfAborted();
|
|
142
145
|
|