Skip to content

Commit

Permalink
Bypes
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 6, 2024
1 parent ff904fc commit 9062262
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl OrderContract<'_> {
fn pre_fill_remotely<'a>(
&self,
ctx: ExecCtx<'a>,
optimal_price: Ratio,
_optimal_price: Ratio,
solver_address: String,
solution_id: SolutionHash,
solver_orders: Vec<SolvedOrder>,
Expand Down
12 changes: 6 additions & 6 deletions contracts/cosmwasm/order/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::SolvedOrder;
/// return filling amounts for all orders from program, which may or may not lead to full fill
pub fn verify(
route: CvmProgram,
in_asset: &AssetItem,
_in_asset: &AssetItem,
out_asset: &AssetItem,
predicted_out_amount: u128,
orders: Vec<SolvedOrder>,
Expand Down Expand Up @@ -80,11 +80,11 @@ pub fn simulate_cows_via_bank(
/// Solve only larger CVM for in volume, assuming other solution will be for other side sent.
/// Produces remaining each order will receive proportional to what is given.
pub fn simulate_route(
storage: &mut dyn Storage,
route: CvmProgram,
token_a_remaining: Coin,
token_b_remaining: Coin,
orders: Vec<SolvedOrder>,
_storage: &mut dyn Storage,
_route: CvmProgram,
_token_a_remaining: Coin,
_token_b_remaining: Coin,
_orders: Vec<SolvedOrder>,
) -> Result<(), StdError> {
todo!()
}
16 changes: 8 additions & 8 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use mantis_node::{
*,
},
indexer::{get_all_orders, get_cvm_glt},
simulate,
simulate, solve::PairSolution,
},
prelude::*,
solver::{orderbook::OrderList, solution::Solution},
Expand Down Expand Up @@ -64,7 +64,7 @@ async fn main() {

async fn solve_orders(solver_args: &SolverArgs) {
let args = &solver_args.shared;
let mut wasm_read_client = create_wasm_query_client(&args.grpc_centauri).await;
let 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 Down Expand Up @@ -187,16 +187,16 @@ async fn solve(
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 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 (a, b) = mantis_node::mantis::solve::IntentBankInput::find_intent_amount(cows.as_ref(), &all_orders, optimal_price, &cvm_glt, cvm_glt.pair.clone());
let cvm_route = blackbox::get_route(router_api, bank, &cvm_glt, salt.as_ref()).await;
for pair_solution in cows_per_pair {;
let (a, b) = mantis_node::mantis::solve::IntentBankInput::find_intent_amount(pair_solution.cows.as_ref(), &all_orders, pair_solution.optimal_price, &cvm_glt, pair_solution.ab.clone());
let cvm_route = panic!(); //blackbox::get_route(router_api, bank, &cvm_glt, salt.as_ref()).await;
send_solution(
cows,
pair_solution.cows,
cvm_route,
tip,
optimal_price,
pair_solution.optimal_price,
signing_key,
order_contract,
rpc,
Expand Down
4 changes: 2 additions & 2 deletions mantis/node/src/mantis/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub fn randomize_coin(coin_0_amount: u128) -> u128 {
///
/// Also calls `timeout` so old orders are cleaned.
pub async fn simulate_order(
write_client: &mut CosmWasmWriteClient,
cosmos_query_client: &mut CosmosQueryClient,
_write_client: &mut CosmWasmWriteClient,
_cosmos_query_client: &mut CosmosQueryClient,
order_contract: String,
coins_pair: &String,
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
Expand Down
9 changes: 5 additions & 4 deletions mantis/node/src/mantis/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl IntentBankInput {
orders: &[OrderItem],
optimal_ratio: Ratio<u64>,
cvm_glt: &GetConfigResponse,
pair: DenomPair,
) -> (IntentBankInput, IntentBankInput) {
// native calculations
let mut pair = OrderCoinPair::zero(pair.a, pair.b);
Expand Down Expand Up @@ -111,17 +112,17 @@ pub struct PairSolution {
pub optimal_price: Ratio<u64>,
}

pub fn find_cows(all_orders: Vec<OrderItem>) -> Vec<PairSolution> {
pub fn find_cows(all_orders: &[OrderItem]) -> Vec<PairSolution> {
let all_orders = all_orders.into_iter().group_by(|x| {
x.pair()
});
let mut cows_per_pair = vec![];
for ((a, b), orders) in all_orders.into_iter() {
for (ab, orders) in all_orders.into_iter() {
let orders = orders.collect::<Vec<_>>();
use crate::solver::cows::*;
use crate::solver::types::*;
let orders = orders.iter().map(|x| {
let side = if x.given.denom == a {
let side = if x.given.denom == ab.a {
OrderType::Buy
} else {
OrderType::Sell
Expand Down Expand Up @@ -160,7 +161,7 @@ pub fn find_cows(all_orders: Vec<OrderItem>) -> Vec<PairSolution> {
println!("cows: {:?}", cows);
if !cows.is_empty() {
let pair_solution = PairSolution {
ab: DenomPair::new(a, b),
ab,
cows,
optimal_price,
};
Expand Down

0 comments on commit 9062262

Please sign in to comment.