@atomiqlabs/lp-lib 15.0.10 → 15.0.11
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/plugins/IPlugin.d.ts +2 -1
- package/dist/plugins/PluginManager.d.ts +2 -1
- package/dist/plugins/PluginManager.js +15 -0
- package/dist/swaps/spv_vault_swap/SpvVaultSwapHandler.js +3 -0
- package/package.json +1 -1
- package/src/plugins/IPlugin.ts +8 -2
- package/src/plugins/PluginManager.ts +20 -2
- package/src/swaps/spv_vault_swap/SpvVaultSwapHandler.ts +8 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BitcoinRpc } from "@atomiqlabs/base";
|
|
2
|
-
import { FromBtcLnRequestType, FromBtcRequestType, FromBtcTrustedRequestType, ISwapPrice, MultichainData, RequestData, SpvVaultSwapRequestType, SwapHandler, SwapHandlerType, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
2
|
+
import { FromBtcLnRequestType, FromBtcRequestType, FromBtcTrustedRequestType, ISwapPrice, MultichainData, RequestData, SpvVaultPostQuote, SpvVaultSwap, SpvVaultSwapRequestType, SwapHandler, SwapHandlerType, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
3
3
|
import { SwapHandlerSwap } from "../swaps/SwapHandlerSwap";
|
|
4
4
|
import { Command } from "@atomiqlabs/server-base";
|
|
5
5
|
import { FromBtcLnTrustedRequestType } from "../swaps/trusted/frombtcln_trusted/FromBtcLnTrusted";
|
|
@@ -128,6 +128,7 @@ export interface IPlugin {
|
|
|
128
128
|
feePPM: bigint;
|
|
129
129
|
networkFeeGetter: (amount: bigint) => Promise<bigint>;
|
|
130
130
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | ToBtcPluginQuote>;
|
|
131
|
+
onHandlePostedFromBtcQuote?(swapType: SwapHandlerType.FROM_BTC_SPV, request: RequestData<SpvVaultPostQuote>, swap: SpvVaultSwap): Promise<QuoteThrow | null>;
|
|
131
132
|
onVaultSelection?(chainIdentifier: string, totalSats: bigint, requestedAmount: {
|
|
132
133
|
amount: bigint;
|
|
133
134
|
token: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BitcoinRpc, SwapData } from "@atomiqlabs/base";
|
|
2
2
|
import { IPlugin, PluginQuote, QuoteAmountTooHigh, QuoteAmountTooLow, QuoteSetFees, QuoteThrow, ToBtcPluginQuote } from "./IPlugin";
|
|
3
|
-
import { FromBtcLnRequestType, FromBtcRequestType, FromBtcTrustedRequestType, ISwapPrice, MultichainData, RequestData, SpvVaultSwapRequestType, SwapHandler, SwapHandlerType, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
3
|
+
import { FromBtcLnRequestType, FromBtcRequestType, FromBtcTrustedRequestType, ISwapPrice, MultichainData, RequestData, SpvVaultPostQuote, SpvVaultSwap, SpvVaultSwapRequestType, SwapHandler, SwapHandlerType, ToBtcLnRequestType, ToBtcRequestType } from "..";
|
|
4
4
|
import { SwapHandlerSwap } from "../swaps/SwapHandlerSwap";
|
|
5
5
|
import { FromBtcLnTrustedRequestType } from "../swaps/trusted/frombtcln_trusted/FromBtcLnTrusted";
|
|
6
6
|
import { IBitcoinWallet } from "../wallets/IBitcoinWallet";
|
|
@@ -101,6 +101,7 @@ export declare class PluginManager {
|
|
|
101
101
|
baseFeeInBtc: bigint;
|
|
102
102
|
feePPM: bigint;
|
|
103
103
|
}): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh>;
|
|
104
|
+
static onHandlePostedFromBtcQuote(swapType: SwapHandlerType.FROM_BTC_SPV, request: RequestData<SpvVaultPostQuote>, swap: SpvVaultSwap): Promise<QuoteThrow | null>;
|
|
104
105
|
static onVaultSelection(chainIdentifier: string, totalSats: bigint, requestedAmount: {
|
|
105
106
|
amount: bigint;
|
|
106
107
|
token: string;
|
|
@@ -214,6 +214,21 @@ class PluginManager {
|
|
|
214
214
|
}
|
|
215
215
|
return null;
|
|
216
216
|
}
|
|
217
|
+
static async onHandlePostedFromBtcQuote(swapType, request, swap) {
|
|
218
|
+
for (let plugin of PluginManager.plugins.values()) {
|
|
219
|
+
try {
|
|
220
|
+
if (plugin.onHandlePostedFromBtcQuote != null) {
|
|
221
|
+
const result = await plugin.onHandlePostedFromBtcQuote(swapType, request, swap);
|
|
222
|
+
if (result != null && (0, IPlugin_1.isQuoteThrow)(result))
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
pluginLogger.error(plugin, "onHandlePostedFromBtcQuote(): plugin error", e);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
217
232
|
static async onVaultSelection(chainIdentifier, totalSats, requestedAmount, gasAmount) {
|
|
218
233
|
for (let plugin of PluginManager.plugins.values()) {
|
|
219
234
|
try {
|
|
@@ -13,6 +13,7 @@ const crypto_1 = require("crypto");
|
|
|
13
13
|
const btc_signer_1 = require("@scure/btc-signer");
|
|
14
14
|
const SpvVaults_1 = require("./SpvVaults");
|
|
15
15
|
const BitcoinUtils_1 = require("../../utils/BitcoinUtils");
|
|
16
|
+
const AmountAssertions_1 = require("../assertions/AmountAssertions");
|
|
16
17
|
const TX_MAX_VSIZE = 16 * 1024;
|
|
17
18
|
class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
18
19
|
constructor(storageDirectory, vaultStorage, path, chainsData, swapPricing, bitcoin, bitcoinRpc, spvVaultSigner, config) {
|
|
@@ -343,6 +344,8 @@ class SpvVaultSwapHandler extends SwapHandler_1.SwapHandler {
|
|
|
343
344
|
msg: "Used vault not found!"
|
|
344
345
|
};
|
|
345
346
|
}
|
|
347
|
+
//Check the posted quote with the plugins
|
|
348
|
+
AmountAssertions_1.AmountAssertions.handlePluginErrorResponses(await PluginManager_1.PluginManager.onHandlePostedFromBtcQuote(this.type, { chainIdentifier: swap.chainIdentifier, raw: req, parsed: parsedBody, metadata }, swap));
|
|
346
349
|
//Try parse psbt
|
|
347
350
|
let transaction;
|
|
348
351
|
try {
|
package/package.json
CHANGED
package/src/plugins/IPlugin.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {BitcoinRpc
|
|
1
|
+
import {BitcoinRpc} from "@atomiqlabs/base";
|
|
2
2
|
import {
|
|
3
3
|
FromBtcLnRequestType,
|
|
4
4
|
FromBtcRequestType, FromBtcTrustedRequestType,
|
|
5
|
-
ISwapPrice, MultichainData, RequestData, SpvVaultSwapRequestType,
|
|
5
|
+
ISwapPrice, MultichainData, RequestData, SpvVaultPostQuote, SpvVaultSwap, SpvVaultSwapRequestType,
|
|
6
6
|
SwapHandler, SwapHandlerType,
|
|
7
7
|
ToBtcLnRequestType,
|
|
8
8
|
ToBtcRequestType
|
|
@@ -151,6 +151,12 @@ export interface IPlugin {
|
|
|
151
151
|
fees: {baseFeeInBtc: bigint, feePPM: bigint, networkFeeGetter: (amount: bigint) => Promise<bigint>}
|
|
152
152
|
): Promise<QuoteThrow | QuoteSetFees | QuoteAmountTooLow | QuoteAmountTooHigh | ToBtcPluginQuote>;
|
|
153
153
|
|
|
154
|
+
onHandlePostedFromBtcQuote?(
|
|
155
|
+
swapType: SwapHandlerType.FROM_BTC_SPV,
|
|
156
|
+
request: RequestData<SpvVaultPostQuote>,
|
|
157
|
+
swap: SpvVaultSwap
|
|
158
|
+
): Promise<QuoteThrow | null>;
|
|
159
|
+
|
|
154
160
|
onVaultSelection?(
|
|
155
161
|
chainIdentifier: string,
|
|
156
162
|
totalSats: bigint,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BitcoinRpc,
|
|
1
|
+
import {BitcoinRpc, SwapData} from "@atomiqlabs/base";
|
|
2
2
|
import {
|
|
3
3
|
IPlugin, isPluginQuote, isQuoteAmountTooHigh, isQuoteAmountTooLow, isQuoteSetFees,
|
|
4
4
|
isQuoteThrow, isToBtcPluginQuote, PluginQuote,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
FromBtcLnRequestType,
|
|
12
12
|
FromBtcRequestType, FromBtcTrustedRequestType,
|
|
13
|
-
ISwapPrice, MultichainData, RequestData, SpvVaultSwapRequestType,
|
|
13
|
+
ISwapPrice, MultichainData, RequestData, SpvVaultPostQuote, SpvVaultSwap, SpvVaultSwapRequestType,
|
|
14
14
|
SwapHandler, SwapHandlerType,
|
|
15
15
|
ToBtcLnRequestType,
|
|
16
16
|
ToBtcRequestType
|
|
@@ -291,6 +291,24 @@ export class PluginManager {
|
|
|
291
291
|
return null;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
static async onHandlePostedFromBtcQuote(
|
|
295
|
+
swapType: SwapHandlerType.FROM_BTC_SPV,
|
|
296
|
+
request: RequestData<SpvVaultPostQuote>,
|
|
297
|
+
swap: SpvVaultSwap
|
|
298
|
+
): Promise<QuoteThrow | null> {
|
|
299
|
+
for(let plugin of PluginManager.plugins.values()) {
|
|
300
|
+
try {
|
|
301
|
+
if(plugin.onHandlePostedFromBtcQuote!=null) {
|
|
302
|
+
const result = await plugin.onHandlePostedFromBtcQuote(swapType, request, swap);
|
|
303
|
+
if(result!=null && isQuoteThrow(result)) return result;
|
|
304
|
+
}
|
|
305
|
+
} catch (e) {
|
|
306
|
+
pluginLogger.error(plugin, "onHandlePostedFromBtcQuote(): plugin error", e);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
294
312
|
static async onVaultSelection(
|
|
295
313
|
chainIdentifier: string,
|
|
296
314
|
totalSats: bigint,
|
|
@@ -30,6 +30,7 @@ import {randomBytes} from "crypto";
|
|
|
30
30
|
import {Transaction} from "@scure/btc-signer";
|
|
31
31
|
import {SpvVaults, VAULT_DUST_AMOUNT} from "./SpvVaults";
|
|
32
32
|
import {isLegacyInput} from "../../utils/BitcoinUtils";
|
|
33
|
+
import {AmountAssertions} from "../assertions/AmountAssertions";
|
|
33
34
|
|
|
34
35
|
export type SpvVaultSwapHandlerConfig = SwapBaseConfig & {
|
|
35
36
|
vaultsCheckInterval: number,
|
|
@@ -470,6 +471,13 @@ export class SpvVaultSwapHandler extends SwapHandler<SpvVaultSwap, SpvVaultSwapS
|
|
|
470
471
|
};
|
|
471
472
|
}
|
|
472
473
|
|
|
474
|
+
//Check the posted quote with the plugins
|
|
475
|
+
AmountAssertions.handlePluginErrorResponses(await PluginManager.onHandlePostedFromBtcQuote(
|
|
476
|
+
this.type,
|
|
477
|
+
{chainIdentifier: swap.chainIdentifier, raw: req, parsed: parsedBody, metadata},
|
|
478
|
+
swap
|
|
479
|
+
));
|
|
480
|
+
|
|
473
481
|
//Try parse psbt
|
|
474
482
|
let transaction: Transaction;
|
|
475
483
|
try {
|