Skip to content

NightInventory

The solver's NIGHT (or the unshielded token it gives) as coins. Every outstanding offer locks its own UTXOs (two offers sharing a coin cannot both settle, and merging them throws), and the DUST-generating reserve is never spent: spending a registered UTXO stops its generation and its DUST decays. The reserve is the largest UTXO worth at least reserve; a token other than NIGHT generates no DUST and has none (null).

new NightInventory(reserve): NightInventory

Parameter Type
reserve bigint | null

NightInventory

readonly reserve: bigint | null

refresh(utxos): void

Parameter Type
utxos NightUtxo[]

void


unlocked(): NightUtxo[]

Every unlocked coin, the reserve included.

NightUtxo[]


lots(): NightUtxo[]

Unlocked coins that may back an offer.

NightUtxo[]


take(amount, swapId, until, maxOver?): NightUtxo[]

Picks coins for amount and locks them until until. Prefers the smallest coin that covers it without tying up more than maxOver × amount (least NIGHT locked by an offer that may never be taken), then a combination of such coins, and only then a larger coin.

Parameter Type Default value
amount bigint undefined
swapId string undefined
until number undefined
maxOver? bigint 4n

NightUtxo[]


shortfall(targets): { from: NightUtxo; sizes: bigint[]; } | null

What a top-up should split, if anything: for each target size with fewer free coins of about that size (within 2×) than wanted, one more coin; taken from the largest free coin outside the reserve when it is big enough to leave change.

Parameter Type
targets object[]

{ from: NightUtxo; sizes: bigint[]; } | null


lock(u, swapId, until): void

Parameter Type
u NightUtxo
swapId string
until number

void


release(swapId): void

Parameter Type
swapId string

void


expire(now): string[]

Releases locks whose offers can no longer be included; returns their swap ids.

Parameter Type
now number

string[]


restore(locks): void

Parameter Type
locks [string, { swapId: string; until: number; }][]

void


dump(): [string, { swapId: string; until: number; }][]

[string, { swapId: string; until: number; }][]


snapshot(): object

object

total: bigint

reserve: bigint

available: bigint

locked: bigint

utxos: number

lots: number = lots.length

reserveShort: boolean