Skip to content

Commit

Permalink
happier
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 30, 2024
1 parent 9bc0863 commit 0af11d1
Show file tree
Hide file tree
Showing 18 changed files with 155 additions and 112 deletions.
37 changes: 29 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ cw-storage-plus = { version = "^1.2.0", features = [
itertools = { version = "^0.12.1", default-features = false }
num-rational = { version = "^0.4.1", default-features = false }
num-integer = { version = "^0.1.46", default-features = false }
cw-multi-test = {version = "^1.0.0", default-features = false}

ibc-proto = { version = "^0.42.2", default-features = false }
serde-json-wasm = { version = "^1.0.1", default-features = false }
Expand All @@ -110,6 +111,8 @@ strum = "^0.25"
strum_macros = "^0.25"
tuples = { version = "^1.14.0" }
serde-cw-value = { git = "https://github.com/dzmitry-lahoda-forks/serde-cw-value.git", branch = "dz/3", default-features = false }
petgraph = {version = "*", default-features = false , features = ["graphmap", "stable_graph", "matrix_graph", "serde-1", "rayon",
]}

no-panic = "^0.1"
scale-info = { version = "^2.10.0", default-features = false }
Expand Down Expand Up @@ -141,25 +144,22 @@ ibc-primitives = { git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.git", b
primitive-types = { git = "https://github.com/dzmitry-lahoda-forks/parity-common.git", branch = "dz/3", default-features = false, features = [
"serde_no_std",
] }
neutron-sdk = { version = "^0.7.0", default-features = false }
neutron-sdk = { version = "^0.10.0", default-features = false }

osmosis-std = { version = "^0.20.1", default-features = false }
osmosis-std = { version = "^0.22.0", default-features = false }

astroport = { version = "^3.6.1", default-features = false }

ndarray = { version = "^0.15.6", default-features = false }

good_lp = { version = "^1.7", default-features = false }

cw-multi-test = { version = "0.20.0" }


cw-mantis-order = { path = "./contracts/cosmwasm/order", features = [
"json-schema",
"std",
] }

fraction = { version = "0.14", default-features = false }
fraction = { version = "0.15.1", default-features = false }

[profile.deployment]
inherits = "release"
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use cosmwasm_std::{
SubMsgResult, WasmMsg, WasmQuery,
};
use cvm_route::{asset::AssetReference, exchange::ExchangeItem};
use cvm_runtime::{executor::*, shared::CvmAddress};
use cvm_runtime::{
apply_bindings,
exchange::*,
executor::{CvmExecutorInstantiated, InstantiateMsg},
outpost::{BridgeExecuteProgramMsg, BridgeForwardMsg},
shared, Amount, BindingValue, Destination, Funds, Instruction, NetworkId, Register,
};
use cvm_runtime::{executor::*, shared::CvmAddress};
use cw2::{ensure_from_older_version, set_contract_version};
use cw20::{BalanceResponse, Cw20Contract, Cw20ExecuteMsg, Cw20QueryMsg};
use num::Zero;
Expand Down
1 change: 0 additions & 1 deletion contracts/cosmwasm/order/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub fn validate_solver(
Ok(())
}


/// Validate solver can solver amount he claimed
pub(crate) fn validate_solvers(
deps: &cosmwasm_std::DepsMut<'_>,
Expand Down
3 changes: 1 addition & 2 deletions contracts/cosmwasm/outpost/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ impl Auth<policy::WasmHook> {
.ics_20
.ok_or(ContractError::ICS20NotFound)?
.source;
let hash_of_channel_and_sender =
derive_intermediate_sender(&channel, &sender, &prefix)?;
let hash_of_channel_and_sender = derive_intermediate_sender(&channel, &sender, &prefix)?;
deps.api.debug(&format!(
"cvm::outpost:auth:: {0} {1}",
&hash_of_channel_and_sender, &info.sender
Expand Down
1 change: 0 additions & 1 deletion contracts/cosmwasm/outpost/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl From<ibc_apps_more::types::error::HookError> for ContractError {
fn from(value: ibc_apps_more::types::error::HookError) -> Self {
Self::HookError(value)
}

}

impl From<cvm_runtime::proto::DecodeError> for ContractError {
Expand Down
1 change: 1 addition & 0 deletions contracts/cosmwasm/settlement/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion crates/cvm-runtime/src/outpost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl ExecutePacketICS20Msg {
let ics20 = self.into_packet()?;
let memo: LazyHookMemo = serde_json_wasm::from_str(&ics20.memo.to_string())
.map_err(|x| StdError::generic_err(format!("{:?}", x)))?;
let wasm: Callback<serde_cw_value::Value> = memo.base
let wasm: Callback<serde_cw_value::Value> = memo
.base
.wasm
.ok_or(StdError::generic_err(format!("no wasm in memo")))?;
ensure!(
Expand Down
16 changes: 7 additions & 9 deletions crates/cvm/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{prelude::*, AssetId};
use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use serde::{de::DeserializeOwned, Serialize};


/// A wrapper around any address on any chain.
/// Similar to `ibc_rs::Signer`(multi encoding), but not depend on ibc code bloat.
/// Unlike parity MultiLocation/Account32/Account20 which hard codes enum into code.
Expand Down Expand Up @@ -57,19 +56,18 @@ impl XcAddr {
#[cfg(feature = "cosmwasm")]
pub fn encode_cosmwasm(&self, api: &dyn Api) -> Result<String, StdError> {
let addr = self.parse()?;

Ok(api.addr_humanize(&CanonicalAddr(addr))?.to_string())
}

#[cfg(feature = "cosmwasm")]
pub fn parse(&self) -> Result<Binary, StdError> {
use bech32::{primitives::decode::CheckedHrpstring, Bech32};
let addr = if let Ok(addr) = CheckedHrpstring::new::<Bech32>(&self.0) {
let addr = if let Ok(addr) = CheckedHrpstring::new::<Bech32>(&self.0) {
Binary(addr.byte_iter().into_iter().collect())
} else if let Ok(addr) = Binary::from_base64(&self.0) {
addr
}
else {
} else {
return Err(StdError::generic_err("Failed to ensure XcAddr encoding")).into();
};
Ok(addr)
Expand All @@ -82,20 +80,20 @@ mod tests {
#[test]
fn xcaddr() {
let addr_a = "osmovalcons1qg7u70m2af8qpx9thg40y0eavkkryjz3rsxafg";
let addr_b = "Aj3PP2rqTgCYq7oq8j89ZawySFE=";
let addr_b = "Aj3PP2rqTgCYq7oq8j89ZawySFE=";
let addr_c = "cosmosvalcons1qg7u70m2af8qpx9thg40y0eavkkryjz35gfmyw";

// this is valid base64 and this is very bad
let addr_d = "023DCF3F6AEA4E0098ABBA2AF23F3D65AC324851";

let xcaddr_a = super::XcAddr(addr_a.to_string());
let xcaddr_b = super::XcAddr(addr_b.to_string());
let xcaddr_c = super::XcAddr(addr_c.to_string());
let xcaddr_d = super::XcAddr(addr_d.to_string());
assert_eq!(addr_b, xcaddr_a.parse().unwrap().to_base64());
assert_eq!(addr_b, xcaddr_b.parse().unwrap().to_base64());
assert_eq!(addr_b, xcaddr_c.parse().unwrap().to_base64());

// next fails
// assert_eq!(addr_b, xcaddr_d.parse().unwrap().to_base64());
}
Expand Down
4 changes: 2 additions & 2 deletions crates/cvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#![cfg_attr(no_std, feature(error_in_core))]
extern crate alloc;

pub mod address;
pub mod asset;
pub mod exchange;
pub mod network;
mod prelude;
pub mod proto;
pub mod shared;
pub mod address;
pub use address::*;
pub use asset::*;
pub use network::*;
pub use address::*;
1 change: 0 additions & 1 deletion crates/cvm/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{prelude::*, AssetId};
use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use serde::{de::DeserializeOwned, Serialize};


/// A wrapper around a type which is serde-serialised as a string.
///
/// For serde-serialisation to be implemented for the type `T` must implement
Expand Down
1 change: 1 addition & 0 deletions mantis/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cvm-runtime = { workspace = true, features = ["std"] }
ndarray ={ workspace = true, features = ["std", "serde"]}
fraction = {workspace = true, features = ["default"]}
env_logger = {workspace = true}
cw-multi-test = { workspace = true }

[dev-dependencies]
rustfmt-wrapper = "0.2.1"
62 changes: 36 additions & 26 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use cosmrs::{
tx::{self, Fee, SignerInfo},
AccountId,
};
use cvm_runtime::shared::CvmProgram;
use cw_mantis_order::{Amount, OrderItem, OrderSolution, OrderSubMsg, SolutionSubMsg};
use mantis_node::{
mantis::{
Expand Down Expand Up @@ -104,14 +105,21 @@ async fn solve_orders(solver_args: &SolverArgs) {
.await;
let all_orders = get_all_orders(&args.order_contract, &mut wasm_read_client, &tip).await;
if !all_orders.is_empty() {
let main_chain = CosmosChainInfo {
rpc: args.rpc_centauri.clone(),
chain_id: args.main_chain_id.clone(),
};
solve(
&mut write_client,
&mut wasm_read_client,
&solver_args.cvm_contract,
&args.order_contract,
&signer,
&args.rpc_centauri,
&main_chain,
&tip,
gas,
all_orders,
solver_args.solution_provider.as_ref(),
)
.await;
};
Expand Down Expand Up @@ -170,40 +178,42 @@ async fn solve(
cvm_contact: &String,
order_contract: &String,
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
rpc: &str,
rpc: &CosmosChainInfo,
tip: &Tip,
gas: Gas,
all_orders: Vec<OrderItem>,
router_api: &str,
) {
panic!()
// let salt = crate::cvm::get_salt(signing_key, tip);
// println!("========================= solve =========================");
//
// if !all_orders.is_empty() {
// let cows_per_pair = mantis_node::mantis::solve::do_cows(all_orders);
// let cvm_glt = get_cvm_glt(cvm_contact, &mut cosmos_query_client).await;
// let cows_cvm = blackbox::route(cows_per_pair, all_orders, &cvm_glt, salt.as_ref()).await;
// for (cows, optimal_price) in cows_per_pair {
// send_solution(
// cows,
// tip,
// optimal_price,
// signing_key,
// order_contract,
// rpc,
// gas,
// )
// .await;
// }
// }
let salt = crate::cvm::get_salt(signing_key, tip);
log::info!(target: "mantis::solver", "Solving orders");

let cows_per_pair = mantis_node::mantis::solve::find_cows(all_orders);
let cvm_glt = get_cvm_glt(cvm_contact, cosmos_query_client).await;
for (cows, optimal_price) in cows_per_pair {
let bank = mantis_node::mantis::solve::find_intent_amount(cows.as_ref());
let cvm_route = blackbox::get_route(router_api, bank, &cvm_glt, salt.as_ref()).await;
send_solution(
cows,
cvm_route,
tip,
optimal_price,
signing_key,
order_contract,
rpc,
gas,
)
.await;
}
}

async fn send_solution(
cows: Vec<OrderSolution>,
cvm: CvmProgram,
tip: &Tip,
optimal_price: (u64, u64),
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
order_contract: &String,
rpc: &str,
rpc: &CosmosChainInfo,
gas: Gas,
) {
println!("========================= settle =========================");
Expand All @@ -220,10 +230,10 @@ async fn send_solution(
let result = tx_broadcast_single_signed_msg(
msg.to_any().expect("proto"),
auth_info,
panic!(), // rpc,
rpc,
signing_key,
tip,
)
.await;
println!("result: {:?}", result);
log::info!("result: {:?}", result);
}
4 changes: 4 additions & 0 deletions mantis/node/src/mantis/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ pub struct SolverArgs {
#[command(flatten)]
pub shared: SharedArgs,

/// CVM
#[arg(long)]
pub cvm_contract: String,

/// http url to call with parameters to obtain route
pub solution_provider: String,
}
Expand Down
Loading

0 comments on commit 0af11d1

Please sign in to comment.