Skip to content

Commit

Permalink
clippy fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 9, 2024
1 parent ba596bc commit cee109d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
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 @@ -3,7 +3,7 @@ use blackbox_rs::{types::*, Client};
use cvm_runtime::{
outpost::GetConfigResponse,
shared::{CvmAddress, CvmFundsFilter, CvmInstruction, CvmProgram, Displayed},
Amount,
Amount,
};

use crate::solver::router::shortest_path;
Expand Down Expand Up @@ -51,7 +51,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) => panic!("fix python not to have float or use to fixed point/fraction first"), // Amount::try_floor_f64(*x).expect("in_asset_amount"),
InAssetAmount::Variant2(x) => {
panic!("fix python not to have float or use to fixed point/fraction first")
} // Amount::try_floor_f64(*x).expect("in_asset_amount"),
};

let out_asset_id = match &spawn.out_asset_id {
Expand Down
5 changes: 1 addition & 4 deletions mantis/node/src/mantis/cosmos/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::prelude::*;

use cosmos_sdk_proto::cosmos::{
auth::v1beta1::BaseAccount,
};
use cosmos_sdk_proto::cosmos::auth::v1beta1::BaseAccount;
use cosmrs::{
rpc::Client,
tendermint::{block::Height, chain},
Expand Down Expand Up @@ -38,7 +36,6 @@ pub fn timeout(height: Height, delta: u32) -> u64 {

pub async fn create_cosmos_query_client(rpc: &str) -> CosmosQueryClient {
use cosmos_sdk_proto::cosmos::auth::v1beta1::query_client::*;
use cosmos_sdk_proto::cosmos::auth::v1beta1::*;

let url = tonic::transport::Endpoint::from_str(rpc).expect("url");
QueryClient::connect(url).await.expect("connected")
Expand Down
8 changes: 1 addition & 7 deletions mantis/node/src/mantis/solve.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use core::num;

use cosmrs::tendermint::block::Height;
use cvm_runtime::{
outpost::GetConfigResponse,
shared::{CvmAddress, CvmBalanceFilter, CvmFunds, CvmFundsFilter, CvmInstruction, Displayed},
Amount, AssetId, Destination,
};
use cw_mantis_order::{CrossChainPart, OrderAmount, OrderItem, OrderSolution, OrderSubMsg};
use mantis_cw::{DenomPair, OrderCoinPair, OrderSide, OrderedTuple2};
use num_rational::{Ratio, Rational64};
use num_rational::Ratio;

use crate::{
prelude::*,
solver::{orderbook::OrderList, solution::Solution},
};

use super::cosmos::client::timeout;

/// input batched summarized from users for routing
pub struct IntentBankInput {
pub in_asset_id: AssetId,
Expand Down Expand Up @@ -117,8 +113,6 @@ pub fn find_cows(all_orders: &[OrderItem]) -> Vec<PairSolution> {
let mut cows_per_pair = vec![];
for (ab, orders) in all_orders.into_iter() {
let orders = orders.collect::<Vec<_>>();
use crate::solver::cows::*;
use crate::solver::types::*;
let orders = orders.iter().map(|x| {
crate::solver::types::Order::new_integer(
x.given.amount.u128(),
Expand Down
11 changes: 4 additions & 7 deletions mantis/node/src/solver/router/shortest_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ use cvm_route::venue::VenueId;
use cvm_runtime::shared::{CvmFundsFilter, CvmInstruction, CvmProgram};
use cvm_runtime::{exchange, AssetId, ExchangeId};
use petgraph::algo::bellman_ford;
use petgraph::data::FromElements;
use petgraph::dot::{Config, Dot};
use petgraph::graph::{NodeIndex, UnGraph};
use std::collections::BTreeMap;
use std::ops::Deref;

Expand Down Expand Up @@ -55,7 +53,7 @@ pub fn route(
let local_venue = graph.add_edge(*from_node, *to_node, 1.0);
venue_local_to_global.insert(local_venue, venue.clone());
}
Venue::Exchange(exchange_id, from, to) => {
Venue::Exchange(_exchange_id, from, to) => {
let from_node = assets_global_to_local.get(&from).unwrap();
let to_node = assets_global_to_local.get(&to).unwrap();
let local_venue = graph.add_edge(*from_node, *to_node, 1.0);
Expand All @@ -71,9 +69,8 @@ pub fn route(
let routes = bellman_ford::bellman_ford(&graph, start_node_index).expect("bf");

let mut out_node_index = *assets_global_to_local
.get(&input.out_asset_id)
.expect("node")
;
.get(&input.out_asset_id)
.expect("node");
let mut in_node_index = routes.predecessors[out_node_index.index()];
let mut instructions = input.order_accounts.clone();
while let Some(in_node_index_value) = in_node_index {
Expand All @@ -85,7 +82,7 @@ pub fn route(
.expect("venue")
.clone();
match venue {
Venue::Transfer(from_asset_id, to_asset_id) => {
Venue::Transfer(from_asset_id, _to_asset_id) => {
let spawn = CvmInstruction::Spawn {
network_id: cvm_glt.get_network_for_asset(from_asset_id),
salt: salt.to_vec(),
Expand Down
12 changes: 10 additions & 2 deletions mantis/node/tests/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
use cosmrs::tendermint::block::Height;
use cosmwasm_std::{testing::*, Addr, Binary, Coin, MessageInfo};
use cw_mantis_order::{sv::*, OrderItem, OrderSubMsg, SolutionSubMsg};
use mantis_node::{mantis::{simulate::randomize_order, solve::PairSolution}, prelude::*};
use mantis_node::{
mantis::{simulate::randomize_order, solve::PairSolution},
prelude::*,
};

#[test]
fn cows_scenarios() {
Expand Down Expand Up @@ -228,7 +231,12 @@ fn do_solve(
info: MessageInfo,
) -> Vec<cosmwasm_std::Response> {
let mut responses = vec![];
for PairSolution {cows, optimal_price, ..} in cows_per_pair {
for PairSolution {
cows,
optimal_price,
..
} in cows_per_pair
{
let msg = ExecMsg::Solve {
msg: SolutionSubMsg {
cows,
Expand Down

0 comments on commit cee109d

Please sign in to comment.