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).
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new NightInventory(
reserve):NightInventory
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
reserve |
bigint | null |
Returns
Section titled “Returns”NightInventory
Properties
Section titled “Properties”reserve
Section titled “reserve”
readonlyreserve:bigint|null
Methods
Section titled “Methods”refresh()
Section titled “refresh()”refresh(
utxos):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
utxos |
NightUtxo[] |
Returns
Section titled “Returns”void
unlocked()
Section titled “unlocked()”unlocked():
NightUtxo[]
Every unlocked coin, the reserve included.
Returns
Section titled “Returns”NightUtxo[]
lots()
Section titled “lots()”lots():
NightUtxo[]
Unlocked coins that may back an offer.
Returns
Section titled “Returns”NightUtxo[]
take()
Section titled “take()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
amount |
bigint |
undefined |
swapId |
string |
undefined |
until |
number |
undefined |
maxOver? |
bigint |
4n |
Returns
Section titled “Returns”NightUtxo[]
shortfall()
Section titled “shortfall()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
targets |
object[] |
Returns
Section titled “Returns”{ from: NightUtxo; sizes: bigint[]; } | null
lock()
Section titled “lock()”lock(
u,swapId,until):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
u |
NightUtxo |
swapId |
string |
until |
number |
Returns
Section titled “Returns”void
release()
Section titled “release()”release(
swapId):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
swapId |
string |
Returns
Section titled “Returns”void
expire()
Section titled “expire()”expire(
now):string[]
Releases locks whose offers can no longer be included; returns their swap ids.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
now |
number |
Returns
Section titled “Returns”string[]
restore()
Section titled “restore()”restore(
locks):void
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
locks |
[string, { swapId: string; until: number; }][] |
Returns
Section titled “Returns”void
dump()
Section titled “dump()”dump(): [
string, {swapId:string;until:number; }][]
Returns
Section titled “Returns”[string, { swapId: string; until: number; }][]
snapshot()
Section titled “snapshot()”snapshot():
object
Returns
Section titled “Returns”object
total:
bigint
reserve
Section titled “reserve”reserve:
bigint
available
Section titled “available”available:
bigint
locked
Section titled “locked”locked:
bigint
utxos:
number
lots:
number=lots.length
reserveShort
Section titled “reserveShort”reserveShort:
boolean