Show trade amounts as a % of current vault balance on the quote table#2730
Show trade amounts as a % of current vault balance on the quote table#2730thedavidmeister wants to merge 3 commits into
Conversation
On the order quotes table, each pair's maximum output and maximum input is now also shown as a percentage of the current balance of the vault it draws from, so large-relative-to-vault trades (drawdown risk) are easy to spot. The percentage is computed in the binding layer (Float division/multiplication is only available there, not in the TS Float API) and attached to each quote's data as `formattedMaxOutputAsPercentOfVault` / `formattedMaxInputAsPercentOfVault`. It reuses the already-fetched subgraph vault balances - no extra network calls. The matching is by (token, vaultId) against the order's decoded on-chain validInputs/validOutputs, since the pair indices address those and their ordering is independent of the subgraph inputs/outputs arrays. When a vault can't be matched or its balance is zero (percentage undefined) the field is omitted and the UI simply shows the absolute amount alone. Tests: - order_quotes.rs: a matching-vault order yields exact "25"/"40" percentages for maxOutput 1 / balance 4 and maxInput 2 / balance 5; a zero output-vault balance omits only the output percentage; the existing mismatched-vault fixture asserts both percentages are None (guards against blind index match). - raindexClient.test.ts (wasm boundary): matching vaults make both percentage fields present non-empty strings. - TanstackOrderQuote.test.ts: renders "25% of vault" / "40% of vault" when the fields are present, and renders neither element when they are absent. Fixes #951 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 8 minutes and 53 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
For #951 the signal is drawdown: depletion of the OUTPUT vault you sell from. The input percentage measured inflow/accumulation, not drawdown, and was misleading, so it is removed entirely - the Rust field, its computation, the wasm/.d.ts surface, the Svelte render, and the input-specific tests. Only `formattedMaxOutputAsPercentOfVault` (maxOutput / output-vault balance * 100) remains. The output percentage already flowed correctly from the binding to the `TanstackOrderQuote` cell on the order detail page; this hardens the proof that it reaches the running app rather than only a mocked unit test: - The wasm-boundary test now asserts the exact computed value reaches JS (maxOutput 1 / output-vault balance 10 * 100 = "10") under the camelCase key the UI reads, instead of a `typeof === "string"` smoke check that would miss a serialization regression. - The component test asserts the percentage renders inside the same cell as the Maximum Output amount (mutation-validated: deleting the render block fails it), and that no input percentage renders. Verified the compiled deployable webapp bundle (the order-detail `+page.svelte` entry and client chunk) contains the render and the field. Fixes #951 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Fixes #951
What the issue wanted
On the webapp quote table, show each trade's amount as a percentage of the current vault balance (alongside the absolute amount), so it's easy to visually spot trades that are large relative to their vaults — i.e. drawdown management.
Output-only (revised)
Drawdown is depletion: it's the output vault you sell from that gets drawn down. The input side measures inflow/accumulation, not drawdown, so it was misleading. This PR now shows only the output percentage:
maxOutput / output-vault balance * 100The percentage is computed in the binding layer (
crates/common), because Float division/multiplication is only exposed on the Rust side, not in the TS Float API. It reuses the already-fetched subgraph vault balances — no extra network calls — and is attached to each quote'sdataas the optional fieldformattedMaxOutputAsPercentOfVault.The output vault is matched to the quote pair by
(token, vaultId)against the order's decoded on-chainvalidOutputs(the pair output index addresses those, and their ordering is independent of the subgraphoutputsarray — so an index-only match would be wrong). When the vault can't be matched or its balance is zero (percentage undefined / division by zero), the field is omitted and the UI shows the absolute amount alone.The
formattedMaxInputAsPercentOfVaultfield, its Rust computation, the.d.ts/wasm surface, the Svelte render, and the input-specific tests have all been removed.Where it renders (rendering fix)
The output percentage renders as a small secondary line directly under the Maximum Output amount in
TanstackOrderQuote— the quote table on the order detail page (OrderDetail→TanstackOrderQuote, route/orders/[chainId]-[raindex]-[orderHash]). E.g.25% of vault.The render and data path were verified end-to-end against a fresh build (not just a mocked unit test):
maxOutput 1 / balance 10 * 100 = "10") reaches JS under the camelCase key the UI reads — proving the field survives the wasm/serde boundary (atypeof === "string"smoke check would not have caught a serialization regression).None; mutation-validated (deleting the render block makes the test fail)..svelte-kit/output/.../[orderHash]/+page.svelte.jsand the client chunk) contains the render and theformattedMaxOutputAsPercentOfVaultfield.Note: the wasm bindings (
packages/raindex/dist) andui-components/distare gitignored and regenerated on every build/deploy; the field appears in the running app once those are rebuilt, which the preview/prod Vercel build (script/vercel-build.sh: raindex → ui-components → webapp) does.Verification
raindex_commonorder_quotes: 7 tests green (output"25"/"10"; zero output-vault balance omits the percentage; mismatched-vault fixture yieldsNone). Input-percentage tests removed.@rainlanguage/raindex: wasm builds,tsccheck passes, generated.d.tscarriesformattedMaxOutputAsPercentOfVault?only. Full JS suite: 124 pass.@rainlanguage/ui-components: full vitest suite 641 pass,svelte-checkand eslint clean.🤖 Generated with Claude Code