From 99f113a2e59475030ff4b7e885a9a8d3ad2cdd36 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 8 Apr 2024 21:27:12 +0100 Subject: [PATCH] fixed expression issues --- contracts/cosmwasm/order/src/lib.rs | 2 +- contracts/cosmwasm/order/src/simulator.rs | 8 ++-- contracts/cosmwasm/order/src/types.rs | 6 +-- contracts/cosmwasm/order/src/validation.rs | 14 +++---- .../cosmwasm/outpost/src/contract/execute.rs | 5 +-- .../outpost/src/contract/ibc/ics20.rs | 6 +-- .../cosmwasm/outpost/src/contract/query.rs | 3 -- contracts/cosmwasm/outpost/src/state/mod.rs | 2 + .../cosmwasm/outpost/src/state/venues.rs | 8 ++++ crates/cvm-runtime/src/cosmwasm/mod.rs | 3 +- crates/cvm-runtime/src/outpost/config.rs | 7 +--- crates/cvm-runtime/src/shared.rs | 7 ++-- crates/cvm-runtime/src/transport/ibc/mod.rs | 4 +- crates/cvm/src/address.rs | 3 +- crates/cvm/src/asset.rs | 41 ++++++++++++++----- crates/cvm/src/prelude.rs | 3 -- mantis/node/src/bin/mantis.rs | 6 +-- mantis/node/src/mantis/blackbox/mod.rs | 12 +++--- mantis/node/src/mantis/cosmos/signer.rs | 1 - mantis/node/src/mantis/solve.rs | 4 +- mantis/node/src/prelude.rs | 1 + mantis/node/src/solver/router/mod.rs | 2 +- ...{optimal-routing.rs => optimal_routing.rs} | 0 .../solver/router/{bf.rs => shortest_path.rs} | 30 +++++++------- 24 files changed, 95 insertions(+), 83 deletions(-) create mode 100644 contracts/cosmwasm/outpost/src/state/venues.rs rename mantis/node/src/solver/router/{optimal-routing.rs => optimal_routing.rs} (100%) rename mantis/node/src/solver/router/{bf.rs => shortest_path.rs} (80%) diff --git a/contracts/cosmwasm/order/src/lib.rs b/contracts/cosmwasm/order/src/lib.rs index a159e154..e9a1c58a 100644 --- a/contracts/cosmwasm/order/src/lib.rs +++ b/contracts/cosmwasm/order/src/lib.rs @@ -540,7 +540,7 @@ impl OrderContract<'_> { solver_address: String, solution_id: SolutionHash, solver_orders: Vec, - pair: DenomPair, + _pair: DenomPair, ) -> Result, StdError> { let mut result = vec![]; for order in solver_orders.iter() { diff --git a/contracts/cosmwasm/order/src/simulator.rs b/contracts/cosmwasm/order/src/simulator.rs index fc138df5..bc23279a 100644 --- a/contracts/cosmwasm/order/src/simulator.rs +++ b/contracts/cosmwasm/order/src/simulator.rs @@ -12,11 +12,11 @@ use crate::SolvedOrder; /// given expected output amount and list of orders and CVM program, produce fill in of orders /// return filling amounts for all orders from program, which may or may not lead to full fill pub fn verify( - route: CvmProgram, + _route: CvmProgram, _in_asset: &AssetItem, - out_asset: &AssetItem, - predicted_out_amount: u128, - orders: Vec, + _out_asset: &AssetItem, + _predicted_out_amount: u128, + _orders: Vec, ) -> Result, StdError> { panic!() } diff --git a/contracts/cosmwasm/order/src/types.rs b/contracts/cosmwasm/order/src/types.rs index dcc01810..3fffd020 100644 --- a/contracts/cosmwasm/order/src/types.rs +++ b/contracts/cosmwasm/order/src/types.rs @@ -53,7 +53,7 @@ impl OrderItem { /// `wanted_fill_amount` - amount to fill in `wants` amounts /// Reduces given amount /// `optimal_price` - the price to solve against, should be same or better than user limit. - pub fn fill(&mut self, wanted_fill_amount: Amount, optimal_ratio: Ratio) -> StdResult<()> { + pub fn fill(&mut self, wanted_fill_amount: Amount, _optimal_ratio: Ratio) -> StdResult<()> { // was given more or exact wanted - user happy or user was given all before, do not give more if wanted_fill_amount >= self.msg.wants.amount || self.msg.wants.amount.u128() == <_>::default() @@ -88,8 +88,8 @@ impl OrderItem { /// simple structure which can be applied to order to fill or partial fill it pub struct Filling { - order_id: u64, - amount: Uint128, + pub order_id: u64, + pub amount: Uint128, } #[cfg(test)] diff --git a/contracts/cosmwasm/order/src/validation.rs b/contracts/cosmwasm/order/src/validation.rs index 2a3a299f..28a39c9a 100644 --- a/contracts/cosmwasm/order/src/validation.rs +++ b/contracts/cosmwasm/order/src/validation.rs @@ -7,18 +7,18 @@ use crate::{OrderItem, SolvedOrder}; /// Validate solver can solve order he tells. /// Minimal requirement is that CVM salt is unique to solver pub fn validate_solver( - as_ref: cosmwasm_std::Deps<'_>, + _as_ref: cosmwasm_std::Deps<'_>, _sender: &Addr, - order: &OrderItem, + _order: &OrderItem, ) -> StdResult<()> { Ok(()) } /// Validate solver can solver amount he claimed pub(crate) fn validate_solvers( - deps: &cosmwasm_std::DepsMut<'_>, - solution: &crate::SolutionItem, - all_orders: &[SolvedOrder], + _deps: &cosmwasm_std::DepsMut<'_>, + _solution: &crate::SolutionItem, + _all_orders: &[SolvedOrder], ) -> StdResult<()> { Ok(()) } @@ -27,8 +27,8 @@ pub(crate) fn validate_solvers( /// Minimal requirement is that CVM salt is unique to solver pub(crate) fn validate_routes( _deps: &cosmwasm_std::DepsMut<'_>, - solution: &crate::SolutionItem, - all_orders: &[SolvedOrder], + _solution: &crate::SolutionItem, + _all_orders: &[SolvedOrder], ) -> StdResult<()> { Ok(()) } diff --git a/contracts/cosmwasm/outpost/src/contract/execute.rs b/contracts/cosmwasm/outpost/src/contract/execute.rs index add812df..2a96a62c 100644 --- a/contracts/cosmwasm/outpost/src/contract/execute.rs +++ b/contracts/cosmwasm/outpost/src/contract/execute.rs @@ -101,9 +101,7 @@ fn handle_config_msg( this_asset, other_network, other_asset, - }) => { - assets::force_asset_to_network_map(auth, deps, this_asset, other_network, other_asset) - } + }) => assets::force_asset_to_network_map(auth, deps, this_asset, other_network, other_asset), ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg), ConfigSubMsg::ForceInstantiate { user_origin, salt } => { executor::force_instantiate(auth, env.contract.address.clone(), deps, user_origin, salt) @@ -116,6 +114,7 @@ fn handle_config_msg( } Ok(aggregated) } + ConfigSubMsg::ForceAssetsVenue(msg) => state::venues::force_assets_venue(auth, deps, msg), } } diff --git a/contracts/cosmwasm/outpost/src/contract/ibc/ics20.rs b/contracts/cosmwasm/outpost/src/contract/ibc/ics20.rs index 60761d0d..cd2ad529 100644 --- a/contracts/cosmwasm/outpost/src/contract/ibc/ics20.rs +++ b/contracts/cosmwasm/outpost/src/contract/ibc/ics20.rs @@ -185,12 +185,12 @@ pub fn get_this_route( let asset: AssetItem = crate::state::assets::ASSETS .load(storage, this_asset_id) .map_err(|_| ContractError::AssetNotFoundById(this_asset_id))?; - let to_asset: AssetId = crate::state::assets::NETWORK_ASSET + let to_asset_id: AssetId = crate::state::assets::NETWORK_ASSET .load(storage, (to_network_id, this_asset_id)) .map_err(|_| { ContractError::AssetCannotBeTransferredToNetwork(this_asset_id, to_network_id) })? - .asset_id; + .to_asset_id; let to_outpost = other .network .outpost @@ -224,7 +224,7 @@ pub fn get_this_route( .ics20 .ok_or(ContractError::ICS20NotFound)? .sender, - on_remote_asset: to_asset, + on_remote_asset: to_asset_id, }) } diff --git a/contracts/cosmwasm/outpost/src/contract/query.rs b/contracts/cosmwasm/outpost/src/contract/query.rs index 67daf9e6..b4087fae 100644 --- a/contracts/cosmwasm/outpost/src/contract/query.rs +++ b/contracts/cosmwasm/outpost/src/contract/query.rs @@ -1,8 +1,5 @@ use crate::{assets, error::Result, msg}; - use cosmwasm_std::{to_json_binary, Binary, Deps, Env}; -use cvm_runtime::outpost::GetConfigResponse; - use super::ibc::ics20::get_this_route; #[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)] diff --git a/contracts/cosmwasm/outpost/src/state/mod.rs b/contracts/cosmwasm/outpost/src/state/mod.rs index 3afabbea..94a64757 100644 --- a/contracts/cosmwasm/outpost/src/state/mod.rs +++ b/contracts/cosmwasm/outpost/src/state/mod.rs @@ -4,6 +4,7 @@ pub mod executors; pub mod ics27; pub mod network; pub mod tracking; +pub mod venues; use crate::{error::ContractError, prelude::*}; use cosmwasm_std::{StdResult, Storage}; @@ -32,5 +33,6 @@ pub(crate) fn get_config(deps: cosmwasm_std::Deps<'_>) -> Result Result { + todo!() +} \ No newline at end of file diff --git a/crates/cvm-runtime/src/cosmwasm/mod.rs b/crates/cvm-runtime/src/cosmwasm/mod.rs index 4ea3adc5..d4572748 100644 --- a/crates/cvm-runtime/src/cosmwasm/mod.rs +++ b/crates/cvm-runtime/src/cosmwasm/mod.rs @@ -66,8 +66,7 @@ use super::{BindingValue, Bindings}; use crate::{ExecutorOrigin, NetworkId, OrderedBindings, UserId, UserOrigin}; use alloc::{fmt::Debug, string::String, vec, vec::Vec}; -use cosmwasm_std::{BankMsg, Coin, CosmosMsg, StdResult, Uint64}; -use cw_storage_plus::{IntKey, Key, KeyDeserialize, Prefixer, PrimaryKey}; +use cosmwasm_std::{BankMsg, Coin, CosmosMsg, Uint64}; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/cvm-runtime/src/outpost/config.rs b/crates/cvm-runtime/src/outpost/config.rs index 315f84a6..b82a3b0d 100644 --- a/crates/cvm-runtime/src/outpost/config.rs +++ b/crates/cvm-runtime/src/outpost/config.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "cosmwasm")] -use cosmwasm_std::{BlockInfo, IbcTimeout}; - use cvm_route::{ asset::AssetToNetwork, exchange::ExchangeItem, transport::NetworkToNetworkItem, venue::AssetsVenueItem, * }; @@ -8,10 +5,8 @@ use ibc_core_host_types::identifiers::ChannelId; use crate::{prelude::*, transport::ibc::IbcEnabled, AssetId, NetworkId}; -type EthAddress = [u8; 20]; // primitive_types::H160; - /// Version of IBC channels used by the gateway. -pub const IBC_VERSION: &str = "xcvm-v0"; +pub const IBC_VERSION: &str = "cvm-v0"; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[serde(rename_all = "snake_case")] diff --git a/crates/cvm-runtime/src/shared.rs b/crates/cvm-runtime/src/shared.rs index 54b7da42..05e97254 100644 --- a/crates/cvm-runtime/src/shared.rs +++ b/crates/cvm-runtime/src/shared.rs @@ -1,7 +1,5 @@ -use core::panic; - use crate::{prelude::*, AssetId}; -use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult}; +use cosmwasm_std::{from_json, to_json_binary, Binary, StdResult}; use cvm::{NetworkId, XcAddr}; use serde::{de::DeserializeOwned, Serialize}; @@ -64,11 +62,12 @@ impl CvmProgram { } } + impl CvmInstruction { pub fn transfer_absolute_to_account(to: &str, asset_id: u128, amount: u128) -> Self { Self::Transfer { to: crate::Destination::Account(XcAddr(to.to_owned())), - assets: CvmFundsFilter::one(asset_id.into(), crate::Amount::new(amount, 0)), + assets: CvmFundsFilter::of(asset_id.into(), crate::Amount::new(amount, 0)), } } diff --git a/crates/cvm-runtime/src/transport/ibc/mod.rs b/crates/cvm-runtime/src/transport/ibc/mod.rs index 766390e4..99aa560a 100644 --- a/crates/cvm-runtime/src/transport/ibc/mod.rs +++ b/crates/cvm-runtime/src/transport/ibc/mod.rs @@ -4,10 +4,10 @@ use crate::{ shared::CvmPacket, AssetId, NetworkId, }; -use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, IbcEndpoint, StdResult}; +use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, StdResult}; use cvm_route::transport::RelativeTimeout; -use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId}; +use ibc_core_host_types::identifiers::{ChannelId, PortId}; use ibc_apps_more::types::hook::Callback; //, HookMemo}; diff --git a/crates/cvm/src/address.rs b/crates/cvm/src/address.rs index 26180fe0..0f652575 100644 --- a/crates/cvm/src/address.rs +++ b/crates/cvm/src/address.rs @@ -1,6 +1,5 @@ use crate::prelude::*; -use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult}; -use serde::{de::DeserializeOwned, Serialize}; +use cosmwasm_std::{Api, Binary, CanonicalAddr, StdError}; /// A wrapper around any address on any chain. /// Similar to `ibc_rs::Signer`(multi encoding), but not depend on ibc code bloat. diff --git a/crates/cvm/src/asset.rs b/crates/cvm/src/asset.rs index 1ff86977..b2172017 100644 --- a/crates/cvm/src/asset.rs +++ b/crates/cvm/src/asset.rs @@ -6,7 +6,7 @@ use cw_storage_plus::{Key, Prefixer}; use crate::shared::Displayed; use core::ops::Add; use cosmwasm_std::{Uint128, Uint256}; -use num::Zero; +use num::{One, Zero}; use serde::{Deserialize, Serialize}; /// Newtype for CVM assets ID. Must be unique for each asset and must never change. @@ -102,6 +102,13 @@ pub struct Amount { pub slope: Displayed, } + +pub trait AmountBuilder { + fn everything() -> Self; + fn one() -> Self; +} + + impl TryFrom for Amount { type Error = ArithmeticError; @@ -158,16 +165,22 @@ impl From<(u64, u64)> for Amount { } } +impl AmountBuilder for Amount { + /// Everything mean that we move 100% of whats left. + fn everything() -> Self { + Self::ratio(Self::MAX_PARTS) + } + fn one() -> Self { + Self::absolute(1) + } +} + impl Amount { /// idiotic idea fom KO, it should be /// u64/u64 ratio // 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; - pub fn one() -> Self { - Self::absolute(1) - } - pub fn try_floor_f64(value: f64) -> Result { if value < 0.0 || value.is_nan() { Err(ArithmeticError::Underflow) @@ -211,11 +224,6 @@ impl Amount { self.intercept.0 == 0 } - /// Everything mean that we move 100% of whats left. - pub const fn everything() -> Self { - Self::ratio(Self::MAX_PARTS) - } - /// `f(x) = a(x - b) + b where a = slope / MAX_PARTS, b = intercept` pub fn apply(&self, value: u128) -> Result { if value.is_zero() { @@ -327,11 +335,22 @@ impl From for Amount { pub struct Funds(pub Vec<(AssetId, T)>); impl Funds { - pub fn one>(id: AssetId, amount: A) -> Self { + pub fn of>(id: AssetId, amount: A) -> Self { Self(vec![(id, amount.into())]) } } +impl Funds { + pub fn all_of(asset_id: AssetId) -> Self { + Self(vec![(asset_id, T::everything())]) + } + + pub fn one_of(asset_id: AssetId) -> Self { + Self(vec![(asset_id, T::one())]) + } +} + + impl Default for Funds { fn default() -> Self { Self(Vec::new()) diff --git a/crates/cvm/src/prelude.rs b/crates/cvm/src/prelude.rs index fc9c416f..384f6b90 100644 --- a/crates/cvm/src/prelude.rs +++ b/crates/cvm/src/prelude.rs @@ -1,5 +1,4 @@ pub use alloc::{ - boxed::Box, format, string::{String, ToString}, vec, @@ -8,8 +7,6 @@ pub use alloc::{ pub use core::{fmt::Display, str::FromStr}; -#[cfg(feature = "cosmwasm")] -pub use cosmwasm_std::{Addr, Binary, Coin, Uint128}; pub use serde::{Deserialize, Serialize}; #[cfg(feature = "parity-scale-codec")] diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index 377f0f30..22103171 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -1,8 +1,4 @@ use bip32::secp256k1::elliptic_curve::rand_core::block; -use cosmos_sdk_proto::{ - cosmos::{auth::v1beta1::BaseAccount, base::v1beta1::Coin}, - cosmwasm::{self, wasm::v1::QuerySmartContractStateRequest}, -}; use cosmos_sdk_proto::{traits::Message, Any}; use cosmrs::{ tendermint::{block::Height, chain}, @@ -204,7 +200,7 @@ async fn solve( ); let a_cvm_route = blackbox::get_route(router_api, a, &cvm_glt, salt.as_ref()).await; let b_cvm_route = blackbox::get_route(router_api, b, &cvm_glt, salt.as_ref()).await; - let program = CvmProgram::ins + panic!(); send_solution( pair_solution.cows, vec![a_cvm_route, b_cvm_route], diff --git a/mantis/node/src/mantis/blackbox/mod.rs b/mantis/node/src/mantis/blackbox/mod.rs index e82c97c0..a9dcbcf4 100644 --- a/mantis/node/src/mantis/blackbox/mod.rs +++ b/mantis/node/src/mantis/blackbox/mod.rs @@ -8,7 +8,7 @@ use cvm_runtime::{ Amount, AssetId, ExchangeId, }; -use crate::solver::router::bf; +use crate::solver::router::shortest_path; use super::solve::IntentBankInput; @@ -71,7 +71,7 @@ fn new_spawn( program, network_id, salt: salt.to_vec(), - assets: CvmFundsFilter::one(in_asset_id, in_amount), + assets: CvmFundsFilter::of(in_asset_id, in_amount), } } @@ -98,8 +98,8 @@ fn new_exchange(exchange: &Exchange) -> CvmInstruction { CvmInstruction::Exchange { exchange_id, - give: CvmFundsFilter::one(in_asset_id, in_amount), - want: CvmFundsFilter::one(out_asset_id, Amount::one()), + give: CvmFundsFilter::of(in_asset_id, in_amount), + want: CvmFundsFilter::one_of(out_asset_id), } } @@ -108,9 +108,9 @@ pub async fn get_route( input: IntentBankInput, cvm_glt: &GetConfigResponse, salt: &[u8], -) -> CvmInstruction { +) -> Vec { if route_provider == "priceless" { - return bf::route(cvm_glt, input, salt); + return shortest_path::route(cvm_glt, input, salt); } else { let blackbox: Client = Client::new(route_provider); let mut route = blackbox diff --git a/mantis/node/src/mantis/cosmos/signer.rs b/mantis/node/src/mantis/cosmos/signer.rs index 6c42b6a1..bef8affc 100644 --- a/mantis/node/src/mantis/cosmos/signer.rs +++ b/mantis/node/src/mantis/cosmos/signer.rs @@ -1,7 +1,6 @@ //! given whatever string, give me the signer struct use cosmrs::crypto::secp256k1::SigningKey; -use prost_types::Any; pub fn from_mnemonic(phrase: &str, derivation_path: &str) -> Result { let seed = bip39::Mnemonic::parse_normalized(phrase) diff --git a/mantis/node/src/mantis/solve.rs b/mantis/node/src/mantis/solve.rs index af589c9b..fbf4aece 100644 --- a/mantis/node/src/mantis/solve.rs +++ b/mantis/node/src/mantis/solve.rs @@ -87,7 +87,7 @@ impl IntentBankInput { let part = CvmBalanceFilter::from((*part.numer(), *part.denom())); CvmInstruction::Transfer { to: Destination::Account(CvmAddress::from(x.0.to_string())), - assets: CvmFundsFilter::one(a_asset, part), + assets: CvmFundsFilter::of(a_asset, part), } }); let a_received = b_to_a.iter().map(|x| { @@ -95,7 +95,7 @@ impl IntentBankInput { let part = CvmBalanceFilter::from((*part.numer(), *part.denom())); CvmInstruction::Transfer { to: Destination::Account(CvmAddress::from(x.0.to_string())), - assets: CvmFundsFilter::one(b_asset, part), + assets: CvmFundsFilter::of(b_asset, part), } }); diff --git a/mantis/node/src/prelude.rs b/mantis/node/src/prelude.rs index efea2b98..584f3c3c 100644 --- a/mantis/node/src/prelude.rs +++ b/mantis/node/src/prelude.rs @@ -16,6 +16,7 @@ pub use std::fmt::format; pub use std::fmt::Debug; pub use std::str::FromStr; pub use tuples::*; +pub use std::vec; #[cfg(test)] pub use cosmwasm_std::testing::*; diff --git a/mantis/node/src/solver/router/mod.rs b/mantis/node/src/solver/router/mod.rs index c3ce10d9..348c0560 100644 --- a/mantis/node/src/solver/router/mod.rs +++ b/mantis/node/src/solver/router/mod.rs @@ -1 +1 @@ -pub mod bf; +pub mod shortest_path; diff --git a/mantis/node/src/solver/router/optimal-routing.rs b/mantis/node/src/solver/router/optimal_routing.rs similarity index 100% rename from mantis/node/src/solver/router/optimal-routing.rs rename to mantis/node/src/solver/router/optimal_routing.rs diff --git a/mantis/node/src/solver/router/bf.rs b/mantis/node/src/solver/router/shortest_path.rs similarity index 80% rename from mantis/node/src/solver/router/bf.rs rename to mantis/node/src/solver/router/shortest_path.rs index d3e46f95..9551a8de 100644 --- a/mantis/node/src/solver/router/bf.rs +++ b/mantis/node/src/solver/router/shortest_path.rs @@ -1,16 +1,14 @@ use std::collections::BTreeMap; - -use blackbox_rs::types::SingleInputAssetCvmRoute; use cvm_route::venue::VenueId; -use cvm_runtime::proto::pb::program::{Exchange, Transfer}; use cvm_runtime::shared::{CvmFundsFilter, CvmInstruction, CvmProgram}; use cvm_runtime::{exchange, AssetId, ExchangeId}; -use petgraph::algo::{bellman_ford, min_spanning_tree}; +use petgraph::algo::bellman_ford; use petgraph::data::FromElements; use petgraph::dot::{Config, Dot}; use petgraph::graph::{NodeIndex, UnGraph}; // need some how unify with python +#[derive(Debug, Clone)] pub enum Venue { Transfer(AssetId, AssetId), Exchange(ExchangeId, AssetId, AssetId), @@ -36,7 +34,7 @@ pub fn route( cvm_glt: &cvm_runtime::outpost::GetConfigResponse, input: crate::mantis::solve::IntentBankInput, salt: &[u8], -) -> vec![CvmInstruction] { +) -> Vec { let mut graph = petgraph::graph::DiGraph::new(); let mut assets_global_to_local = std::collections::BTreeMap::new(); for asset_id in cvm_glt.get_all_asset_ids() { @@ -62,25 +60,29 @@ pub fn route( } } - let routes = bellman_ford::bellman_ford(&graph, *in_node_index).expect("bf"); + let start_node_index = assets_global_to_local + .get(&input.in_asset_id) + .expect("node") + .clone(); + 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") .clone(); - let mut in_node_index = routes.predecessors[out_node_index]; + let mut in_node_index = routes.predecessors[out_node_index.index()]; let mut instructions = input.order_accounts.clone(); - while let Some(in_node_index) = in_node_index { + while let Some(in_node_index_value) = in_node_index { let venue_index = graph - .find_edge(out_node_index, in_node_index) + .find_edge(out_node_index,in_node_index_value) .expect("edge"); - let venue: Venue = venue_local_to_global.get(&venue_index).expect("venue"); + let venue = venue_local_to_global.get(&venue_index).expect("venue").clone(); match venue { 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(), - assets: CvmFundsFilter::all_of(id), + assets: CvmFundsFilter::all_of(from_asset_id), program: CvmProgram { tag: salt.to_vec(), instructions, @@ -92,13 +94,13 @@ pub fn route( let exchange = CvmInstruction::Exchange { exchange_id, give: CvmFundsFilter::all_of(from_asset_id), - want: CvmFundsFilter::one(to_asset_id), + want: CvmFundsFilter::one_of(to_asset_id), }; - instructions = [[exchange], instructions].concat(); + instructions = [[exchange].as_ref(), instructions.as_ref()].concat(); } } - (in_node_index, out_node_index) = (routes.predecessors[in_node_index], in_node_index); + (in_node_index, out_node_index) = (routes.predecessors[in_node_index_value.index()], in_node_index_value); } instructions }