Skip to content

RAI-752 use REST token details in website - #211

Merged
findolor merged 3 commits into
mainfrom
feature/rai-752-token-details-website
Jul 2, 2026
Merged

RAI-752 use REST token details in website#211
findolor merged 3 commits into
mainfrom
feature/rai-752-token-details-website

Conversation

@findolor

@findolor findolor commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Dependent PRs

Motivation

RAI-752 moves ST0x token detail data behind the REST API. The website was still reading SFT product data directly through getSfts / getSftById, including holder lists, transfer arrays, and deposit/withdraw rows.

Solution

  • Add typed REST client methods for /v1/tokens/details and /v1/tokens/{address}/details.
  • Allow the token-details endpoints through the website /api/st0x proxy with shared caching.
  • Rewire the existing sfts query/store path to use REST token details while preserving the current vault-shaped UI contract.
  • Update landing, sidebar, dashboard, trade, and proofs consumers to use REST aggregate fields and recent activity.
  • Preserve wallet holdings through wrapped-token multicall reads without falling back to the removed holder list.
  • Update the wrap-ratio E2E stub and add proxy allowlist coverage for token details.

Checks

  • bun run test -- run tests/lib/api/st0x-proxy.test.ts
  • bunx eslint src/lib/api/st0xApi.ts src/lib/queries/vaults.ts src/lib/types/OffchainAssetReceiptVault.ts 'src/routes/api/st0x/[...path]/+server.ts' 'src/routes/(main)/+page.svelte' 'src/routes/(main)/dashboard/+page.svelte' 'src/routes/(main)/trade/[id]/+page.svelte' 'src/routes/(main)/trade/[id]/proofs/+layout.svelte' src/lib/components/Sidebar.svelte tests/lib/api/st0x-proxy.test.ts tests/integration/ui/wrapRatio.spec.ts
  • bunx svelte-check --no-tsconfig --ignore "tests,node_modules,.svelte-kit,build" --threshold error
  • git diff --check origin/main...HEAD

bun run check is still blocked locally by the existing missing @playwright/test type-resolution errors under tests/integration/ui.

Summary by CodeRabbit

  • New Features
    • Token details and trade views now include expanded on-chain metrics: holder count, total transfers, activity volume, and bridged supply.
  • Improvements
    • Token lists, dashboard, and supply/distribution pages now use ST0x REST token details for consistent metrics and calculations.
    • Proof/route data handling now prefers live query results with safe fallbacks; wallet holdings gracefully degrades to zero balances on multicall failure.
    • Sidebar sorting and “Bridged On-Chain”/market cap calculations now use bridged supply.
  • Performance/Robustness
    • Improved proxy caching for token detail responses, only applying cache headers for valid, readable upstream JSON.

@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
st0x Ready Ready Preview, Comment Jun 30, 2026 10:12am

Request Review

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 47a4c667-75ce-40e8-a527-514cad810877

📥 Commits

Reviewing files that changed from the base of the PR and between c9ee118 and b9cab7a.

📒 Files selected for processing (4)
  • src/lib/api/st0xApi.ts
  • src/lib/queries/vaults.ts
  • src/routes/(main)/+page.svelte
  • src/routes/(main)/trade/[id]/+page.svelte
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/lib/api/st0xApi.ts
  • src/routes/(main)/+page.svelte
  • src/lib/queries/vaults.ts

📝 Walkthrough

Walkthrough

Adds ST0x token-details REST endpoints, typed client helpers, vault mapping, new vault fields, updated UI consumers, a dashboard fallback change, and expanded proxy/integration tests.

Changes

ST0x REST API token details migration

Layer / File(s) Summary
Token details types, proxy routes, and REST client functions
src/lib/api/st0xApi.ts, src/routes/api/st0x/[...path]/+server.ts
Defines token-detail response types, allows the new proxied details routes, adds cache gating for list responses, and exposes browser-only client helpers for token-details list and by-address fetches.
Vault query rewiring and REST-to-vault mapping
src/lib/queries/vaults.ts
Adds mapping helpers and rewrites the SFT queries to fetch ST0x token details, converting summary and activity payloads into OffchainAssetReceiptVault values for list and single-token lookups.
Landing page and sidebar metrics
src/lib/types/OffchainAssetReceiptVault.ts, src/routes/(main)/+page.svelte, src/lib/components/Sidebar.svelte
Extends the vault type with REST-sourced metrics and updates the landing-page token table and sidebar sorting to read the new fields directly.
Trade page and proofs token state
src/routes/(main)/trade/[id]/+page.svelte, src/routes/(main)/trade/[id]/proofs/+layout.svelte
Updates trade-page supply metrics to use the new count and supply fields, and changes the proofs layout to prefer fetched token data while merging cached vault fields and token config fallbacks.
Dashboard multicall fallback update
src/routes/(main)/dashboard/+page.svelte
Removes the subgraph token-holder recovery path so multicall failures return $sfts-derived rows with zero wallet balances and resolved token metadata.
Proxy and integration tests for token details endpoints
tests/lib/api/st0x-proxy.test.ts, tests/integration/ui/wrapRatio.spec.ts
Adds proxy tests for cached and non-cached token-details responses, and updates the wrap-ratio Playwright test to stub the new REST details routes while removing the Goldsky subgraph stub.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • SARKEX/st0x#131: Modifies the same src/routes/(main)/trade/[id]/proofs/+layout.svelte currentToken initialization flow and overlaps with this PR’s cached-vs-live data merge logic.
  • SARKEX/st0x#197: The wrap-ratio test updates mock the same tokens/details REST routes introduced here to drive the UI.
  • SARKEX/st0x#199: Also extends the ST0x proxy/client surface in src/routes/api/st0x/[...path]/+server.ts and src/lib/api/st0xApi.ts with additional /api/st0x REST endpoints.

Suggested reviewers

  • Siddharth2207
  • alastairong1

Poem

🐇 Hop, hop — the details now arrive,
From REST-wired paths the token facts revive.
Counts and volumes dance in tidy view,
And caching keeps the proxy fast and true.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: switching the website to REST token details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/rai-752-token-details-website

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/routes/(main)/dashboard/+page.svelte (1)

408-421: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Do not replace real holdings with synthetic zero balances on multicall failure.

The catch path currently returns valid-looking holdings with walletBalance: 0n, which can collapse the portfolio into a false “no holdings” state during transient RPC outages. Surface the failure instead of committing incorrect balances.

Suggested fix
 				} catch (error) {
 					console.error('Multicall failed for wallet holdings:', error);
-					return $sfts.map((sft) => {
-						const tokenConfig = findApiTokenByAnyAddress(ALL_TOKENS, sft.address);
-						return {
-							id: sft.id,
-							address: tokenConfig?.address ?? sft.address,
-							name: tokenConfig?.name ?? sft.name,
-							symbol: tokenConfig?.symbol ?? sft.symbol,
-							walletBalance: 0n,
-							decimals: 18
-						};
-					});
+					throw error instanceof Error
+						? error
+						: new Error('Multicall failed for wallet holdings');
 				}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routes/`(main)/dashboard/+page.svelte around lines 408 - 421, The catch
block for the multicall failure in the wallet holdings section is returning
synthetic SFT data with walletBalance: 0n, which masks the actual error and
causes the portfolio to incorrectly display zero holdings. Instead of returning
this fake data, rethrow the error or allow it to propagate so the caller can
handle the failure appropriately and display the correct error state to the user
rather than committing incorrect zero balances to the portfolio.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/lib/queries/vaults.ts`:
- Line 61: The `tokenDetailsSummaryToVault` function is hard-setting
deployTimestamp to an empty string when detail is not available, which causes
list-backed views to lose created-at data. In the function where deployTimestamp
is mapped (around line 61 in the current diff, and also in lines 83-85), replace
the fallback of empty string with logic that preserves the deployTimestamp from
the summary data when detail is unavailable. This ensures that the created-at
information is retained even when the detail object is missing, allowing
list-backed views consuming sft.deployTimestamp to access the proper timestamp
data.

In `@src/routes/`(main)/+page.svelte:
- Around line 150-152: The totalSupply field calculation directly calls BigInt()
on potentially malformed string values from sft.bridgedSupply or sft.totalShares
without validation, which will throw an error if the API returns non-numeric,
decimal, or whitespace-only strings. Replace the BigInt() call in the
formatUnits(BigInt(sft.bridgedSupply ?? sft.totalShares), 18) expression with
toBigInt() imported from src/lib/utils/tokenMath.ts, which safely handles
invalid inputs and returns null on error, preventing runtime failures during
render.

---

Outside diff comments:
In `@src/routes/`(main)/dashboard/+page.svelte:
- Around line 408-421: The catch block for the multicall failure in the wallet
holdings section is returning synthetic SFT data with walletBalance: 0n, which
masks the actual error and causes the portfolio to incorrectly display zero
holdings. Instead of returning this fake data, rethrow the error or allow it to
propagate so the caller can handle the failure appropriately and display the
correct error state to the user rather than committing incorrect zero balances
to the portfolio.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c75d3583-dd1c-4be3-a0c9-5c4b578a614f

📥 Commits

Reviewing files that changed from the base of the PR and between 53f78f8 and 725ef5d.

📒 Files selected for processing (11)
  • src/lib/api/st0xApi.ts
  • src/lib/components/Sidebar.svelte
  • src/lib/queries/vaults.ts
  • src/lib/types/OffchainAssetReceiptVault.ts
  • src/routes/(main)/+page.svelte
  • src/routes/(main)/dashboard/+page.svelte
  • src/routes/(main)/trade/[id]/+page.svelte
  • src/routes/(main)/trade/[id]/proofs/+layout.svelte
  • src/routes/api/st0x/[...path]/+server.ts
  • tests/integration/ui/wrapRatio.spec.ts
  • tests/lib/api/st0x-proxy.test.ts

Comment thread src/lib/queries/vaults.ts Outdated
Comment thread src/routes/(main)/+page.svelte
Siddharth2207

This comment was marked as duplicate.

@Siddharth2207

Copy link
Copy Markdown
Contributor

Two small nits before merge:

  1. Trade page supply — landing uses bridgedSupply ?? totalShares, but the Supply tab on trade/[id]/+page.svelte still uses totalShares only. Same token can show different supply on landing vs trade.

  2. deployTimestamp on listcreateSftsQuery maps without detail, so tokenDetailsSummaryToVault sets deployTimestamp: ''. List-backed views lose created-at unless the list API includes it on the summary type.

@findolor
findolor merged commit d75ad90 into main Jul 2, 2026
6 of 7 checks passed
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