Skip to content

SwapClient

new SwapClient(opts): SwapClient

Parameter Type
opts SwapClientOptions

SwapClient

readonly relayUrl: string


readonly opts: SwapClientOptions

get appId(): string

string

network(): Promise<NetworkInfo>

Promise<NetworkInfo>


token(symbolOrRaw): Promise<NetworkToken>

A token by symbol or raw type (from /network, cached).

Parameter Type
symbolOrRaw string

Promise<NetworkToken>


settlements(asked?): ("solver_offer" | "user_offer")[]

The settlements this client can make: solver_offer only with a leg checker (draft §10).

Parameter Type
asked? ("solver_offer" | "user_offer")[]

("solver_offer" | "user_offer")[]


quote(p): Promise<QuoteResponse>

POST /api/v2/rfq: every quote, best first, and the relay's attestation of them. The response is returned only after the client's checks of it (§8 of the MIP draft): the attestation is signed with the relay key this client holds and states what was asked for; every quote repeats those terms and, when firm, carries a valid signature; the attestation commits to exactly these quotes, and the one it calls best pays the most. A response that fails any of them is a RelayError (502).

Parameter Type
p QuoteParams

Promise<QuoteResponse>


static best(q): Quote | null

The quote the relay ranked best (null without quotes): the one the attestation names.

Parameter Type
q QuoteResponse

Quote | null


accept(requestId, quoteDigest, o?): Promise<Accepted>

POST /api/v2/rfq/:id/accept: reserves the quote with this digest (quoteDigest of a returned quote). For solver_offer the response waits for the solver's sealed leg (tx); for user_offer it carries the terms.

Parameter Type
requestId string
quoteDigest string
o? { dustMode?: "wallet" | "sponsored"; }
o.dustMode? "wallet" | "sponsored"

Promise<Accepted>


event(fillId, stage, clientToken?): Promise<void>

Reports a client stage; best effort (status tracking does not depend on it).

Parameter Type
fillId string
stage ClientStage
clientToken? string | undefined

Promise<void>


execute(wallet, accepted, o): Promise<Executed>

The wallet's part of an accepted fill. Wallet failures are thrown as SwapWalletError (failure: wallet_rejected, insufficient_funds, no_dust, proof_failed, …) after the relay is told (rejected or failed); relay refusals as RelayError.

Parameter Type
wallet ConnectedAPI
accepted Accepted
o ExecuteOptions

Promise<Executed>


fill(fillId): Promise<FillStatus>

Parameter Type
fillId string

Promise<FillStatus>


track(fillId, onStatus?, o?): Promise<FillStatus>

Follows a fill until finalized, failed or expired and resolves with that status. The relay's WebSocket pushes every change; polling backs it up (slowly while the socket is open, every pollMs without one). onStatus sees each new state.

Parameter Type
fillId string
onStatus? (s) => void
o? { timeoutMs?: number; signal?: AbortSignal; }
o.timeoutMs? number
o.signal? AbortSignal

Promise<FillStatus>


swap(wallet, p): Promise<SwapResult>

Quote, accept the best quote, the wallet's part, and track to a final state.

Parameter Type
wallet ConnectedAPI
p SwapParams

Promise<SwapResult>


postLimitOffer(wallet, p): Promise<PostedOffer>

Rests an offer in the relay's book: the wallet makes it (makeIntent, the wanted tokens to its own address) and the relay screens and lists it for the matcher. The offer lasts until its intent's TTL, which the wallet sets (MIP-0005).

Parameter Type
wallet ConnectedAPI
p LimitOfferParams

Promise<PostedOffer>


cancelLimitOffer(offerId, cancelToken?): Promise<void>

Cancels a resting offer: by the app's key, or by the cancelToken its post returned.

Parameter Type
offerId string
cancelToken? string

Promise<void>


book(): Promise<BookEntry[]>

Promise<BookEntry[]>