Update order quotes sdk function to return pre-formetted strings#2001
Update order quotes sdk function to return pre-formetted strings#2001
Conversation
WalkthroughThis set of changes introduces structured, formatted balance and quote data retrieval across the Rust backend and TypeScript/Svelte frontend. New methods and types allow querying ERC-20 token balances and order quotes, returning both raw and formatted values. UI components and tests are refactored to use these new abstractions, removing direct blockchain calls and formatting logic from the frontend. Changes
Sequence Diagram(s)sequenceDiagram
participant UI
participant Vault
participant ERC20
participant Blockchain
UI->>Vault: getOwnerBalance()
Vault->>ERC20: get_account_balance(owner_address)
ERC20->>Blockchain: balanceOf(owner_address)
Blockchain-->>ERC20: U256 balance
ERC20-->>Vault: U256 balance
Vault-->>UI: AccountBalance { balance, formatted_balance }
sequenceDiagram
participant UI
participant RaindexOrder
participant Backend
UI->>RaindexOrder: get_quotes()
RaindexOrder->>Backend: fetch batch order quotes
Backend-->>RaindexOrder: raw quote data
RaindexOrder-->>UI: RaindexOrderQuote[] (with formatted fields)
Suggested labels
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Clippy (1.86.0)error: failed to get Caused by: Caused by: Caused by: Caused by: 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (2)📓 Common learningscrates/common/src/raindex_client/vaults.rs (35)<retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> <retrieved_learning> 🔇 Additional comments (5)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
WalkthroughThe changes introduce a new abstraction for fetching ERC20 account balances via the Changes
Sequence Diagram(s)sequenceDiagram
participant UI
participant RaindexVaultToken
participant RaindexClient
participant ERC20
participant EthereumRPC
UI->>RaindexVaultToken: getAccountBalance(account)
RaindexVaultToken->>RaindexClient: get_rpc_urls()
RaindexVaultToken->>ERC20: new(contract_address, rpc_urls)
RaindexVaultToken->>ERC20: get_account_balance(account)
ERC20->>EthereumRPC: balanceOf(account)
EthereumRPC-->>ERC20: balance (U256)
ERC20-->>RaindexVaultToken: balance (U256)
RaindexVaultToken-->>UI: AccountBalance { balance, formatted_balance }
sequenceDiagram
participant UI
participant RaindexOrder
participant RaindexClient
participant OrderbookQuoteAPI
UI->>RaindexOrder: get_quotes()
RaindexOrder->>RaindexClient: fetch_batch_order_quotes()
RaindexClient->>OrderbookQuoteAPI: getBatchOrderQuotes()
OrderbookQuoteAPI-->>RaindexClient: BatchOrderQuotesResponse[]
RaindexClient-->>RaindexOrder: BatchOrderQuotesResponse[]
RaindexOrder->>RaindexOrder: convert to RaindexOrderQuote (add formatted fields)
RaindexOrder-->>UI: RaindexOrderQuote[]
Suggested labels
Suggested reviewers
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! 🔧 Clippy (1.86.0)error: failed to get Caused by: Caused by: Caused by: Caused by: ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
| value: Math.abs( | ||
| Number( | ||
| formatUnits( | ||
| BigInt(d.inputVaultBalanceChange.amount), | ||
| Number(d.inputVaultBalanceChange.token.decimals ?? 0) | ||
| ) | ||
| ) / | ||
| Number( | ||
| formatUnits( | ||
| BigInt(d.outputVaultBalanceChange.amount), | ||
| Number(d.outputVaultBalanceChange.token.decimals ?? 0) | ||
| ) | ||
| ) | ||
| Number(d.inputVaultBalanceChange.formattedAmount) / | ||
| Number(d.outputVaultBalanceChange.formattedAmount) | ||
| ), |
There was a problem hiding this comment.
Potential precision loss when converting formatted strings to numbers
Converting formatted decimal strings to JavaScript Number type can lead to precision loss for large values. Consider using a decimal arithmetic library like decimal.js for accurate calculations.
- value: Math.abs(
- Number(d.inputVaultBalanceChange.formattedAmount) /
- Number(d.outputVaultBalanceChange.formattedAmount)
- ),
+ value: Math.abs(
+ parseFloat(d.inputVaultBalanceChange.formattedAmount) /
+ parseFloat(d.outputVaultBalanceChange.formattedAmount)
+ ),Alternatively, if high precision is required:
import { Decimal } from 'decimal.js';
// ...
value: new Decimal(d.inputVaultBalanceChange.formattedAmount)
.div(d.outputVaultBalanceChange.formattedAmount)
.abs()
.toNumber(),🤖 Prompt for AI Agents
In packages/ui-components/src/lib/services/historicalOrderCharts.ts around lines
18 to 21, the code converts formatted decimal strings to JavaScript Number,
which can cause precision loss for large values. To fix this, import a decimal
arithmetic library like decimal.js, then replace the Number conversions with
Decimal instances and perform the division and absolute value operations using
Decimal methods. Finally, convert the result back to a Number if needed using
toNumber().
There was a problem hiding this comment.
this is fine and working as expected
There was a problem hiding this comment.
@findolor Thanks for the clarification! I understand that the current implementation with Number() conversion is working as expected for your use case. I'll note this preference for future reference.
✏️ Learnings added
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2001
File: packages/ui-components/src/lib/services/historicalOrderCharts.ts:18-21
Timestamp: 2025-07-16T14:33:03.414Z
Learning: User findolor is comfortable with potential precision loss when converting formatted decimal strings to JavaScript Number type in historicalOrderCharts.ts, preferring the simpler implementation over using decimal arithmetic libraries like decimal.js.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1907
File: packages/orderbook/test/common/test.test.ts:75-77
Timestamp: 2025-06-04T10:21:01.388Z
Learning: The DotrainOrder.create API in packages/orderbook/test/common/test.test.ts is internal and not used directly in consumer applications, so API changes here don't require external breaking change documentation.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1599
File: tauri-app/src/routes/orders/add/+page.svelte:287-287
Timestamp: 2025-04-11T06:05:46.473Z
Learning: The ScenarioDebugTable component in tauri-app/src/routes/orders/add/+page.svelte has been designed to manage its own data fetching internally without requiring a chartData prop.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.656Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T23:09:27.578Z
Learning: For PR #1884 in rainlanguage/rain.orderbook repository, I must always reassess the PR size after each new commit, calculating the total changes up to the very latest commit and ensuring accuracy of the report. The calculation must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and report in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number".
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: packages/webapp/src/lib/components/DepositOrWithdrawModal.svelte:73-76
Timestamp: 2025-05-09T05:30:02.520Z
Learning: In Rain.orderbook, `VaultCalldataResult` is a wrapper type that contains both `error` and `value` properties. When using this in the `DepositOrWithdrawModal` component, only the inner `value` field is passed to the `handleTransaction` function, not the complete wrapper.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1916
File: packages/webapp/src/routes/+layout.ts:26-26
Timestamp: 2025-06-10T12:01:07.418Z
Learning: The user findolor prefers to keep string concatenation using the plus operator over template literals in the rainlanguage/rain.orderbook project, even when static analysis tools suggest the change.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1994
File: crates/common/src/raindex_client/vaults.rs:59-59
Timestamp: 2025-07-16T05:52:05.538Z
Learning: User findolor prefers to handle documentation updates for getter methods in batch via dedicated PRs rather than addressing them individually during feature development, as mentioned for the formatted amount string fields in crates/common/src/raindex_client/vaults.rs.
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1896
File: tauri-app/src/lib/services/executeWalletConnectOrder.ts:41-45
Timestamp: 2025-05-27T12:01:51.647Z
Learning: In the tauri-app codebase, the formatEthersTransactionErrorFn function already handles error formatting appropriately for toast messages in executeWalletConnectOrder, so additional granular error handling based on error types is not needed.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1971
File: packages/orderbook/package.json:45-46
Timestamp: 2025-07-09T18:31:46.308Z
Learning: In the rain.orderbook project, maintainer findolor prefers to keep TypeDoc dependencies with caret version ranges (e.g., "^0.28.7") rather than pinning to exact versions, even when this might cause unstable HTML output and noisy diffs in generated documentation.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1956
File: crates/common/src/fuzz/mod.rs:64-64
Timestamp: 2025-07-04T09:02:57.301Z
Learning: In rainlanguage/rain.orderbook, user findolor prefers to limit type consistency changes to only the parts directly related to the current work scope. For example, when updating chain_id fields from u64 to u32 in fuzz-related code, unrelated files like tauri-app wallet commands can remain as u64 if they serve different purposes and aren't part of the current changes.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:26:31.566Z
Learning: For PR #1884 and future PRs in rainlanguage/rain.orderbook repository, provide PR size reports in a separate comment with ONLY the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number", without any additional text or explanation. Reports should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1512
File: packages/ui-components/src/__tests__/OrderDetail.test.ts:125-143
Timestamp: 2025-04-08T12:56:03.272Z
Learning: The OrderDetail component in the Rain orderbook UI doesn't currently have error handling tests, but issue #1605 has been created to address this in the future.
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1870
File: packages/webapp/src/lib/components/WithdrawModal.svelte:31-31
Timestamp: 2025-05-20T12:03:18.032Z
Learning: The VaultActionArgs type no longer contains an action property after refactoring the deposit/withdraw modals into separate components.
Learnt from: hardingjam
PR: rainlanguage/rain.orderbook#1559
File: packages/ui-components/src/__tests__/OrderOrVaultHash.test.ts:94-94
Timestamp: 2025-04-04T11:25:21.518Z
Learning: In the rain.orderbook project, minimal test fixtures are preferred over complete mocks that implement the entire interface. Type casting (e.g., `as unknown as SgVault`) is an acceptable approach to maintain both minimal fixtures and TypeScript type compatibility.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1925
File: crates/settings/src/remote_tokens.rs:44-62
Timestamp: 2025-07-11T08:45:43.961Z
Learning: findolor prefers to avoid performance micro-optimizations like changing `.values()` to `.into_values()` in HashMap iterations in the rainlanguage/rain.orderbook codebase, even when they would eliminate unnecessary cloning.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/js_api/src/subgraph/vault.rs:129-138
Timestamp: 2025-06-17T16:33:58.549Z
Learning: findolor prefers downstream error handling over early validation checks for empty RPC lists in vault functions, allowing errors to bubble up from provider creation logic naturally.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1975
File: crates/js_api/src/config.rs:44-45
Timestamp: 2025-07-09T07:42:48.458Z
Learning: User findolor prefers to defer code improvements and refactoring suggestions to future PRs when they are not directly related to the current PR's scope, even when the suggestions are valid improvements.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1947
File: crates/common/src/raindex_client/orders.rs:462-1643
Timestamp: 2025-06-24T08:45:10.971Z
Learning: User findolor prefers to keep tests simple and avoid refactoring for maintainability when the code is stable and viewed as "one time thing" that won't require frequent changes.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T23:34:42.328Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must use the format:
TOTAL:number
ADDITIONS:number
DELETIONS:number
with no extra text, formatting blocks, or explanations, and must still exclude lock files and reassess after each new commit.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any additional text or formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:46:08.530Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report should be the only content in the comment - no text before it, no text after it, no formatting blocks, just the raw report in the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:47:21.927Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must always be placed at the very beginning of any comment, before any learning used section or other content.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:47:21.927Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must always be placed at the very beginning of any comment, before any learning used section or other content.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
| max_output: value.max_output, | ||
| formatted_max_output: format_amount_u256(value.max_output, 18)?, | ||
| max_input, | ||
| formatted_max_input: format_amount_u256(max_input, 36)?, | ||
| ratio: value.ratio, | ||
| formatted_ratio: format_amount_u256(value.ratio, 18)?, | ||
| inverse_ratio, | ||
| formatted_inverse_ratio: format_amount_u256(inverse_ratio, 18)?, |
There was a problem hiding this comment.
Hardcoded decimal values may not be appropriate for all tokens
The formatting uses hardcoded decimal values (18 for most fields, 36 for max_input) which might not match the actual token decimals. This could lead to incorrect display values.
Consider using the actual token decimals from the order's input/output vaults instead of hardcoded values. The token information should be available through the order structure.
🤖 Prompt for AI Agents
In crates/common/src/raindex_client/order_quotes.rs around lines 62 to 69, the
code uses hardcoded decimal values (18 and 36) for formatting amounts, which may
not match the actual token decimals. To fix this, retrieve the correct decimal
values from the order's input and output vault token metadata instead of using
fixed numbers. Replace the hardcoded decimals in the format_amount_u256 calls
with these dynamic decimals to ensure accurate formatting for all tokens.
There was a problem hiding this comment.
this is fine for our use case
There was a problem hiding this comment.
@findolor Understood! I've noted that the hardcoded decimal values are intentional for your use case.
🐰
◕ ◕
( ‿ )
︶ ︶
✏️ Learnings added
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2001
File: crates/common/src/raindex_client/order_quotes.rs:62-69
Timestamp: 2025-07-16T14:33:13.409Z
Learning: In the rainlanguage/rain.orderbook codebase, findolor considers hardcoded decimal values (18 and 36) in order quote formatting logic to be acceptable for their use case, even when dynamic token decimals could theoretically provide more accurate formatting for different tokens.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.656Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1956
File: crates/common/src/raindex_client/orders.rs:609-609
Timestamp: 2025-07-04T10:27:22.544Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor prefers not to implement overflow protection for trades count casting (usize to u16) at this time, considering it unnecessary for the current scope since the practical risk of orders having 65,535+ trades is extremely low.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1956
File: crates/common/src/raindex_client/trades.rs:215-223
Timestamp: 2025-07-04T10:24:56.163Z
Learning: In the rain.orderbook codebase, the get_trade_count method implementation that fetches all trades to count them is intentionally consistent with previous implementations and not considered a performance issue, as indicated by findolor for the trades counting functionality in crates/common/src/raindex_client/trades.rs.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1994
File: crates/common/src/raindex_client/vaults.rs:282-292
Timestamp: 2025-07-15T08:01:38.534Z
Learning: In the rainlanguage/rain.orderbook codebase, findolor prefers to avoid concurrency optimizations like using `futures::future::try_join_all` for parallel processing of balance changes, considering such optimizations "not that critical at the moment" when the performance impact is minimal.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/js_api/src/gui/order_operations.rs:124-134
Timestamp: 2025-06-17T16:32:04.554Z
Learning: In the rain.orderbook codebase, RPC lists are typically small (2 items maximum), so performance optimizations around cloning and converting small Vec<Url> collections are generally unnecessary.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1706
File: crates/quote/src/js_api/mod.rs:57-61
Timestamp: 2025-04-29T06:19:15.446Z
Learning: In the rain.orderbook codebase, the `get_id` function is designed to use `U256::from_str()` rather than `U256::from_hex()` for parsing order hashes, despite the potential for hex string inputs.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1744
File: crates/js_api/src/subgraph/vault.rs:19-37
Timestamp: 2025-05-09T05:21:40.234Z
Learning: In the rain.orderbook project, the developer prefers to use tuple structs for WASM wrappers (like VaultCalldataResult, GetVaultsResult) rather than structs with named fields.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1950
File: crates/common/src/raindex_client/orders.rs:301-301
Timestamp: 2025-06-24T13:36:28.797Z
Learning: In the RaindexClient codebase, when Arc::new(RwLock::new(self.clone())) is used (e.g., in get_orders and get_order_by_hash methods), this creates new Arc/RwLock wrappers around a cloned RaindexClient, but the underlying client data is functionally the same. This pattern is used to provide the correct Arc<RwLock<RaindexClient>> type expected by RaindexOrder::try_from_sg_order() method.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1947
File: crates/common/src/raindex_client/orders.rs:98-125
Timestamp: 2025-06-24T08:46:03.368Z
Learning: In the vault merging logic in crates/common/src/raindex_client/orders.rs, optimization isn't necessary because the maximum list items are usually around 5 items. For such small datasets, the simple three-loop approach is preferred over HashMap-based optimization due to clarity and minimal performance impact.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1994
File: crates/common/src/raindex_client/vaults.rs:59-59
Timestamp: 2025-07-16T05:52:05.538Z
Learning: User findolor prefers to handle documentation updates for getter methods in batch via dedicated PRs rather than addressing them individually during feature development, as mentioned for the formatted amount string fields in crates/common/src/raindex_client/vaults.rs.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1956
File: crates/common/src/fuzz/mod.rs:64-64
Timestamp: 2025-07-04T09:02:57.301Z
Learning: In rainlanguage/rain.orderbook, user findolor prefers to limit type consistency changes to only the parts directly related to the current work scope. For example, when updating chain_id fields from u64 to u32 in fuzz-related code, unrelated files like tauri-app wallet commands can remain as u64 if they serve different purposes and aren't part of the current changes.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1983
File: crates/settings/src/gui.rs:965-973
Timestamp: 2025-07-11T08:37:24.423Z
Learning: In the rainlanguage/rain.orderbook project, user findolor prefers to keep user-facing error messages generic and user-friendly rather than technically specific. For example, using "a valid number" instead of "a valid u8 (0-255)" in GUI validation error messages to maintain simplicity for end users.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/cli/src/commands/order/calldata.rs:47-57
Timestamp: 2025-06-17T16:46:19.035Z
Learning: In the CLI command `crates/cli/src/commands/order/calldata.rs`, the user prefers to let lower-level errors from `try_into_call()` bubble up when the RPCs list is empty, rather than adding early validation checks with custom error messages.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/settings/src/yaml/orderbook.rs:371-377
Timestamp: 2025-06-17T16:21:24.384Z
Learning: In crates/settings/src/yaml/orderbook.rs tests, the user findolor considers RPC ordering in Vec<Url> assertions to be intentional and not a test brittleness issue. The ordering of RPCs in tests should be preserved as specified.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1938
File: crates/js_api/src/raindex/mod.rs:102-118
Timestamp: 2025-06-18T12:56:44.290Z
Learning: In the rainlanguage/rain.orderbook codebase, it's acceptable to scaffold unused enum variants in initial implementation PRs when they will be implemented in future PRs, as confirmed by findolor.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:26:31.566Z
Learning: For PR #1884 and future PRs in rainlanguage/rain.orderbook repository, provide PR size reports in a separate comment with ONLY the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number", without any additional text or explanation. Reports should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1715
File: crates/js_api/src/common/mod.rs:55-59
Timestamp: 2025-05-14T05:51:50.277Z
Learning: In the Rain Orderbook project, the error handling for WASM exported functions uses WasmEncodedError which includes both the original error message and a human-readable version, making direct modification of the JsValue conversion unnecessary.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1925
File: crates/settings/src/remote_tokens.rs:44-62
Timestamp: 2025-07-11T08:45:43.961Z
Learning: findolor prefers to avoid performance micro-optimizations like changing `.values()` to `.into_values()` in HashMap iterations in the rainlanguage/rain.orderbook codebase, even when they would eliminate unnecessary cloning.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/js_api/src/subgraph/vault.rs:129-138
Timestamp: 2025-06-17T16:33:58.549Z
Learning: findolor prefers downstream error handling over early validation checks for empty RPC lists in vault functions, allowing errors to bubble up from provider creation logic naturally.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1916
File: packages/webapp/src/routes/+layout.ts:26-26
Timestamp: 2025-06-10T12:01:07.418Z
Learning: The user findolor prefers to keep string concatenation using the plus operator over template literals in the rainlanguage/rain.orderbook project, even when static analysis tools suggest the change.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1975
File: crates/js_api/src/config.rs:44-45
Timestamp: 2025-07-09T07:42:48.458Z
Learning: User findolor prefers to defer code improvements and refactoring suggestions to future PRs when they are not directly related to the current PR's scope, even when the suggestions are valid improvements.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1947
File: crates/common/src/raindex_client/orders.rs:462-1643
Timestamp: 2025-06-24T08:45:10.971Z
Learning: User findolor prefers to keep tests simple and avoid refactoring for maintainability when the code is stable and viewed as "one time thing" that won't require frequent changes.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T23:34:42.328Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must use the format:
TOTAL:number
ADDITIONS:number
DELETIONS:number
with no extra text, formatting blocks, or explanations, and must still exclude lock files and reassess after each new commit.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any additional text or formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:46:08.530Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report should be the only content in the comment - no text before it, no text after it, no formatting blocks, just the raw report in the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:47:21.927Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must always be placed at the very beginning of any comment, before any learning used section or other content.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:47:21.927Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must always be placed at the very beginning of any comment, before any learning used section or other content.
| #[tokio::test] | ||
| async fn test_get_account_balance_from_token() { | ||
| let server = MockServer::start_async().await; | ||
| server.mock(|when, then| { | ||
| when.path("/sg1"); | ||
| then.status(200).json_body_obj(&json!({ | ||
| "data": { | ||
| "vault": get_vault1_json() | ||
| } | ||
| })); | ||
| }); | ||
| server.mock(|when, then| { | ||
| when.method("POST") | ||
| .path("/rpc1") | ||
| .body_contains("0x70a08231"); | ||
| then.body( | ||
| Response::new_success( | ||
| 1, | ||
| "0x00000000000000000000000000000000000000000000000000000000000003e8", | ||
| ) | ||
| .to_json_string() | ||
| .unwrap(), | ||
| ); | ||
| }); | ||
|
|
||
| let raindex_client = RaindexClient::new( | ||
| vec![get_test_yaml( | ||
| &server.url("/sg1"), | ||
| &server.url("/sg2"), | ||
| &server.url("/rpc1"), | ||
| &server.url("/rpc2"), | ||
| )], | ||
| None, | ||
| ) | ||
| .unwrap(); | ||
| let vault = raindex_client | ||
| .get_vault( | ||
| 1, | ||
| Address::from_str(CHAIN_ID_1_ORDERBOOK_ADDRESS).unwrap(), | ||
| Bytes::from_str("0x0123").unwrap(), | ||
| ) | ||
| .await | ||
| .unwrap(); | ||
|
|
||
| let balance = vault | ||
| .token | ||
| .get_account_balance(Address::random()) | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(balance, U256::from(1000)); | ||
| } |
There was a problem hiding this comment.
🧹 Nitpick (assertive)
Use a fixed address for deterministic testing.
The test uses Address::random() which could make the test non-deterministic. Consider using a fixed address for better test reproducibility.
- let balance = vault
- .token
- .get_account_balance(Address::random())
- .await
- .unwrap();
+ let test_address = Address::from_str("0x1234567890123456789012345678901234567890").unwrap();
+ let balance = vault
+ .token
+ .get_account_balance(test_address)
+ .await
+ .unwrap();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #[tokio::test] | |
| async fn test_get_account_balance_from_token() { | |
| let server = MockServer::start_async().await; | |
| server.mock(|when, then| { | |
| when.path("/sg1"); | |
| then.status(200).json_body_obj(&json!({ | |
| "data": { | |
| "vault": get_vault1_json() | |
| } | |
| })); | |
| }); | |
| server.mock(|when, then| { | |
| when.method("POST") | |
| .path("/rpc1") | |
| .body_contains("0x70a08231"); | |
| then.body( | |
| Response::new_success( | |
| 1, | |
| "0x00000000000000000000000000000000000000000000000000000000000003e8", | |
| ) | |
| .to_json_string() | |
| .unwrap(), | |
| ); | |
| }); | |
| let raindex_client = RaindexClient::new( | |
| vec![get_test_yaml( | |
| &server.url("/sg1"), | |
| &server.url("/sg2"), | |
| &server.url("/rpc1"), | |
| &server.url("/rpc2"), | |
| )], | |
| None, | |
| ) | |
| .unwrap(); | |
| let vault = raindex_client | |
| .get_vault( | |
| 1, | |
| Address::from_str(CHAIN_ID_1_ORDERBOOK_ADDRESS).unwrap(), | |
| Bytes::from_str("0x0123").unwrap(), | |
| ) | |
| .await | |
| .unwrap(); | |
| let balance = vault | |
| .token | |
| .get_account_balance(Address::random()) | |
| .await | |
| .unwrap(); | |
| assert_eq!(balance, U256::from(1000)); | |
| } | |
| #[tokio::test] | |
| async fn test_get_account_balance_from_token() { | |
| let server = MockServer::start_async().await; | |
| server.mock(|when, then| { | |
| when.path("/sg1"); | |
| then.status(200).json_body_obj(&json!({ | |
| "data": { | |
| "vault": get_vault1_json() | |
| } | |
| })); | |
| }); | |
| server.mock(|when, then| { | |
| when.method("POST") | |
| .path("/rpc1") | |
| .body_contains("0x70a08231"); | |
| then.body( | |
| Response::new_success( | |
| 1, | |
| "0x00000000000000000000000000000000000000000000000000000000000003e8", | |
| ) | |
| .to_json_string() | |
| .unwrap(), | |
| ); | |
| }); | |
| let raindex_client = RaindexClient::new( | |
| vec![get_test_yaml( | |
| &server.url("/sg1"), | |
| &server.url("/sg2"), | |
| &server.url("/rpc1"), | |
| &server.url("/rpc2"), | |
| )], | |
| None, | |
| ) | |
| .unwrap(); | |
| let vault = raindex_client | |
| .get_vault( | |
| 1, | |
| Address::from_str(CHAIN_ID_1_ORDERBOOK_ADDRESS).unwrap(), | |
| Bytes::from_str("0x0123").unwrap(), | |
| ) | |
| .await | |
| .unwrap(); | |
| let test_address = Address::from_str("0x1234567890123456789012345678901234567890").unwrap(); | |
| let balance = vault | |
| .token | |
| .get_account_balance(test_address) | |
| .await | |
| .unwrap(); | |
| assert_eq!(balance, U256::from(1000)); | |
| } |
🤖 Prompt for AI Agents
In crates/common/src/raindex_client/vaults.rs around lines 2338 to 2388, the
test_get_account_balance_from_token function uses Address::random() which makes
the test non-deterministic. Replace Address::random() with a fixed, hardcoded
address value to ensure the test produces consistent and reproducible results
every time it runs.
There was a problem hiding this comment.
address is not used so this is valid code
There was a problem hiding this comment.
@findolor You're absolutely right! Looking at the mock setup, the server only checks for the balanceOf function selector (0x70a08231) and returns a fixed response of 1000, regardless of which address is passed as the parameter. Since the mock doesn't validate the actual address value, using Address::random() doesn't make the test non-deterministic - it will always return the same mocked result.
Thanks for the clarification. The test is indeed deterministic in this context.
🐰
/| /|
( ✌️ )
|()|
O("_")_O
✏️ Learnings added
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2001
File: crates/common/src/raindex_client/vaults.rs:0-0
Timestamp: 2025-07-16T14:33:45.855Z
Learning: In the rainlanguage/rain.orderbook codebase, findolor considers using Address::random() in tests to be acceptable when the mock server doesn't validate the address parameter and returns a fixed response, making the test deterministic regardless of the address value used.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
🧠 Learnings used
Learnt from: 0xgleb
PR: rainlanguage/rain.orderbook#1859
File: crates/quote/src/quote_debug.rs:472-492
Timestamp: 2025-05-20T10:20:08.206Z
Learning: In the Rain Orderbook codebase, the `#[tokio::test(flavor = "multi_thread")]` annotation is specifically needed for tests that use `LocalEvm`, not just for consistency across all async tests.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2000
File: crates/common/src/raindex_client/vaults.rs:183-183
Timestamp: 2025-07-16T10:40:05.656Z
Learning: In the rainlanguage/rain.orderbook codebase, user findolor considers breaking changes from Option<U256> to U256 for required fields like decimals in RaindexVaultToken to be acceptable and safe, even when they affect multiple usage sites across the codebase.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/settings/src/yaml/orderbook.rs:371-377
Timestamp: 2025-06-17T16:21:24.384Z
Learning: In crates/settings/src/yaml/orderbook.rs tests, the user findolor considers RPC ordering in Vec<Url> assertions to be intentional and not a test brittleness issue. The ordering of RPCs in tests should be preserved as specified.
Learnt from: 0xgleb
PR: rainlanguage/rain.orderbook#1844
File: tauri-app/src-tauri/src/commands/wallet.rs:27-28
Timestamp: 2025-05-16T17:24:34.724Z
Learning: In Rust projects, dependencies listed in the [dependencies] section of Cargo.toml are available for both application code and tests. The tokio crate with the "full" feature set includes the "test" feature needed for `#[tokio::test]` to work properly.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1872
File: packages/webapp/src/__tests__/handleVaultDeposit.test.ts:20-53
Timestamp: 2025-06-07T05:19:46.330Z
Learning: In the rain.orderbook codebase, simple wrapper/adapter functions that just delegate to other functions (like handleVaultDeposit) don't need extensive edge case testing for missing parameters or error handling - the current test coverage focusing on core functionality is sufficient.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1941
File: crates/js_api/src/raindex/vaults.rs:175-181
Timestamp: 2025-06-20T07:51:08.790Z
Learning: In the RaindexClient vault methods, `&self` parameters are intentionally kept for API consistency to make all vault operations instance methods, even when the methods don't use client state. This is a design preference for maintaining a uniform interface.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1994
File: crates/common/src/raindex_client/vaults.rs:59-59
Timestamp: 2025-07-16T05:52:05.538Z
Learning: User findolor prefers to handle documentation updates for getter methods in batch via dedicated PRs rather than addressing them individually during feature development, as mentioned for the formatted amount string fields in crates/common/src/raindex_client/vaults.rs.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1874
File: tauri-app/src-tauri/src/transaction_status.rs:69-127
Timestamp: 2025-05-27T06:16:35.738Z
Learning: In tauri-app/src-tauri/src/transaction_status.rs, directly accessing internal RwLock state in tests using `notice.0.read().unwrap()` is acceptable and does not require encapsulation through public getter methods.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1994
File: crates/common/src/raindex_client/vaults.rs:282-292
Timestamp: 2025-07-15T08:01:38.534Z
Learning: In the rainlanguage/rain.orderbook codebase, findolor prefers to avoid concurrency optimizations like using `futures::future::try_join_all` for parallel processing of balance changes, considering such optimizations "not that critical at the moment" when the performance impact is minimal.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1483
File: crates/settings/src/remote_tokens.rs:32-57
Timestamp: 2025-04-07T09:51:52.614Z
Learning: The implementation for remote token fetching in `crates/settings/src/remote_tokens.rs` does not include explicit timeouts/retries, as the team considers the current implementation sufficient for now.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1882
File: packages/webapp/src/lib/services/handleVaultDeposit.ts:96-125
Timestamp: 2025-06-07T09:07:53.733Z
Learning: In the vault deposit flow, vault.token.address is already validated before reaching the approval transaction creation, so casting it to Hex type is safe and doesn't require additional validation.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1938
File: crates/settings/src/yaml/orderbook.rs:180-199
Timestamp: 2025-06-18T18:24:32.049Z
Learning: In crates/settings/src/yaml/orderbook.rs, the user prefers to avoid refactoring duplicate search logic between get_orderbook_by_address and get_orderbook_by_network_key when there are only 2 functions, indicating they would consider it if more similar functions are added in the future.
Learnt from: thedavidmeister
PR: rainlanguage/rain.orderbook#1926
File: test/concrete/ob/OrderBook.clear.zeroAmount.t.sol:24-32
Timestamp: 2025-06-16T10:49:47.770Z
Learning: LibTestAddOrder.conformConfig() in test/util/lib/LibTestAddOrder.sol automatically constrains OrderConfigV3 to prevent common test failures by ensuring validInputs[0].token != validOutputs[0].token, setting them to address(0) and address(1) respectively if they're equal. This prevents TokenSelfTrade errors in fuzz tests.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1925
File: crates/settings/src/remote_tokens.rs:44-62
Timestamp: 2025-07-11T08:45:43.961Z
Learning: findolor prefers to avoid performance micro-optimizations like changing `.values()` to `.into_values()` in HashMap iterations in the rainlanguage/rain.orderbook codebase, even when they would eliminate unnecessary cloning.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1903
File: crates/js_api/src/subgraph/vault.rs:129-138
Timestamp: 2025-06-17T16:33:58.549Z
Learning: findolor prefers downstream error handling over early validation checks for empty RPC lists in vault functions, allowing errors to bubble up from provider creation logic naturally.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1916
File: packages/webapp/src/routes/+layout.ts:26-26
Timestamp: 2025-06-10T12:01:07.418Z
Learning: The user findolor prefers to keep string concatenation using the plus operator over template literals in the rainlanguage/rain.orderbook project, even when static analysis tools suggest the change.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1975
File: crates/js_api/src/config.rs:44-45
Timestamp: 2025-07-09T07:42:48.458Z
Learning: User findolor prefers to defer code improvements and refactoring suggestions to future PRs when they are not directly related to the current PR's scope, even when the suggestions are valid improvements.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#1947
File: crates/common/src/raindex_client/orders.rs:462-1643
Timestamp: 2025-06-24T08:45:10.971Z
Learning: User findolor prefers to keep tests simple and avoid refactoring for maintainability when the code is stable and viewed as "one time thing" that won't require frequent changes.
Learnt from: findolor
PR: rainlanguage/rain.orderbook#2001
File: crates/common/src/raindex_client/order_quotes.rs:62-69
Timestamp: 2025-07-16T14:33:13.409Z
Learning: In the rainlanguage/rain.orderbook codebase, findolor considers hardcoded decimal values (18 and 36) in order quote formatting logic to be acceptable for their use case, even when dynamic token decimals could theoretically provide more accurate formatting for different tokens.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T23:34:42.328Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must use the format:
TOTAL:number
ADDITIONS:number
DELETIONS:number
with no extra text, formatting blocks, or explanations, and must still exclude lock files and reassess after each new commit.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any additional text or formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:26:31.566Z
Learning: For PR #1884 and future PRs in rainlanguage/rain.orderbook repository, provide PR size reports in a separate comment with ONLY the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number", without any additional text or explanation. Reports should exclude irrelevant files such as lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:14:22.646Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, I must consistently report the PR size after EVERY new commit in the exact format "TOTAL=number\nADDITIONS=number\nDELETIONS=number" without any formatting blocks. The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock) and can be included either as part of the review or as a separate comment.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:46:08.530Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report should be the only content in the comment - no text before it, no text after it, no formatting blocks, just the raw report in the exact format: "TOTAL=number\nADDITIONS=number\nDELETIONS=number". The report must exclude lock files (package-lock.json, yarn.lock, pnpm-lock.yaml, cargo.lock).
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:47:21.927Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must always be placed at the very beginning of any comment, before any learning used section or other content.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T22:47:21.927Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, the PR size report must always be placed at the very beginning of any comment, before any learning used section or other content.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
Learnt from: rouzwelt
PR: rainlanguage/rain.orderbook#0
File: :0-0
Timestamp: 2025-05-21T21:24:53.708Z
Learning: For PR #1884 in rainlanguage/rain.orderbook, provide a separate comment after each review with PR size statistics in the format: `TOTAL=number ADDITIONS=number DELETIONS=number`, excluding lock files like package-lock.json and cargo.lock.
| #[serde(rename_all = "camelCase")] | ||
| #[wasm_bindgen] | ||
| pub struct RaindexVaultToken { | ||
| raindex_client: Arc<RwLock<RaindexClient>>, |
There was a problem hiding this comment.
🧹 Nitpick (assertive)
Architectural consideration: Circular reference pattern introduced.
Adding raindex_client to RaindexVaultToken creates a circular dependency between the token and client. While Arc<RwLock<>> prevents memory issues, this increases architectural complexity. Consider documenting this design decision for future maintainers.
🤖 Prompt for AI Agents
In crates/common/src/raindex_client/vaults.rs at line 177, the addition of
raindex_client as an Arc<RwLock<RaindexClient>> in RaindexVaultToken introduces
a circular reference pattern. To address this, add clear documentation comments
near this field explaining the intentional circular dependency and the use of
Arc<RwLock<>> to manage memory safely, so future maintainers understand the
architectural decision and complexity involved.
| pub async fn get_account_balance_wasm_binding( | ||
| &self, | ||
| #[wasm_export(param_description = "Account address to check balance for")] account: String, | ||
| ) -> Result<AccountBalance, RaindexError> { | ||
| let account = Address::from_str(&account)?; | ||
| let balance = self.clone().get_account_balance(account).await?; | ||
| let decimals = self.decimals.try_into()?; | ||
| let account_balance = AccountBalance { | ||
| balance, | ||
| formatted_balance: format_amount_u256(balance, decimals)?, | ||
| }; | ||
| Ok(account_balance) | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Avoid unnecessary cloning in get_account_balance call.
The method clones self when calling get_account_balance, but this is unnecessary since the method only needs to read the token's fields.
- let balance = self.clone().get_account_balance(account).await?;
+ let balance = self.get_account_balance(account).await?;Then update the get_account_balance method signature to take &self instead of self:
- pub async fn get_account_balance(self, account: Address) -> Result<U256, RaindexError> {
+ pub async fn get_account_balance(&self, account: Address) -> Result<U256, RaindexError> {🤖 Prompt for AI Agents
In crates/common/src/raindex_client/vaults.rs around lines 259 to 271, remove
the unnecessary cloning of self when calling get_account_balance by changing the
call from self.clone().get_account_balance(account).await to
self.get_account_balance(account).await. Then update the get_account_balance
method signature to accept &self instead of self to allow calling it without
cloning.
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
packages/ui-components/src/__tests__/TanstackOrderQuote.test.ts (1)
240-248: Update test data to use formatted fields.This test case still uses raw hex values (
maxOutput,ratio) instead of the formatted fields (formattedMaxOutput,formattedRatio) that the component now expects. This inconsistency may cause test failures.Apply this diff to fix the test data:
- data: { maxOutput: '0x158323e942e36d8c', ratio: '0x5b16799fcb6114f7' }, + data: { formattedMaxOutput: '1.550122181502135692', formattedRatio: '6.563567234157974775' },- data: { maxOutput: '0x54fa82f5c7001dad', ratio: '0x53e0089714d06709' }, + data: { formattedMaxOutput: '6.066479884955967059', formattedRatio: '6.485589855485802559' },
♻️ Duplicate comments (4)
packages/ui-components/src/lib/components/detail/TanstackOrderQuote.svelte (1)
114-120: LGTM: Template simplified with pre-formatted fields.The template now uses pre-formatted fields (
formattedMaxOutput,formattedRatio,formattedInverseRatio,formattedMaxInput) instead of inline formatting withformatUnits. This is a clean architectural improvement that:
- Reduces template complexity
- Moves formatting logic to the backend
- Ensures consistent formatting across the application
- Improves maintainability
packages/ui-components/src/lib/services/historicalOrderCharts.ts (1)
18-21: Potential precision loss when converting formatted strings to numbersConverting formatted decimal strings to JavaScript
Numbertype can lead to precision loss for large values. Consider using a decimal arithmetic library likedecimal.jsfor accurate calculations.crates/common/src/raindex_client/vaults.rs (1)
2346-2346: Use a fixed address for deterministic testing.The test uses
Address::random()which could make the test non-deterministic. Consider using a fixed address for better test reproducibility.- let balance = vault.get_owner_balance(Address::random()).await.unwrap(); + let test_address = Address::from_str("0x1234567890123456789012345678901234567890").unwrap(); + let balance = vault.get_owner_balance(test_address).await.unwrap();crates/common/src/raindex_client/order_quotes.rs (1)
62-70: Hardcoded decimal values may not be appropriate for all tokens.The formatting uses hardcoded decimal values (18 for most fields, 36 for max_input) which might not match the actual token decimals. This could lead to incorrect display values.
Consider retrieving the actual token decimals from the order's input/output vaults instead of using hardcoded values.
Motivation
See issue: #1968
This PR updates the return type of the order quotes logic to include pre-formatted strings.
Solution
Checks
By submitting this for review, I'm confirming I've done the following:
Summary by CodeRabbit
New Features
Refactor
Bug Fixes
Tests