Skip to content

Commit

Permalink
rust, i am so happy using you. fuck you also
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 26, 2024
1 parent e8f752d commit 6f9034b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
13 changes: 5 additions & 8 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ use cw_mantis_order::{Amount, OrderItem, OrderSolution, OrderSubMsg, SolutionSub
use mantis_node::{
mantis::{
args::*, autopilot, blackbox, cosmos::{
client::*,
cosmwasm::{smart_query, to_exec_signed, to_exec_signed_with_fund},
*,
client::*, cosmwasm::{smart_query, to_exec_signed, to_exec_signed_with_fund}, cvm::get_salt, *
}, indexer::{get_all_orders, get_cvm_glt}, simulate
},
prelude::*,
Expand Down Expand Up @@ -117,9 +115,8 @@ async fn main() {

async fn simulate_orders(simulate_args: &SimulateArgs) {


let args = simulate_args.shared;
let mut wasm_read_client = create_wasm_query_client(&args.).await;
let args = &simulate_args.shared;
let mut wasm_read_client = create_wasm_query_client(&args.grpc_centauri).await;

let signer = mantis_node::mantis::cosmos::signer::from_mnemonic(
args.wallet.as_str(),
Expand All @@ -144,7 +141,7 @@ async fn simulate_orders(simulate_args: &SimulateArgs) {
&mut write_client,
&mut cosmos_query_client,
args.order_contract.clone(),
assets,
pair,
&signer,
&args.rpc_centauri,
&tip,
Expand Down Expand Up @@ -173,7 +170,7 @@ async fn solve(
gas: Gas,
) {

let salt = get_salt(signing_key, tip);
let salt = crate::cvm::get_salt(signing_key, tip);
println!("========================= solve =========================");
let all_orders = get_all_orders(order_contract, cosmos_query_client, tip).await;
if !all_orders.is_empty() {
Expand Down
9 changes: 0 additions & 9 deletions mantis/node/src/mantis/cosmos/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,4 @@ pub async fn simulate_and_set_fee(
granter: None,
});
auth_info
}



pub fn parse_coin_pair(coins_pair: String) -> (cosmrs::Coin, cosmrs::Coin) {
coins_pair
.split(',')
.map(|x| cosmwasm_std::Coin::from_str(x).expect("coin"))
.collect()
}
10 changes: 10 additions & 0 deletions mantis/node/src/mantis/cosmos/cosmwasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::str::FromStr;

use cosmos_sdk_proto::cosmwasm::{self, wasm::v1::QuerySmartContractStateRequest};
use cosmrs::{cosmwasm::MsgExecuteContract, AccountId};
use cosmwasm_std::Coin;

pub fn to_exec_signed_with_fund<T: serde::ser::Serialize>(
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
Expand Down Expand Up @@ -56,3 +57,12 @@ pub async fn smart_query<T: serde::ser::Serialize, O: serde::de::DeserializeOwne
.data;
serde_json_wasm::from_slice(&result).expect("result parsed")
}

pub fn parse_coin_pair(pair: &String) -> (Coin, Coin) {
let pair: Vec<_> = pair
.split(',')
.map(|x| Coin::from_str(x).expect("coin"))
.collect();
assert_eq!(pair.len(), 2);
(pair[0].clone(), pair[1].clone())
}
24 changes: 12 additions & 12 deletions mantis/node/src/mantis/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ use crate::{
mantis::cosmos::{client::{simulate_and_set_fee, tx_broadcast_single_signed_msg}, cosmwasm::to_exec_signed_with_fund}, prelude::*, solver::{orderbook::OrderList, solution::Solution, types::OrderType}
};

use super::cosmos::client::{timeout, CosmWasmWriteClient, CosmosQueryClient, Tip};
use super::cosmos::{client::{timeout, CosmWasmWriteClient, CosmosQueryClient, Tip}, cosmwasm::parse_coin_pair};

pub fn randomize_order(
coins_pair: String,
pair: &String,
tip: Height,
) -> (cw_mantis_order::ExecMsg, cosmrs::Coin) {
let coins = fun_name(coins_pair);
let pair = parse_coin_pair(pair);

let coins = if rand::random::<bool>() {
(coins[0].clone(), coins[1].clone())
let pair = if rand::random::<bool>() {
(pair.0.clone(), pair.1.clone())
} else {
(coins[1].clone(), coins[0].clone())
(pair.1.clone(), pair.0.clone())
};
let coin_0_random = randomize_coin(coins.0.amount.u128());
let coin_1_random = randomize_coin(coins.1.amount.u128());
let coin_0_random = randomize_coin(pair.0.amount.u128());
let coin_1_random = randomize_coin(pair.1.amount.u128());

let msg = cw_mantis_order::ExecMsg::Order {
msg: OrderSubMsg {
wants: cosmwasm_std::Coin {
amount: coin_0_random.into(),
denom: coins.0.denom.clone(),
denom: pair.0.denom.clone(),
},
transfer: None,
timeout: timeout(tip, 100),
Expand All @@ -34,7 +34,7 @@ pub fn randomize_order(
};
let fund = cosmrs::Coin {
amount: coin_1_random.into(),
denom: cosmrs::Denom::from_str(&coins.1.denom).expect("denom"),
denom: cosmrs::Denom::from_str(&pair.1.denom).expect("denom"),
};
(msg, fund)
}
Expand Down Expand Up @@ -64,14 +64,14 @@ pub async fn simulate_order(
write_client: &mut CosmWasmWriteClient,
cosmos_query_client: &mut CosmosQueryClient,
order_contract: String,
coins_pair: String,
coins_pair: &String,
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
rpc: &str,
tip: &Tip,
gas: Gas,
) {
log::info!("========================= simulate_order =========================");
let (msg, fund) = randomize_order(coins_pair, tip.block);
let (msg, fund) = randomize_order(&coins_pair, tip.block);

println!("msg: {:?}", msg);

Expand Down

0 comments on commit 6f9034b

Please sign in to comment.