Skip to content

Commit

Permalink
fixed expression issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 8, 2024
1 parent 62e3496 commit 99f113a
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 83 deletions.
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ impl OrderContract<'_> {
solver_address: String,
solution_id: SolutionHash,
solver_orders: Vec<SolvedOrder>,
pair: DenomPair,
_pair: DenomPair,
) -> Result<Vec<CvmFillResult>, StdError> {
let mut result = vec![];
for order in solver_orders.iter() {
Expand Down
8 changes: 4 additions & 4 deletions contracts/cosmwasm/order/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::SolvedOrder;
/// given expected output amount and list of orders and CVM program, produce fill in of orders
/// return filling amounts for all orders from program, which may or may not lead to full fill
pub fn verify(
route: CvmProgram,
_route: CvmProgram,
_in_asset: &AssetItem,
out_asset: &AssetItem,
predicted_out_amount: u128,
orders: Vec<SolvedOrder>,
_out_asset: &AssetItem,
_predicted_out_amount: u128,
_orders: Vec<SolvedOrder>,
) -> Result<Vec<Filling>, StdError> {
panic!()
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl OrderItem {
/// `wanted_fill_amount` - amount to fill in `wants` amounts
/// Reduces given amount
/// `optimal_price` - the price to solve against, should be same or better than user limit.
pub fn fill(&mut self, wanted_fill_amount: Amount, optimal_ratio: Ratio) -> StdResult<()> {
pub fn fill(&mut self, wanted_fill_amount: Amount, _optimal_ratio: Ratio) -> StdResult<()> {
// was given more or exact wanted - user happy or user was given all before, do not give more
if wanted_fill_amount >= self.msg.wants.amount
|| self.msg.wants.amount.u128() == <_>::default()
Expand Down Expand Up @@ -88,8 +88,8 @@ impl OrderItem {

/// simple structure which can be applied to order to fill or partial fill it
pub struct Filling {
order_id: u64,
amount: Uint128,
pub order_id: u64,
pub amount: Uint128,
}

#[cfg(test)]
Expand Down
14 changes: 7 additions & 7 deletions contracts/cosmwasm/order/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use crate::{OrderItem, SolvedOrder};
/// Validate solver can solve order he tells.
/// Minimal requirement is that CVM salt is unique to solver
pub fn validate_solver(
as_ref: cosmwasm_std::Deps<'_>,
_as_ref: cosmwasm_std::Deps<'_>,
_sender: &Addr,
order: &OrderItem,
_order: &OrderItem,
) -> StdResult<()> {
Ok(())
}

/// Validate solver can solver amount he claimed
pub(crate) fn validate_solvers(
deps: &cosmwasm_std::DepsMut<'_>,
solution: &crate::SolutionItem,
all_orders: &[SolvedOrder],
_deps: &cosmwasm_std::DepsMut<'_>,
_solution: &crate::SolutionItem,
_all_orders: &[SolvedOrder],
) -> StdResult<()> {
Ok(())
}
Expand All @@ -27,8 +27,8 @@ pub(crate) fn validate_solvers(
/// Minimal requirement is that CVM salt is unique to solver
pub(crate) fn validate_routes(
_deps: &cosmwasm_std::DepsMut<'_>,
solution: &crate::SolutionItem,
all_orders: &[SolvedOrder],
_solution: &crate::SolutionItem,
_all_orders: &[SolvedOrder],
) -> StdResult<()> {
Ok(())
}
5 changes: 2 additions & 3 deletions contracts/cosmwasm/outpost/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ fn handle_config_msg(
this_asset,
other_network,
other_asset,
}) => {
assets::force_asset_to_network_map(auth, deps, this_asset, other_network, other_asset)
}
}) => assets::force_asset_to_network_map(auth, deps, this_asset, other_network, other_asset),
ConfigSubMsg::ForceNetwork(msg) => network::force_network(auth, deps, msg),
ConfigSubMsg::ForceInstantiate { user_origin, salt } => {
executor::force_instantiate(auth, env.contract.address.clone(), deps, user_origin, salt)
Expand All @@ -116,6 +114,7 @@ fn handle_config_msg(
}
Ok(aggregated)
}
ConfigSubMsg::ForceAssetsVenue(msg) => state::venues::force_assets_venue(auth, deps, msg),
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/cosmwasm/outpost/src/contract/ibc/ics20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ pub fn get_this_route(
let asset: AssetItem = crate::state::assets::ASSETS
.load(storage, this_asset_id)
.map_err(|_| ContractError::AssetNotFoundById(this_asset_id))?;
let to_asset: AssetId = crate::state::assets::NETWORK_ASSET
let to_asset_id: AssetId = crate::state::assets::NETWORK_ASSET
.load(storage, (to_network_id, this_asset_id))
.map_err(|_| {
ContractError::AssetCannotBeTransferredToNetwork(this_asset_id, to_network_id)
})?
.asset_id;
.to_asset_id;
let to_outpost = other
.network
.outpost
Expand Down Expand Up @@ -224,7 +224,7 @@ pub fn get_this_route(
.ics20
.ok_or(ContractError::ICS20NotFound)?
.sender,
on_remote_asset: to_asset,
on_remote_asset: to_asset_id,
})
}

Expand Down
3 changes: 0 additions & 3 deletions contracts/cosmwasm/outpost/src/contract/query.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::{assets, error::Result, msg};

use cosmwasm_std::{to_json_binary, Binary, Deps, Env};
use cvm_runtime::outpost::GetConfigResponse;

use super::ibc::ics20::get_this_route;

#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)]
Expand Down
2 changes: 2 additions & 0 deletions contracts/cosmwasm/outpost/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod executors;
pub mod ics27;
pub mod network;
pub mod tracking;
pub mod venues;
use crate::{error::ContractError, prelude::*};

use cosmwasm_std::{StdResult, Storage};
Expand Down Expand Up @@ -32,5 +33,6 @@ pub(crate) fn get_config(deps: cosmwasm_std::Deps<'_>) -> Result<GetConfigRespon
exchanges,
networks: network::get_all_networks(deps)?,
network_assets: assets::get_all_network_assets(deps)?,
asset_venue_items: vec![],
})
}
8 changes: 8 additions & 0 deletions contracts/cosmwasm/outpost/src/state/venues.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use cosmwasm_std::DepsMut;
use cvm_route::venue::AssetsVenueItem;

use crate::{auth::Admin, prelude::*};

pub(crate) fn force_assets_venue(_: Admin, deps: DepsMut, msg: AssetsVenueItem) -> Result<crate::batch::BatchResponse, crate::error::ContractError> {
todo!()
}
3 changes: 1 addition & 2 deletions crates/cvm-runtime/src/cosmwasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
use super::{BindingValue, Bindings};
use crate::{ExecutorOrigin, NetworkId, OrderedBindings, UserId, UserOrigin};
use alloc::{fmt::Debug, string::String, vec, vec::Vec};
use cosmwasm_std::{BankMsg, Coin, CosmosMsg, StdResult, Uint64};
use cw_storage_plus::{IntKey, Key, KeyDeserialize, Prefixer, PrimaryKey};
use cosmwasm_std::{BankMsg, Coin, CosmosMsg, Uint64};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
Expand Down
7 changes: 1 addition & 6 deletions crates/cvm-runtime/src/outpost/config.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#[cfg(feature = "cosmwasm")]
use cosmwasm_std::{BlockInfo, IbcTimeout};

use cvm_route::{
asset::AssetToNetwork, exchange::ExchangeItem, transport::NetworkToNetworkItem, venue::AssetsVenueItem, *
};
use ibc_core_host_types::identifiers::ChannelId;

use crate::{prelude::*, transport::ibc::IbcEnabled, AssetId, NetworkId};

type EthAddress = [u8; 20]; // primitive_types::H160;

/// Version of IBC channels used by the gateway.
pub const IBC_VERSION: &str = "xcvm-v0";
pub const IBC_VERSION: &str = "cvm-v0";

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
Expand Down
7 changes: 3 additions & 4 deletions crates/cvm-runtime/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::panic;

use crate::{prelude::*, AssetId};
use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use cosmwasm_std::{from_json, to_json_binary, Binary, StdResult};
use cvm::{NetworkId, XcAddr};
use serde::{de::DeserializeOwned, Serialize};

Expand Down Expand Up @@ -64,11 +62,12 @@ impl CvmProgram {
}
}


impl CvmInstruction {
pub fn transfer_absolute_to_account(to: &str, asset_id: u128, amount: u128) -> Self {
Self::Transfer {
to: crate::Destination::Account(XcAddr(to.to_owned())),
assets: CvmFundsFilter::one(asset_id.into(), crate::Amount::new(amount, 0)),
assets: CvmFundsFilter::of(asset_id.into(), crate::Amount::new(amount, 0)),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/cvm-runtime/src/transport/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use crate::{
shared::CvmPacket,
AssetId, NetworkId,
};
use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, IbcEndpoint, StdResult};
use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, StdResult};

use cvm_route::transport::RelativeTimeout;
use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId};
use ibc_core_host_types::identifiers::{ChannelId, PortId};

use ibc_apps_more::types::hook::Callback;
//, HookMemo};
Expand Down
3 changes: 1 addition & 2 deletions crates/cvm/src/address.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;
use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use serde::{de::DeserializeOwned, Serialize};
use cosmwasm_std::{Api, Binary, CanonicalAddr, StdError};

/// A wrapper around any address on any chain.
/// Similar to `ibc_rs::Signer`(multi encoding), but not depend on ibc code bloat.
Expand Down
41 changes: 30 additions & 11 deletions crates/cvm/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cw_storage_plus::{Key, Prefixer};
use crate::shared::Displayed;
use core::ops::Add;
use cosmwasm_std::{Uint128, Uint256};
use num::Zero;
use num::{One, Zero};
use serde::{Deserialize, Serialize};

/// Newtype for CVM assets ID. Must be unique for each asset and must never change.
Expand Down Expand Up @@ -102,6 +102,13 @@ pub struct Amount {
pub slope: Displayed<u64>,
}


pub trait AmountBuilder {
fn everything() -> Self;
fn one() -> Self;
}


impl TryFrom<i64> for Amount {
type Error = ArithmeticError;

Expand Down Expand Up @@ -158,16 +165,22 @@ impl From<(u64, u64)> for Amount {
}
}

impl AmountBuilder for Amount {
/// Everything mean that we move 100% of whats left.
fn everything() -> Self {
Self::ratio(Self::MAX_PARTS)
}
fn one() -> Self {
Self::absolute(1)
}
}

impl Amount {
/// idiotic idea fom KO, it should be
/// u64/u64 ratio
// with rounding to reduce or reduce down part up to some seven bit parts
pub const MAX_PARTS: u64 = 1_000_000_000_000_000_000;

pub fn one() -> Self {
Self::absolute(1)
}

pub fn try_floor_f64(value: f64) -> Result<Self, ArithmeticError> {
if value < 0.0 || value.is_nan() {
Err(ArithmeticError::Underflow)
Expand Down Expand Up @@ -211,11 +224,6 @@ impl Amount {
self.intercept.0 == 0
}

/// Everything mean that we move 100% of whats left.
pub const fn everything() -> Self {
Self::ratio(Self::MAX_PARTS)
}

/// `f(x) = a(x - b) + b where a = slope / MAX_PARTS, b = intercept`
pub fn apply(&self, value: u128) -> Result<u128, ArithmeticError> {
if value.is_zero() {
Expand Down Expand Up @@ -327,11 +335,22 @@ impl From<u128> for Amount {
pub struct Funds<T = Amount>(pub Vec<(AssetId, T)>);

impl<T> Funds<T> {
pub fn one<A: Into<T>>(id: AssetId, amount: A) -> Self {
pub fn of<A: Into<T>>(id: AssetId, amount: A) -> Self {
Self(vec![(id, amount.into())])
}
}

impl<T: AmountBuilder> Funds<T> {
pub fn all_of(asset_id: AssetId) -> Self {
Self(vec![(asset_id, T::everything())])
}

pub fn one_of(asset_id: AssetId) -> Self {
Self(vec![(asset_id, T::one())])
}
}


impl<T> Default for Funds<T> {
fn default() -> Self {
Self(Vec::new())
Expand Down
3 changes: 0 additions & 3 deletions crates/cvm/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub use alloc::{
boxed::Box,
format,
string::{String, ToString},
vec,
Expand All @@ -8,8 +7,6 @@ pub use alloc::{

pub use core::{fmt::Display, str::FromStr};

#[cfg(feature = "cosmwasm")]
pub use cosmwasm_std::{Addr, Binary, Coin, Uint128};
pub use serde::{Deserialize, Serialize};

#[cfg(feature = "parity-scale-codec")]
Expand Down
6 changes: 1 addition & 5 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use bip32::secp256k1::elliptic_curve::rand_core::block;
use cosmos_sdk_proto::{
cosmos::{auth::v1beta1::BaseAccount, base::v1beta1::Coin},
cosmwasm::{self, wasm::v1::QuerySmartContractStateRequest},
};
use cosmos_sdk_proto::{traits::Message, Any};
use cosmrs::{
tendermint::{block::Height, chain},
Expand Down Expand Up @@ -204,7 +200,7 @@ async fn solve(
);
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
panic!();
send_solution(
pair_solution.cows,
vec![a_cvm_route, b_cvm_route],
Expand Down
12 changes: 6 additions & 6 deletions mantis/node/src/mantis/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cvm_runtime::{
Amount, AssetId, ExchangeId,
};

use crate::solver::router::bf;
use crate::solver::router::shortest_path;

use super::solve::IntentBankInput;

Expand Down Expand Up @@ -71,7 +71,7 @@ fn new_spawn(
program,
network_id,
salt: salt.to_vec(),
assets: CvmFundsFilter::one(in_asset_id, in_amount),
assets: CvmFundsFilter::of(in_asset_id, in_amount),
}
}

Expand All @@ -98,8 +98,8 @@ fn new_exchange(exchange: &Exchange) -> CvmInstruction {

CvmInstruction::Exchange {
exchange_id,
give: CvmFundsFilter::one(in_asset_id, in_amount),
want: CvmFundsFilter::one(out_asset_id, Amount::one()),
give: CvmFundsFilter::of(in_asset_id, in_amount),
want: CvmFundsFilter::one_of(out_asset_id),
}
}

Expand All @@ -108,9 +108,9 @@ pub async fn get_route(
input: IntentBankInput,
cvm_glt: &GetConfigResponse,
salt: &[u8],
) -> CvmInstruction {
) -> Vec<CvmInstruction> {
if route_provider == "priceless" {
return bf::route(cvm_glt, input, salt);
return shortest_path::route(cvm_glt, input, salt);
} else {
let blackbox: Client = Client::new(route_provider);
let mut route = blackbox
Expand Down
1 change: 0 additions & 1 deletion mantis/node/src/mantis/cosmos/signer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! given whatever string, give me the signer struct

use cosmrs::crypto::secp256k1::SigningKey;
use prost_types::Any;

pub fn from_mnemonic(phrase: &str, derivation_path: &str) -> Result<SigningKey, String> {
let seed = bip39::Mnemonic::parse_normalized(phrase)
Expand Down
Loading

0 comments on commit 99f113a

Please sign in to comment.