Skip to content

Commit

Permalink
Merge pull request #81 from malik672/clippy
Browse files Browse the repository at this point in the history
Make clippy happy
  • Loading branch information
malik672 authored Sep 13, 2024
2 parents b80660a + 6320be5 commit 3eb67dc
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/entities/ether.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Currency for Ether {
impl Ether {
/// Creates a new instance of [`Ether`] with the specified chain ID.
#[inline]
#[must_use]
pub fn new(chain_id: u64) -> Self {
Self {
chain_id,
Expand All @@ -44,6 +45,7 @@ impl Ether {

/// Retrieves or creates an [`Ether`] instance for the specified chain ID.
#[inline]
#[must_use]
pub fn on_chain(chain_id: u64) -> Self {
Self::new(chain_id)
}
Expand Down
2 changes: 1 addition & 1 deletion src/entities/fractions/currency_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<T: Currency> CurrencyAmount<T> {
denominator,
CurrencyMeta {
currency,
decimal_scale: BigUint::from(10u64).pow(exponent as u32),
decimal_scale: BigUint::from(10_u64).pow(exponent as u32),
},
))
}
Expand Down
4 changes: 1 addition & 3 deletions src/entities/fractions/fraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ impl<M: Clone> FractionBase<M> for FractionLike<M> {
fn new(numerator: impl Into<BigInt>, denominator: impl Into<BigInt>, meta: M) -> Self {
let denominator = denominator.into();
// Ensure the denominator is not zero
if denominator.is_zero() {
panic!("denominator is zero");
}
assert!(!denominator.is_zero(), "denominator is zero");
Self {
numerator: numerator.into(),
denominator,
Expand Down
1 change: 1 addition & 0 deletions src/entities/fractions/percent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Percent {
/// Converts the [`Percent`] to a string with a fixed number of decimal places and rounding
/// strategy
#[inline]
#[must_use]
pub fn to_fixed(&self, decimal_places: u8, rounding: Rounding) -> String {
// Convert the Percent to a simple Fraction, multiply by 100, and then call to_fixed on the
// result
Expand Down
2 changes: 2 additions & 0 deletions src/entities/native_currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use crate::prelude::*;

/// Represents the native currency of the chain on which it resides
pub trait NativeCurrency: Currency {
#[inline]
fn is_native(&self) -> bool {
true
}

#[inline]
fn is_token(&self) -> bool {
false
}
Expand Down
5 changes: 2 additions & 3 deletions src/entities/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl Token {
///
/// Panics if `chain_id` is 0.
#[inline]
#[must_use]
pub const fn new(
chain_id: u64,
address: Address,
Expand All @@ -69,9 +70,7 @@ impl Token {
buy_fee_bps: Option<BigUint>,
sell_fee_bps: Option<BigUint>,
) -> Self {
if chain_id == 0 {
panic!("chain id can't be zero");
}
assert!(chain_id != 0, "chain id can't be zero");
Self {
chain_id,
decimals,
Expand Down
4 changes: 4 additions & 0 deletions src/entities/weth9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct WETH9 {
/// Default implementation for [`WETH9`], creating an instance with predefined WETH tokens on
/// various chains.
impl Default for WETH9 {
#[inline]
fn default() -> Self {
Self::new()
}
Expand All @@ -28,6 +29,7 @@ impl WETH9 {
///
/// A new `WETH9` instance with predefined WETH tokens.
#[inline]
#[must_use]
pub fn new() -> Self {
let tokens = FxHashMap::from_iter(vec![
(1, Self::on_chain(1).unwrap()),
Expand Down Expand Up @@ -55,6 +57,7 @@ impl WETH9 {
///
/// Returns: `Some(Token)` if the token exists, `None` otherwise.
#[inline]
#[must_use]
pub fn on_chain(chain_id: u64) -> Option<Token> {
match chain_id {
1 => Some(token!(
Expand Down Expand Up @@ -160,6 +163,7 @@ impl WETH9 {
///
/// Returns: `Some(Token)` if the token exists, `None` otherwise.
#[inline]
#[must_use]
pub fn get(&self, chain_id: u64) -> Option<&Token> {
self.tokens.get(&chain_id)
}
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@
//!
//! The Uniswap SDK Core in Rust provides essential functionality for interacting with the Uniswap
//! decentralized exchange.
#![cfg_attr(not(any(feature = "std", test)), no_std)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
unreachable_pub,
clippy::missing_const_for_fn,
clippy::missing_inline_in_public_items,
clippy::needless_pass_by_value,
clippy::redundant_clone,
clippy::manual_assert,
clippy::must_use_candidate,
clippy::unseparated_literal_suffix,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

extern crate alloc;

/// Contains functionality related to All Contracts deployed and supported by the Uniswap SDK.
Expand Down
12 changes: 6 additions & 6 deletions src/utils/compute_price_impact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::prelude::*;
/// returns: Percent
#[inline]
pub fn compute_price_impact<TBase: Currency, TQuote: Currency>(
mid_price: Price<TBase, TQuote>,
mid_price: &Price<TBase, TQuote>,
input_amount: &CurrencyAmount<TBase>,
output_amount: &CurrencyAmount<TQuote>,
) -> Result<Percent, Error> {
Expand Down Expand Up @@ -42,7 +42,7 @@ mod tests {
//is correct for zero
assert!(
compute_price_impact(
Price::new(Ether::on_chain(1), token.clone(), 10, 100),
&Price::new(Ether::on_chain(1), token.clone(), 10, 100),
&CurrencyAmount::from_raw_amount(Ether::on_chain(1), 10).unwrap(),
&CurrencyAmount::from_raw_amount(token.clone(), 100).unwrap()
)
Expand All @@ -53,7 +53,7 @@ mod tests {
//is correct for half output
assert!(
compute_price_impact(
Price::new(token.clone(), token_1.clone(), 10, 100),
&Price::new(token.clone(), token_1.clone(), 10, 100),
&CurrencyAmount::from_raw_amount(token.clone(), 10).unwrap(),
&CurrencyAmount::from_raw_amount(token_1.clone(), 50).unwrap()
)
Expand All @@ -64,9 +64,9 @@ mod tests {
//is negative for more output
assert_eq!(
compute_price_impact(
Price::new(token.clone(), token_1.clone(), 10, 100),
&CurrencyAmount::from_raw_amount(token.clone(), 10).unwrap(),
&CurrencyAmount::from_raw_amount(token_1.clone(), 200).unwrap()
&Price::new(token.clone(), token_1.clone(), 10, 100),
&CurrencyAmount::from_raw_amount(token, 10).unwrap(),
&CurrencyAmount::from_raw_amount(token_1, 200).unwrap()
)
.unwrap(),
Percent::new(-10000, 10000)
Expand Down
1 change: 1 addition & 0 deletions src/utils/sorted_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::prelude::*;

/// Given an array of items sorted by `comparator`, insert an item into its sort index and constrain
/// the size to `maxSize` by removing the last item
#[inline]
pub fn sorted_insert<T: Clone>(
items: &mut Vec<T>,
add: T,
Expand Down
1 change: 1 addition & 0 deletions src/utils/sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use num_traits::Signed;
/// * `value`: the value for which to compute the square root, rounded down
///
/// returns: BigInt
#[inline]
pub fn sqrt(value: &BigInt) -> Result<BigInt, Error> {
if value.is_negative() {
Err(Error::Invalid)
Expand Down
2 changes: 2 additions & 0 deletions src/utils/validate_and_parse_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use regex::Regex;
/// with only hexadecimal characters after `0x`, returns `Ok(ethereum_address.to_string())`.
/// * Otherwise, returns an error message in the form of `Err(format!("{} is not a valid Ethereum
/// address.", ethereum_address))`.
#[inline]
pub fn check_valid_ethereum_address(ethereum_address: &str) -> Result<&str, String> {
let valid_address_regex = Regex::new(r"^0x[0-9a-fA-F]{40}$").unwrap();
if valid_address_regex.is_match(ethereum_address) {
Expand All @@ -37,6 +38,7 @@ pub fn check_valid_ethereum_address(ethereum_address: &str) -> Result<&str, Stri
/// with only hexadecimal characters after `0x`, returns the checksummed address.
/// * Otherwise, returns an error message in the form of `Err(format!("{} is not a valid Ethereum
/// address.", ethereum_address))`.
#[inline]
pub fn validate_and_parse_address(ethereum_address: &str) -> Result<String, String> {
let checksummed_address = eth_checksum::checksum(ethereum_address);
check_valid_ethereum_address(&checksummed_address)?;
Expand Down

0 comments on commit 3eb67dc

Please sign in to comment.