Skip to content

Spec: auto-routing orders (+ tighten ckBTC lot)#190

Draft
gregorydemay wants to merge 3 commits into
mainfrom
dex_DEFI-2861_auto-routing-orders
Draft

Spec: auto-routing orders (+ tighten ckBTC lot)#190
gregorydemay wants to merge 3 commits into
mainfrom
dex_DEFI-2861_auto-routing-orders

Conversation

@gregorydemay

Copy link
Copy Markdown
Contributor

Adds the spec for auto-routing orders: placing an order on a non-listed spoke↔spoke pair (e.g. ICP/ckBTC) that the canister executes transparently as two real orders meeting at the ckUSDT hub, in a single hop.

Key decisions captured in the spec, in the order they were worked out this session:

  • Topology is a star quoted in ckUSDT, so the transit token is always the hub — "discovery" is a hub lookup, not a graph search; scope is a single hop.
  • Execution is a synchronous atomic taker (multi-leg fill-or-kill): plan both legs read-only, then kill-or-apply in one message; settlement is deferred and chunked via the existing settling drain.
  • The two book grids cannot generally chain to exactly zero leftover transit; the bounded residual is returned to the user as change in the hub token (ckUSDT), which is the fairest and simplest disposition. Strict-kill, sweep-to-fee-pool and a tolerance band were all considered and rejected.
  • Transparent entry point: same endpoint and request type as a direct order; one id back; the canister auto-detects direct vs routable.
  • Identity: a filled route is recorded as its two leg orders (where prices/fees are unambiguous); a route_id resolves the returned id to the legs; a killed route is a single Expired record.

Also folds in a small independent listing fix: the ckBTC/ckUSDT lot was retightened to 0.00001 BTC (tick 0.1 USDT), which also shrinks the worst-case routing residual ~10×.

One sub-decision is intentionally left open in the spec (Implementation → Limit semantics): whether the limit is expressed as an input budget or a synthetic limit price. Recommendation noted inline.

Draft — spec only, no implementation yet.

gregorydemay and others added 2 commits June 29, 2026 08:38
The launch-basket ckBTC lot (0.0001 BTC) priced one lot at ~$6-10, coarser
than the doc's own $0.10-$1 lot-notional guidance and 10x Binance's. Rebalance
to tick 0.1 USDT / lot 0.00001 BTC, keeping tick x lot = 10^8 so the
settlement-exactness invariant still holds.

DEFI-2861

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Spec for placing an order on a non-listed spoke/spoke pair, routed through the
ckUSDT hub in a single hop. Covers the synchronous atomic taker execution model
(plan + kill-or-apply, deferred chunked settlement), the discrete-lot transit
residual returned to the user as hub change, the transparent entry point, and
the route_id / two-leg / Expired-on-kill identity model.

DEFI-2861

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 29, 2026 08:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new design/spec document describing auto-routing orders (synthetic spoke↔spoke orders executed atomically as two ckUSDT-hub legs), and updates docs navigation plus an admin-facing listing parameter tweak for ckBTC/ckUSDT.

Changes:

  • Introduces spec DEFI-2861 — Auto-Routing Orders covering topology assumptions, FOK two-leg execution, residual disposition, and identity model (route_id).
  • Adds the new spec to the docs sidebar (SUMMARY).
  • Updates the documented ckBTC/ckUSDT tick/lot values in the admin usage table.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
docs/src/usage/for-admins.md Updates the documented ckBTC/ckUSDT tick/lot parameters.
docs/src/SUMMARY.md Adds the DEFI-2861 spec page to the documentation index.
docs/src/development/specs/DEFI-2861-auto-routing-orders.md New spec defining requirements and design decisions for auto-routing spoke↔spoke orders via the ckUSDT hub.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to +27
The hard constraint, from the ticket: this must be **all-or-nothing**. The user must
never be left holding the transit token (ckUSDT) — a token they neither provided nor
requested.
Comment on lines +86 to +87
and may additionally receive **bounded change in the hub token (ckUSDT)** — the leftover
transit, strictly less than one funding-leg lot. The user never ends with an unrequested
Comment on lines +172 to +173
*Leg 1 — sell ckBTC on `ckBTC/ckUSDT`* (tick `0.1 USDT`, **lot `0.00001 BTC`** — the
tightened value; the previous `0.0001 BTC` lot made this ~10× worse). Best bid
Comment on lines +237 to +240
Independently of routing, the launch-basket ckBTC lot (`0.0001 BTC`, ~$6–$10/lot) was
coarser than the doc's own `$0.10–$1` guidance and 10× Binance's. It has been retightened
to **tick `0.1 USDT` / lot `0.00001 BTC`** (`docs/src/usage/for-admins.md`), keeping
`tick × lot = 10⁸` so the settlement-exactness invariant holds. This also reduces the
| | Coinbase `ICP-USD` | `0.001` | `0.0001` | `$1` |
| | Kraken `ICPUSD` | `0.001` | `0.00000001` | `$0.50` |
| **ckBTC/ckUSDT** | OISY TRADE | `0.01` USDT = `10_000` | `0.0001` BTC = `10_000` | `$5` = `5_000_000` |
| **ckBTC/ckUSDT** | OISY TRADE | `0.1` USDT = `100_000` | `0.00001` BTC = `1_000` | `$5` = `5_000_000` |
@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

canbench 🏋 (dir: canister) 4857ee7 2026-06-29 09:07:43 UTC

canister/canbench_results.yml is up to date
📦 canbench_results_benchmark.csv available in artifacts

---------------------------------------------------

Summary:
  instructions:
    status:   No significant changes 👍
    counts:   [total 14 | regressed 0 | improved 0 | new 0 | unchanged 14]
    change:   [max +365.22K | p75 +2.11K | median 0 | p25 0 | min -32]
    change %: [max +1.58% | p75 +0.21% | median 0.00% | p25 0.00% | min -0.00%]

  heap_increase:
    status:   No significant changes 👍
    counts:   [total 14 | regressed 0 | improved 0 | new 0 | unchanged 14]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

  stable_memory_increase:
    status:   No significant changes 👍
    counts:   [total 14 | regressed 0 | improved 0 | new 0 | unchanged 14]
    change:   [max 0 | p75 0 | median 0 | p25 0 | min 0]
    change %: [max 0.00% | p75 0.00% | median 0.00% | p25 0.00% | min 0.00%]

---------------------------------------------------
CSV results saved to canbench_results.csv

Lock the limit-price decision to an input budget (reserve price x quantity of
the input token; fund the smallest whole-lot sale netting the destination cost,
capped at the reservation, else kill), with a worked buy example. Record the
two-taker-fee / gross-matched-target contract (R9) and move the synthetic
limit-price alternative to Discussed Alternatives.

DEFI-2861

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants