Skip to content

Commit

Permalink
fixing overfloiw
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 11, 2024
1 parent 7743ca7 commit b064e3f
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 8 deletions.
27 changes: 27 additions & 0 deletions crates/cvm-route/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ pub struct AssetItem {
pub bridged: Option<BridgeAsset>,
}

impl AssetItem {
pub fn new(asset_id: AssetId, network_id: NetworkId, local: AssetReference) -> Self {
Self {
asset_id,
network_id,
local,
bridged: None,
}
}

}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(
Expand All @@ -50,6 +62,17 @@ pub struct NetworkAssetItem {
pub to_asset_id: AssetId,
}

impl NetworkAssetItem {
pub fn new(to_network_id: NetworkId, from_asset_id: AssetId, to_asset_id: AssetId) -> Self {
Self {
to_network_id,
from_asset_id,
to_asset_id,
}
}
}


impl AssetItem {
pub fn denom(&self) -> String {
self.local.denom()
Expand Down Expand Up @@ -78,11 +101,15 @@ pub struct BridgeAsset {
derive(schemars::JsonSchema)
)]
pub enum AssetReference {
/// Cosmos SDK native
Native { denom: String },
Cw20 { contract: cosmwasm_std::Addr },
// Erc20 { contract: EthAddress },
// SPL20 { mint: Pubkey },
}



impl AssetReference {
pub fn denom(&self) -> String {
match self {
Expand Down
11 changes: 11 additions & 0 deletions crates/cvm-route/src/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ pub struct ExchangeItem {
// if was set, means that cannot exchange via this venue
pub closed: Option<u64>,
}

impl ExchangeItem {
pub fn new(exchange_id: ExchangeId, network_id: NetworkId, exchange: ExchangeType) -> Self {
Self {
exchange_id,
network_id,
exchange,
closed: None,
}
}
}
10 changes: 10 additions & 0 deletions crates/cvm-route/src/venue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ pub struct AssetsVenueItem {
pub from_asset_id: AssetId,
pub to_asset_id: AssetId,
}

impl AssetsVenueItem {
pub fn new(venue_id: VenueId, from_asset_id: AssetId, to_asset_id: AssetId) -> Self {
Self {
venue_id,
from_asset_id,
to_asset_id,
}
}
}
1 change: 1 addition & 0 deletions mantis/node/src/mantis/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl IntentBankInput {
let b_asset = cvm_glt.cvm_asset_by_cw(pair.b.denom);

let b_received = a_to_b.iter().map(|x| {
panic!("{:?} {:?}", x.1.u128(), pair.a.amount.u128());
let part = Ratio::new(x.1.u128(), pair.a.amount.u128()).msb_limit_unsigned();
let part = CvmBalanceFilter::from((*part.numer(), *part.denom()));
CvmInstruction::Transfer {
Expand Down
49 changes: 41 additions & 8 deletions mantis/node/tests/cvms.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use bounded_collections::Get;
use cosmrs::tendermint::block::Height;
use cosmwasm_std::{Addr, Coin, Coins, Empty};
use cvm_route::transport::NetworkToNetworkItem;
use cw_cvm_outpost::msg::{CvmGlt, HereItem};
use cvm_route::{asset::{AssetItem, AssetReference, NetworkAssetItem}, exchange::ExchangeItem, transport::{NetworkToNetworkItem, OtherNetworkItem}, venue::AssetsVenueItem};
use cw_cvm_outpost::msg::{CvmGlt, HereItem, NetworkItem, OutpostId};
use cw_mantis_order::{OrderItem, OrderSubMsg};
use cw_multi_test::{App, Contract, ContractWrapper, Executor};
use mantis_node::mantis::cosmos::{client::Tip, signer::from_mnemonic};
Expand Down Expand Up @@ -128,13 +128,46 @@ async fn cvm_devnet_case() {
NetworkToNetworkItem::new(1.into(), 2.into(), OtherNetworkItem::new()),
NetworkToNetworkItem::new(2.into(), 1.into(), OtherNetworkItem::new()),
],
assets: todo!(),
exchanges: todo!(),
networks: todo!(),
network_assets: todo!(),
asset_venue_items: todo!(),
assets: vec![
AssetItem::new(11.into(), 1.into(), AssetReference::Native { denom: "a".to_string() } ),
AssetItem::new(12.into(), 1.into(), AssetReference::Native { denom: "ibc/b".to_string() } ),
AssetItem::new(21.into(), 2.into(), AssetReference::Native { denom: "b".to_string() } ),
AssetItem::new(22.into(), 2.into(), AssetReference::Native { denom: "ibc/a".to_string() } ),
],
exchanges:
vec![
ExchangeItem::new(1.into(), 2.into(), cvm_route::exchange::ExchangeType::OsmosisPoolManagerModuleV1Beta1 { pool_id: 1, token_a: "b".to_string(), token_b: "ibc/a".to_string() }),
],
networks:
vec![
NetworkItem {
network_id: 1.into(),
outpost: Some(
OutpostId::CosmWasm { contract: cw_cvm_outpost_contract.clone(), executor_code_id: cw_cvm_executor_code_id, admin: sender.clone() }),
accounts: None,
ibc: None,
},
NetworkItem {
network_id: 2.into(),
outpost: Some(
OutpostId::CosmWasm { contract: cw_cvm_outpost_contract.clone(), executor_code_id: cw_cvm_executor_code_id, admin: sender.clone() }),
accounts: None,
ibc: None,
},
],
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()),
],
asset_venue_items: vec![
AssetsVenueItem::new(cvm_route::venue::VenueId::Exchange(1.into()), 21.into(), 22.into()),
AssetsVenueItem::new(cvm_route::venue::VenueId::Exchange(1.into()), 22.into(), 21.into()),
],
});
let solution = mantis_node::mantis::blackbox::solve::<True>(active_orders, &alice, &tip, cvm_glt, router);
let solution = mantis_node::mantis::blackbox::solve::<True>(active_orders, &alice, &tip, cvm_glt, router).await;
panic!("solution: {:?}", solution);
}

enum True{}
Expand Down

0 comments on commit b064e3f

Please sign in to comment.