From b064e3f7d9b2f3c5e4c18ecf644d1720e3b9b0df Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Thu, 11 Apr 2024 23:58:21 +0100 Subject: [PATCH] fixing overfloiw --- crates/cvm-route/src/asset.rs | 27 ++++++++++++++++++ crates/cvm-route/src/exchange.rs | 11 +++++++ crates/cvm-route/src/venue.rs | 10 +++++++ mantis/node/src/mantis/solve.rs | 1 + mantis/node/tests/cvms.rs | 49 ++++++++++++++++++++++++++------ 5 files changed, 90 insertions(+), 8 deletions(-) diff --git a/crates/cvm-route/src/asset.rs b/crates/cvm-route/src/asset.rs index d099b944..76aec966 100644 --- a/crates/cvm-route/src/asset.rs +++ b/crates/cvm-route/src/asset.rs @@ -38,6 +38,18 @@ pub struct AssetItem { pub bridged: Option, } +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( @@ -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() @@ -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 { diff --git a/crates/cvm-route/src/exchange.rs b/crates/cvm-route/src/exchange.rs index fd3a904a..352b59a0 100644 --- a/crates/cvm-route/src/exchange.rs +++ b/crates/cvm-route/src/exchange.rs @@ -36,3 +36,14 @@ pub struct ExchangeItem { // if was set, means that cannot exchange via this venue pub closed: Option, } + +impl ExchangeItem { + pub fn new(exchange_id: ExchangeId, network_id: NetworkId, exchange: ExchangeType) -> Self { + Self { + exchange_id, + network_id, + exchange, + closed: None, + } + } +} \ No newline at end of file diff --git a/crates/cvm-route/src/venue.rs b/crates/cvm-route/src/venue.rs index 1f1cddba..69f59d7b 100644 --- a/crates/cvm-route/src/venue.rs +++ b/crates/cvm-route/src/venue.rs @@ -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, + } + } +} \ No newline at end of file diff --git a/mantis/node/src/mantis/solve.rs b/mantis/node/src/mantis/solve.rs index d0f14e7e..7e3a5912 100644 --- a/mantis/node/src/mantis/solve.rs +++ b/mantis/node/src/mantis/solve.rs @@ -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 { diff --git a/mantis/node/tests/cvms.rs b/mantis/node/tests/cvms.rs index 9b1932c9..2bd68351 100644 --- a/mantis/node/tests/cvms.rs +++ b/mantis/node/tests/cvms.rs @@ -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}; @@ -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::(active_orders, &alice, &tip, cvm_glt, router); + let solution = mantis_node::mantis::blackbox::solve::(active_orders, &alice, &tip, cvm_glt, router).await; + panic!("solution: {:?}", solution); } enum True{}