Skip to content

Commit

Permalink
fix: change rounding parameters to use defaults (#105)
Browse files Browse the repository at this point in the history
* fix: change rounding parameters to use defaults

* pass None in default

* fix rustfmt
  • Loading branch information
byhashdong authored Nov 11, 2024
1 parent 43921d0 commit 355ea2d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rustc-hash = "2.0"
serde_json = { version = "1.0", optional = true }
thiserror = { version = "2", default-features = false }
uniswap-lens = { version = "0.7", optional = true }
uniswap-sdk-core = "3.1.0"
uniswap-sdk-core = "3.2.0"

[features]
default = []
Expand Down
22 changes: 4 additions & 18 deletions src/entities/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,7 @@ mod tests {
0,
)
.unwrap();
assert_eq!(
pool.token0_price()
.to_significant(5, Rounding::RoundHalfUp)
.unwrap(),
"1.01"
);
assert_eq!(pool.token0_price().to_significant(5, None).unwrap(), "1.01");
let pool = Pool::new(
DAI.clone(),
USDC.clone(),
Expand All @@ -486,12 +481,7 @@ mod tests {
0,
)
.unwrap();
assert_eq!(
pool.token0_price()
.to_significant(5, Rounding::RoundHalfUp)
.unwrap(),
"1.01"
);
assert_eq!(pool.token0_price().to_significant(5, None).unwrap(), "1.01");
}

#[test]
Expand All @@ -505,9 +495,7 @@ mod tests {
)
.unwrap();
assert_eq!(
pool.token1_price()
.to_significant(5, Rounding::RoundHalfUp)
.unwrap(),
pool.token1_price().to_significant(5, None).unwrap(),
"0.9901"
);
let pool = Pool::new(
Expand All @@ -519,9 +507,7 @@ mod tests {
)
.unwrap();
assert_eq!(
pool.token1_price()
.to_significant(5, Rounding::RoundHalfUp)
.unwrap(),
pool.token1_price().to_significant(5, None).unwrap(),
"0.9901"
);
}
Expand Down
22 changes: 8 additions & 14 deletions src/entities/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ mod tests {
fn correct_for_0_1() {
let route = Route::new(vec![POOL_0_1.clone()], TOKEN0.clone(), TOKEN1.clone());
let price = route.mid_price().unwrap();
assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.2000");
assert_eq!(price.to_fixed(4, None), "0.2000");
assert_eq!(price.base_currency, *TOKEN0);
assert_eq!(price.quote_currency, *TOKEN1);
}
Expand All @@ -243,7 +243,7 @@ mod tests {
fn correct_for_1_0() {
let route = Route::new(vec![POOL_0_1.clone()], TOKEN1.clone(), TOKEN0.clone());
let price = route.mid_price().unwrap();
assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "5.0000");
assert_eq!(price.to_fixed(4, None), "5.0000");
assert_eq!(price.base_currency, *TOKEN1);
assert_eq!(price.quote_currency, *TOKEN0);
}
Expand All @@ -256,7 +256,7 @@ mod tests {
TOKEN2.clone(),
);
let price = route.mid_price().unwrap();
assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.1000");
assert_eq!(price.to_fixed(4, None), "0.1000");
assert_eq!(price.base_currency, *TOKEN0);
assert_eq!(price.quote_currency, *TOKEN2);
}
Expand All @@ -269,7 +269,7 @@ mod tests {
TOKEN0.clone(),
);
let price = route.mid_price().unwrap();
assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "10.0000");
assert_eq!(price.to_fixed(4, None), "10.0000");
assert_eq!(price.base_currency, *TOKEN2);
assert_eq!(price.quote_currency, *TOKEN0);
}
Expand All @@ -278,7 +278,7 @@ mod tests {
fn correct_for_ether_0() {
let route = Route::new(vec![POOL_0_WETH.clone()], ETHER.clone(), TOKEN0.clone());
let price = route.mid_price().unwrap();
assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.3333");
assert_eq!(price.to_fixed(4, None), "0.3333");
assert_eq!(price.base_currency, *ETHER);
assert_eq!(price.quote_currency, *TOKEN0);
}
Expand All @@ -287,7 +287,7 @@ mod tests {
fn correct_for_1_weth() {
let route = Route::new(vec![POOL_1_WETH.clone()], TOKEN1.clone(), WETH.clone());
let price = route.mid_price().unwrap();
assert_eq!(price.to_fixed(4, Rounding::RoundHalfUp), "0.1429");
assert_eq!(price.to_fixed(4, None), "0.1429");
assert_eq!(price.base_currency, *TOKEN1);
assert_eq!(price.quote_currency, *WETH);
}
Expand All @@ -300,10 +300,7 @@ mod tests {
WETH.clone(),
);
let price = route.mid_price().unwrap();
assert_eq!(
price.to_significant(4, Rounding::RoundHalfUp).unwrap(),
"0.009524"
);
assert_eq!(price.to_significant(4, None).unwrap(), "0.009524");
assert_eq!(price.base_currency, *ETHER);
assert_eq!(price.quote_currency, *WETH);
}
Expand All @@ -316,10 +313,7 @@ mod tests {
ETHER.clone(),
);
let price = route.mid_price().unwrap();
assert_eq!(
price.to_significant(4, Rounding::RoundHalfUp).unwrap(),
"0.009524"
);
assert_eq!(price.to_significant(4, None).unwrap(), "0.009524");
assert_eq!(price.base_currency, *WETH);
assert_eq!(price.quote_currency, *ETHER);
}
Expand Down
8 changes: 4 additions & 4 deletions src/entities/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ mod tests {
.clone()
.price_impact()
.unwrap()
.to_significant(3, Rounding::RoundHalfUp)
.to_significant(3, None)
.unwrap(),
"17.2"
);
Expand All @@ -1589,7 +1589,7 @@ mod tests {
.clone()
.price_impact()
.unwrap()
.to_significant(3, Rounding::RoundHalfUp)
.to_significant(3, None)
.unwrap(),
"19.8"
);
Expand Down Expand Up @@ -1663,7 +1663,7 @@ mod tests {
.clone()
.price_impact()
.unwrap()
.to_significant(3, Rounding::RoundHalfUp)
.to_significant(3, None)
.unwrap(),
"23.1"
);
Expand All @@ -1685,7 +1685,7 @@ mod tests {
.clone()
.price_impact()
.unwrap()
.to_significant(3, Rounding::RoundHalfUp)
.to_significant(3, None)
.unwrap(),
"25.5"
);
Expand Down
20 changes: 10 additions & 10 deletions src/utils/price_tick_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ mod tests {
assert_eq!(
tick_to_price(TOKEN1.clone(), TOKEN0.clone(), -I24::from_limbs([74959]))
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"1800"
);
Expand All @@ -114,7 +114,7 @@ mod tests {
assert_eq!(
tick_to_price(TOKEN0.clone(), TOKEN1.clone(), -I24::from_limbs([74959]))
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"0.00055556"
);
Expand All @@ -125,7 +125,7 @@ mod tests {
assert_eq!(
tick_to_price(TOKEN0.clone(), TOKEN1.clone(), I24::from_limbs([74959]))
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"1800"
);
Expand All @@ -136,7 +136,7 @@ mod tests {
assert_eq!(
tick_to_price(TOKEN1.clone(), TOKEN0.clone(), I24::from_limbs([74959]))
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"0.00055556"
);
Expand All @@ -151,7 +151,7 @@ mod tests {
-I24::from_limbs([276225])
)
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"1.01"
);
Expand All @@ -166,7 +166,7 @@ mod tests {
-I24::from_limbs([276225])
)
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"0.99015"
);
Expand All @@ -181,7 +181,7 @@ mod tests {
-I24::from_limbs([276423])
)
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"0.99015"
);
Expand All @@ -196,7 +196,7 @@ mod tests {
-I24::from_limbs([276423])
)
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"1.0099"
);
Expand All @@ -211,7 +211,7 @@ mod tests {
-I24::from_limbs([276225])
)
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"1.01"
);
Expand All @@ -226,7 +226,7 @@ mod tests {
-I24::from_limbs([276225])
)
.unwrap()
.to_significant(5, Rounding::RoundHalfUp)
.to_significant(5, None)
.unwrap(),
"0.99015"
);
Expand Down

0 comments on commit 355ea2d

Please sign in to comment.