From 36b0d07a38a89520ece3aa5fa4a5ded9b2502462 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Thu, 27 Oct 2022 19:38:41 +0900 Subject: [PATCH 01/13] Add maxPaymentFeeRatio in LndConfig --- lib/Config.ts | 4 ++++ lib/lightning/LndClient.ts | 7 +++++-- test/integration/Nodes.ts | 1 + test/integration/lightning/LndClient.spec.ts | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Config.ts b/lib/Config.ts index b5c925986..c4f0868c9 100644 --- a/lib/Config.ts +++ b/lib/Config.ts @@ -35,6 +35,8 @@ type CurrencyConfig = { // Expiry for invoices of this currency in seconds invoiceExpiry?: number; + // Max fee ratio for LND's sendPayment + maxPaymentFeeRatio?: number; maxSwapAmount: number; minSwapAmount: number; @@ -264,6 +266,7 @@ class Config { port: 10009, certpath: path.join(getServiceDataDir('lnd'), 'tls.cert'), macaroonpath: path.join(getServiceDataDir('lnd'), 'data', 'chain', 'bitcoin', Network.Testnet, 'admin.macaroon'), + maxPaymentFeeRatio: 0.03, }, }, { @@ -291,6 +294,7 @@ class Config { port: 11009, certpath: path.join(getServiceDataDir('lnd'), 'tls.cert'), macaroonpath: path.join(getServiceDataDir('lnd'), 'data', 'chain', 'litecoin', Network.Testnet, 'admin.macaroon'), + maxPaymentFeeRatio: 0.03, }, }, ], diff --git a/lib/lightning/LndClient.ts b/lib/lightning/LndClient.ts index 5fdbf9ea3..09c628456 100644 --- a/lib/lightning/LndClient.ts +++ b/lib/lightning/LndClient.ts @@ -21,6 +21,7 @@ type LndConfig = { port: number; certpath: string; macaroonpath: string; + maxPaymentFeeRatio: number; }; type LndMethodFunction = (params: any, meta: Metadata, listener) => any; @@ -67,7 +68,7 @@ class LndClient extends BaseClient implements LndClient { private static readonly minPaymentFee = 21; private static readonly paymentTimeout = 60; - private static readonly maxPaymentFeeRatio = 0.03; + private static maxPaymentFeeRatio: number; private readonly uri!: string; private readonly credentials!: ChannelCredentials; @@ -92,7 +93,9 @@ class LndClient extends BaseClient implements LndClient { ) { super(); - const { host, port, certpath, macaroonpath } = config; + const { host, port, certpath, macaroonpath, maxPaymentFeeRatio } = config; + + LndClient.maxPaymentFeeRatio = maxPaymentFeeRatio > 0 ? maxPaymentFeeRatio: 0.03; if (fs.existsSync(certpath)) { this.uri = `${host}:${port}`; diff --git a/test/integration/Nodes.ts b/test/integration/Nodes.ts index 87d3c6f97..c0d2f917a 100644 --- a/test/integration/Nodes.ts +++ b/test/integration/Nodes.ts @@ -20,4 +20,5 @@ export const bitcoinLndClient = new LndClient(Logger.disabledLogger, 'BTC', { port: 10009, certpath: `${lndDataPath}/certificates/tls.cert`, macaroonpath: `${lndDataPath}/macaroons/admin.macaroon`, + maxPaymentFeeRatio: 0.03, }); diff --git a/test/integration/lightning/LndClient.spec.ts b/test/integration/lightning/LndClient.spec.ts index 2779c5bb6..ec71ef087 100644 --- a/test/integration/lightning/LndClient.spec.ts +++ b/test/integration/lightning/LndClient.spec.ts @@ -70,6 +70,7 @@ describe('LndClient', () => { const serverHost = '127.0.0.1'; const serverPort = await getPort(); + const maxPaymentFeeRatio = 0.03; const bindPort = await new Promise((resolve) => { server.bindAsync(`${serverHost}:${serverPort}`, grpc.ServerCredentials.createSsl(null, @@ -96,6 +97,7 @@ describe('LndClient', () => { port: serverPort, certpath: `${lndDataPath}/certificates/tls.cert`, macaroonpath: `${lndDataPath}/macaroons/admin.macaroon`, + maxPaymentFeeRatio: maxPaymentFeeRatio, }, ); await lndClient.connect(false); From f469850ddb83d3f20d41df496f6c51d1ac03c416 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Thu, 27 Oct 2022 20:32:16 +0900 Subject: [PATCH 02/13] Fix docs --- docs/deployment.md | 2 ++ docs/regtest.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/deployment.md b/docs/deployment.md index 2c36edf76..371c94b38 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -151,6 +151,7 @@ maxZeroConfAmount = 10_000_000 port = 10_009 certpath = "/home/boltz/.lnd/bitcoin/tls.cert" macaroonpath = "/home/boltz/.lnd/bitcoin/admin.macaroon" + maxPaymentFeeRatio = 0.03 [[currencies]] symbol = "LTC" @@ -175,4 +176,5 @@ maxZeroConfAmount = 1_000_000_000 port = 11_009 certpath = "/home/boltz/.lnd/litecoin/tls.cert" macaroonpath = "/home/boltz/.lnd/litecoin/admin.macaroon" + maxPaymentFeeRatio = 0.03 ``` diff --git a/docs/regtest.md b/docs/regtest.md index 8fa4cd3f9..281cf03f6 100644 --- a/docs/regtest.md +++ b/docs/regtest.md @@ -68,6 +68,7 @@ maxZeroConfAmount = 10_000_000 port = 10_009 certpath = "docker/regtest/data/lnd/certificates/tls.cert" macaroonpath = "docker/regtest/data/lnd/macaroons/admin.macaroon" + maxPaymentFeeRatio = 0.03 [[currencies]] symbol = "LTC" @@ -90,6 +91,7 @@ maxZeroConfAmount = 0 port = 11_009 certpath = "docker/regtest/data/lnd/certificates/tls.cert" macaroonpath = "docker/regtest/data/lnd/macaroons/admin.macaroon" + maxPaymentFeeRatio = 0.03 [ethereum] providerEndpoint = "http://127.0.0.1:8546" From f5125428a455e3c01b2ff266ce43d190aab5d4be Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 28 Oct 2022 09:09:11 +0900 Subject: [PATCH 03/13] Delete static type --- lib/lightning/LndClient.ts | 6 +++--- test/integration/lightning/LndClient.spec.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/lightning/LndClient.ts b/lib/lightning/LndClient.ts index 09c628456..bb95593da 100644 --- a/lib/lightning/LndClient.ts +++ b/lib/lightning/LndClient.ts @@ -68,7 +68,7 @@ class LndClient extends BaseClient implements LndClient { private static readonly minPaymentFee = 21; private static readonly paymentTimeout = 60; - private static maxPaymentFeeRatio: number; + private maxPaymentFeeRatio: number; private readonly uri!: string; private readonly credentials!: ChannelCredentials; @@ -95,7 +95,7 @@ class LndClient extends BaseClient implements LndClient { const { host, port, certpath, macaroonpath, maxPaymentFeeRatio } = config; - LndClient.maxPaymentFeeRatio = maxPaymentFeeRatio > 0 ? maxPaymentFeeRatio: 0.03; + this.maxPaymentFeeRatio = maxPaymentFeeRatio > 0 ? maxPaymentFeeRatio: 0.03; if (fs.existsSync(certpath)) { this.uri = `${host}:${port}`; @@ -700,7 +700,7 @@ class LndClient extends BaseClient implements LndClient { const invoiceAmt = bolt11.decode(invoice).satoshis || 0; return Math.max( - Math.ceil(invoiceAmt * LndClient.maxPaymentFeeRatio), + Math.ceil(invoiceAmt * this.maxPaymentFeeRatio), LndClient.minPaymentFee, ); }; diff --git a/test/integration/lightning/LndClient.spec.ts b/test/integration/lightning/LndClient.spec.ts index ec71ef087..45047735e 100644 --- a/test/integration/lightning/LndClient.spec.ts +++ b/test/integration/lightning/LndClient.spec.ts @@ -20,10 +20,11 @@ describe('LndClient', () => { const calculatePaymentFee = bitcoinLndClient['calculatePaymentFee']; const bigInvoiceAmount = 8754398; + const maxPaymentFeeRatio = 0.03; let invoice = await bitcoinLndClient.addInvoice(bigInvoiceAmount); // Should use the payment fee ratio for big payments - expect(calculatePaymentFee(invoice.paymentRequest)).toEqual(Math.ceil(bigInvoiceAmount * LndClient['maxPaymentFeeRatio'])); + expect(calculatePaymentFee(invoice.paymentRequest)).toEqual(Math.ceil(bigInvoiceAmount * maxPaymentFeeRatio)); // Should use the minimal payment fee for small payments invoice = await bitcoinLndClient.addInvoice(1); From af1c59d5a40d6b9d78cfbef87460cce36ec501df Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 25 Nov 2022 09:37:11 +0900 Subject: [PATCH 04/13] Add requirements --- docs/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 000000000..1edb123f0 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,2 @@ +Jinja2==2.11.3 +mkdocs==1.2.3 \ No newline at end of file From 9b3d7e3a5b08233b6f2fb7647fd746824c2a5aa1 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 25 Nov 2022 10:08:51 +0900 Subject: [PATCH 05/13] Fix r --- docs/requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 1edb123f0..b8a279522 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1 @@ -Jinja2==2.11.3 -mkdocs==1.2.3 \ No newline at end of file +jinja2<3.1.0 \ No newline at end of file From 8be7215d65648944a99cfce43dc0155663b7f6b8 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 25 Nov 2022 10:15:58 +0900 Subject: [PATCH 06/13] Fix r --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index b8a279522..908ea81d9 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1 +1,2 @@ -jinja2<3.1.0 \ No newline at end of file +Jinja2==2.11.3 +Markdown==3.3.4 \ No newline at end of file From f76a1a6a66e68ddd6680fbdb3a5129b0ce57e1cd Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 25 Nov 2022 10:20:14 +0900 Subject: [PATCH 07/13] Fix r --- docs/requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 908ea81d9..edd005796 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ -Jinja2==2.11.3 -Markdown==3.3.4 \ No newline at end of file +jinja2<3.1.0 +Markdown<3.2 \ No newline at end of file From e21f6a11af856d09453617e99ca0457d1c3caa51 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 25 Nov 2022 11:08:28 +0900 Subject: [PATCH 08/13] Fix links --- docs/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/index.md b/docs/index.md index 701e0afaf..fcdf6df41 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,15 +8,15 @@ Boltz is a privacy first, account-free crypto exchange built on top of second la ## Instances -We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet.boltz.exchange) and one on [mainnet](https://boltz.exchange). +We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet-diamond-boltz.web.app/) and one on [mainnet](http://swap.diamondhands.technology/). The Rest API can be accessed at: -* [Testnet](https://testnet.boltz.exchange/api) -* [Mainnet](https://boltz.exchange/api) +* [Testnet](https://testnet.dlc.soy/9001/api) +* [Mainnet](https://boltz.diamondhands.technology/api) > Note: If you access the API from your browser, you will get 404. -> Run `curl https://boltz.exchange/api/version`, (or `curl https://testnet.boltz.exchange/api/version` for testnet) to check that it is available. +> Run `curl https://boltz.diamondhands.technology/api/version`, (or `curl https://testnet.dlc.soy/9001/version` for testnet) to check that it is available. ## Useful Links From 5604cb81ac3905a386dfe23efe8d214f01f233b1 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 2 Dec 2022 23:14:30 +0900 Subject: [PATCH 09/13] Add swapInFee --- lib/consts/Types.ts | 1 + lib/rates/FeeProvider.ts | 15 +++++++++++++++ lib/rates/RateProvider.ts | 9 +++++++++ lib/service/Service.ts | 11 +++++++++-- test/unit/rates/FeeProvider.spec.ts | 5 +++++ test/unit/rates/RateProvider.spec.ts | 14 ++++++++++++++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/consts/Types.ts b/lib/consts/Types.ts index 90264a676..d43715f12 100644 --- a/lib/consts/Types.ts +++ b/lib/consts/Types.ts @@ -31,6 +31,7 @@ export type PairConfig = { // Percentage of the amount that will be charged as fee fee?: number; + swapInFee?: number; // If there is a hardcoded rate the APIs of the exchanges will not be queried rate?: number; diff --git a/lib/rates/FeeProvider.ts b/lib/rates/FeeProvider.ts index 15ad65032..f5432f3de 100644 --- a/lib/rates/FeeProvider.ts +++ b/lib/rates/FeeProvider.ts @@ -19,6 +19,7 @@ type MinerFees = { class FeeProvider { // A map between the symbols of the pairs and their percentage fees public percentageFees = new Map(); + public percentageSwapInFees = new Map(); public minerFees = new Map(); @@ -65,6 +66,9 @@ class FeeProvider { } this.percentageFees.set(getPairId(pair), percentage / 100); + + const percentageSwapIn = pair.swapInFee !== undefined ? pair.swapInFee : 0; + this.percentageSwapInFees.set(getPairId(pair), percentageSwapIn / 100); }); this.logger.debug(`Prepared data for fee estimations: ${stringify(mapToObject(this.percentageFees))}`); @@ -74,6 +78,10 @@ class FeeProvider { return this.percentageFees.get(pair) || 0; }; + public getPercentageSwapInFee = (pair: string): number => { + return this.percentageSwapInFees.get(pair) || 0; + }; + public getFees = ( pair: string, rate: number, @@ -83,18 +91,25 @@ class FeeProvider { ): { baseFee: number, percentageFee: number, + percentageSwapInFee: number, } => { let percentageFee = this.getPercentageFee(pair); + let percentageSwapInFee = this.getPercentageSwapInFee(pair); if (percentageFee !== 0) { percentageFee = percentageFee * amount * rate; } + if (percentageSwapInFee !== 0) { + percentageSwapInFee = percentageSwapInFee * amount * rate; + } + const { base, quote } = splitPairId(pair); const chainCurrency = getChainCurrency(base, quote, orderSide, type !== BaseFeeType.NormalClaim); return { percentageFee: Math.ceil(percentageFee), + percentageSwapInFee: Math.ceil(percentageSwapInFee), baseFee: this.getBaseFee(chainCurrency, type), }; }; diff --git a/lib/rates/RateProvider.ts b/lib/rates/RateProvider.ts index 5c579e8c2..43bd42a11 100644 --- a/lib/rates/RateProvider.ts +++ b/lib/rates/RateProvider.ts @@ -37,6 +37,7 @@ type PairType = { }; fees: { percentage: number; + swapInFee: number; minerFees: { baseAsset: MinerFees, quoteAsset: MinerFees, @@ -64,6 +65,7 @@ class RateProvider { // A copy of the "percentageFees" Map in the FeeProvider but all values are multiplied with 100 private percentageFees = new Map(); + private percentageSwapInFees = new Map(); private timer!: any; @@ -83,6 +85,11 @@ class RateProvider { this.percentageFees.set(pair, percentage * 100); }); + this.feeProvider.percentageSwapInFees.forEach((swapInFee, pair) => { + // Multiply with 100 to get the percentage + this.percentageSwapInFees.set(pair, swapInFee * 100); + }); + await this.updateMinerFees(); pairs.forEach((pair) => { @@ -99,6 +106,7 @@ class RateProvider { limits: this.getLimits(id, pair.base, pair.quote, pair.rate), fees: { percentage: this.percentageFees.get(id)!, + swapInFee: this.percentageSwapInFees.get(id)!, minerFees: { baseAsset: emptyMinerFees, quoteAsset: emptyMinerFees, @@ -189,6 +197,7 @@ class RateProvider { hash: '', fees: { percentage: this.percentageFees.get(pairId)!, + swapInFee: this.percentageSwapInFees.get(pairId)!, minerFees: { baseAsset: this.feeProvider.minerFees.get(base)!, quoteAsset: this.feeProvider.minerFees.get(quote)!, diff --git a/lib/service/Service.ts b/lib/service/Service.ts index 489e7a983..f8249a9bd 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -674,9 +674,13 @@ class Service { const rate = getRate(swap.rate!, swap.orderSide, false); - const percentageFee = this.rateProvider.feeProvider.getPercentageFee(swap.pair); + let percentageFee = this.rateProvider.feeProvider.getPercentageFee(swap.pair); + const percentageSwapInFee = this.rateProvider.feeProvider.getPercentageSwapInFee(swap.pair); const baseFee = this.rateProvider.feeProvider.getBaseFee(onchainCurrency, BaseFeeType.NormalClaim); + if (percentageSwapInFee !== 0) { + percentageFee = percentageSwapInFee; + } const invoiceAmount = this.calculateInvoiceAmount(swap.orderSide, rate, swap.onchainAmount, baseFee, percentageFee); this.verifyAmount(swap.pair, rate, invoiceAmount, swap.orderSide, false); @@ -730,13 +734,16 @@ class Service { this.verifyAmount(swap.pair, rate, invoiceAmount, swap.orderSide, false); - const { baseFee, percentageFee } = this.rateProvider.feeProvider.getFees( + let { baseFee, percentageFee, percentageSwapInFee } = this.rateProvider.feeProvider.getFees( swap.pair, rate, swap.orderSide, invoiceAmount, BaseFeeType.NormalClaim, ); + if (percentageSwapInFee !== 0) { + percentageFee = percentageSwapInFee; + } const expectedAmount = Math.floor(invoiceAmount * rate) + baseFee + percentageFee; if (swap.onchainAmount && expectedAmount > swap.onchainAmount) { diff --git a/test/unit/rates/FeeProvider.spec.ts b/test/unit/rates/FeeProvider.spec.ts index 6bd53f608..595360969 100644 --- a/test/unit/rates/FeeProvider.spec.ts +++ b/test/unit/rates/FeeProvider.spec.ts @@ -34,11 +34,13 @@ describe('FeeProvider', () => { base: 'LTC', quote: 'BTC', fee: 2, + swapInFee: -1, }, { base: 'BTC', quote: 'BTC', fee: 0, + swapInFee: -1, }, { base: 'LTC', @@ -46,6 +48,7 @@ describe('FeeProvider', () => { // The FeeProvider should set this to 1 fee: undefined, + swapInFee: undefined, }, ]); @@ -112,11 +115,13 @@ describe('FeeProvider', () => { expect(feeProvider.getFees('LTC/BTC', 2, OrderSide.BUY, amount, BaseFeeType.NormalClaim)).toEqual({ baseFee: 6120, percentageFee: 4000000, + percentageSwapInFee: -2000000, }); expect(feeProvider.getFees('LTC/BTC', 2, OrderSide.BUY, amount, BaseFeeType.ReverseLockup)).toEqual({ baseFee: 459, percentageFee: 4000000, + percentageSwapInFee: -2000000, }); }); diff --git a/test/unit/rates/RateProvider.spec.ts b/test/unit/rates/RateProvider.spec.ts index 65da402c6..f588f8b34 100644 --- a/test/unit/rates/RateProvider.spec.ts +++ b/test/unit/rates/RateProvider.spec.ts @@ -25,6 +25,11 @@ const percentageFees = new Map([ ['BTC/BTC', 0.005], ]); +const percentageSwapInFees = new Map([ + ['LTC/BTC', 0.01], + ['BTC/BTC', -0.01], +]); + const minerFees = new Map([ [ 'BTC', @@ -70,6 +75,7 @@ jest.mock('../../../lib/rates/FeeProvider', () => { return { minerFees, percentageFees, + percentageSwapInFees, getBaseFee: mockGetBaseFee, updateMinerFees: mockUpdateMinerFees, }; @@ -196,6 +202,14 @@ describe('RateProvider', () => { }); }); + test('should get percentage fees for swapin', () => { + const { pairs } = rateProvider; + + percentageSwapInFees.forEach((_, pairId) => { + expect(pairs.get(pairId)!.fees.swapInFee).toEqual(percentageSwapInFees.get(pairId)! * 100); + }); + }); + test('should get miner fees', () => { const { pairs } = rateProvider; From 6b6a339757a8d1832e672478589cb3008fd0ab83 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Fri, 2 Dec 2022 23:42:15 +0900 Subject: [PATCH 10/13] Fix declaration --- docs/index.md | 8 ++++---- lib/service/Service.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/index.md b/docs/index.md index fcdf6df41..fa50f0f96 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,15 +8,15 @@ Boltz is a privacy first, account-free crypto exchange built on top of second la ## Instances -We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet-diamond-boltz.web.app/) and one on [mainnet](http://swap.diamondhands.technology/). +We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet.boltz.exchange) and one on [mainnet](https://boltz.exchange).technology/). The Rest API can be accessed at: -* [Testnet](https://testnet.dlc.soy/9001/api) -* [Mainnet](https://boltz.diamondhands.technology/api) +* [Testnet](https://testnet.boltz.exchange/api) +* [Mainnet](https://boltz.exchange/api) > Note: If you access the API from your browser, you will get 404. -> Run `curl https://boltz.diamondhands.technology/api/version`, (or `curl https://testnet.dlc.soy/9001/version` for testnet) to check that it is available. +> Run `curl https://boltz.exchange/api/version`, (or `curl https://testnet.boltz.exchange/api/version` for testnet) to check that it is available. ## Useful Links diff --git a/lib/service/Service.ts b/lib/service/Service.ts index f8249a9bd..6e38a0890 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -734,13 +734,21 @@ class Service { this.verifyAmount(swap.pair, rate, invoiceAmount, swap.orderSide, false); - let { baseFee, percentageFee, percentageSwapInFee } = this.rateProvider.feeProvider.getFees( + const { baseFee, percentageSwapInFee } = this.rateProvider.feeProvider.getFees( swap.pair, rate, swap.orderSide, invoiceAmount, BaseFeeType.NormalClaim, ); + let { percentageFee } = this.rateProvider.feeProvider.getFees( + swap.pair, + rate, + swap.orderSide, + invoiceAmount, + BaseFeeType.NormalClaim, + ); + if (percentageSwapInFee !== 0) { percentageFee = percentageSwapInFee; } @@ -752,7 +760,7 @@ class Service { rate, swap.onchainAmount, baseFee, - this.rateProvider.feeProvider.getPercentageFee(swap.pair), + Math.max(this.rateProvider.feeProvider.getPercentageFee(swap.pair),this.rateProvider.feeProvider.getPercentageSwapInFee(swap.pair)), ); throw Errors.INVALID_INVOICE_AMOUNT(maxInvoiceAmount); From c68cd7f6fa457ee8f4cdba316d3d3f9b6ac871cb Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Sat, 3 Dec 2022 08:48:39 +0900 Subject: [PATCH 11/13] Fix test cases --- docs/index.md | 2 +- lib/service/Service.ts | 16 +++++----------- test/unit/service/Service.spec.ts | 7 +++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/index.md b/docs/index.md index fa50f0f96..f2fa08298 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,7 +8,7 @@ Boltz is a privacy first, account-free crypto exchange built on top of second la ## Instances -We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet.boltz.exchange) and one on [mainnet](https://boltz.exchange).technology/). +We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet.boltz.exchange) and one on [mainnet](https://boltz.exchange)). The Rest API can be accessed at: diff --git a/lib/service/Service.ts b/lib/service/Service.ts index 6e38a0890..74f7be96a 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -734,14 +734,7 @@ class Service { this.verifyAmount(swap.pair, rate, invoiceAmount, swap.orderSide, false); - const { baseFee, percentageSwapInFee } = this.rateProvider.feeProvider.getFees( - swap.pair, - rate, - swap.orderSide, - invoiceAmount, - BaseFeeType.NormalClaim, - ); - let { percentageFee } = this.rateProvider.feeProvider.getFees( + const { baseFee, percentageFee, percentageSwapInFee } = this.rateProvider.feeProvider.getFees( swap.pair, rate, swap.orderSide, @@ -749,10 +742,11 @@ class Service { BaseFeeType.NormalClaim, ); + let serviceFee = percentageFee; if (percentageSwapInFee !== 0) { - percentageFee = percentageSwapInFee; + serviceFee = percentageSwapInFee; } - const expectedAmount = Math.floor(invoiceAmount * rate) + baseFee + percentageFee; + const expectedAmount = Math.floor(invoiceAmount * rate) + baseFee + serviceFee; if (swap.onchainAmount && expectedAmount > swap.onchainAmount) { const maxInvoiceAmount = this.calculateInvoiceAmount( @@ -772,7 +766,7 @@ class Service { swap, invoice, expectedAmount, - percentageFee, + serviceFee, acceptZeroConf, this.eventHandler.emitSwapInvoiceSet, ); diff --git a/test/unit/service/Service.spec.ts b/test/unit/service/Service.spec.ts index 019e026fd..77ae8ff7e 100644 --- a/test/unit/service/Service.spec.ts +++ b/test/unit/service/Service.spec.ts @@ -240,6 +240,7 @@ const mockInitFeeProvider = jest.fn().mockReturnValue(undefined); const mockGetFees = jest.fn().mockReturnValue({ baseFee: 1, percentageFee: 1, + percentageSwapInFee: 0, }); const mockGetBaseFeeResult = 320; @@ -248,12 +249,16 @@ const mockGetBaseFee = jest.fn().mockReturnValue(mockGetBaseFeeResult); const mockGetPercentageFeeResult = 0.02; const mockGetPercentageFee = jest.fn().mockReturnValue(mockGetPercentageFeeResult); +const mockGetPercentageSwapInFeeResult = 0.02; +const mockGetPercentageSwapInFee = jest.fn().mockReturnValue(mockGetPercentageSwapInFeeResult); + jest.mock('../../../lib/rates/FeeProvider', () => { return jest.fn().mockImplementation(() => ({ init: mockInitFeeProvider, getFees: mockGetFees, getBaseFee: mockGetBaseFee, getPercentageFee: mockGetPercentageFee, + getPercentageSwapInFee: mockGetPercentageSwapInFee, })); }); @@ -965,6 +970,7 @@ describe('Service', () => { })).rejects.toEqual(Errors.SWAP_WITH_PREIMAGE_EXISTS()); }); + // TODO: Add anohter test for swapInFee test('should get swap rates', async () => { const id = 'id'; @@ -993,6 +999,7 @@ describe('Service', () => { await expect(service.getSwapRates(id)).rejects.toEqual(Errors.SWAP_NOT_FOUND(id)); }); + // TODO: Add anohter test for swapInFee test('should set invoices of swaps', async () => { mockGetSwapResult = { id: 'invoiceId', From 1cc7e51a885902c5a6bd92f10504ef35005202a8 Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Wed, 7 Dec 2022 06:58:32 +0900 Subject: [PATCH 12/13] Add documentation --- docs/deployment.md | 3 +++ docs/index.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/deployment.md b/docs/deployment.md index 371c94b38..3ee5e9272 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -92,6 +92,8 @@ otpsecretpath = "/home/boltz/.boltz/otpSecret.dat" # - Kraken # - Poloniex # - "fee": percentage of the swapped amount that should be charged as fee +# - "swapInFee" (optional): percentage of the swapped in amount that should be charged as fee +# "fee" is applied if this is not configured [[pairs]] base = "LTC" @@ -109,6 +111,7 @@ base = "LTC" quote = "LTC" rate = 1 fee = 0.5 +swapInFee = 1.0 timeoutDelta = 300 # The array "currencies" configures the chain and LND clients for the "pairs" diff --git a/docs/index.md b/docs/index.md index f2fa08298..701e0afaf 100644 --- a/docs/index.md +++ b/docs/index.md @@ -8,7 +8,7 @@ Boltz is a privacy first, account-free crypto exchange built on top of second la ## Instances -We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet.boltz.exchange) and one on [mainnet](https://boltz.exchange)). +We are running and maintaining two Boltz instances that can be used - one on [testnet](https://testnet.boltz.exchange) and one on [mainnet](https://boltz.exchange). The Rest API can be accessed at: From 1569decd5e1722cde4be31632343cf1b47b185af Mon Sep 17 00:00:00 2001 From: Yuya Ogawa Date: Wed, 25 Jan 2023 20:35:00 +0900 Subject: [PATCH 13/13] Add dependencies in Poetry --- docs/requirements.txt | 2 -- tools/pyproject.toml | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt deleted file mode 100644 index edd005796..000000000 --- a/docs/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -jinja2<3.1.0 -Markdown<3.2 \ No newline at end of file diff --git a/tools/pyproject.toml b/tools/pyproject.toml index 317c7b403..accb045b2 100644 --- a/tools/pyproject.toml +++ b/tools/pyproject.toml @@ -10,7 +10,8 @@ python-bitcoinrpc = "^1.0" pyotp = "^2.8.0" sseclient = "^0.0.27" ruff = "^0.0.188" - +jinja2 = "<3.1.0" +Markdown = "<3.2" [build-system] requires = ["poetry-core"]