From 37693b5e5776d12767b6181b05c6a94d6f203aed Mon Sep 17 00:00:00 2001 From: boufni95 Date: Mon, 24 Jun 2024 18:16:05 +0200 Subject: [PATCH] fixies --- src/services/lnd/liquidityProvider.ts | 6 ++++++ src/services/main/liquidityManager.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/lnd/liquidityProvider.ts b/src/services/lnd/liquidityProvider.ts index 295d3bf9..fc7bbe61 100644 --- a/src/services/lnd/liquidityProvider.ts +++ b/src/services/lnd/liquidityProvider.ts @@ -117,6 +117,9 @@ export class LiquidityProvider { } AddInvoice = async (amount: number, memo: string) => { + if (this.latestMaxWithdrawable === null) { + throw new Error("liquidity provider is not ready yet") + } const res = await this.client.NewInvoice({ amountSats: amount, memo }) if (res.status === 'ERROR') { this.log("error creating invoice", res.reason) @@ -128,6 +131,9 @@ export class LiquidityProvider { } PayInvoice = async (invoice: string) => { + if (this.latestMaxWithdrawable === null) { + throw new Error("liquidity provider is not ready yet") + } const res = await this.client.PayInvoice({ invoice, amount: 0 }) if (res.status === 'ERROR') { this.log("error paying invoice", res.reason) diff --git a/src/services/main/liquidityManager.ts b/src/services/main/liquidityManager.ts index c583e149..a3eac088 100644 --- a/src/services/main/liquidityManager.ts +++ b/src/services/main/liquidityManager.ts @@ -37,7 +37,7 @@ export class LiquidityManager { onNewBlock = async () => { const balance = await this.liquidityProvider.GetLatestMaxWithdrawable() const { remote } = await this.lnd.ChannelBalance() - if (remote > balance) { + if (remote > balance && balance > 0) { this.log("draining provider balance to channel") const invoice = await this.lnd.NewInvoice(balance, "liqudity provider drain", defaultInvoiceExpiry) const res = await this.liquidityProvider.PayInvoice(invoice.payRequest)