This commit is contained in:
boufni95 2025-12-19 15:25:39 +00:00
parent 7733a9f377
commit 5c93f29209

View file

@ -171,27 +171,7 @@ export type LiquiditySettings = {
} }
export const LoadLiquiditySettingsFromEnv = (dbEnv: Record<string, string | undefined>, addToDb?: EnvCacher): LiquiditySettings => { export const LoadLiquiditySettingsFromEnv = (dbEnv: Record<string, string | undefined>, addToDb?: EnvCacher): LiquiditySettings => {
const providerNprofile = chooseEnv("PROVIDER_NPROFILE", dbEnv, "nprofile1qyd8wumn8ghj7um5wfn8y7fwwd5x7cmt9ehx2arhdaexkqpqwmk5tuqvafa6ckwc6zmaypyy3af3n4aeds2ql7m0ew42kzsn638q9s9z8p", addToDb) const providerNprofile = chooseEnv("PROVIDER_NPROFILE", dbEnv, "nprofile1qyd8wumn8ghj7um5wfn8y7fwwd5x7cmt9ehx2arhdaexkqpqwmk5tuqvafa6ckwc6zmaypyy3af3n4aeds2ql7m0ew42kzsn638q9s9z8p", addToDb)
const { liquidityProviderPub, providerRelayUrl } = decodeNprofile(providerNprofile)
// Decode nprofile to extract pubkey and relay URL
let liquidityProviderPub = ""
let providerRelayUrl = ""
if (providerNprofile) {
try {
const decoded = nip19.decode(providerNprofile)
if (decoded.type === 'nprofile') {
liquidityProviderPub = decoded.data.pubkey
if (decoded.data.relays && decoded.data.relays.length > 0) {
providerRelayUrl = decoded.data.relays[0]
} else {
throw new Error("PROVIDER_NPROFILE must contain at least one relay")
}
} else {
throw new Error("PROVIDER_NPROFILE must be a valid nprofile")
}
} catch (e) {
throw new Error(`Failed to decode PROVIDER_NPROFILE as nprofile: ${e}`)
}
}
const disableLiquidityProvider = chooseEnvBool("DISABLE_LIQUIDITY_PROVIDER", dbEnv, false, addToDb) || liquidityProviderPub === "null" const disableLiquidityProvider = chooseEnvBool("DISABLE_LIQUIDITY_PROVIDER", dbEnv, false, addToDb) || liquidityProviderPub === "null"
const useOnlyLiquidityProvider = chooseEnvBool("USE_ONLY_LIQUIDITY_PROVIDER", dbEnv, false, addToDb) const useOnlyLiquidityProvider = chooseEnvBool("USE_ONLY_LIQUIDITY_PROVIDER", dbEnv, false, addToDb)
@ -199,6 +179,20 @@ export const LoadLiquiditySettingsFromEnv = (dbEnv: Record<string, string | unde
return { liquidityProviderPub, useOnlyLiquidityProvider, disableLiquidityProvider, providerRelayUrl } return { liquidityProviderPub, useOnlyLiquidityProvider, disableLiquidityProvider, providerRelayUrl }
} }
const decodeNprofile = (nprofile: string) => {
const decoded = nip19.decode(nprofile)
if (decoded.type !== 'nprofile') {
throw new Error("PROVIDER_NPROFILE must be a valid nprofile")
}
if (!decoded.data.pubkey) {
throw new Error("PROVIDER_NPROFILE must contain a pubkey")
}
if (!decoded.data.relays || decoded.data.relays.length === 0) {
throw new Error("PROVIDER_NPROFILE must contain at least one relay")
}
return { liquidityProviderPub: decoded.data.pubkey, providerRelayUrl: decoded.data.relays[0] }
}
export type SwapsSettings = { export type SwapsSettings = {
boltzHttpUrl: string boltzHttpUrl: string
boltzWebSocketUrl: string boltzWebSocketUrl: string