From cb0b1c6e04d595ba0a504446b7c612896e64ba37 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 9 Apr 2024 10:47:17 +0100 Subject: [PATCH] fixed a lot of clippy --- contracts/cosmwasm/executor/src/events.rs | 1 + contracts/cosmwasm/order/src/events.rs | 2 +- contracts/cosmwasm/order/src/lib.rs | 7 ++++++- contracts/cosmwasm/order/src/simulator.rs | 2 +- crates/cvm-runtime-exchange/src/lib.rs | 2 -- crates/cvm-runtime/src/executor.rs | 1 + crates/cvm/src/asset.rs | 1 + mantis/node/src/mantis/blackbox/mod.rs | 6 ++++-- mantis/node/src/solver/router/shortest_path.rs | 3 +++ 9 files changed, 18 insertions(+), 7 deletions(-) diff --git a/contracts/cosmwasm/executor/src/events.rs b/contracts/cosmwasm/executor/src/events.rs index 3cb985d6..07526ffe 100644 --- a/contracts/cosmwasm/executor/src/events.rs +++ b/contracts/cosmwasm/executor/src/events.rs @@ -1,3 +1,4 @@ +#![allow(clippy::new_ret_no_self)] use cosmwasm_std::{Addr, Event}; use cvm_runtime::{ exchange::ExchangeId, executor::CvmExecutorInstantiated, NetworkId, diff --git a/contracts/cosmwasm/order/src/events.rs b/contracts/cosmwasm/order/src/events.rs index 5a0fa8e7..423ada81 100644 --- a/contracts/cosmwasm/order/src/events.rs +++ b/contracts/cosmwasm/order/src/events.rs @@ -65,7 +65,7 @@ pub mod solution { pub fn mantis_solution_chosen( ab: DenomPair, ctx: &ExecCtx<'_>, - transfers: &Vec, + transfers: &[CowFillResult], cow_volume: u128, cross_chain_volume: u128, owner: Addr, diff --git a/contracts/cosmwasm/order/src/lib.rs b/contracts/cosmwasm/order/src/lib.rs index 174c687d..fe0d44e4 100644 --- a/contracts/cosmwasm/order/src/lib.rs +++ b/contracts/cosmwasm/order/src/lib.rs @@ -10,6 +10,7 @@ mod state; mod types; mod validation; +use constants::MIN_SOLUTION_COUNT; use events::order::*; use events::solution::*; use itertools::Itertools; @@ -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; @@ -480,7 +485,7 @@ impl OrderContract<'_> { solver_address: String, solution_block_added: u64, optimal_price: Ratio, - solver_orders: &mut Vec, + solver_orders: &mut [SolvedOrder], ) -> StdResult> { let mut results = vec![]; for (transfer, order) in cows.into_iter() { diff --git a/contracts/cosmwasm/order/src/simulator.rs b/contracts/cosmwasm/order/src/simulator.rs index dcba3883..a47d385a 100644 --- a/contracts/cosmwasm/order/src/simulator.rs +++ b/contracts/cosmwasm/order/src/simulator.rs @@ -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, + orders: &[SolvedOrder], mut a_total_from_orders: u128, mut b_total_from_orders: u128, ) -> Result { diff --git a/crates/cvm-runtime-exchange/src/lib.rs b/crates/cvm-runtime-exchange/src/lib.rs index 4f309be2..c82980ca 100644 --- a/crates/cvm-runtime-exchange/src/lib.rs +++ b/crates/cvm-runtime-exchange/src/lib.rs @@ -20,7 +20,6 @@ pub fn exchange( response_id: u64, ) -> Result { use cvm_route::exchange::ExchangeType::*; - use prost::Message; ensure_eq!( give.0.len(), 1, @@ -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, diff --git a/crates/cvm-runtime/src/executor.rs b/crates/cvm-runtime/src/executor.rs index f70f0059..3cf6390b 100644 --- a/crates/cvm-runtime/src/executor.rs +++ b/crates/cvm-runtime/src/executor.rs @@ -1,3 +1,4 @@ +#![allow(clippy::new_ret_no_self)] use cosmwasm_std::Event; use crate::prelude::*; diff --git a/crates/cvm/src/asset.rs b/crates/cvm/src/asset.rs index 668c56db..98fa118a 100644 --- a/crates/cvm/src/asset.rs +++ b/crates/cvm/src/asset.rs @@ -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 { if value < 0.0 || value.is_nan() { Err(ArithmeticError::Underflow) diff --git a/mantis/node/src/mantis/blackbox/mod.rs b/mantis/node/src/mantis/blackbox/mod.rs index a9dcbcf4..7720939e 100644 --- a/mantis/node/src/mantis/blackbox/mod.rs +++ b/mantis/node/src/mantis/blackbox/mod.rs @@ -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 { @@ -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 { diff --git a/mantis/node/src/solver/router/shortest_path.rs b/mantis/node/src/solver/router/shortest_path.rs index 9551a8de..40991b6d 100644 --- a/mantis/node/src/solver/router/shortest_path.rs +++ b/mantis/node/src/solver/router/shortest_path.rs @@ -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};