Merge branch 'master' into http-upgrade

This commit is contained in:
boufni95 2025-05-12 16:51:01 +00:00
commit 8759625581
6 changed files with 6752 additions and 6728 deletions

1
.gitignore vendored
View file

@ -22,6 +22,7 @@ app.nprofile
admin.connect
debug.txt
proto/autogenerated/debug.txt
.specstory
metrics_cache/
metric_cache/
metrics_events/

17
package-lock.json generated
View file

@ -56,7 +56,7 @@
"@types/chai-string": "^1.4.5",
"@types/cors": "^2.8.17",
"@types/eccrypto": "^1.1.6",
"@types/jsonwebtoken": "^9.0.6",
"@types/jsonwebtoken": "^9.0.9",
"@types/lodash": "^4.14.182",
"@types/node": "^16.11.10",
"@types/node-fetch": "^2.6.3",
@ -745,11 +745,13 @@
}
},
"node_modules/@types/jsonwebtoken": {
"version": "9.0.6",
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.6.tgz",
"integrity": "sha512-/5hndP5dCjloafCXns6SZyESp3Ldq7YjH3zwzwczYnjxIT0Fqzk5ROSYVGfFyczIue7IUEj8hkvLbPoLQ18vQw==",
"version": "9.0.9",
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.9.tgz",
"integrity": "sha512-uoe+GxEuHbvy12OUQct2X9JenKM3qAscquYymuQN4fMWG9DBQtykrQEFcAbVACF7qaLw9BePSodUL0kquqBJpQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/ms": "*",
"@types/node": "*"
}
},
@ -769,6 +771,13 @@
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA=="
},
"node_modules/@types/ms": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/@types/ms/-/ms-2.1.0.tgz",
"integrity": "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
"version": "16.18.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.3.tgz",

View file

@ -73,7 +73,7 @@
"@types/chai-string": "^1.4.5",
"@types/cors": "^2.8.17",
"@types/eccrypto": "^1.1.6",
"@types/jsonwebtoken": "^9.0.6",
"@types/jsonwebtoken": "^9.0.9",
"@types/lodash": "^4.14.182",
"@types/node": "^16.11.10",
"@types/node-fetch": "^2.6.3",

View file

@ -75,9 +75,8 @@ 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)
}
Stop() {

View file

@ -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)

View file

@ -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,