Conversation
Extract active_dex_entries helper to deduplicate DEX iteration across get_positions, get_perpetuals_data, and get_perpetual_portfolio. Add is_active filtering to skip inactive builder DEXs. Add unit tests for merge functions, perp_asset_index, and integration tests for new RPC endpoints.
Changed Files
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the system's capabilities by re-enabling and enhancing support for HIP3, allowing for seamless integration and aggregation of data from multiple perpetual decentralized exchanges. It introduces new data structures to represent DEXs, refactors the core client to interact with these multiple sources, and implements robust logic to combine diverse data streams into a single, comprehensive view for users. This change broadens the scope of supported trading platforms and improves data consistency. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for multiple perpetual DEXs (HIP3), which is a significant feature. The changes are extensive, touching models, the RPC client, and provider logic to fetch and aggregate data from multiple sources. The implementation appears solid and is accompanied by a good set of unit and integration tests. I have a couple of suggestions to improve code style and use more idiomatic Rust, but overall this is a great contribution.
| let mut positions = Vec::new(); | ||
| let mut balance = PerpetualBalance { | ||
| available: 0.0, | ||
| reserved: 0.0, | ||
| withdrawable: 0.0, | ||
| }; | ||
| for summary in summaries { | ||
| positions.extend(summary.positions); | ||
| balance.available += summary.balance.available; | ||
| balance.reserved += summary.balance.reserved; | ||
| balance.withdrawable += summary.balance.withdrawable; | ||
| } |
There was a problem hiding this comment.
This aggregation logic can be expressed more concisely and functionally using fold. This would reduce the need for mutable variables and make the intent clearer.
let (positions, balance) = summaries.into_iter().fold(
(Vec::new(), PerpetualBalance { available: 0.0, reserved: 0.0, withdrawable: 0.0 }),
|(mut acc_pos, mut acc_bal), summary| {
acc_pos.extend(summary.positions);
acc_bal.available += summary.balance.available;
acc_bal.reserved += summary.balance.reserved;
acc_bal.withdrawable += summary.balance.withdrawable;
(acc_pos, acc_bal)
},
);| pub fn map_account_summary_aggregate(positions: &[AssetPositions]) -> PerpetualAccountSummary { | ||
| let mut account_value = 0.0; | ||
| let mut total_ntl_pos = 0.0; | ||
| let mut total_margin_used = 0.0; | ||
| let mut unrealized_pnl = 0.0; | ||
|
|
||
| for positions in positions { | ||
| account_value += positions.margin_summary.account_value.parse::<f64>().unwrap_or(0.0); | ||
| total_ntl_pos += positions.margin_summary.total_ntl_pos.parse::<f64>().unwrap_or(0.0); | ||
| total_margin_used += positions.margin_summary.total_margin_used.parse::<f64>().unwrap_or(0.0); | ||
| for position in &positions.asset_positions { | ||
| unrealized_pnl += position.position.unrealized_pnl.parse::<f64>().unwrap_or(0.0); | ||
| } | ||
| } | ||
|
|
||
| let account_leverage = if account_value > 0.0 { total_ntl_pos / account_value } else { 0.0 }; | ||
| let margin_usage = if account_value > 0.0 { total_margin_used / account_value } else { 0.0 }; | ||
|
|
||
| PerpetualAccountSummary { | ||
| account_value, | ||
| account_leverage, | ||
| margin_usage, | ||
| unrealized_pnl, | ||
| } | ||
| } |
There was a problem hiding this comment.
This function can be written more idiomatically and concisely using Rust's iterator methods like map, flat_map, and sum. This would eliminate the manual loop and mutable variables, improving readability.
pub fn map_account_summary_aggregate(positions: &[AssetPositions]) -> PerpetualAccountSummary {
let account_value: f64 = positions.iter().map(|p| p.margin_summary.account_value.parse().unwrap_or(0.0)).sum();
let total_ntl_pos: f64 = positions.iter().map(|p| p.margin_summary.total_ntl_pos.parse().unwrap_or(0.0)).sum();
let total_margin_used: f64 = positions.iter().map(|p| p.margin_summary.total_margin_used.parse().unwrap_or(0.0)).sum();
let unrealized_pnl: f64 = positions.iter().flat_map(|p| &p.asset_positions).map(|p| p.position.unrealized_pnl.parse().unwrap_or(0.0)).sum();
let account_leverage = if account_value > 0.0 { total_ntl_pos / account_value } else { 0.0 };
let margin_usage = if account_value > 0.0 { total_margin_used / account_value } else { 0.0 };
PerpetualAccountSummary {
account_value,
account_leverage,
margin_usage,
unrealized_pnl,
}
}| if let Some(dex) = dex | ||
| && !dex.is_empty() | ||
| { |
There was a problem hiding this comment.
|
@gemcoder21 I've opened a new pull request, #1012, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@gemcoder21 I've opened a new pull request, #1013, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@gemcoder21 I've opened a new pull request, #1014, to work on those changes. Once the pull request is ready, I'll request review from you. |
…thods (#1012) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com>
…itions (#1013) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com>
No description provided.