diff --git a/mantis/node/src/bin/mantis.rs b/mantis/node/src/bin/mantis.rs index fede9d2c..377f0f30 100644 --- a/mantis/node/src/bin/mantis.rs +++ b/mantis/node/src/bin/mantis.rs @@ -202,10 +202,12 @@ async fn solve( &cvm_glt, pair_solution.ab.clone(), ); - let cvm_route = blackbox::get_route(router_api, a, b, &cvm_glt, salt.as_ref()).await; + 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 send_solution( pair_solution.cows, - cvm_route, + vec![a_cvm_route, b_cvm_route], tip, pair_solution.optimal_price, signing_key, @@ -219,7 +221,7 @@ async fn solve( async fn send_solution( cows: Vec, - _cvm: CvmProgram, + cvm: Vec, tip: &Tip, optimal_price: Ratio, signing_key: &cosmrs::crypto::secp256k1::SigningKey, diff --git a/mantis/node/src/mantis/blackbox/mod.rs b/mantis/node/src/mantis/blackbox/mod.rs index 1ef48809..e82c97c0 100644 --- a/mantis/node/src/mantis/blackbox/mod.rs +++ b/mantis/node/src/mantis/blackbox/mod.rs @@ -103,28 +103,25 @@ fn new_exchange(exchange: &Exchange) -> CvmInstruction { } } -/// `order_accounts` - account of order where to dispatch amounts (part of whole) pub async fn get_route( route_provider: &str, - a: IntentBankInput, - b: IntentBankInput, + input: IntentBankInput, cvm_glt: &GetConfigResponse, salt: &[u8], -) -> CvmProgram { - if route_provider == "priceless" { - panic!() - //bf::route(input, cvm_glt, salt); +) -> CvmInstruction { + if route_provider == "priceless" { + return bf::route(cvm_glt, input, salt); } else { let blackbox: Client = Client::new(route_provider); let mut route = blackbox .simulator_router_simulator_router_get( &InAssetAmount::Variant0( - a.in_asset_amount.0.try_into().expect("in_asset_amount"), + input.in_asset_amount.0.try_into().expect("in_asset_amount"), ), - &InAssetId::Variant1(a.in_asset_id.to_string()), + &InAssetId::Variant1(input.in_asset_id.to_string()), true, &OutAssetAmount::Variant0(10), - &OutAssetId::Variant1(a.out_asset_id.to_string().into()), + &OutAssetId::Variant1(input.out_asset_id.to_string().into()), ) .await .expect("route found") @@ -134,6 +131,6 @@ pub async fn get_route( let mut program = CvmProgram::default(); build_next(&mut program, &mut route.next, cvm_glt, salt); - return program; + panic!("so need to build instruction so can plug into one program (transaciton)") } } diff --git a/mantis/node/src/solver/router/bf.rs b/mantis/node/src/solver/router/bf.rs index 0948bf77..58a47b90 100644 --- a/mantis/node/src/solver/router/bf.rs +++ b/mantis/node/src/solver/router/bf.rs @@ -1,7 +1,9 @@ +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::CvmProgram; +use cvm_runtime::shared::{CvmInstruction, CvmProgram}; use cvm_runtime::{exchange, AssetId, ExchangeId}; use petgraph::algo::{bellman_ford, min_spanning_tree}; use petgraph::data::FromElements; @@ -31,7 +33,8 @@ pub fn get_all_asset_maps(cvm_glt: &cvm_runtime::outpost::GetConfigResponse) -> pub fn route( cvm_glt: &cvm_runtime::outpost::GetConfigResponse, input: crate::mantis::solve::IntentBankInput, -) -> CvmProgram { + salt: &[u8], +) -> CvmInstruction { 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() { @@ -39,17 +42,20 @@ pub fn route( assets_global_to_local.insert(asset_id, node); } + let mut venue_local_to_global = BTreeMap::new(); for venue in get_all_asset_maps(cvm_glt) { match venue { Venue::Transfer(from, to) => { let from_node = assets_global_to_local.get(&from).unwrap(); let to_node = assets_global_to_local.get(&to).unwrap(); - graph.add_edge(*from_node, *to_node, 1.0); + 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) => { let from_node = assets_global_to_local.get(&from).unwrap(); let to_node = assets_global_to_local.get(&to).unwrap(); - graph.add_edge(*from_node, *to_node, 1.0); + let local_venue = graph.add_edge(*from_node, *to_node, 1.0); + venue_local_to_global.insert(local_venue, venue.clone()); } } } @@ -58,7 +64,14 @@ pub fn route( let routes = bellman_ford::bellman_ford(&graph, *in_node_index) .expect("bf"); - let out_node_index = assets_global_to_local.get(&input.out_asset_id).unwrap(); - let path = routes.predecessors[out_node_index.index()]; + let out_node_index = assets_global_to_local.get(&input.out_asset_id).expect("node"); + + + let mut out_node_index = out_node_index.index(); + let mut in_node_index = routes.predecessors[out_node_index].expect("routable"); + while true { + + } + panic!() }