Skip to content

MakerSolver

A maker solver over a wallet runtime: builds and proves maker offers from distinct NIGHT coins, completes counterparty offers, sponsors DUST for balanced fills, watches settlement and reports inventory. Everything our own solver does goes through this class (no private hooks).

new MakerSolver(wallet, cfg): MakerSolver

Parameter Type
wallet WalletRuntime
cfg MakerConfig

MakerSolver

readonly inventory: NightInventory


readonly giveToken: string

The unshielded token given (MakerConfig.giveToken).


readonly wallet: WalletRuntime


readonly cfg: MakerConfig

get networkId(): string

string

start(): Promise<void>

Follows the chain and reports settlements and expiries to on(...) listeners.

Promise<void>


stop(): void

void


on(fn): () => void

Parameter Type
fn (s) => void

() => void


refreshInventory(): Promise<void>

Promise<void>


prepareLots(sizes, opts?): Promise<{ txHashes: string[]; }>

Splits NIGHT into offer-sized coins (the ladder's distinct coins). Normally only coins outside the reserve are split; fromReserve (bootstrap, when the reserve is the only coin) re-outputs the reserve in full beside the lots, restarting its DUST generation. Up to two lots per transaction, each waiting for the previous; fewer when a node would refuse the split as too slow to check for its size (see fittedSplit).

Parameter Type
sizes bigint[]
opts? { fromReserve?: boolean; timeoutMs?: number; }
opts.fromReserve? boolean
opts.timeoutMs? number

Promise<{ txHashes: string[]; }>


topUpLots(targets): Promise<string | null>

Keeps offer-sized coins available (replenishment): each fill spends a coin and returns only its change, so free coins of each target size run out unless the large remainder is split again. Splits at most two coins per call; call it periodically.

Parameter Type
targets object[]

Promise<string | null>


buildMakerOffer(terms, opts?): Promise<MadeOffer>

buildMakerOffer (the initSwap → finalizeRecipe shape): a proven leg giving terms.give NIGHT to terms.giveTo and wanting terms.want USDM, of which the fee outputs are part. Its coins stay locked until it settles or its TTL passes.

Parameter Type
terms SwapTerms
opts? { background?: boolean; }
opts.background? boolean

Promise<MadeOffer>


sponsorFees(swapId, txHex, maxDust?, requireOutputs?): Promise<{ txHash: string; dustFee: bigint; bytes: number; }>

Sponsorship: the user's wallet balanced our offer without paying fees; add a DUST-only intent priced on the whole transaction and submit. Refuses transactions that do not contain an outstanding offer of ours, are not otherwise balanced, or would cost more than maxDust.

Parameter Type Default value
swapId string undefined
txHex string undefined
maxDust? bigint ...
requireOutputs? object[] []

Promise<{ txHash: string; dustFee: bigint; bytes: number; }>


completeOffer(offer, opts?): Promise<{ txHash: string; dustFee: bigint; bytes: number; }>

completeOffer (balanceFinalizedTransaction → finalizeRecipe → submit): fills a counterparty's offer from our inventory, paying the DUST, optionally taking a fee output from the surplus. The taker flow.

Parameter Type
offer string
opts? { fee?: { token: string; amount: bigint; to: ShieldedRecipient; }; ttlMs?: number; }
opts.fee? { token: string; amount: bigint; to: ShieldedRecipient; }
opts.fee.token string
opts.fee.amount bigint
opts.fee.to ShieldedRecipient
opts.ttlMs? number

Promise<{ txHash: string; dustFee: bigint; bytes: number; }>


buildOffer(fillId, terms, opts?): Promise<MadeOffer>

rfq.accept (solver_offer): the leg for the accepted quote. Buy side (the user receives NIGHT): the maker leg with the NIGHT output to the quoted address. Sell side (the user receives USDM): a leg spending our USDM into the user's shielded output and the fee outputs, wanting NIGHT to us; the wallet covers that NIGHT deficit (balanceSealedTransaction spending its NIGHT).

Parameter Type
fillId string
terms MakeTerms
opts? { background?: boolean; }
opts.background? boolean

Promise<MadeOffer>


completeJob(fillId, offers, fees, opts?): Promise<CompletedJob>

Completes the offers of a job with our leg. expect bounds what the offers may take from us per token (see JobExpect: the quote's or the ladder's terms); an offer outside it, or one that does not settle entirely in its guaranteed section, is refused before any coin is taken. Without expect (and without surplusOnly) a job could spend anything we hold: callers that pay out pass one.

Parameter Type
fillId string
offers string[]
fees SwapFeeOutput[]
opts? { surplusOnly?: boolean; ttlMs?: number; maxDust?: bigint; expect?: JobExpect; }
opts.surplusOnly? boolean
opts.ttlMs? number
opts.maxDust? bigint
opts.expect? JobExpect

Promise<CompletedJob>


estimateFee(tx): bigint

estimateFee: Specks for a sealed transaction (accurate for proven ones).

Parameter Type
tx string | SealedTx

bigint


dustBudget(): object

dustBudget: DUST on hand against the recent sponsored cost per fill.

object

balance: bigint

perFillEstimate: bigint

fillsCovered: number


watchSettlement(swapId, timeoutMs?): Promise<MakerStatus>

watchSettlement: resolves when the offer settles, expires or fails on chain.

Parameter Type Default value
swapId string undefined
timeoutMs? number 600_000

Promise<MakerStatus>


release(swapId): void

Parameter Type
swapId string

void


outstandingCount(): number

number


snapshot(): MakerInventory

MakerInventory