Skip to content

Commit

Permalink
fixed a lot of clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 9, 2024
1 parent 78d29e2 commit cb0b1c6
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions contracts/cosmwasm/executor/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::new_ret_no_self)]
use cosmwasm_std::{Addr, Event};
use cvm_runtime::{
exchange::ExchangeId, executor::CvmExecutorInstantiated, NetworkId,
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub mod solution {
pub fn mantis_solution_chosen(
ab: DenomPair,
ctx: &ExecCtx<'_>,
transfers: &Vec<CowFillResult>,
transfers: &[CowFillResult],
cow_volume: u128,
cross_chain_volume: u128,
owner: Addr,
Expand Down
7 changes: 6 additions & 1 deletion contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod state;
mod types;
mod validation;

use constants::MIN_SOLUTION_COUNT;
use events::order::*;
use events::solution::*;
use itertools::Itertools;
Expand Down Expand Up @@ -321,6 +322,10 @@ impl OrderContract<'_> {
let mut transfers = vec![];
let mut solution_item: SolutionItem = possible_solution;
let mut volume = 0u128;
if all_solutions.len() < MIN_SOLUTION_COUNT as usize {
return Ok(Response::default());
}

for solution in all_solutions {
if validation::validate_solvers(&ctx.deps, &solution, &all_orders).is_err() {
continue;
Expand Down Expand Up @@ -480,7 +485,7 @@ impl OrderContract<'_> {
solver_address: String,
solution_block_added: u64,
optimal_price: Ratio,
solver_orders: &mut Vec<SolvedOrder>,
solver_orders: &mut [SolvedOrder],
) -> StdResult<Vec<CowFillResult>> {
let mut results = vec![];
for (transfer, order) in cows.into_iter() {
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn verify(
/// `a_total_from_orders` - total amount of `a` given by `orders`
/// `b_total_from_orders` - total amount of `b` given by `orders`
pub fn simulate_cows_via_bank(
orders: &Vec<SolvedOrder>,
orders: &[SolvedOrder],
mut a_total_from_orders: u128,
mut b_total_from_orders: u128,
) -> Result<CowSolutionCalculation, StdError> {
Expand Down
2 changes: 0 additions & 2 deletions crates/cvm-runtime-exchange/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub fn exchange(
response_id: u64,
) -> Result<Response, ContractError> {
use cvm_route::exchange::ExchangeType::*;
use prost::Message;
ensure_eq!(
give.0.len(),
1,
Expand Down Expand Up @@ -65,7 +64,6 @@ pub fn exchange(
};

use crate::osmosis_std::types::osmosis::poolmanager::v1beta1::*;
use prost::Message;
let msg = MsgSwapExactAmountIn {
routes: vec![SwapAmountInRoute {
pool_id,
Expand Down
1 change: 1 addition & 0 deletions crates/cvm-runtime/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::new_ret_no_self)]
use cosmwasm_std::Event;

use crate::prelude::*;
Expand Down
1 change: 1 addition & 0 deletions crates/cvm/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl Amount {
// with rounding to reduce or reduce down part up to some seven bit parts
pub const MAX_PARTS: u64 = 1_000_000_000_000_000_000;

#[cfg(not(feature="cosmwasm"))]
pub fn try_floor_f64(value: f64) -> Result<Self, ArithmeticError> {
if value < 0.0 || value.is_nan() {
Err(ArithmeticError::Underflow)
Expand Down
6 changes: 4 additions & 2 deletions mantis/node/src/mantis/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ fn new_spawn(
let in_amount: Amount = match spawn.in_asset_amount.as_ref().expect("in_asset_amount") {
InAssetAmount::Variant0(x) => (*x).try_into().expect("in_asset_amount"),
InAssetAmount::Variant1(x) => x.parse().expect("in_asset_amount"),
InAssetAmount::Variant2(x) => Amount::try_floor_f64(*x).expect("in_asset_amount"),
InAssetAmount::Variant2(x) => {
Amount::try_floor_f64(*x).expect("in_asset_amount")
}
};

let out_asset_id = match &spawn.out_asset_id {
Expand Down Expand Up @@ -88,7 +90,7 @@ fn new_exchange(exchange: &Exchange) -> CvmInstruction {
let in_amount: Amount = match &exchange.in_asset_amount {
InAssetAmount::Variant0(x) => (*x).try_into().expect("in_asset_amount"),
InAssetAmount::Variant1(x) => x.parse().expect("in_asset_amount"),
InAssetAmount::Variant2(x) => Amount::try_floor_f64(*x).expect("in_asset_amount"),
InAssetAmount::Variant2(x) => panic!("covert f64 to fraction, but really just fix python to give strings"), // Amount::try_floor_f64(*x).expect("in_asset_amount"),
};

let out_asset_id = match &exchange.out_asset_id {
Expand Down
3 changes: 3 additions & 0 deletions mantis/node/src/solver/router/shortest_path.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! cannot be used as the only production solver
//! used in tests when hard to get data from apis
//! and/or need to fund some possible route (still needs simulation of this route possible)
use std::collections::BTreeMap;
use cvm_route::venue::VenueId;
use cvm_runtime::shared::{CvmFundsFilter, CvmInstruction, CvmProgram};
Expand Down

0 comments on commit cb0b1c6

Please sign in to comment.