Skip to content

Commit

Permalink
asset mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 14, 2024
1 parent 6afadec commit 63093a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
5 changes: 3 additions & 2 deletions mantis/node/src/mantis/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ impl IntentBankInput {
let mut intents = vec![];
let a_asset = cvm_glt.cvm_asset_by_cw(pair.a.denom);
let b_asset = cvm_glt.cvm_asset_by_cw(pair.b.denom);

if pair.a.amount.u128() > 0 {
let b_received = a_to_b.iter().map(|x| {
let part = Ratio::new(x.1.u128(), pair.a.amount.u128()).msb_limit_unsigned();
let part = CvmBalanceFilter::from((*part.numer(), *part.denom()));
CvmInstruction::Transfer {
to: Destination::Account(CvmAddress::from(x.0.to_string())),
assets: CvmFundsFilter::of(a_asset, part),
assets: CvmFundsFilter::of(b_asset, part),
}
});
let intent =
Expand All @@ -98,7 +99,7 @@ impl IntentBankInput {
let part = CvmBalanceFilter::from((*part.numer(), *part.denom()));
CvmInstruction::Transfer {
to: Destination::Account(CvmAddress::from(x.0.to_string())),
assets: CvmFundsFilter::of(b_asset, part),
assets: CvmFundsFilter::of(a_asset, part),
}
});
let intent =
Expand Down
2 changes: 1 addition & 1 deletion mantis/node/src/solver/router/shortest_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn route(
let mut instructions = input.order_accounts.clone();
while let Some(in_node_index_value) = in_node_index {
let venue_index = graph
.find_edge(out_node_index, in_node_index_value)
.find_edge(in_node_index_value, out_node_index, )
.expect("edge");
let venue = venue_local_to_global
.get(&venue_index)
Expand Down
48 changes: 27 additions & 21 deletions mantis/node/tests/cvms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,44 +156,48 @@ async fn cvm_devnet_case() {
let router = "shortest_path";
let OSMOSIS = 2;
let CENTAURI = 1;
let CENTAURI_OSMOSIS_OSMO = 12;
let CENTAURI_PICA = 11;
let OSMOSIS_OSMO = 22;
let OSMOSIS_CENTAURI_PICA = 21;
let cvm_glt = CvmGlt {
network_to_networks: vec![
NetworkToNetworkItem::new(1.into(), 2.into(), OtherNetworkItem::new()),
NetworkToNetworkItem::new(2.into(), 1.into(), OtherNetworkItem::new()),
NetworkToNetworkItem::new(OSMOSIS.into(), CENTAURI.into(), OtherNetworkItem::new()),
NetworkToNetworkItem::new(CENTAURI.into(), OSMOSIS.into(), OtherNetworkItem::new()),
],
assets: vec![
AssetItem::new(
11.into(),
1.into(),
CENTAURI_PICA.into(),
CENTAURI.into(),
AssetReference::Native {
denom: "a".to_string(),
},
),
AssetItem::new(
12.into(),
1.into(),
CENTAURI_OSMOSIS_OSMO.into(),
CENTAURI.into(),
AssetReference::Native {
denom: "ibc/b".to_string(),
},
),
AssetItem::new(
21.into(),
2.into(),
OSMOSIS_OSMO.into(),
OSMOSIS.into(),
AssetReference::Native {
denom: "b".to_string(),
},
),
AssetItem::new(
22.into(),
2.into(),
OSMOSIS_CENTAURI_PICA.into(),
OSMOSIS.into(),
AssetReference::Native {
denom: "ibc/a".to_string(),
},
),
],
exchanges: vec![ExchangeItem::new(
1.into(),
2.into(),
OSMOSIS.into(),
cvm_route::exchange::ExchangeType::OsmosisPoolManagerModuleV1Beta1 {
pool_id: 1,
token_a: "b".to_string(),
Expand All @@ -202,7 +206,7 @@ async fn cvm_devnet_case() {
)],
networks: vec![
NetworkItem {
network_id: 1.into(),
network_id: CENTAURI.into(),
outpost: Some(OutpostId::CosmWasm {
contract: cw_cvm_outpost_contract.clone(),
executor_code_id: cw_cvm_executor_code_id,
Expand All @@ -212,7 +216,7 @@ async fn cvm_devnet_case() {
ibc: None,
},
NetworkItem {
network_id: 2.into(),
network_id: OSMOSIS.into(),
outpost: Some(OutpostId::CosmWasm {
contract: cw_cvm_outpost_contract.clone(),
executor_code_id: cw_cvm_executor_code_id,
Expand All @@ -223,21 +227,21 @@ async fn cvm_devnet_case() {
},
],
network_assets: vec![
NetworkAssetItem::new(2.into(), 11.into(), 22.into()),
NetworkAssetItem::new(2.into(), 12.into(), 21.into()),
NetworkAssetItem::new(1.into(), 21.into(), 12.into()),
NetworkAssetItem::new(1.into(), 22.into(), 11.into()),
NetworkAssetItem::new(OSMOSIS.into(), CENTAURI_OSMOSIS_OSMO.into(), OSMOSIS_OSMO.into()),
NetworkAssetItem::new(OSMOSIS.into(), CENTAURI_PICA.into(), OSMOSIS_CENTAURI_PICA.into()),
NetworkAssetItem::new(CENTAURI.into(), OSMOSIS_CENTAURI_PICA.into(), CENTAURI_PICA.into()),
NetworkAssetItem::new(CENTAURI.into(), OSMOSIS_OSMO.into(), CENTAURI_OSMOSIS_OSMO.into()),
],
asset_venue_items: vec![
AssetsVenueItem::new(
cvm_route::venue::VenueId::Exchange(1.into()),
21.into(),
22.into(),
OSMOSIS_CENTAURI_PICA.into(),
OSMOSIS_OSMO.into(),
),
AssetsVenueItem::new(
cvm_route::venue::VenueId::Exchange(1.into()),
22.into(),
21.into(),
OSMOSIS_OSMO.into(),
OSMOSIS_CENTAURI_PICA.into(),
),
],
};
Expand Down Expand Up @@ -298,6 +302,8 @@ async fn cvm_devnet_case() {
)
.await;

panic!("{:?}", solution);

centauri
.execute_contract(
sender.clone(),
Expand Down

0 comments on commit 63093a5

Please sign in to comment.