Skip to content

Conversation

@findolor
Copy link
Collaborator

@findolor findolor commented Dec 22, 2025

Motivation

See issues:

The SDK previously lacked a convenient way to query token metadata from YAML configuration. Users needed to work through the GUI layer or manually parse YAML to access token information. Additionally, there was no direct way to access the shared OrderbookYaml instance from a DotrainRegistry for querying networks, tokens, and orderbooks.

This PR addresses these gaps by:

  1. Providing a unified TokenInfoExtended type that includes chain_id alongside other token metadata
  2. Adding OrderbookYaml.getTokens() for fetching all tokens including remote tokens from using-tokens-from URLs
  3. Adding DotrainRegistry.getOrderbookYaml() to access the shared settings YAML instance

Solution

New Shared Type: TokenInfoExtended

Introduced a new struct in crates/common/src/erc20.rs that consolidates token information:

  • key, address, decimals, name, symbol, chain_id
  • Replaces the local TokenInfo struct that was defined in the GUI module
  • Used consistently across GUI methods (getTokenInfo, getAllTokenInfos, getAllTokens) and the new YAML methods

New Method: OrderbookYaml.getTokens()

  • Async method that returns TokenInfoExtended[]
  • Automatically fetches remote tokens from using-tokens-from URLs if configured
  • Merges local and remote tokens before returning
  • Includes comprehensive error handling for missing required fields

New Method: DotrainRegistry.getOrderbookYaml()

  • Returns an OrderbookYaml instance from the registry's shared settings
  • Enables direct querying of tokens, networks, orderbooks without going through GUI layer

UI Component Updates

Updated Svelte components to use TokenInfoExtended:

  • SelectToken.svelte
  • TokenSelectionModal.svelte
  • DeploymentSteps.svelte
  • TokenSelectionModal.test.ts

Documentation

Updated architecture and README documentation to reflect the new APIs.

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • Added chain ID field to token information for enhanced network context.
    • Introduced getOrderbookYaml() method on registry to access token configurations.
    • Introduced getTokens() method to retrieve all tokens, including support for remote token sources.
  • Documentation

    • Updated API documentation to reflect new token access methods and capabilities.
  • Tests

    • Added comprehensive test coverage for token retrieval, including remote token fetching scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@findolor findolor requested review from 0xgleb and hardyjosh December 22, 2025 10:37
@findolor findolor self-assigned this Dec 22, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

Walkthrough

A new TokenInfoExtended struct adds chain_id metadata to token information and is propagated through GUI token-retrieval functions. New get_orderbook_yaml() and get_tokens() methods enable registry and YAML-based token querying, including support for fetching remote tokens from configured sources.

Changes

Cohort / File(s) Summary
Token struct definition
crates/common/src/erc20.rs
New TokenInfoExtended struct with chain_id, address, decimals, name, symbol, key fields; derives Debug, Clone, PartialEq, Eq, Serialize, Deserialize, and Tsify (wasm); includes wasm trait implementations.
GUI module updates
crates/js_api/src/gui/mod.rs, crates/js_api/src/gui/select_tokens.rs
Exported TokenInfoExtended; replaced all TokenInfo usage with TokenInfoExtended in get_token_info(), get_all_token_infos(), and get_all_tokens() functions; updated wasm export metadata and chain_id population from token network.
Registry and YAML API
crates/js_api/src/registry.rs, crates/js_api/src/yaml/mod.rs
Added get_orderbook_yaml() method to DotrainRegistry; introduced new get_tokens() async method on OrderbookYaml supporting remote token fetching via using-tokens-from URLs; added OrderbookYamlError variants for missing fields and remote token parsing.
Documentation updates
crates/js_api/ARCHITECTURE.md, packages/orderbook/ARCHITECTURE.md, packages/orderbook/README.md
Updated API surface documentation to reflect getOrderbookYaml() and getTokens() methods with token-querying capabilities and remote token-fetching behavior.
Integration tests
packages/orderbook/test/js_api/dotrainRegistry.test.ts, packages/orderbook/test/js_api/orderbookYaml.test.ts
Added test suite for getOrderbookYaml() method; comprehensive tests for getTokens() covering local tokens, multi-network tokens, missing fields, and remote token-fetching scenarios with mock HTTP server.
UI component type updates
packages/ui-components/src/__tests__/TokenSelectionModal.test.ts, packages/ui-components/src/lib/components/deployment/DeploymentSteps.svelte, packages/ui-components/src/lib/components/deployment/SelectToken.svelte, packages/ui-components/src/lib/components/deployment/TokenSelectionModal.svelte
Replaced TokenInfo with TokenInfoExtended in type imports, function signatures, and state variables across test mocks and Svelte components; added chain_id field to mock token objects.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant App as Application
    participant Registry as DotrainRegistry
    participant YAML as OrderbookYaml
    participant RemoteAPI as Remote Token API

    User->>App: Request tokens
    App->>Registry: getOrderbookYaml()
    Registry->>YAML: new(settings, None)
    YAML-->>Registry: OrderbookYaml instance
    Registry-->>App: OrderbookYaml

    App->>YAML: getTokens()
    
    alt using-tokens-from configured
        YAML->>RemoteAPI: fetch_tokens(urls)
        RemoteAPI-->>YAML: remote token configs
        YAML->>YAML: merge with local tokens
    else local-only
        YAML->>YAML: use local tokens
    end
    
    YAML->>YAML: assemble TokenInfoExtended[]<br/>(key, address, decimals,<br/>name, symbol, chain_id)
    YAML-->>App: Vec<TokenInfoExtended>
    App-->>User: Display tokens
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • TokenInfoExtended struct: Verify derives and wasm serialization correctness for the new chain_id field
  • Remote token fetching logic in get_tokens(): Review async flow, error handling for ParseRemoteTokensError, and token merging logic
  • Chain_id population: Confirm chain_id is correctly extracted from token.network across all token construction paths in GUI functions
  • Wasm bindings: Validate js_name, unchecked_return_type, and export consistency across updated methods
  • Test coverage: Verify remote token fetch tests and multi-network scenarios exercise the new functionality adequately

Possibly related PRs

Suggested labels

rust, webapp, test

Suggested reviewers

  • 0xgleb
  • hardyjosh

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main changes: introducing OrderbookYaml.getTokens() and DotrainRegistry.getOrderbookYaml() methods for token querying capabilities. It accurately reflects the core additions across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-12-22-get-tokens-orderbook-yaml

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

@findolor findolor linked an issue Dec 22, 2025 that may be closed by this pull request
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.

Expose getTokens method from OrderbookYaml to the js SDK

2 participants