This commit is contained in:
boufni95 2024-06-24 18:16:05 +02:00
parent 406ffa615b
commit 37693b5e57
2 changed files with 7 additions and 1 deletions

View file

@ -117,6 +117,9 @@ export class LiquidityProvider {
} }
AddInvoice = async (amount: number, memo: string) => { 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 }) const res = await this.client.NewInvoice({ amountSats: amount, memo })
if (res.status === 'ERROR') { if (res.status === 'ERROR') {
this.log("error creating invoice", res.reason) this.log("error creating invoice", res.reason)
@ -128,6 +131,9 @@ export class LiquidityProvider {
} }
PayInvoice = async (invoice: string) => { 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 }) const res = await this.client.PayInvoice({ invoice, amount: 0 })
if (res.status === 'ERROR') { if (res.status === 'ERROR') {
this.log("error paying invoice", res.reason) this.log("error paying invoice", res.reason)

View file

@ -37,7 +37,7 @@ export class LiquidityManager {
onNewBlock = async () => { onNewBlock = async () => {
const balance = await this.liquidityProvider.GetLatestMaxWithdrawable() const balance = await this.liquidityProvider.GetLatestMaxWithdrawable()
const { remote } = await this.lnd.ChannelBalance() const { remote } = await this.lnd.ChannelBalance()
if (remote > balance) { if (remote > balance && balance > 0) {
this.log("draining provider balance to channel") this.log("draining provider balance to channel")
const invoice = await this.lnd.NewInvoice(balance, "liqudity provider drain", defaultInvoiceExpiry) const invoice = await this.lnd.NewInvoice(balance, "liqudity provider drain", defaultInvoiceExpiry)
const res = await this.liquidityProvider.PayInvoice(invoice.payRequest) const res = await this.liquidityProvider.PayInvoice(invoice.payRequest)