-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3879d3
commit 202e3eb
Showing
9 changed files
with
154 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
async fn cleanup( | ||
write_client: &mut CosmWasmWriteClient, | ||
cosmos_query_client: &mut CosmosQueryClient, | ||
order_contract: String, | ||
signing_key: &cosmrs::crypto::secp256k1::SigningKey, | ||
rpc: &str, | ||
tip: &Tip, | ||
gas: Gas, | ||
) { | ||
println!("========================= cleanup ========================="); | ||
let auth_info = simulate_and_set_fee(signing_key, &tip.account, gas).await; | ||
let msg = cw_mantis_order::ExecMsg::Timeout { | ||
orders: vec![], | ||
solutions: vec![], | ||
}; | ||
let msg = to_exec_signed(signing_key, order_contract, msg); | ||
tx_broadcast_single_signed_msg( | ||
msg.to_any().expect("proto"), | ||
auth_info, | ||
rpc, | ||
signing_key, | ||
tip, | ||
) | ||
.await; | ||
} | ||
|
||
/// move protocol forwards, cranks auctions ending and also cleans up old orders | ||
async fn move(){ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
async fn get_all_orders( | ||
order_contract: &String, | ||
cosmos_query_client: &mut CosmWasmReadClient, | ||
tip: &Tip, | ||
) -> Vec<OrderItem> { | ||
let query = cw_mantis_order::QueryMsg::GetAllOrders {}; | ||
let all_orders = smart_query::<_, Vec<OrderItem>>(order_contract, query, cosmos_query_client) | ||
.await | ||
.into_iter() | ||
.filter(|x| x.msg.timeout > tip.block.value()) | ||
.collect::<Vec<OrderItem>>(); | ||
println!("all_orders: {:?}", all_orders); | ||
all_orders | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod args; | ||
pub mod cosmos; | ||
pub mod mantis; | ||
pub mod solve; | ||
pub mod blackbox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use cosmrs::tendermint::block::Height; | ||
use cw_mantis_order::{OrderItem, OrderSolution, OrderSubMsg}; | ||
|
||
use crate::{ | ||
prelude::*, | ||
solver::{orderbook::OrderList, solution::Solution, types::OrderType}, | ||
}; | ||
|
||
use super::cosmos::client::timeout; | ||
|
||
pub fn randomize_order( | ||
coins_pair: String, | ||
tip: Height, | ||
) -> (cw_mantis_order::ExecMsg, cosmrs::Coin) { | ||
let coins: Vec<_> = coins_pair | ||
.split(',') | ||
.map(|x| cosmwasm_std::Coin::from_str(x).expect("coin")) | ||
.collect(); | ||
|
||
let coins = if rand::random::<bool>() { | ||
(coins[0].clone(), coins[1].clone()) | ||
} else { | ||
(coins[1].clone(), coins[0].clone()) | ||
}; | ||
let coin_0_random = randomize_coin(coins.0.amount.u128()); | ||
let coin_1_random = randomize_coin(coins.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(), | ||
}, | ||
transfer: None, | ||
timeout: timeout(tip, 100), | ||
min_fill: None, | ||
}, | ||
}; | ||
let fund = cosmrs::Coin { | ||
amount: coin_1_random.into(), | ||
denom: cosmrs::Denom::from_str(&coins.1.denom).expect("denom"), | ||
}; | ||
(msg, fund) | ||
} | ||
|
||
fn randomize_coin(coin_0_amount: u128) -> u128 { | ||
let delta_0 = 1.max(coin_0_amount / 10); | ||
let coin_0_random = rand_distr::Uniform::new(coin_0_amount - delta_0, coin_0_amount + delta_0); | ||
let coin_0_random: u128 = coin_0_random.sample(&mut rand::thread_rng()); | ||
coin_0_random | ||
} | ||
|
||
|
||
/// `assets` - is comma separate list. each entry is amount u64 glued with alphanumeric denomination | ||
/// that is splitted into array of CosmWasm coins. | ||
/// one coin is chosen as given, | ||
/// from remaining 2 other coins one is chosen as wanted | ||
/// amount of count is randomized around values | ||
/// | ||
/// `write_client` | ||
/// `order_contract` - orders are formed for give and want, and send to orders contract. | ||
/// timeout is also randomized starting from 10 to 100 blocks | ||
/// | ||
/// Also calls `timeout` so old orders are cleaned. | ||
async fn simulate_order( | ||
write_client: &mut CosmWasmWriteClient, | ||
cosmos_query_client: &mut CosmosQueryClient, | ||
order_contract: String, | ||
coins_pair: String, | ||
signing_key: &cosmrs::crypto::secp256k1::SigningKey, | ||
rpc: &str, | ||
tip: &Tip, | ||
gas: Gas, | ||
) { | ||
println!("========================= simulate_order ========================="); | ||
let (msg, fund) = randomize_order(coins_pair, tip.block); | ||
|
||
println!("msg: {:?}", msg); | ||
|
||
let auth_info = simulate_and_set_fee(signing_key, &tip.account, gas).await; | ||
|
||
let msg = to_exec_signed_with_fund(signing_key, order_contract, msg, fund); | ||
|
||
let result = tx_broadcast_single_signed_msg( | ||
msg.to_any().expect("proto"), | ||
auth_info, | ||
rpc, | ||
signing_key, | ||
&tip, | ||
) | ||
.await; | ||
|
||
println!("simulated tx {:?}", result.height) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters