Skip to content

Commit

Permalink
routing
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 7, 2024
1 parent c831d02 commit b932c44
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contracts/cosmwasm/outpost/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub(crate) fn force_asset_to_network_map(
other_asset: AssetId,
) -> Result<BatchResponse> {
let item = NetworkAssetItem {
asset_id: this_asset,
from_asset_id: this_asset,
to_network_id: other_network,
to_asset_id: other_asset,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/cvm-route/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct AssetItem {
)]
pub struct NetworkAssetItem {
pub to_network_id: NetworkId,
pub asset_id: AssetId,
pub from_asset_id: AssetId,
pub to_asset_id: AssetId,
}

Expand Down
13 changes: 9 additions & 4 deletions mantis/node/src/solver/router/bf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use blackbox_rs::types::SingleInputAssetCvmRoute;
use cvm_runtime::proto::pb::program::{Exchange, Transfer};
use cvm_runtime::shared::CvmProgram;
use cvm_runtime::{AssetId, ExchangeId};
use petgraph::algo::{dijkstra, min_spanning_tree};
Expand All @@ -15,15 +16,18 @@ pub enum Venue{


pub fn get_all_asset_maps(cvm_glt: &cvm_runtime::outpost::GetConfigResponse) -> Vec<Venue> {
let transfers = self
let transfers = cvm_glt
.network_assets
.iter()
// CVM GLT has 2 entires for each direction for bidirectional transfers
.map(|x| (x.asset_id, x.to_asset_id));
let exchanges = self
.map(|x| Venue::Transfer(x.from_asset_id, x.to_asset_id));
let exchanges = cvm_glt
.asset_venue_items
.iter()
.map(|x| (x.from_asset_id, x.to_asset_id));
.map(|x| match x.venue_id {
Transfer => panic!(),
Exchange => Venue::Exchange(x.exchange_id, x.from_asset_id, x.to_asset_id),
});

transfers.chain(exchanges).collect()
}
Expand All @@ -33,6 +37,7 @@ pub fn route(
input: crate::mantis::solve::IntentBankInput,
) -> SingleInputAssetCvmRoute {
let mut graph = petgraph::graph::DiGraph::new();
let mut assets_global_to_local = std::collections::BTreeMap::new();
for (from_asset_id, to_asset_id) in cvm_glt.get_all_asset_maps() {
graph.add_edge(a, b, weight)
}
Expand Down

0 comments on commit b932c44

Please sign in to comment.