Skip to content

Commit

Permalink
full migration
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Nov 27, 2023
1 parent 1a71a52 commit 178b40a
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 44 deletions.
6 changes: 3 additions & 3 deletions contracts/cosmwasm/executor/src/bin/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(feature = "std")]
#[cfg(feature = "json-schema")]
#[allow(clippy::disallowed_methods)]
fn main() {
use cosmwasm_schema::write_api;
Expand All @@ -20,8 +20,8 @@ fn main() {

let path = out_dir.join(concat!("events", ".json"));

write(&path, serde_json::to_string_pretty(&events).unwrap()).unwrap();
write(&path, serde_json_wasm::to_string_pretty(&events).unwrap()).unwrap();
}

#[cfg(not(feature = "std"))]
#[cfg(not(feature = "json-schema"))]
fn main() {}
3 changes: 1 addition & 2 deletions contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ use cosmwasm_std::{
DepsMut, Env, MessageInfo, QueryRequest, Reply, Response, StdError, StdResult, SubMsg,
SubMsgResult, WasmQuery,
};
use cw2::set_contract_version;
use cw2::{set_contract_version, ensure_from_older_version};
use cw20::{BalanceResponse, Cw20Contract, Cw20ExecuteMsg, Cw20QueryMsg};
use cw_utils::ensure_from_older_version;
use num::Zero;
use cvm_runtime::{
apply_bindings,
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm/executor/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ impl CvmInterpreterTransferred {
}

impl CvmInterpreterInstantiated {
pub const NAME: &str = "cvm.executor.instantiated";
pub const INTERPRETER_ORIGIN: &str = "interpreter_origin";
pub const NAME: &'static str = "cvm.executor.instantiated";
pub const INTERPRETER_ORIGIN: &'static str = "interpreter_origin";
pub fn new(interpreter_origin: &InterpreterOrigin) -> Event {
Event::new(Self::NAME).add_attribute(
Self::INTERPRETER_ORIGIN,
Expand Down
6 changes: 2 additions & 4 deletions contracts/cosmwasm/executor/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ pub use alloc::{string::String, vec::Vec};
pub use cosmwasm_std::Addr;
pub use serde::{Deserialize, Serialize};

#[cfg(feature = "std")]
pub use cosmwasm_schema::{cw_serde, QueryResponses};

#[cfg(feature = "std")]
pub use schemars::JsonSchema;


2 changes: 1 addition & 1 deletion contracts/cosmwasm/gateway/src/contract/ibc/ics20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) fn handle_bridge_forward(
));

ensure_eq!(msg.msg.assets.0.len(), 1, ContractError::ProgramCannotBeHandledByDestination);
let (local_asset, amount) = msg.msg.assets.0.get(0).expect("proved above");
let (local_asset, amount) = msg.msg.assets.0.first().expect("proved above");

let (msg, event) = if let Ok(transfer_shortcut) =
ibc_ics_20_transfer_shortcut(deps.as_ref(), &msg)
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/gateway/src/contract/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{assets, error::Result, exchange, msg, prelude::*};
use crate::{assets, error::Result, exchange, msg};

use cosmwasm_std::{Binary, Deps, Env, to_json_binary};

Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm/gateway/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! mostly ensuring std vs no_std, and unified identifiers and numbers representation
pub use alloc::format;
pub use cosmwasm_std::{to_json_binary, Addr};
pub use cosmwasm_std::{Addr};
pub use cw_storage_plus::Map;
pub use ibc::core::host::types::identifiers::{ChannelId, ConnectionId};
pub use ibc::core::host::types::identifiers::{ChannelId};
pub use serde::{Deserialize, Serialize};
pub use cvm_runtime::{gateway::config::*, shared::Displayed};
30 changes: 14 additions & 16 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,22 @@ use store::*;
pub use types::*;

pub use crate::sv::{ExecMsg, QueryMsg};
use cosmwasm_schema::{cw_serde, schemars};
use cosmwasm_schema::{schemars};
use cosmwasm_std::{
wasm_execute, Addr, BankMsg, Coin, Event, Order, StdError, Storage, Uint128, Uint64,
wasm_execute, Addr, BankMsg, Coin, Event, Order, StdError, Storage,
};
use cvm_runtime::{
ExchangeId,
shared::{XcInstruction, XcProgram},
};
use cw_storage_plus::{Index, IndexList, IndexedMap, Item, Map, MultiIndex};
use cw_storage_plus::{Index, IndexList, IndexedMap, Item, Map};
use sylvia::{
contract,
cw_std::{ensure, Response, StdResult},
entry_points,
types::{ExecCtx, InstantiateCtx, QueryCtx},
};

use cvm_runtime::NetworkId;


pub struct OrderContract<'a> {
pub orders: Map<'a, u128, OrderItem>,
Expand Down Expand Up @@ -78,8 +77,7 @@ impl OrderContract<'_> {
// for now we just use bank for ics20 tokens
let funds = ctx
.info
.funds
.get(0)
.funds.first()
.expect("there are some funds in order");

// just save order under incremented id
Expand Down Expand Up @@ -156,8 +154,8 @@ impl OrderContract<'_> {
pub fn cancel(
&self,
_ctx: ExecCtx,
_orders: Vec<OrderId>,
_solution: Option<Addr>,
orders: Vec<OrderId>,
solution: Option<Addr>,
) -> StdResult<Response> {
todo!("remove order and send event")
}
Expand Down Expand Up @@ -272,7 +270,7 @@ impl OrderContract<'_> {
let solution_upserted = Event::new("mantis-solution-upserted")
.add_attribute("token_a", ab.clone().0)
.add_attribute("token_b", ab.clone().1)
.add_attribute("solver_address", &ctx.info.sender.to_string());
.add_attribute("solver_address", ctx.info.sender.to_string());
ctx.deps.api.debug(&format!(
"mantis::solution::upserted {:?}",
&solution_upserted
Expand Down Expand Up @@ -353,7 +351,7 @@ impl OrderContract<'_> {
let solution_chosen = Event::new("mantis-solution-chosen")
.add_attribute("token_a", ab.clone().0)
.add_attribute("token_b", ab.clone().1)
.add_attribute("solver_address", &ctx.info.sender.to_string())
.add_attribute("solver_address", ctx.info.sender.to_string())
.add_attribute("total_transfers", transfers.len().to_string());

ctx.deps
Expand Down Expand Up @@ -452,14 +450,14 @@ impl OrderContract<'_> {
}

fn order_created(order_id: u128, order: &OrderItem) -> Event {
let order_created = Event::new("mantis-order-created")

Event::new("mantis-order-created")
.add_attribute("order_id", order_id.to_string())
.add_attribute("order_given_amount", order.given.amount.to_string())
.add_attribute("order_given_denom", order.given.denom.to_string())
.add_attribute("order_owner", order.owner.to_string())
.add_attribute("order_wants_amount", order.msg.wants.amount.to_string())
.add_attribute("order_wants_denom", order.msg.wants.denom.to_string());
order_created
.add_attribute("order_wants_denom", order.msg.wants.denom.to_string())
}

/// given all orders amounts aggregated into common pool,
Expand All @@ -486,15 +484,15 @@ fn solves_cows_via_bank(
StdError::generic_err(format!(
"a underflow: {} {}",
a_total_in,
cowed.u128().to_string()
cowed.u128()
))
})?;
} else {
b_total_in = b_total_in.checked_sub(cowed.u128()).ok_or_else(|| {
StdError::generic_err(format!(
"b underflow: {} {}",
b_total_in,
cowed.u128().to_string()
cowed.u128()
))
})?;
};
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{ensure, BankMsg, Event, OverflowError, StdError, StdResult, Uint64};
use cosmwasm_std::{BankMsg, Event, StdResult, Uint64};
use cvm_runtime::{ExchangeId, NetworkId};

use crate::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/cvm-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub use crate::{
asset::*, bridge::*, instruction::*, network::*, packet::*, program::*, protocol::*, service::dex::ExchangeId,
};
use core::marker::PhantomData;
use alloc::collections::VecDeque;

use prelude::*;

/// Strongly typed network builder originating on `CurrentNetwork` network.
Expand Down
4 changes: 2 additions & 2 deletions crates/cvm-runtime/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ pub use alloc::{
vec::Vec,
};
pub use core::{fmt::Display, str::FromStr};
pub use cosmwasm_std::{Addr, Binary, Coin, HexBinary, Uint128};
pub use cosmwasm_std::{Addr, Binary, Coin, Uint128};
pub use serde::{Deserialize, Serialize};

pub use parity_scale_codec::{Decode, Encode};

#[cfg(feature = "json-schema")]
pub use cosmwasm_schema::{cw_serde, QueryResponses};
pub use cosmwasm_schema::{QueryResponses};

#[cfg(feature = "json-schema")]
pub use schemars::JsonSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct MsgSwapExactAmountIn {
}

impl MsgSwapExactAmountIn {
pub const PROTO_MESSAGE_URL: &str = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn";
pub const PROTO_MESSAGE_URL: &'static str = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn";
}

#[allow(clippy::derive_partial_eq_without_eq)]
Expand All @@ -30,5 +30,5 @@ pub struct SwapAmountInRoute {
}

impl SwapAmountInRoute {
pub const PROTO_MESSAGE_URL: &str = "/osmosis.poolmanager.v1beta1.SwapAmountInRoute";
pub const PROTO_MESSAGE_URL: &'static str = "/osmosis.poolmanager.v1beta1.SwapAmountInRoute";
}
4 changes: 2 additions & 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_binary, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use serde::{de::DeserializeOwned, Serialize};

pub type Salt = Vec<u8>;
Expand All @@ -17,7 +17,7 @@ pub fn encode_base64<T: Serialize>(x: &T) -> StdResult<String> {
}

pub fn decode_base64<S: AsRef<str>, T: DeserializeOwned>(encoded: S) -> StdResult<T> {
from_binary::<T>(&Binary::from_base64(encoded.as_ref())?)
from_json::<T>(&Binary::from_base64(encoded.as_ref())?)
}

/// A wrapper around any address on any chain.
Expand Down
6 changes: 3 additions & 3 deletions crates/cvm-runtime/src/transport/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use crate::{
shared::XcPacket,
AssetId, NetworkId,
};
use cosmwasm_std::{to_json_binary, Api, BlockInfo, CosmosMsg, Deps, IbcEndpoint, StdResult, WasmMsg};
use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, IbcEndpoint, StdResult};

use ibc::core::host::types::identifiers::{ChannelId, ConnectionId, PortId};

use ibc_apps::{
hook::{Callback, IBCLifecycleComplete, SendMemo},
hook::{Callback, SendMemo},
memo::Memo,
};

Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn to_cosmwasm_message<T>(
let memo = serde_json_wasm::to_string(&memo).expect("any memo can be to string");
api.debug(&format!("cvm::gateway::ibc::ics20::memo {}", &memo));
match route.ibc_ics_20_sender {
IbcIcs20Sender::SubstratePrecompile(addr) => {
IbcIcs20Sender::SubstratePrecompile(_addr) => {
unimplemented!("pallet-cosmwasm development was frozen")
}
IbcIcs20Sender::CosmosStargateIbcApplicationsTransferV1MsgTransfer => {
Expand Down
2 changes: 1 addition & 1 deletion mantis/node/src/bin/simulator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::process::exit;


use mantis_node::solver::types::OrderType;
use mantis_node::solver::{orderbook::OrderList, solution::Solution, types::Order};
Expand Down
2 changes: 1 addition & 1 deletion mantis/node/src/mantis/cosmos/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub async fn sign_and_tx_tendermint(
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
) -> cosmrs::rpc::endpoint::broadcast::tx_commit::Response {
let rpc_client: cosmrs::rpc::HttpClient = cosmrs::rpc::HttpClient::new(rpc).unwrap();
let tx_raw = sign_doc.sign(&signing_key).expect("signed");
let tx_raw = sign_doc.sign(signing_key).expect("signed");
let result = tx_raw
.broadcast_commit(&rpc_client)
.await
Expand Down

0 comments on commit 178b40a

Please sign in to comment.