Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

add swap sim example #90

Open
wants to merge 26 commits into
base: development
Choose a base branch
from
Open

Conversation

Evan-Kim2028
Copy link

@Evan-Kim2028 Evan-Kim2028 commented May 15, 2023

  • extracted test_swap_sim test into an example file
  • write docs for sync and pool

This was referenced May 17, 2023
@Evan-Kim2028
Copy link
Author

Not sure why the test suite is failing, I didn't touch any code that should affect those tests.

Regarding rustfmt fail, I adjusted the doc lines to conform to rustfmt line size

@Evan-Kim2028
Copy link
Author

Ran cargo fmt and cargo clippy --fix

async fn main() -> Result<(), Box<dyn Error>> {
// load rpc endpoint from local environment
let rpc_endpoint = std::env::var("ETHEREUM_MAINNET_ENDPOINT")
.expect("Could not get ETHEREUM_MAINNET_ENDPOINT");
Copy link
Owner

Choose a reason for hiding this comment

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

Since you are using Box, you can just use ? instead of expect().

provider.clone(),
)
.await // use ? at end of await??
.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

Lets use ? instead of unwrap()

provider.clone(),
);

let current_block = provider.get_block_number().await.unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

Same thing here, lets use ?

.block(current_block)
.call()
.await
.unwrap()
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above, use ? instead.


let float_price_b = pool.calculate_price(pool.token_b);

dbg!(pool);
Copy link
Owner

Choose a reason for hiding this comment

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

Can you remove the dbg!() from this?

async fn main() -> Result<(), Box<dyn Error>> {
// load rpc endpoint from local environment
let rpc_endpoint = std::env::var("ETHEREUM_MAINNET_ENDPOINT")
.expect("Could not get ETHEREUM_MAINNET_ENDPOINT");
Copy link
Owner

Choose a reason for hiding this comment

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

Same as in the calculate-price example, lets use ? everywhere instead of unwrap() or expect().

src/pool/mod.rs Outdated
@@ -40,14 +47,16 @@ impl Pool {
}
}

/// Returns the fee percentage associated with the pool.
Copy link
Owner

Choose a reason for hiding this comment

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

Can we reword this to "Returns the fee associated with the pool, represented as a percentage?

@0xKitsune
Copy link
Owner

Thanks for making this PR! I think we should probably separate the docs into a separate PR. I think that there are a few places where some additional information and rewording could be useful, but we can get the examples merged in once the changes requested are made.

@0xKitsune 0xKitsune changed the base branch from main to development June 19, 2023 02:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants