@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,192 @@
|
|
|
1
|
+
import {SwapData} from "@atomiqlabs/base";
|
|
2
|
+
import {SwapHandlerType} from "../../../index";
|
|
3
|
+
import {FromBtcBaseSwap} from "../FromBtcBaseSwap";
|
|
4
|
+
import {deserializeBN, serializeBN} from "../../../utils/Utils";
|
|
5
|
+
|
|
6
|
+
export enum FromBtcLnAutoSwapState {
|
|
7
|
+
REFUNDED = -2,
|
|
8
|
+
CANCELED = -1,
|
|
9
|
+
CREATED = 0,
|
|
10
|
+
RECEIVED = 1,
|
|
11
|
+
TXS_SENT = 2,
|
|
12
|
+
COMMITED = 3,
|
|
13
|
+
CLAIMED = 4,
|
|
14
|
+
SETTLED = 5,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class FromBtcLnAutoSwap<T extends SwapData = SwapData> extends FromBtcBaseSwap<T, FromBtcLnAutoSwapState> {
|
|
18
|
+
|
|
19
|
+
readonly pr: string;
|
|
20
|
+
readonly lnPaymentHash: string;
|
|
21
|
+
readonly claimHash: string;
|
|
22
|
+
|
|
23
|
+
readonly claimer: string;
|
|
24
|
+
|
|
25
|
+
readonly token: string;
|
|
26
|
+
readonly gasToken: string;
|
|
27
|
+
readonly amountToken: bigint;
|
|
28
|
+
readonly amountGasToken: bigint;
|
|
29
|
+
|
|
30
|
+
readonly tokenSwapFee: bigint;
|
|
31
|
+
readonly tokenSwapFeeInToken: bigint;
|
|
32
|
+
readonly gasSwapFee: bigint;
|
|
33
|
+
readonly gasSwapFeeInToken: bigint;
|
|
34
|
+
|
|
35
|
+
readonly claimerBounty: bigint;
|
|
36
|
+
|
|
37
|
+
secret: string;
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
chainIdentifier: string,
|
|
41
|
+
pr: string,
|
|
42
|
+
lnPaymentHash: string,
|
|
43
|
+
claimHash: string,
|
|
44
|
+
amountMtokens: bigint,
|
|
45
|
+
|
|
46
|
+
claimer: string,
|
|
47
|
+
token: string,
|
|
48
|
+
gasToken: string,
|
|
49
|
+
amountToken: bigint,
|
|
50
|
+
amountGasToken: bigint,
|
|
51
|
+
|
|
52
|
+
tokenSwapFee: bigint,
|
|
53
|
+
tokenSwapFeeInToken: bigint,
|
|
54
|
+
gasSwapFee: bigint,
|
|
55
|
+
gasSwapFeeInToken: bigint,
|
|
56
|
+
|
|
57
|
+
claimerBounty: bigint
|
|
58
|
+
);
|
|
59
|
+
constructor(obj: any);
|
|
60
|
+
|
|
61
|
+
constructor(
|
|
62
|
+
chainIdOrObj: string | any,
|
|
63
|
+
pr?: string,
|
|
64
|
+
lnPaymentHash?: string,
|
|
65
|
+
claimHash?: string,
|
|
66
|
+
amountMtokens?: bigint,
|
|
67
|
+
|
|
68
|
+
claimer?: string,
|
|
69
|
+
token?: string,
|
|
70
|
+
gasToken?: string,
|
|
71
|
+
amountToken?: bigint,
|
|
72
|
+
amountGasToken?: bigint,
|
|
73
|
+
|
|
74
|
+
tokenSwapFee?: bigint,
|
|
75
|
+
tokenSwapFeeInToken?: bigint,
|
|
76
|
+
gasSwapFee?: bigint,
|
|
77
|
+
gasSwapFeeInToken?: bigint,
|
|
78
|
+
|
|
79
|
+
claimerBounty?: bigint
|
|
80
|
+
) {
|
|
81
|
+
if(typeof(chainIdOrObj)==="string") {
|
|
82
|
+
super(chainIdOrObj, (amountMtokens + 999n) / 1000n, tokenSwapFee + gasSwapFee, tokenSwapFeeInToken);
|
|
83
|
+
this.state = FromBtcLnAutoSwapState.CREATED;
|
|
84
|
+
this.pr = pr;
|
|
85
|
+
this.lnPaymentHash = lnPaymentHash;
|
|
86
|
+
this.claimHash = claimHash;
|
|
87
|
+
this.claimer = claimer;
|
|
88
|
+
this.token = token;
|
|
89
|
+
this.gasToken = gasToken;
|
|
90
|
+
this.amountToken = amountToken;
|
|
91
|
+
this.amountGasToken = amountGasToken;
|
|
92
|
+
this.tokenSwapFee = tokenSwapFee;
|
|
93
|
+
this.tokenSwapFeeInToken = tokenSwapFeeInToken;
|
|
94
|
+
this.gasSwapFee = gasSwapFee;
|
|
95
|
+
this.gasSwapFeeInToken = gasSwapFeeInToken;
|
|
96
|
+
this.claimerBounty = claimerBounty;
|
|
97
|
+
} else {
|
|
98
|
+
super(chainIdOrObj);
|
|
99
|
+
this.pr = chainIdOrObj.pr;
|
|
100
|
+
this.lnPaymentHash = chainIdOrObj.lnPaymentHash;
|
|
101
|
+
this.claimHash = chainIdOrObj.claimHash;
|
|
102
|
+
this.claimer = chainIdOrObj.claimer;
|
|
103
|
+
this.token = chainIdOrObj.token;
|
|
104
|
+
this.gasToken = chainIdOrObj.gasToken;
|
|
105
|
+
this.amountToken = deserializeBN(chainIdOrObj.amountToken);
|
|
106
|
+
this.amountGasToken = deserializeBN(chainIdOrObj.amountGasToken);
|
|
107
|
+
this.tokenSwapFee = deserializeBN(chainIdOrObj.tokenSwapFee);
|
|
108
|
+
this.tokenSwapFeeInToken = deserializeBN(chainIdOrObj.tokenSwapFeeInToken);
|
|
109
|
+
this.gasSwapFee = deserializeBN(chainIdOrObj.gasSwapFee);
|
|
110
|
+
this.gasSwapFeeInToken = deserializeBN(chainIdOrObj.gasSwapFeeInToken);
|
|
111
|
+
this.claimerBounty = deserializeBN(chainIdOrObj.claimerBounty);
|
|
112
|
+
this.secret = chainIdOrObj.secret;
|
|
113
|
+
}
|
|
114
|
+
this.type = SwapHandlerType.FROM_BTCLN;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
serialize(): any {
|
|
118
|
+
const partialSerialized = super.serialize();
|
|
119
|
+
partialSerialized.pr = this.pr;
|
|
120
|
+
partialSerialized.secret = this.secret;
|
|
121
|
+
partialSerialized.lnPaymentHash = this.lnPaymentHash;
|
|
122
|
+
partialSerialized.claimHash = this.claimHash;
|
|
123
|
+
partialSerialized.claimer = this.claimer;
|
|
124
|
+
partialSerialized.token = this.token;
|
|
125
|
+
partialSerialized.gasToken = this.gasToken;
|
|
126
|
+
partialSerialized.amountToken = serializeBN(this.amountToken);
|
|
127
|
+
partialSerialized.amountGasToken = serializeBN(this.amountGasToken);
|
|
128
|
+
partialSerialized.tokenSwapFee = serializeBN(this.tokenSwapFee);
|
|
129
|
+
partialSerialized.tokenSwapFeeInToken = serializeBN(this.tokenSwapFeeInToken);
|
|
130
|
+
partialSerialized.gasSwapFee = serializeBN(this.gasSwapFee);
|
|
131
|
+
partialSerialized.gasSwapFeeInToken = serializeBN(this.gasSwapFeeInToken);
|
|
132
|
+
partialSerialized.claimerBounty = serializeBN(this.claimerBounty);
|
|
133
|
+
return partialSerialized;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
getIdentifierHash(): string {
|
|
137
|
+
return this.lnPaymentHash;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getOutputGasAmount(): bigint {
|
|
141
|
+
return this.amountGasToken;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
getOutputAmount(): bigint {
|
|
145
|
+
return this.amountToken;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
getTotalOutputAmount(): bigint {
|
|
149
|
+
return this.amountToken;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getTotalOutputGasAmount(): bigint {
|
|
153
|
+
return this.amountGasToken + this.claimerBounty;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getSequence(): bigint {
|
|
157
|
+
return 0n;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
getSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
|
|
161
|
+
return {inInputToken: this.swapFee, inOutputToken: this.swapFeeInToken};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getTokenSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
|
|
165
|
+
return {inInputToken: this.tokenSwapFee, inOutputToken: this.tokenSwapFeeInToken};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
getGasSwapFee(): { inInputToken: bigint; inOutputToken: bigint } {
|
|
169
|
+
return {inInputToken: this.gasSwapFee, inOutputToken: this.gasSwapFeeInToken};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getToken(): string {
|
|
173
|
+
return this.token;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
getGasToken(): string {
|
|
177
|
+
return this.gasToken;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
isInitiated(): boolean {
|
|
181
|
+
return this.state!==FromBtcLnAutoSwapState.CREATED;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
isFailed(): boolean {
|
|
185
|
+
return this.state===FromBtcLnAutoSwapState.CANCELED || this.state===FromBtcLnAutoSwapState.REFUNDED;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
isSuccess(): boolean {
|
|
189
|
+
return this.state===FromBtcLnAutoSwapState.SETTLED;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
}
|