mirror of
https://github.com/tompro/sattle.git
synced 2026-08-27 07:15:59 +00:00
refactor: tighten protocol amount helpers
This commit is contained in:
@@ -22,7 +22,7 @@ import {
|
|||||||
grossUpForMintFee,
|
grossUpForMintFee,
|
||||||
mintAddressUrl,
|
mintAddressUrl,
|
||||||
resolveMintInput,
|
resolveMintInput,
|
||||||
serverOf
|
serverOf,
|
||||||
} from 'lnurlcash-kit'
|
} from 'lnurlcash-kit'
|
||||||
import type {LnurlcashOptions, MintFee} from 'lnurlcash-kit'
|
import type {LnurlcashOptions, MintFee} from 'lnurlcash-kit'
|
||||||
import {ceilMsatToSat, floorMsatToSat} from './units'
|
import {ceilMsatToSat, floorMsatToSat} from './units'
|
||||||
@@ -55,7 +55,7 @@ export const clearMintFeeQuoteCache = (): void => quoteCache.clear()
|
|||||||
// reached right now.
|
// reached right now.
|
||||||
export const quoteMintFee = async (
|
export const quoteMintFee = async (
|
||||||
mintInput: string,
|
mintInput: string,
|
||||||
options: LnurlcashOptions = {}
|
options: LnurlcashOptions = {},
|
||||||
): Promise<MintFee | null> => {
|
): Promise<MintFee | null> => {
|
||||||
const url = resolveMintInput(mintInput)
|
const url = resolveMintInput(mintInput)
|
||||||
if (!url) return null
|
if (!url) return null
|
||||||
@@ -69,8 +69,9 @@ export const quoteMintFee = async (
|
|||||||
if (addressUrl) {
|
if (addressUrl) {
|
||||||
try {
|
try {
|
||||||
payUrl = (await fetchMintAddress(addressUrl, opts)).payLink
|
payUrl = (await fetchMintAddress(addressUrl, opts)).payLink
|
||||||
} catch {
|
} catch (error) {
|
||||||
// no mint-address support - the plain payRequest guess still works
|
// no mint-address support - the plain payRequest guess still works
|
||||||
|
if (!(error instanceof Error)) throw error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let fee: MintFee | null
|
let fee: MintFee | null
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ export const MSAT_PER_SAT = 1000
|
|||||||
|
|
||||||
export const msatToSats = (msat: number): number => msat / MSAT_PER_SAT
|
export const msatToSats = (msat: number): number => msat / MSAT_PER_SAT
|
||||||
|
|
||||||
export const satsToMsat = (sats: number): number =>
|
export const satsToMsat = (sats: number): number => Math.round(sats * MSAT_PER_SAT)
|
||||||
Math.round(sats * MSAT_PER_SAT)
|
|
||||||
|
|
||||||
// rounds up to the next whole sat - for an msat amount about to be
|
// rounds up to the next whole sat - for an msat amount about to be
|
||||||
// requested as an invoice, where sub-sat precision (e.g. from a mint fee's
|
// requested as an invoice, where sub-sat precision (e.g. from a mint fee's
|
||||||
// percentage cut, see grossUpForMintFee) isn't reliably payable
|
// percentage cut, see grossUpForMintFee) isn't reliably payable
|
||||||
export const ceilMsatToSat = (msat: number): number =>
|
export const ceilMsatToSat = (msat: number): number => Math.ceil(msat / MSAT_PER_SAT) * MSAT_PER_SAT
|
||||||
Math.ceil(msat / MSAT_PER_SAT) * MSAT_PER_SAT
|
|
||||||
|
|
||||||
// rounds down to the nearest whole sat - for a fee-adjusted amount shown
|
// rounds down to the nearest whole sat - for a fee-adjusted amount shown
|
||||||
// as an upper bound: rounding up there would advertise a note value that
|
// as an upper bound: rounding up there would advertise a note value that
|
||||||
|
|||||||
Reference in New Issue
Block a user