diff --git a/.gitignore b/.gitignore index 0e58d9f6..e202e9d3 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ app.nprofile admin.connect debug.txt proto/autogenerated/debug.txt +.specstory diff --git a/src/services/main/index.ts b/src/services/main/index.ts index 18860b99..161b4c34 100644 --- a/src/services/main/index.ts +++ b/src/services/main/index.ts @@ -75,7 +75,7 @@ export default class { this.applicationManager = new ApplicationManager(this.storage, this.settings, this.paymentManager) this.appUserManager = new AppUserManager(this.storage, this.settings, this.applicationManager) this.debitManager = new DebitManager(this.storage, this.lnd, this.applicationManager) - this.offerManager = new OfferManager(this.storage, this.lnd, this.applicationManager, this.productManager) + this.offerManager = new OfferManager(this.storage, this.lnd, this.applicationManager, this.productManager, this.liquidityManager) this.webRTC = new webRTC(this.storage, this.utils) } diff --git a/src/services/main/offerManager.ts b/src/services/main/offerManager.ts index e1a4a3e1..0e91caba 100644 --- a/src/services/main/offerManager.ts +++ b/src/services/main/offerManager.ts @@ -17,6 +17,7 @@ import { UserOffer } from '../storage/entity/UserOffer.js'; import { DeepPartial } from 'typeorm'; import { nip19 } from 'nostr-tools'; import { LoadNosrtSettingsFromEnv } from '../nostr/index.js'; +import { LiquidityManager } from "./liquidityManager.js" const mapToOfferConfig = (appUserId: string, offer: UserOffer, { pubkey, relay }: { pubkey: string, relay: string }): Types.OfferConfig => { if (offer.expected_data) { @@ -50,12 +51,14 @@ export class OfferManager { productManager: ProductManager storage: Storage lnd: LND + liquidityManager: LiquidityManager logger = getLogger({ component: 'DebitManager' }) - constructor(storage: Storage, lnd: LND, applicationManager: ApplicationManager, productManager: ProductManager) { + constructor(storage: Storage, lnd: LND, applicationManager: ApplicationManager, productManager: ProductManager, liquidityManager: LiquidityManager) { this.storage = storage this.lnd = lnd this.applicationManager = applicationManager this.productManager = productManager + this.liquidityManager = liquidityManager } attachNostrSend = (nostrSend: NostrSend) => { @@ -219,14 +222,18 @@ export class OfferManager { async getNofferInvoice(offerReq: NofferData, appId: string): Promise<{ success: true, invoice: string } | { success: false, code: number, max: number }> { try { const { remote } = await this.lnd.ChannelBalance() + let maxSendable = remote + if (remote === 0 && (await this.liquidityManager.liquidityProvider.IsReady())) { + maxSendable = 10_000_000 + } const split = offerReq.offer.split(':') if (split.length === 1) { - return this.HandleUserOffer(offerReq, appId, remote) + return this.HandleUserOffer(offerReq, appId, maxSendable) } else if (split[0] === 'p') { const product = await this.productManager.NewProductInvoice(split[1]) return { success: true, invoice: product.invoice } } else { - return { success: false, code: 1, max: remote } + return { success: false, code: 1, max: maxSendable } } } catch (e: any) { getLogger({ component: "noffer" })(ERROR, e.message || e) diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 2a1c1c34..47508e91 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -497,10 +497,14 @@ export default class { const payK1 = await this.storage.paymentStorage.AddUserEphemeralKey(userId, 'pay', linkedApplication) const url = baseUrl ? baseUrl : `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle` const { remote } = await this.lnd.ChannelBalance() + let maxSendable = remote * 1000 + if (remote === 0 && (await this.liquidityManager.liquidityProvider.IsReady())) { + maxSendable = 10_000_000 * 1000 + } return { tag: 'payRequest', callback: `${url}?k1=${payK1.key}`, - maxSendable: remote * 1000, + maxSendable: maxSendable, minSendable: 10000, metadata: metadata ? metadata : defaultLnurlPayMetadata(this.settings.lnurlMetaText), allowsNostr: !!linkedApplication.nostr_public_key, @@ -517,10 +521,14 @@ export default class { throw new Error("invalid lnurl request") } const { remote } = await this.lnd.ChannelBalance() + let maxSendable = remote * 1000 + if (remote === 0 && (await this.liquidityManager.liquidityProvider.IsReady())) { + maxSendable = 10_000_000 * 1000 + } return { tag: 'payRequest', callback: `${this.settings.serviceUrl}/api/guest/lnurl_pay/handle?k1=${payInfoK1}`, - maxSendable: remote * 1000, + maxSendable: maxSendable, minSendable: 10000, metadata: defaultLnurlPayMetadata(this.settings.lnurlMetaText), allowsNostr: !!key.linkedApplication.nostr_public_key,