Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 9, 2024
1 parent a235d1c commit 27f6d41
Show file tree
Hide file tree
Showing 36 changed files with 76 additions and 111 deletions.
8 changes: 4 additions & 4 deletions contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use alloc::borrow::Cow;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
ensure, to_json_binary, wasm_execute, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps,
DepsMut, Env, MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg,
SubMsgResult, WasmQuery,
ensure, to_json_binary, wasm_execute, Addr, BankMsg, Binary, Coin, CosmosMsg, Deps, DepsMut,
Env, MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg, SubMsgResult,
WasmQuery,
};
use cvm_route::{asset::AssetReference, exchange::ExchangeItem};
use cvm_runtime::{
apply_bindings,
exchange::*,
executor::{CvmExecutorInstantiated},
executor::CvmExecutorInstantiated,
outpost::{BridgeExecuteProgramMsg, BridgeForwardMsg},
shared, Amount, BindingValue, Destination, Funds, Instruction, NetworkId, Register,
};
Expand Down
5 changes: 1 addition & 4 deletions contracts/cosmwasm/executor/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![allow(clippy::new_ret_no_self)]
use cosmwasm_std::{Addr, Event};
use cvm_runtime::{
exchange::ExchangeId, executor::CvmExecutorInstantiated, NetworkId,
UserId,
};
use cvm_runtime::{exchange::ExchangeId, executor::CvmExecutorInstantiated, NetworkId, UserId};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/executor/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{prelude::*, state, state::State};
use cvm_runtime::{Register};
use cvm_runtime::Register;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
Expand Down
3 changes: 1 addition & 2 deletions contracts/cosmwasm/order/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub mod solution {
block_added: Block,
) -> Event {
let solution_id = crate::types::solution_id(&(owner.to_string(), ab.clone(), block_added));

Event::new("mantis-solution-chosen")
.add_attribute("token_a", ab.clone().a)
.add_attribute("token_b", ab.clone().b)
Expand All @@ -85,7 +85,6 @@ pub mod solution {
}

pub fn mantis_solution_upserted(ab: &DenomPair, ctx: &ExecCtx<'_>) -> Event {

Event::new("mantis-solution-upserted")
.add_attribute("token_a", ab.clone().a)
.add_attribute("token_b", ab.clone().b)
Expand Down
8 changes: 3 additions & 5 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub use types::*;
pub use crate::sv::{ExecMsg, QueryMsg};

use cosmwasm_std::{wasm_execute, Addr, BankMsg, Coin, Event, Order, StdError, Storage};
use cvm_runtime::shared::{CvmProgram};
use cvm_runtime::shared::CvmProgram;
use cw_storage_plus::{Index, IndexList, IndexedMap, Item, Map};
use sylvia::{
contract,
Expand Down Expand Up @@ -325,7 +325,7 @@ impl OrderContract<'_> {
if all_solutions.len() < MIN_SOLUTION_COUNT as usize {
return Ok(Response::default());
}

for solution in all_solutions {
if validation::validate_solvers(&ctx.deps, &solution, &all_orders).is_err() {
continue;
Expand Down Expand Up @@ -442,9 +442,7 @@ impl OrderContract<'_> {
self.pair_to_block
.save(ctx.deps.storage, ab, &ctx.env.block.height)?;
};
Ok(
(),
)
Ok(())
}

/// Simple get all orders
Expand Down
1 change: 0 additions & 1 deletion contracts/cosmwasm/order/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use cosmwasm_std::Storage;
use cvm_route::asset::AssetItem;
use cvm_runtime::shared::CvmProgram;


use crate::prelude::*;

use crate::CowSolutionCalculation;
Expand Down
3 changes: 1 addition & 2 deletions contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub struct OrderItem {
}

impl OrderItem {

pub fn side(&self) -> OrderSide {
if self.msg.wants.denom == self.given.denom {
OrderSide::A
Expand Down Expand Up @@ -96,7 +95,7 @@ pub struct Filling {
mod test {
use cosmwasm_std::Coin;
use num_rational::Ratio;

use crate::prelude::*;
use crate::types::*;

Expand Down
4 changes: 3 additions & 1 deletion contracts/cosmwasm/outpost/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ 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 Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/outpost/src/contract/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::ibc::ics20::get_this_route;
use crate::{assets, error::Result, msg};
use cosmwasm_std::{to_json_binary, Binary, Deps, Env};
use super::ibc::ics20::get_this_route;

#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)]
pub fn query(deps: Deps, _env: Env, msg: msg::QueryMsg) -> Result<Binary> {
Expand Down
1 change: 0 additions & 1 deletion contracts/cosmwasm/outpost/src/contract/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use cosmwasm_std::{entry_point, wasm_execute, Coin, DepsMut, Env, Event, Respons

use ibc_apps_more::types::hook::{IBCLifecycleComplete, SudoMsg};


#[cfg_attr(not(feature = "library"), entry_point)]
pub fn sudo(deps: DepsMut, env: Env, msg: SudoMsg) -> crate::error::Result {
deps.api.debug(&format!(
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/outpost/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{IbcOrder, Response, StdError};
use cvm_runtime::{AssetId, NetworkId};
use ibc_core_host_types::{error::IdentifierError};
use ibc_core_host_types::error::IdentifierError;
use thiserror::Error;

pub type Result<T = Response, E = ContractError> = core::result::Result<T, E>;
Expand Down
3 changes: 1 addition & 2 deletions contracts/cosmwasm/outpost/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ pub(crate) fn force_instantiate(
let config = load_this(deps.storage)?;
let executor_code_id = match config.outpost.expect("expected setup") {
OutpostId::CosmWasm {
executor_code_id,
..
executor_code_id, ..
} => executor_code_id,
//OutpostId::Evm { .. } => Err(ContractError::RuntimeUnsupportedOnNetwork)?,
};
Expand Down
2 changes: 0 additions & 2 deletions contracts/cosmwasm/outpost/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ pub use cvm_runtime::{outpost::config::*, shared::Displayed};
pub use cw_storage_plus::Map;
pub use ibc_core_host_types::identifiers::ChannelId;
pub use serde::{Deserialize, Serialize};


16 changes: 11 additions & 5 deletions contracts/cosmwasm/outpost/src/state/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub fn get_all_exchange_venues(deps: Deps) -> StdResult<Vec<AssetsVenueItem>> {
.collect()
}


pub(crate) fn force_exchange(
_: auth::Admin,
deps: DepsMut,
Expand All @@ -51,7 +50,8 @@ pub type VenueMultiMap<'a> =
IndexedMap<'a, (VenuePairId, u128), cvm_route::venue::AssetsVenueItem, VenueIndexes<'a>>;

pub struct VenueIndexes<'a> {
pub pair_first: MultiIndex<'a, VenuePairId, cvm_route::venue::AssetsVenueItem, (VenuePairId, u128,)>,
pub pair_first:
MultiIndex<'a, VenuePairId, cvm_route::venue::AssetsVenueItem, (VenuePairId, u128)>,
}

impl<'a> cw_storage_plus::IndexList<cvm_route::venue::AssetsVenueItem> for VenueIndexes<'a> {
Expand Down Expand Up @@ -79,8 +79,11 @@ pub const fn venues<'a>() -> VenueMultiMap<'a> {
IndexedMap::new("venues", indexes)
}

pub const EXCHANGE_VENUE: IndexedMap<(VenuePairId, u128), cvm_route::venue::AssetsVenueItem, VenueIndexes> =
venues();
pub const EXCHANGE_VENUE: IndexedMap<
(VenuePairId, u128),
cvm_route::venue::AssetsVenueItem,
VenueIndexes,
> = venues();

pub(crate) fn force_assets_venue(
_: auth::Admin,
Expand All @@ -91,7 +94,10 @@ pub(crate) fn force_assets_venue(
cvm_route::venue::VenueId::Exchange(exchange_id) => {
EXCHANGE_VENUE.save(
deps.storage,
((msg.from_asset_id.0.0, msg.to_asset_id.0.0), exchange_id.0),
(
(msg.from_asset_id.0 .0, msg.to_asset_id.0 .0),
exchange_id.0,
),
&msg,
)?;
Ok(BatchResponse::new().add_event(
Expand Down
4 changes: 1 addition & 3 deletions contracts/cosmwasm/outpost/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ use crate::{error::ContractError, prelude::*};

use cosmwasm_std::{StdResult, Storage};

use cvm_runtime::outpost::{GetConfigResponse};
use cvm_runtime::outpost::GetConfigResponse;
use cw_storage_plus::Item;



const CONFIG: Item<HereItem> = Item::new("this");

pub(crate) fn load(storage: &dyn Storage) -> StdResult<HereItem> {
Expand Down
13 changes: 1 addition & 12 deletions crates/cvm-route/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
pub use alloc::{
boxed::Box,
string::{String},
vec,
vec::Vec,
};


pub use alloc::{boxed::Box, string::String, vec, vec::Vec};

pub use serde::{Deserialize, Serialize};

Expand All @@ -14,7 +7,3 @@ pub use parity_scale_codec::{Decode, Encode};

#[cfg(feature = "parity-scale-codec")]
pub use scale_info::TypeInfo;




4 changes: 2 additions & 2 deletions crates/cvm-route/src/venue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub enum VenueId {
pub struct AssetsVenueItem {
pub venue_id: VenueId,
pub from_asset_id: AssetId,
pub to_asset_id : AssetId,
}
pub to_asset_id: AssetId,
}
1 change: 0 additions & 1 deletion crates/cvm-runtime-exchange/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use cvm_route::exchange::ExchangeItem;
use cvm_runtime::{Amount, ExchangeId, Funds};
use error::ContractError;


pub fn exchange(
give: Funds,
want: Funds,
Expand Down
2 changes: 1 addition & 1 deletion crates/cvm-runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ fn add_files(dir: std::fs::ReadDir, files: &mut Vec<String>) -> Result<(), std::
files.push([PROTOS_DIR, "/", name.as_str()].concat())
}
}
};
}
Ok(())
}
2 changes: 1 addition & 1 deletion crates/cvm-runtime/src/cosmwasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
//! variants of both of them.

use super::{BindingValue, Bindings};
use crate::{OrderedBindings};
use crate::OrderedBindings;
use alloc::{fmt::Debug, string::String, vec, vec::Vec};
use cosmwasm_std::{BankMsg, Coin, CosmosMsg, Uint64};
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion crates/cvm-runtime/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<Payload, Account, Assets> Instruction<Payload, Account, Assets> {
pub fn is_async_with_sub(&self) -> bool {
matches!(&self, Instruction::Spawn { .. })
}
}
}

/// Error types for late binding operation
#[derive(Clone, Debug, PartialEq)]
Expand Down
4 changes: 2 additions & 2 deletions crates/cvm-runtime/src/outpost/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use cvm_route::{
asset::AssetToNetwork, exchange::ExchangeItem, transport::NetworkToNetworkItem, venue::AssetsVenueItem
asset::AssetToNetwork, exchange::ExchangeItem, transport::NetworkToNetworkItem,
venue::AssetsVenueItem,
};


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

/// Version of IBC channels used by the gateway.
Expand Down
2 changes: 0 additions & 2 deletions crates/cvm-runtime/src/outpost/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod config;
mod query;


pub use config::*;
use cosmwasm_std::{ensure, StdError};
use cvm_route::{
Expand Down Expand Up @@ -113,7 +112,6 @@ impl ExecutePacketICS20Msg {

#[cfg(test)]
pub mod test {


use super::ExecutePacketICS20Msg;

Expand Down
7 changes: 5 additions & 2 deletions crates/cvm-runtime/src/outpost/query.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{prelude::*, AssetId, ExchangeId, NetworkId};

use cvm_route::{
asset::{AssetItem, AssetReference, NetworkAssetItem}, exchange::ExchangeItem, transport::NetworkToNetworkItem, venue::AssetsVenueItem,
asset::{AssetItem, AssetReference, NetworkAssetItem},
exchange::ExchangeItem,
transport::NetworkToNetworkItem,
venue::AssetsVenueItem,
};

use super::NetworkItem;
Expand Down Expand Up @@ -108,7 +111,7 @@ pub struct GetConfigResponse {
pub exchanges: Vec<ExchangeItem>,
pub networks: Vec<NetworkItem>,
pub network_assets: Vec<NetworkAssetItem>,
pub asset_venue_items : Vec<AssetsVenueItem>,
pub asset_venue_items: Vec<AssetsVenueItem>,
}

impl GetConfigResponse {
Expand Down
3 changes: 1 addition & 2 deletions crates/cvm-runtime/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{prelude::*, AssetId};
use cosmwasm_std::{from_json, to_json_binary, Binary, StdResult};
use cosmwasm_std::{from_json, to_json_binary, Binary, StdResult};
use cvm::{NetworkId, XcAddr};
use serde::{de::DeserializeOwned, Serialize};

Expand Down Expand Up @@ -62,7 +62,6 @@ impl CvmProgram {
}
}


impl CvmInstruction {
pub fn transfer_absolute_to_account(to: &str, asset_id: u128, amount: u128) -> Self {
Self::Transfer {
Expand Down
7 changes: 2 additions & 5 deletions crates/cvm/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,11 @@ 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 @@ -172,7 +170,7 @@ impl AmountBuilder for Amount {
}
fn one() -> Self {
Self::absolute(1)
}
}
}

impl Amount {
Expand All @@ -181,7 +179,7 @@ impl Amount {
// 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;

#[cfg(not(feature="cosmwasm"))]
#[cfg(not(feature = "cosmwasm"))]
pub fn try_floor_f64(value: f64) -> Result<Self, ArithmeticError> {
if value < 0.0 || value.is_nan() {
Err(ArithmeticError::Underflow)
Expand Down Expand Up @@ -351,7 +349,6 @@ impl<T: AmountBuilder> Funds<T> {
}
}


impl<T> Default for Funds<T> {
fn default() -> Self {
Self(Vec::new())
Expand Down
2 changes: 0 additions & 2 deletions crates/cvm/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ pub use parity_scale_codec::{Decode, Encode};
#[cfg(feature = "parity-scale-codec")]
pub use scale_info::TypeInfo;



#[cfg(all(feature = "json-schema", not(target_arch = "wasm32")))]
pub use schemars::JsonSchema;
2 changes: 1 addition & 1 deletion crates/cvm/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{prelude::*};
use crate::prelude::*;

/// A wrapper around a type which is serde-serialised as a string.
///
Expand Down
Loading

0 comments on commit 27f6d41

Please sign in to comment.