@teleportdao/bitcoin 2.2.5 → 2.2.8-beta.0
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/bitcoin-wallet-base copy.d.ts +122 -0
- package/dist/bitcoin-wallet-base copy.d.ts.map +1 -0
- package/dist/bitcoin-wallet-base copy.js +279 -0
- package/dist/bitcoin-wallet-base copy.js.map +1 -0
- package/dist/multisig-coordinator-wallet.d.ts +2 -0
- package/dist/multisig-coordinator-wallet.d.ts.map +1 -0
- package/dist/multisig-coordinator-wallet.js +6 -0
- package/dist/multisig-coordinator-wallet.js.map +1 -0
- package/dist/multisig-wallet-helper.d.ts +40 -0
- package/dist/multisig-wallet-helper.d.ts.map +1 -0
- package/dist/multisig-wallet-helper.js +190 -0
- package/dist/multisig-wallet-helper.js.map +1 -0
- package/dist/multisig-wallet.d.ts +20 -0
- package/dist/multisig-wallet.d.ts.map +1 -0
- package/dist/multisig-wallet.js +119 -0
- package/dist/multisig-wallet.js.map +1 -0
- package/dist/teleswap-wallet.d.ts +2 -2
- package/dist/teleswap-wallet.d.ts.map +1 -1
- package/dist/teleswap-wallet.js +6 -4
- package/dist/teleswap-wallet.js.map +1 -1
- package/dist/transaction-builder/coin-select.d.ts +87 -0
- package/dist/transaction-builder/coin-select.d.ts.map +1 -0
- package/dist/transaction-builder/coin-select.js +359 -0
- package/dist/transaction-builder/coin-select.js.map +1 -0
- package/dist/transaction-builder/transaction-builder.d.ts +5 -2
- package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder/transaction-builder.js +5 -3
- package/dist/transaction-builder/transaction-builder.js.map +1 -1
- package/package.json +2 -2
- package/src/teleswap-wallet.ts +6 -1
- package/src/transaction-builder/transaction-builder.ts +7 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MultisigWalletHelper = void 0;
|
|
16
|
+
const providers_1 = require("@teleportdao/providers");
|
|
17
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
18
|
+
class MultisigWalletHelper {
|
|
19
|
+
constructor(baseWallet, coordinatorUrl, coordinatorApiKey, txCounterMonitor = true, acceptableFeeDiffPercentage, txCheckConfig) {
|
|
20
|
+
this.baseWallet = baseWallet;
|
|
21
|
+
this.coordinator = new providers_1.TeleportdaoMultisigCoordinator(coordinatorUrl, coordinatorApiKey);
|
|
22
|
+
this.acceptableFeeDiff = acceptableFeeDiffPercentage || 30;
|
|
23
|
+
this.txCheckConfig = txCheckConfig || {
|
|
24
|
+
sleepTime: 1500,
|
|
25
|
+
maxRetry: 30,
|
|
26
|
+
};
|
|
27
|
+
this.txCounterMonitor = txCounterMonitor;
|
|
28
|
+
this.txCounter = undefined;
|
|
29
|
+
}
|
|
30
|
+
get bitcoinAddress() {
|
|
31
|
+
return this.baseWallet.bitcoinAddress;
|
|
32
|
+
}
|
|
33
|
+
setAccountType(addressType, publicKeys, numberOfSigners) {
|
|
34
|
+
if (!this.baseWallet.publicKey ||
|
|
35
|
+
!publicKeys.includes(this.baseWallet.publicKey.toString("hex"))) {
|
|
36
|
+
throw new Error("public keys not match with the key");
|
|
37
|
+
}
|
|
38
|
+
return this.baseWallet.setAccountType(addressType, {
|
|
39
|
+
publicKeys,
|
|
40
|
+
numberOfSigners,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
setTxCounter(txCounter) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (this.txCounterMonitor)
|
|
46
|
+
this.txCounter = txCounter;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
resetTxCounter() {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const wallet = yield this.coordinator.getWallet();
|
|
52
|
+
this.setTxCounter(wallet.txCounter);
|
|
53
|
+
return wallet.txCounter;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
step1SendBTCToMultipleAddressUnsigned(receivers, signerInfo, fee = "normal", staticExtendedUtxo, fullAmount = false) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
try {
|
|
59
|
+
let unsignedTx = yield this.baseWallet.sendBTCToMultipleAddressUnsignedTx(receivers, signerInfo, fee, staticExtendedUtxo, fullAmount);
|
|
60
|
+
console.log("this.txCounter step 1 start", this.txCounter);
|
|
61
|
+
let txRequest = yield this.coordinator.createOrConfirmNewTx({
|
|
62
|
+
inputs: unsignedTx.inputs.map((x) => ({
|
|
63
|
+
hash: x.hash,
|
|
64
|
+
index: x.index,
|
|
65
|
+
value: x.value,
|
|
66
|
+
})),
|
|
67
|
+
outputs: unsignedTx.outputs,
|
|
68
|
+
feeRate: unsignedTx.feeRate,
|
|
69
|
+
unsignedPsbt: unsignedTx.unsignedTransaction,
|
|
70
|
+
txCounter: this.txCounter,
|
|
71
|
+
});
|
|
72
|
+
if (txRequest.status !== "Rejected" && txRequest.status !== "Broadcasted") {
|
|
73
|
+
this.setTxCounter(txRequest.txCounter);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
yield this.resetTxCounter();
|
|
77
|
+
}
|
|
78
|
+
console.log("this.txCounter step 1 end", this.txCounter);
|
|
79
|
+
return {
|
|
80
|
+
txRequest,
|
|
81
|
+
unsignedTx,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
yield this.resetTxCounter();
|
|
86
|
+
throw e;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
step2WaitForUnsignedTxApproval(input) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const feeRateDiffPercentage = this.acceptableFeeDiff;
|
|
93
|
+
let newUnsignedTx = input.unsignedTx;
|
|
94
|
+
let newTxRequest = input.txRequest;
|
|
95
|
+
if (newTxRequest.status === "Pending") {
|
|
96
|
+
this.setTxCounter(newTxRequest.txCounter);
|
|
97
|
+
if (newTxRequest.unsignedPsbt !== newUnsignedTx.unsignedTransaction) {
|
|
98
|
+
const feeDiff = (0, bignumber_js_1.default)(newTxRequest.feeRate)
|
|
99
|
+
.minus(newUnsignedTx.feeRate)
|
|
100
|
+
.abs()
|
|
101
|
+
.dividedBy(newUnsignedTx.feeRate);
|
|
102
|
+
if (!feeDiff.isLessThan(feeRateDiffPercentage / 100)) {
|
|
103
|
+
const txRequest = yield this.coordinator.rejectTxRequest(newTxRequest.id);
|
|
104
|
+
this.setTxCounter((this.txCounter || txRequest.txCounter) + 1);
|
|
105
|
+
throw new Error("Reject because of Invalid FeeRate");
|
|
106
|
+
}
|
|
107
|
+
const { signerInfo } = newUnsignedTx.inputs[0];
|
|
108
|
+
console.log(newUnsignedTx.outputs, newTxRequest.outputs);
|
|
109
|
+
newUnsignedTx = yield this.baseWallet.sendBTCToMultipleAddressUnsignedTx(newUnsignedTx.outputs, signerInfo, +newTxRequest.feeRate, newTxRequest.inputs.map((x) => (Object.assign(Object.assign({}, x), { signerInfo }))));
|
|
110
|
+
let updatedTxRequest = yield this.coordinator.confirmOrRejectTxRequest(newTxRequest.id, newUnsignedTx.unsignedTransaction);
|
|
111
|
+
if (updatedTxRequest.status === "Rejected" ||
|
|
112
|
+
updatedTxRequest.unsignedPsbt !== newUnsignedTx.unsignedTransaction) {
|
|
113
|
+
console.log("not equal unsignedPsbt");
|
|
114
|
+
console.log(updatedTxRequest.unsignedPsbt);
|
|
115
|
+
console.log(newUnsignedTx.unsignedTransaction);
|
|
116
|
+
this.setTxCounter((this.txCounter || updatedTxRequest.txCounter) + 1);
|
|
117
|
+
throw new Error("Reject because of invalid outputs");
|
|
118
|
+
}
|
|
119
|
+
newTxRequest = updatedTxRequest;
|
|
120
|
+
}
|
|
121
|
+
const updatedTxRequest = yield this.coordinator.waitTxStatusChange(newTxRequest.id, "Pending", this.txCheckConfig.sleepTime, this.txCheckConfig.maxRetry);
|
|
122
|
+
if (!updatedTxRequest) {
|
|
123
|
+
yield this.coordinator.rejectTxRequest(newTxRequest.id);
|
|
124
|
+
if (this.txCounter)
|
|
125
|
+
this.setTxCounter(this.txCounter + 1);
|
|
126
|
+
throw new Error("Tx Timeout");
|
|
127
|
+
}
|
|
128
|
+
newTxRequest = updatedTxRequest;
|
|
129
|
+
if (newTxRequest.status === "Rejected") {
|
|
130
|
+
if (this.txCounter)
|
|
131
|
+
this.setTxCounter(this.txCounter + 1);
|
|
132
|
+
throw new Error("Tx Rejected");
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (newTxRequest.status === "Rejected") {
|
|
136
|
+
yield this.resetTxCounter();
|
|
137
|
+
throw new Error("Tx was Rejected");
|
|
138
|
+
}
|
|
139
|
+
console.log("this.txCounter step 2 end", this.txCounter);
|
|
140
|
+
return {
|
|
141
|
+
unsignedTx: newUnsignedTx,
|
|
142
|
+
txRequest: newTxRequest,
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
step3SignTxAndWaitForBroadcast(input) {
|
|
147
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
+
if (!this.baseWallet.privateKey)
|
|
149
|
+
throw new Error("account is not initialized");
|
|
150
|
+
const { unsignedTx, txRequest } = input;
|
|
151
|
+
let newTxRequest = txRequest;
|
|
152
|
+
if (newTxRequest.status === "Approved") {
|
|
153
|
+
const signed = yield this.baseWallet.signer.signPsbt(unsignedTx, this.baseWallet.privateKey);
|
|
154
|
+
newTxRequest = yield this.coordinator.submitSignedPsbt(newTxRequest.id, signed);
|
|
155
|
+
}
|
|
156
|
+
if (newTxRequest.status === "Approved") {
|
|
157
|
+
if (this.txCounter)
|
|
158
|
+
this.setTxCounter(newTxRequest.txCounter);
|
|
159
|
+
const finalTx = yield this.coordinator.waitTxStatusChange(newTxRequest.id, "Approved", this.txCheckConfig.sleepTime, this.txCheckConfig.maxRetry);
|
|
160
|
+
if (!finalTx || finalTx.status === "Failed") {
|
|
161
|
+
throw new Error("Tx not broadcasted for long time");
|
|
162
|
+
}
|
|
163
|
+
newTxRequest = finalTx;
|
|
164
|
+
}
|
|
165
|
+
if (this.txCounter)
|
|
166
|
+
this.setTxCounter(this.txCounter + 1);
|
|
167
|
+
console.log("this.txCounter step3", this.txCounter);
|
|
168
|
+
return newTxRequest;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
sendBTCMultipleAddress(receivers, fee = "normal", staticExtendedUtxo, fullAmount = false) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
if (!this.baseWallet.signerInfo || !this.baseWallet.privateKey) {
|
|
174
|
+
throw new Error("account not initialized");
|
|
175
|
+
}
|
|
176
|
+
let unsignedResponse = yield this.step1SendBTCToMultipleAddressUnsigned(receivers, this.baseWallet.signerInfo, fee, staticExtendedUtxo, fullAmount);
|
|
177
|
+
unsignedResponse = yield this.step2WaitForUnsignedTxApproval(unsignedResponse);
|
|
178
|
+
const txRequest = yield this.step3SignTxAndWaitForBroadcast(unsignedResponse);
|
|
179
|
+
return txRequest;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
sendBTC(receiverAddress, amountInSatoshi, fee = "normal", staticExtendedUtxo) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
const txRequest = yield this.sendBTCMultipleAddress([{ address: receiverAddress, value: amountInSatoshi === "all" ? 0 : amountInSatoshi }], fee, staticExtendedUtxo, amountInSatoshi === "all");
|
|
185
|
+
return txRequest;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.MultisigWalletHelper = MultisigWalletHelper;
|
|
190
|
+
//# sourceMappingURL=multisig-wallet-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multisig-wallet-helper.js","sourceRoot":"","sources":["../src/multisig-wallet-helper.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAkF;AAClF,gEAAoC;AASpC,MAAa,oBAAoB;IAO/B,YACE,UAA6B,EAC7B,cAAsB,EACtB,iBAAyB,EACzB,gBAAgB,GAAG,IAAI,EACvB,2BAAoC,EACpC,aAAuD;QAEvD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,0CAA8B,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAA;QACxF,IAAI,CAAC,iBAAiB,GAAG,2BAA2B,IAAI,EAAE,CAAA;QAC1D,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI;YACpC,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,EAAE;SACb,CAAA;QACD,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC,cAAc,CAAA;IACvC,CAAC;IAED,cAAc,CACZ,WAA4C,EAC5C,UAAoB,EACpB,eAAwB;QAExB,IACE,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS;YAC1B,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CA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AAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;aAC3C;YAED,IAAI,gBAAgB,GAAG,MAAM,IAAI,CAAC,qCAAqC,CACrE,SAAS,EACT,IAAI,CAAC,UAAU,CAAC,UAAU,EAC1B,GAAG,EACH,kBAAkB,EAClB,UAAU,CACX,CAAA;YACD,gBAAgB,GAAG,MAAM,IAAI,CAAC,8BAA8B,CAAC,gBAAgB,CAAC,CAAA;YAC9E,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,8BAA8B,CAAC,gBAAgB,CAAC,CAAA;YAC7E,OAAO,SAAS,CAAA;QAClB,CAAC;KAAA;IAEK,OAAO,CACX,eAAuB,EACvB,eAA+B,EAC/B,MAAmB,QAAQ,EAC3B,kBAAmC;;YAEnC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,sBAAsB,CACjD,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,eAAe,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC,EACtF,GAAG,EACH,kBAAkB,EAClB,eAAe,KAAK,KAAK,CAC1B,CAAA;YACD,OAAO,SAAS,CAAA;QAClB,CAAC;KAAA;CACF;AAvQD,oDAuQC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TeleportdaoMultisigCoordinator, TxRequest } from "@teleportdao/providers";
|
|
2
|
+
import { BitcoinBaseWallet, FeeRateType } from "./bitcoin-wallet-base";
|
|
3
|
+
import { ExtendedUnsignedTransaction, ExtendedUtxo, SignerInfo, TargetAddress } from "./transaction-builder";
|
|
4
|
+
export declare class MultisigWalletHelper {
|
|
5
|
+
baseWallet: BitcoinBaseWallet;
|
|
6
|
+
coordinator: TeleportdaoMultisigCoordinator;
|
|
7
|
+
constructor(baseWallet: BitcoinBaseWallet, coordinatorApiKey: string, coordinatorUrl: string);
|
|
8
|
+
step1SendBTCToMultipleAddressUnsigned(receivers: TargetAddress[], signerInfo: SignerInfo, fee?: FeeRateType, staticExtendedUtxo?: ExtendedUtxo[], fullAmount?: boolean): Promise<{
|
|
9
|
+
txRequest: TxRequest;
|
|
10
|
+
unsignedTx: ExtendedUnsignedTransaction;
|
|
11
|
+
}>;
|
|
12
|
+
step2WaitForUnsignedTxApproval(unsignedTx: ExtendedUnsignedTransaction, txRequest: TxRequest, feeRateDiffPercentage?: number): Promise<{
|
|
13
|
+
unsignedTx: ExtendedUnsignedTransaction;
|
|
14
|
+
txRequest: TxRequest;
|
|
15
|
+
}>;
|
|
16
|
+
step3SignTxAndWaitForBroadcast(unsignedTx: ExtendedUnsignedTransaction, txRequest: TxRequest): Promise<TxRequest>;
|
|
17
|
+
sendBTCMultipleAddress(receivers: TargetAddress[], fee?: FeeRateType, staticExtendedUtxo?: ExtendedUtxo[], fullAmount?: boolean): Promise<TxRequest>;
|
|
18
|
+
sendBTC(receiverAddress: string, amountInSatoshi: number | "all", fee?: FeeRateType, staticExtendedUtxo?: ExtendedUtxo[]): Promise<TxRequest>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=multisig-wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multisig-wallet.d.ts","sourceRoot":"","sources":["../src/multisig-wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAElF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EACL,2BAA2B,EAC3B,YAAY,EACZ,UAAU,EACV,aAAa,EACd,MAAM,uBAAuB,CAAA;AAE9B,qBAAa,oBAAoB;IAC/B,UAAU,EAAE,iBAAiB,CAAA;IAC7B,WAAW,EAAE,8BAA8B,CAAA;gBAC/B,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAKtF,qCAAqC,CACzC,SAAS,EAAE,aAAa,EAAE,EAC1B,UAAU,EAAE,UAAU,EACtB,GAAG,GAAE,WAAsB,EAC3B,kBAAkB,CAAC,EAAE,YAAY,EAAE,EACnC,UAAU,UAAQ;;;;IA2Bd,8BAA8B,CAClC,UAAU,EAAE,2BAA2B,EACvC,SAAS,EAAE,SAAS,EACpB,qBAAqB,SAAK;;;;IA4DtB,8BAA8B,CAClC,UAAU,EAAE,2BAA2B,EACvC,SAAS,EAAE,SAAS;IAoBhB,sBAAsB,CAC1B,SAAS,EAAE,aAAa,EAAE,EAC1B,GAAG,GAAE,WAAsB,EAC3B,kBAAkB,CAAC,EAAE,YAAY,EAAE,EACnC,UAAU,UAAQ;IAwBd,OAAO,CACX,eAAe,EAAE,MAAM,EACvB,eAAe,EAAE,MAAM,GAAG,KAAK,EAC/B,GAAG,GAAE,WAAsB,EAC3B,kBAAkB,CAAC,EAAE,YAAY,EAAE;CAUtC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MultisigWalletHelper = void 0;
|
|
16
|
+
const providers_1 = require("@teleportdao/providers");
|
|
17
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
18
|
+
class MultisigWalletHelper {
|
|
19
|
+
constructor(baseWallet, coordinatorApiKey, coordinatorUrl) {
|
|
20
|
+
this.baseWallet = baseWallet;
|
|
21
|
+
this.coordinator = new providers_1.TeleportdaoMultisigCoordinator(coordinatorUrl, coordinatorApiKey);
|
|
22
|
+
}
|
|
23
|
+
step1SendBTCToMultipleAddressUnsigned(receivers, signerInfo, fee = "normal", staticExtendedUtxo, fullAmount = false) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
let unsignedTx = yield this.baseWallet.sendBTCToMultipleAddressUnsignedTx(receivers, signerInfo, fee, staticExtendedUtxo, fullAmount);
|
|
26
|
+
let txRequest = yield this.coordinator.createOrConfirmNewTx({
|
|
27
|
+
inputs: unsignedTx.inputs.map((x) => ({
|
|
28
|
+
hash: x.hash,
|
|
29
|
+
index: x.index,
|
|
30
|
+
value: x.value,
|
|
31
|
+
})),
|
|
32
|
+
outputs: unsignedTx.outputs,
|
|
33
|
+
feeRate: unsignedTx.feeRate,
|
|
34
|
+
unsignedPsbt: unsignedTx.unsignedTransaction,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
txRequest,
|
|
38
|
+
unsignedTx,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
step2WaitForUnsignedTxApproval(unsignedTx, txRequest, feeRateDiffPercentage = 10) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
let newUnsignedTx = unsignedTx;
|
|
45
|
+
let newTxRequest = txRequest;
|
|
46
|
+
if (newTxRequest.unsignedPsbt !== unsignedTx.unsignedTransaction) {
|
|
47
|
+
const feeDiff = (0, bignumber_js_1.default)(newTxRequest.feeRate)
|
|
48
|
+
.minus(unsignedTx.feeRate)
|
|
49
|
+
.abs()
|
|
50
|
+
.dividedBy(unsignedTx.feeRate);
|
|
51
|
+
if (!feeDiff.isLessThan(feeRateDiffPercentage / 100)) {
|
|
52
|
+
yield this.coordinator.rejectTxRequest(newTxRequest.id);
|
|
53
|
+
throw new Error("Reject because of Invalid FeeRate");
|
|
54
|
+
}
|
|
55
|
+
const { signerInfo } = unsignedTx.inputs[0];
|
|
56
|
+
newUnsignedTx = yield this.baseWallet.sendBTCToMultipleAddressUnsignedTx(unsignedTx.outputs, signerInfo, +newTxRequest.feeRate, newTxRequest.inputs.map((x) => (Object.assign(Object.assign({}, x), { signerInfo }))));
|
|
57
|
+
let updatedTxRequest = yield this.coordinator.confirmOrRejectTxRequest(newTxRequest.id, unsignedTx.unsignedTransaction);
|
|
58
|
+
if (updatedTxRequest.unsignedPsbt !== unsignedTx.unsignedTransaction ||
|
|
59
|
+
updatedTxRequest.status === "Rejected") {
|
|
60
|
+
throw new Error("Reject because of invalid outputs");
|
|
61
|
+
}
|
|
62
|
+
newTxRequest = updatedTxRequest;
|
|
63
|
+
}
|
|
64
|
+
if (newTxRequest.status === "Pending") {
|
|
65
|
+
const updatedTxRequest = yield this.coordinator.waitTxStatusChange(newTxRequest.id);
|
|
66
|
+
if (!updatedTxRequest) {
|
|
67
|
+
yield this.coordinator.rejectTxRequest(newTxRequest.id);
|
|
68
|
+
throw new Error("Tx Timeout");
|
|
69
|
+
}
|
|
70
|
+
newTxRequest = updatedTxRequest;
|
|
71
|
+
}
|
|
72
|
+
if (newTxRequest.status === "Rejected") {
|
|
73
|
+
throw new Error("Tx rejected");
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
unsignedTx: newUnsignedTx,
|
|
77
|
+
txRequest: newTxRequest,
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
step3SignTxAndWaitForBroadcast(unsignedTx, txRequest) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (!this.baseWallet.privateKey)
|
|
84
|
+
throw new Error("account is not initialized");
|
|
85
|
+
let newTxRequest = txRequest;
|
|
86
|
+
if (newTxRequest.status === "Approved") {
|
|
87
|
+
const signed = yield this.baseWallet.signer.signPsbt(unsignedTx, this.baseWallet.privateKey);
|
|
88
|
+
newTxRequest = yield this.coordinator.submitSignedPsbt(newTxRequest.id, signed);
|
|
89
|
+
}
|
|
90
|
+
if (newTxRequest.status === "Approved") {
|
|
91
|
+
const finalTx = yield this.coordinator.waitTxStatusChange(newTxRequest.id, "Approved");
|
|
92
|
+
if (!finalTx || finalTx.status === "Failed") {
|
|
93
|
+
throw new Error("Tx not broadcasted for long time");
|
|
94
|
+
}
|
|
95
|
+
newTxRequest = finalTx;
|
|
96
|
+
}
|
|
97
|
+
return newTxRequest;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
sendBTCMultipleAddress(receivers, fee = "normal", staticExtendedUtxo, fullAmount = false) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
if (!this.baseWallet.signerInfo || !this.baseWallet.privateKey) {
|
|
103
|
+
throw new Error("account not initialized");
|
|
104
|
+
}
|
|
105
|
+
let unsignedResponse = yield this.step1SendBTCToMultipleAddressUnsigned(receivers, this.baseWallet.signerInfo, fee, staticExtendedUtxo, fullAmount);
|
|
106
|
+
unsignedResponse = yield this.step2WaitForUnsignedTxApproval(unsignedResponse.unsignedTx, unsignedResponse.txRequest);
|
|
107
|
+
const txRequest = yield this.step3SignTxAndWaitForBroadcast(unsignedResponse.unsignedTx, unsignedResponse.txRequest);
|
|
108
|
+
return txRequest;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
sendBTC(receiverAddress, amountInSatoshi, fee = "normal", staticExtendedUtxo) {
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const txRequest = yield this.sendBTCMultipleAddress([{ address: receiverAddress, value: amountInSatoshi === "all" ? 0 : amountInSatoshi }], fee, staticExtendedUtxo, amountInSatoshi === "all");
|
|
114
|
+
return txRequest;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.MultisigWalletHelper = MultisigWalletHelper;
|
|
119
|
+
//# sourceMappingURL=multisig-wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multisig-wallet.js","sourceRoot":"","sources":["../src/multisig-wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAkF;AAClF,gEAAoC;AASpC,MAAa,oBAAoB;IAG/B,YAAY,UAA6B,EAAE,iBAAyB,EAAE,cAAsB;QAC1F,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,0CAA8B,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAA;IAC1F,CAAC;IAEK,qCAAqC,CACzC,SAA0B,EAC1B,UAAsB,EACtB,MAAmB,QAAQ,EAC3B,kBAAmC,EACnC,UAAU,GAAG,KAAK;;YAElB,IAAI,UAAU,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,kCAAkC,CACvE,SAAS,EACT,UAAU,EACV,GAAG,EACH,kBAAkB,EAClB,UAAU,CACX,CAAA;YAED,IAAI,SAAS,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC;gBAC1D,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACpC,IAAI,EAAE,CAAC,CAAC,IAAI;oBACZ,KAAK,EAAE,CAAC,CAAC,KAAK;oBACd,KAAK,EAAE,CAAC,CAAC,KAAK;iBACf,CAAC,CAAC;gBACH,OAAO,EAAE,UAAU,CAAC,OAAc;gBAClC,OAAO,EAAE,UAAU,CAAC,OAAO;gBAC3B,YAAY,EAAE,UAAU,CAAC,mBAAmB;aAC7C,CAAC,CAAA;YAEF,OAAO;gBACL,SAAS;gBACT,UAAU;aACX,CAAA;QACH,CAAC;KAAA;IAEK,8BAA8B,CAClC,UAAuC,EACvC,SAAoB,EACpB,qBAAqB,GAAG,EAAE;;YAE1B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
|
outputToken: string;
|
|
24
24
|
outputAmount: string;
|
|
25
25
|
bridgePercentageFee?: number;
|
|
26
|
-
}, appId?: number, fee?: FeeRateType, thirdPartyId?: number, staticExtendedUtxo?: ExtendedUtxo[], changeAddress?: string, fullAmount?: boolean): Promise<any>;
|
|
26
|
+
}, appId?: number, speed?: boolean, fee?: FeeRateType, thirdPartyId?: number, staticExtendedUtxo?: ExtendedUtxo[], changeAddress?: string, fullAmount?: boolean): Promise<any>;
|
|
27
27
|
wrapUnsigned(recipientAddress: string, amount: string, networkFee: string, lockerAddress: string, chainId: number, signer: SignerInfo, exchange?: {
|
|
28
28
|
outputToken: string;
|
|
29
29
|
outputAmount: string;
|
|
30
30
|
bridgePercentageFee?: number;
|
|
31
|
-
}, appId?: number, fee?: FeeRateType, thirdPartyId?: number, staticExtendedUtxo?: ExtendedUtxo[], changeAddress?: string, fullAmount?: boolean): Promise<{
|
|
31
|
+
}, appId?: number, speed?: boolean, fee?: FeeRateType, thirdPartyId?: number, staticExtendedUtxo?: ExtendedUtxo[], changeAddress?: string, fullAmount?: boolean): Promise<{
|
|
32
32
|
unsignedTransaction: string;
|
|
33
33
|
outputs: import("./transaction-builder/transaction-builder").Target[];
|
|
34
34
|
inputs: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"teleswap-wallet.d.ts","sourceRoot":"","sources":["../src/teleswap-wallet.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,UAAU,EAEX,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGtE,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;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M,CAAA;KAC7B,EACD,KAAK,SAEiC,EACtC,KAAK,UAAQ,EACb,GAAG,GAAE,WAAsB,EAC3B,YAAY,CAAC,EAAE,MAAM,EACrB,kBAAkB,CAAC,EAAE,YAAY,EAAE,EACnC,aAAa,CAAC,EAAE,MAAM,EACtB,UAAU,UAAQ;;;;;;;;;;;;;CAuCrB;AACD,eAAe,cAAc,CAAA"}
|
package/dist/teleswap-wallet.js
CHANGED
|
@@ -16,26 +16,26 @@ const teleswap_helper_1 = require("./helper/teleswap-helper");
|
|
|
16
16
|
class TeleswapWallet extends bitcoin_wallet_base_1.BitcoinBaseWallet {
|
|
17
17
|
wrap(recipientAddress, amount, networkFee, lockerAddress, chainId, exchange, appId = exchange
|
|
18
18
|
? configs_1.teleswap.requestAppId.WrapAndSwap.default
|
|
19
|
-
: configs_1.teleswap.requestAppId.Wrap.default, fee = "normal", thirdPartyId, staticExtendedUtxo, changeAddress, fullAmount = false) {
|
|
19
|
+
: configs_1.teleswap.requestAppId.Wrap.default, speed = false, fee = "normal", thirdPartyId, staticExtendedUtxo, changeAddress, fullAmount = false) {
|
|
20
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
21
|
if (!this.signerInfo || !this.privateKey) {
|
|
22
22
|
throw new Error("account not initialized");
|
|
23
23
|
}
|
|
24
|
-
let unsignedTransaction = yield this.wrapUnsigned(recipientAddress, amount, networkFee, lockerAddress, chainId, this.signerInfo, exchange, appId, fee, thirdPartyId, staticExtendedUtxo, changeAddress, fullAmount);
|
|
24
|
+
let unsignedTransaction = yield this.wrapUnsigned(recipientAddress, amount, networkFee, lockerAddress, chainId, this.signerInfo, exchange, appId, speed, fee, thirdPartyId, staticExtendedUtxo, changeAddress, fullAmount);
|
|
25
25
|
let signedPsbt = yield this.signer.signPsbt(unsignedTransaction, this.privateKey);
|
|
26
26
|
return this.sendSignedPsbt(signedPsbt);
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
wrapUnsigned(recipientAddress, amount, networkFee, lockerAddress, chainId, signer, exchange, appId = exchange
|
|
30
30
|
? configs_1.teleswap.requestAppId.WrapAndSwap.default
|
|
31
|
-
: configs_1.teleswap.requestAppId.Wrap.default, fee = "normal", thirdPartyId, staticExtendedUtxo, changeAddress, fullAmount = false) {
|
|
31
|
+
: configs_1.teleswap.requestAppId.Wrap.default, speed = false, fee = "normal", thirdPartyId, staticExtendedUtxo, changeAddress, fullAmount = false) {
|
|
32
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
33
|
const dataHex = (0, teleswap_helper_1.generateWrapOpReturn)({
|
|
34
34
|
chainId,
|
|
35
35
|
appId,
|
|
36
36
|
recipientAddress,
|
|
37
37
|
networkFee,
|
|
38
|
-
speed
|
|
38
|
+
speed,
|
|
39
39
|
isExchange: !!exchange,
|
|
40
40
|
outputAmount: exchange === null || exchange === void 0 ? void 0 : exchange.outputAmount,
|
|
41
41
|
outputToken: exchange === null || exchange === void 0 ? void 0 : exchange.outputToken,
|
|
@@ -53,12 +53,14 @@ class TeleswapWallet extends bitcoin_wallet_base_1.BitcoinBaseWallet {
|
|
|
53
53
|
},
|
|
54
54
|
this.transactionBuilder.getOpReturnTarget(dataHex),
|
|
55
55
|
];
|
|
56
|
+
const sequenceNumber = speed === true ? this.transactionBuilder.NO_RBF_SEQUENCE : undefined;
|
|
56
57
|
const unsignedTx = this.transactionBuilder.processUnsignedTransaction({
|
|
57
58
|
extendedUtxo,
|
|
58
59
|
feeRate,
|
|
59
60
|
targets,
|
|
60
61
|
changeAddress: fullAmount ? lockerAddress : changeAddress || signer.address,
|
|
61
62
|
fullAmount,
|
|
63
|
+
sequenceNumber,
|
|
62
64
|
});
|
|
63
65
|
return unsignedTx;
|
|
64
66
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"teleswap-wallet.js","sourceRoot":"","sources":["../src/teleswap-wallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA0D;AAM1D,+DAAsE;AACtE,8DAA+D;AA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AAC,CAAC,CAAC,SAAS,CAAA;YAC3F,MAAM,UAAU,GAAG,IAAI,CAAC,kBAAkB,CAAC,0BAA0B,CAAC;gBACpE,YAAY;gBACZ,OAAO;gBACP,OAAO;gBACP,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,IAAI,MAAM,CAAC,OAAO;gBAC3E,UAAU;gBACV,cAAc;aACf,CAAC,CAAA;YAEF,OAAO,UAAU,CAAA;QACnB,CAAC;KAAA;CACF;AA3GD,wCA2GC;AACD,kBAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as bitcoin from "bitcoinjs-lib";
|
|
3
|
+
import { ExtendedUtxo, Target } from "./transaction-builder";
|
|
4
|
+
export declare const componentBytes: {
|
|
5
|
+
bytePerInput: {
|
|
6
|
+
p2pkh: number;
|
|
7
|
+
p2wpkh: number;
|
|
8
|
+
"p2sh-p2wpkh": number;
|
|
9
|
+
p2tr: number;
|
|
10
|
+
default: number;
|
|
11
|
+
};
|
|
12
|
+
baseTxBytes: number;
|
|
13
|
+
bytePerOutput: {
|
|
14
|
+
p2pkh: number;
|
|
15
|
+
p2wpkh: number;
|
|
16
|
+
p2sh: number;
|
|
17
|
+
p2tr: number;
|
|
18
|
+
p2wsh: number;
|
|
19
|
+
default: number;
|
|
20
|
+
max: number;
|
|
21
|
+
};
|
|
22
|
+
scriptExtraBytes: {
|
|
23
|
+
lessThan255: number;
|
|
24
|
+
moreThan255: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare const DUST = 600;
|
|
28
|
+
export declare function getInputSize(addressType: string, details?: {
|
|
29
|
+
script?: string;
|
|
30
|
+
n?: number;
|
|
31
|
+
m?: number;
|
|
32
|
+
}): number;
|
|
33
|
+
export declare function getOutputSize(output: {
|
|
34
|
+
addressType?: string;
|
|
35
|
+
address?: string;
|
|
36
|
+
script?: Buffer;
|
|
37
|
+
}, network?: bitcoin.Network): number;
|
|
38
|
+
export declare function calculateTxSize(inputTypes: {
|
|
39
|
+
addressType: string;
|
|
40
|
+
n?: number;
|
|
41
|
+
m?: number;
|
|
42
|
+
script?: string;
|
|
43
|
+
}[], outputs: {
|
|
44
|
+
script?: Buffer;
|
|
45
|
+
address?: string;
|
|
46
|
+
value: number;
|
|
47
|
+
}[], changeAddressType?: string, network?: bitcoin.Network): number;
|
|
48
|
+
export declare function coinSelectBnB(inputs: ExtendedUtxo[], outputs: Target[], feeRate: number, changeAddressType?: string, network?: bitcoin.Network): {
|
|
49
|
+
success: boolean;
|
|
50
|
+
inputs: ExtendedUtxo[];
|
|
51
|
+
outputs: Target[];
|
|
52
|
+
fee: number;
|
|
53
|
+
totalInputValue: number;
|
|
54
|
+
totalOutputValue: number;
|
|
55
|
+
needed: number;
|
|
56
|
+
change?: {
|
|
57
|
+
value: number;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export declare function coinSelectAccumulative(inputs: ExtendedUtxo[], outputs: Target[], feeRate: number, changeAddressType?: string, network?: bitcoin.Network, minInputAggregate?: {
|
|
61
|
+
minInputCount: number;
|
|
62
|
+
maxInputValue: number;
|
|
63
|
+
}): {
|
|
64
|
+
success: boolean;
|
|
65
|
+
inputs: ExtendedUtxo[];
|
|
66
|
+
outputs: Target[];
|
|
67
|
+
fee: number;
|
|
68
|
+
totalInputValue: number;
|
|
69
|
+
totalOutputValue: number;
|
|
70
|
+
needed: number;
|
|
71
|
+
change?: {
|
|
72
|
+
value: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
export declare function coinSelectAll(inputs: ExtendedUtxo[], targets: Target[], feeRate: number, changeAddressType?: string, network?: bitcoin.Network): {
|
|
76
|
+
success: boolean;
|
|
77
|
+
inputs: ExtendedUtxo[];
|
|
78
|
+
outputs: Target[];
|
|
79
|
+
fee: number;
|
|
80
|
+
totalInputValue: number;
|
|
81
|
+
totalOutputValue: number;
|
|
82
|
+
needed: number;
|
|
83
|
+
change?: {
|
|
84
|
+
value: number;
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=coin-select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coin-select.d.ts","sourceRoot":"","sources":["../../src/transaction-builder/coin-select.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,OAAO,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAG5D,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;CAuB1B,CAAA;AA0BD,eAAO,MAAM,IAAI,MAAM,CAAA;AAEvB,wBAAgB,YAAY,CAC1B,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;IAER,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,CAAC,CAAC,EAAE,MAAM,CAAA;IACV,CAAC,CAAC,EAAE,MAAM,CAAA;CACX,UAkBF;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE;IACN,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EAED,OAAO,GAAE,OAAO,CAAC,OAAkC,UA6BpD;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,CAAC,CAAC,EAAE,MAAM,CAAA;IACV,CAAC,CAAC,EAAE,MAAM,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,EAAE,EACH,OAAO,EAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;CACd,EAAE,EACH,iBAAiB,SAAY,EAC7B,OAAO,GAAE,OAAO,CAAC,OAAkC,UAqBpD;AAWD,wBAAgB,aAAa,CAC3B,MAAM,EAA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