Open anaciri opened 5 months ago
b5b2dd466b
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/margin.rs
✓ https://github.com/anaciri/perp_cli_curie/commit/e6d3a4ccdad8f38582a97637746f72ce57c00733 Edit
Create src/margin.rs with contents:
• Create a new Rust file `src/margin.rs`.
• Import necessary modules from ethers, such as `ethers::prelude::*` for blockchain interaction.
• Import the `contracts` module with `use crate::contracts;` to access smart contract functions.
• Import the `utils` module with `use crate::utils;` for utility functions like getting the HTTP provider or wallet.
• Define a public asynchronous function `process_margin_command` that takes an address (or uses the default wallet address) and calculates the margin ratio for the trader. This function will fetch the trader's positions, account value, and collateral, then calculate and print the margin ratio.
• Utilize the `contracts::get_clearing_house().await?` to fetch the clearing house contract and call necessary methods to get the trader's positions and account values.
• Calculate the margin ratio based on the fetched data and print the result.
src/margin.rs
✓ Edit
Check src/margin.rs with contents:
Ran GitHub Actions for e6d3a4ccdad8f38582a97637746f72ce57c00733:
src/args.rs
✓ https://github.com/anaciri/perp_cli_curie/commit/a0a0812211a9bd610550f2d3b153578b9693bcbc Edit
Modify src/args.rs with contents:
• Add a new variant to the `SubCommand` enum named `Margin` with a corresponding `MarginCommand` struct.
• Define the `MarginCommand` struct within the `args.rs` file. This struct should include an optional trader address field, similar to the `PortfolioCommand` struct.
• Ensure the `MarginCommand` struct is annotated with `#[derive(Debug, Args)]` for CLI parsing and includes documentation comments for user guidance.
--- +++ @@ -31,6 +31,8 @@ Open(OpenCommand), /// Close all positions in a CLOSED market. Quit(QuitCommand), + /// Retrieve the current margin for the trader + Margin(MarginCommand), /// Swap ETH or ERC-20 tokens on Velodrome for collateral tokens Swap(SwapCommand), /// Setup or edit the configuration settings of the app @@ -168,3 +170,10 @@ /// Base token address to close positions for pub token: String, } + +#[derive(Debug, Args)] +/// Retrieve the current margin for the trader +pub struct MarginCommand { + /// The address of the trader + pub trader_address: Option, +}
src/args.rs
✓ Edit
Check src/args.rs with contents:
Ran GitHub Actions for a0a0812211a9bd610550f2d3b153578b9693bcbc:
src/main.rs
✓ https://github.com/anaciri/perp_cli_curie/commit/79cb7e84510d5e5c8f8389217c9770a9daf7b7e3 Edit
Modify src/main.rs with contents:
• Import the `margin` module at the top of the file with `use perpcli_rs::margin;`.
• Add a new match arm in the `match_args` async function for the `Margin` command that calls the `margin::process_margin_command` function with the provided arguments.
--- +++ @@ -2,6 +2,7 @@ use eyre::Result; use perpcli_rs::{ amm, + margin, args::{PerpArgs, SubCommand::*}, close, config, deposit, open, portfolio, position, quit, swap, tokens, withdraw, }; @@ -26,6 +27,7 @@ Open(open_args) => open::process(open_args).await?, Close(close_args) => close::process(close_args).await?, Swap(swap_args) => swap::process(swap_args).await?, + Margin(margin_args) => margin::process_margin_command(margin_args).await?, Config(config_args) => { if config_args.rpc.expect("true/false") { config::change_rpc()?;
src/main.rs
✓ Edit
Check src/main.rs with contents:
Ran GitHub Actions for 79cb7e84510d5e5c8f8389217c9770a9daf7b7e3:
I have finished reviewing the code for completeness. I did not find errors for sweep/add_a_margin_cli_option_that_prints_the
.
💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.
This is an automated message generated by Sweep AI.
when user types perp margin, it will look at all positions for that trader and retrieve the current margin ratio
Checklist
- [X] Create `src/margin.rs` ✓ https://github.com/anaciri/perp_cli_curie/commit/e6d3a4ccdad8f38582a97637746f72ce57c00733 [Edit](https://github.com/anaciri/perp_cli_curie/edit/sweep/add_a_margin_cli_option_that_prints_the/src/margin.rs) - [X] Running GitHub Actions for `src/margin.rs` ✓ [Edit](https://github.com/anaciri/perp_cli_curie/edit/sweep/add_a_margin_cli_option_that_prints_the/src/margin.rs) - [X] Modify `src/args.rs` ✓ https://github.com/anaciri/perp_cli_curie/commit/a0a0812211a9bd610550f2d3b153578b9693bcbc [Edit](https://github.com/anaciri/perp_cli_curie/edit/sweep/add_a_margin_cli_option_that_prints_the/src/args.rs) - [X] Running GitHub Actions for `src/args.rs` ✓ [Edit](https://github.com/anaciri/perp_cli_curie/edit/sweep/add_a_margin_cli_option_that_prints_the/src/args.rs) - [X] Modify `src/main.rs` ✓ https://github.com/anaciri/perp_cli_curie/commit/79cb7e84510d5e5c8f8389217c9770a9daf7b7e3 [Edit](https://github.com/anaciri/perp_cli_curie/edit/sweep/add_a_margin_cli_option_that_prints_the/src/main.rs) - [X] Running GitHub Actions for `src/main.rs` ✓ [Edit](https://github.com/anaciri/perp_cli_curie/edit/sweep/add_a_margin_cli_option_that_prints_the/src/main.rs)