Skip to content

Show trade amounts as a % of current vault balance on the quote table#2730

Open
thedavidmeister wants to merge 3 commits into
mainfrom
2026-06-13-issue-951
Open

Show trade amounts as a % of current vault balance on the quote table#2730
thedavidmeister wants to merge 3 commits into
mainfrom
2026-06-13-issue-951

Conversation

@thedavidmeister

@thedavidmeister thedavidmeister commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

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:

  • Maximum OutputmaxOutput / output-vault balance * 100

The 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's data as the optional field formattedMaxOutputAsPercentOfVault.

The output vault is matched to the quote pair by (token, vaultId) against the order's decoded on-chain validOutputs (the pair output index addresses those, and their ordering is independent of the subgraph outputs array — 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 formattedMaxInputAsPercentOfVault field, 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 (OrderDetailTanstackOrderQuote, 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):

  • The wasm-boundary test asserts the exact computed value (maxOutput 1 / balance 10 * 100 = "10") reaches JS under the camelCase key the UI reads — proving the field survives the wasm/serde boundary (a typeof === "string" smoke check would not have caught a serialization regression).
  • A component test asserts the percentage renders inside the same cell as the Maximum Output amount, and is absent when the field is None; mutation-validated (deleting the render block makes the test fail).
  • The compiled deployable webapp bundle (.svelte-kit/output/.../[orderHash]/+page.svelte.js and the client chunk) contains the render and the formattedMaxOutputAsPercentOfVault field.

Note: the wasm bindings (packages/raindex/dist) and ui-components/dist are 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

  • Rust raindex_common order_quotes: 7 tests green (output "25"/"10"; zero output-vault balance omits the percentage; mismatched-vault fixture yields None). Input-percentage tests removed.
  • @rainlanguage/raindex: wasm builds, tsc check passes, generated .d.ts carries formattedMaxOutputAsPercentOfVault? only. Full JS suite: 124 pass.
  • @rainlanguage/ui-components: full vitest suite 641 pass, svelte-check and eslint clean.
  • webapp builds; the order-detail page bundle includes the render.

🤖 Generated with Claude Code

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>
@thedavidmeister thedavidmeister self-assigned this Jun 13, 2026
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b3ef3580-2e6c-47eb-974f-c66d93c40128

📥 Commits

Reviewing files that changed from the base of the PR and between 005b989 and 1d94658.

📒 Files selected for processing (9)
  • crates/common/src/raindex_client/order_quotes.rs
  • crates/common/src/raindex_client/orders.rs
  • crates/common/src/raindex_client/take_orders/single.rs
  • crates/common/src/raindex_client/vaults.rs
  • crates/common/src/take_orders/candidates.rs
  • crates/common/src/test_helpers.rs
  • packages/raindex/test/js_api/raindexClient.test.ts
  • packages/ui-components/src/__tests__/TanstackOrderQuote.test.ts
  • packages/ui-components/src/lib/components/detail/TanstackOrderQuote.svelte
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-13-issue-951

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

thedavidmeister and others added 2 commits June 14, 2026 18:57
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>
@thedavidmeister

Copy link
Copy Markdown
Contributor Author

screenshot
Maximum Output now shows N% of the output vault balance (drawdown view), output-only.

thedavidmeister added a commit that referenced this pull request Jun 14, 2026
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.

show trade amounts on the quote table as a % of current vault balances

1 participant