offers liquidity
This commit is contained in:
parent
ab76283131
commit
fa2a2a593d
4 changed files with 22 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -22,3 +22,4 @@ app.nprofile
|
|||
admin.connect
|
||||
debug.txt
|
||||
proto/autogenerated/debug.txt
|
||||
.specstory
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue