Intents and orders
What an intent is
Section titled “What an intent is”An intent is a declaration of an acceptable outcome, authorized by its owner: what must be true when it settles, not the steps to get there.
“Get me from New York to Paris tomorrow, in under eight hours, for under $800.” The traveller fixes price, timing and destination. The travel agent chooses the airlines and the connections.
On Khalani an intent escrows its source value up front and states the outcome it accepts. The hub releases the escrow only for a fill that meets that outcome. A fill that doesn’t meet it cannot execute, so the user never carries that risk.
An intent has two sides:
- Give: the escrowed source, an amount of one mToken.
- Get: the outcome it accepts. For an API order that is a rate: the least amount of the destination mToken per unit of source, on any fraction of the source that fills.
How an order becomes an intent
Section titled “How an order becomes an intent”An order created with POST /v3/orders becomes one intent on the hub, the root intent, when its deposit arrives:
- Give: the deposit, in source mTokens, less the fees withheld at publish.
- Get: the destination mToken at no less than the order’s rate, the quote less any slippage, fillable in any fraction.
- Valid until: the order’s deadline.
The order’s terms (pair, amount, rate, slippage, flat fee, accounts, deadline) were signed when the order was created and must match the deposit the user sent. No API call or transaction can change them after the deposit. fills in the order lists each fill by the intent it solved.
The intent’s rate applies to the deposit less the fees withheld at publish. The order’s terms.minRate states the same guarantee over the whole deposit, fees included, which is what the user sees.
Partial fills form a chain
Section titled “Partial fills form a chain”A rate-based intent can fill in pieces. When a solver fills part of it, the hub splits the intent in the same transaction: the filled slice’s output is credited to the order on the hub, the parent closes, and the remainder becomes a child intent. Nothing is paid out to the user until the order settles.
The child is not a new order. The hub requires it to carry the parent’s exact terms (same author, rate and deadline), so only the amount shrinks. A sequence of partial fills therefore forms a chain in which every link holds the rate of the original order:
flowchart LR
root["root intent<br/>1,000"] -- "remainder 400" --> c1["child 1<br/>400"]
c1 -- "remainder 150" --> c2["child 2<br/>150"]
c2 --> tip["tip<br/>open, filled, expired<br/>or cancelled"]
root -. "filled 600" .-> p1["credited at the rate or better"]
c1 -. "filled 250" .-> p2["credited at the rate or better"]
The API reports the whole chain as one order. Its fills list each link’s fill as it is observed.
How an intent ends
Section titled “How an intent ends”The last child in the chain is its tip. It either fills completely, reaches the deadline, or is cancelled, and one settlement transaction then closes the order:
- the filled part, priced between the order’s rate and its quote, is paid to
recipienton the destination chain, - the unfilled share of the deposit, after the flat fee, is refunded to
refundToon the source chain, - the fees are taken: the flat fee in full, the percentage fees on the filled part only.
Each order settles once. Cancels and fills are applied in sequence, so a cancel that races a fill settles what was filled and refunds the rest.