-
Notifications
You must be signed in to change notification settings - Fork 13
Open
0 / 40 of 4 issues completedDescription
Summary
Add a high‑level “take orders” builder to the SDK that:
- Discovers candidate orders for a given
(inputToken, outputToken, networkKey). - Quotes them via
quote2(outputMax,IORatio) and builds take‑order candidates. - Runs an off‑chain exact‑in simulation to derive:
- Expected output, minimum output, effective price.
- A slippage‑safe
TakeOrdersConfigV4suitable forIOrderBookV5.takeOrders3.
- Exposes this as a wasm/JS API (no UI work in this epic).
This work is implemented via smaller issues for:
- Phase 1: Directional token filters for order discovery (subgraph + local DB) and API plumbing.
- Phase 2: Take‑order candidates and quoting (turn orders + quotes into
TakeOrderCandidate[]). - Phase 3+: Exact‑in simulation + slippage mapping + js_api builder (future issues, out of scope for this PR batch).
Motivation
Today, Raindex exposes:
- Subgraph/local‑DB backed order discovery (
GetOrdersFilters/SgOrdersListFilterArgs). - On‑chain pricing via
quote2(get_order_quotes,RaindexOrder::get_quotes). - Low‑level ABI helpers (
getTakeOrders3Calldata).
But there is no single SDK call for:
“Given network + tokens + amount + slippage, tell me the expected output and give me calldata/config for
takeOrders3using the best available orders.”
This epic adds that orchestration while keeping:
- Directional token filters and order discovery cleanly abstracted.
- Economic logic (quotes, simulation, slippage) as pure functions.
- js_api as a thin orchestration/interop layer.
Assumptions (to validate, see design questions)
- Amount semantics (tentative): v1 will be exact‑in –
amountis the taker’s inputToken amount (tokens they give). - Multi‑orderbook behavior (tentative):
- For a given network, we fetch orders from all configured orderbooks.
- We pool take‑order candidates across those books for a pair.
- We sort candidates globally by
ratioascending (cheapest first), even if that mixes orderbooks.
- Simulation & slippage:
- We will simulate off‑chain using
quote2outputs (outputMax,IORatio) to compute a blended expected price and output. - We will map those into
maximumIORatio,minimumInput(minOut), andmaximumInput, and back this with local‑EVM integration tests that compare outcomes totakeOrders3.
- We will simulate off‑chain using
If any of these assumptions change, the architecture (filters → candidates → simulation → config) should remain valid; only the simulation/mapping strategy and builder API surface need to be adjusted.
Scope of this issue
In scope:
- Rust + wasm/JS code changes in:
crates/subgraphcrates/commoncrates/quotecrates/js_api
- New pure types/functions:
- Directional order filters (
input_tokens/output_tokens) wired through subgraph + local‑DB. TakeOrderCandidateand builders derived fromRaindexOrder+get_quotes.- A pure exact‑in simulator and a pure
TakeOrdersConfigV4mapper.
- Directional order filters (
- js_api builder:
buildTakeOrdersExactIn(params)→{ expectedOutput, minimumOutput, effectivePrice, takeOrdersConfig }.
Out of scope:
- Webapp / Svelte UI changes.
- Tauri / desktop app wiring.
- UX flows, routing, or state management outside the wasm/JS API surface.
Sub‑issues
- Phase 1 – Directional token filters for order discovery
- Implemented in
TAKE_ORDERS_SDK_PHASE1_FILTERS_ISSUE.md.
- Implemented in
- Phase 2 – Take‑order candidates and quoting
- Implemented in
TAKE_ORDERS_SDK_PHASE2_CANDIDATES_ISSUE.md.
- Implemented in
- Phase 3 – Exact‑in simulation + slippage + js_api builder
- To be split into separate issues once Phase 1 and 2 are stable.
Sub-issues
Metadata
Metadata
Assignees
Labels
No labels