Skip to content

Commit

Permalink
denom
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Nov 22, 2023
1 parent fdfe07f commit 96c73ea
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
4 changes: 1 addition & 3 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ impl OrderContract<'_> {

let alternative_transfers = solves_cows_via_bank(
&alternative_all_orders.clone(),
a.clone(),
a_total_in,
b_total_in,
);
Expand Down Expand Up @@ -473,7 +472,6 @@ fn order_created(order_id: u128, order: &OrderItem) -> Event {
/// and return proper action to handle settling funds locally according solution
fn solves_cows_via_bank(
all_orders: &Vec<SolvedOrder>,
a: String,
a_total_in: u128,
b_total_in: u128,
) -> Result<Vec<CowFilledOrder>, StdError> {
Expand All @@ -489,7 +487,7 @@ fn solves_cows_via_bank(

// so if not enough was deposited as was taken from original orders, it will fail - so
// solver cannot rob the bank
if filled_wanted.denom == a {
if order.pair().0 == filled_wanted.denom {
a_total_in -= BigRational::from_integer(cowed.u128().into());
} else {
b_total_in -= BigRational::from_integer(cowed.u128().into());
Expand Down
6 changes: 6 additions & 0 deletions contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ impl SolvedOrder {
Ok(Self { order, solution })
}

pub fn pair(&self) -> Pair {
let mut pair = (self.order.given.denom.clone(), self.order.msg.wants.denom.clone());
pair.sort_selection();
pair
}

pub fn cross_chain(&self) -> u128 {
self.order.msg.wants.amount.u128() - self.solution.cow_amount.u128()
}
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
pname = "mantis";
name = "mantis";
cargoBuildCommand = "cargo build --release --bin mantis";
doCheck = false;
};
default = mantis;
ci = pkgs.writeShellApplication {
Expand Down
2 changes: 1 addition & 1 deletion mainnet.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
RUST_BACKTRACE=1 RUST_TRACE=trace cargo run --bin mantis -- --rpc-centauri "https://composable-rpc.polkachu.com:443" --grpc-centauri "https://composable-grpc.polkachu.com:22290" --osmosis "todo" --neutron "todo" --cvm-contract "centauri1wpf2szs4uazej8pe7g8vlck34u24cvxx7ys0esfq6tuw8yxygzuqpjsn0d" --wallet "$WALLET" --order-contract "centauri1jmr5uttywk0qgzhcme5z4tfy7kg6aprz9wyrdr9tekx25f0lck2qt2vy4q" --simulate "200000ppica,3ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0"
RUST_BACKTRACE=1 RUST_TRACE=trace cargo run --bin mantis -- --rpc-centauri "https://composable-rpc.polkachu.com:443" --grpc-centauri "https://composable-grpc.polkachu.com:22290" --osmosis "todo" --neutron "todo" --cvm-contract "centauri1wpf2szs4uazej8pe7g8vlck34u24cvxx7ys0esfq6tuw8yxygzuqpjsn0d" --wallet "$WALLET" --order-contract "centauri18ag4r8s6qug4gxwllzw04nj3ht6unk9g93e9sj5lscsukfkf4j6qxe7wsx" --simulate "200000ppica,3ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0"
3 changes: 2 additions & 1 deletion mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,15 @@ async fn solve(
let auth_info = simulate_and_set_fee(signing_key, &tip.account).await;
let msg = cw_mantis_order::ExecMsg::Solve { msg: solution };
let msg = to_exec_signed(signing_key, order_contract.clone(), msg);
tx_broadcast_single_signed_msg(
let result = tx_broadcast_single_signed_msg(
msg.to_any().expect("proto"),
auth_info,
rpc,
signing_key,
tip,
)
.await;
println!("result: {:?}", result);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions mantis/node/src/mantis/cosmos/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub async fn tx_broadcast_single_signed_msg(
rpc: &str,
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
tip: &Tip,
) {
) -> cosmrs::rpc::endpoint::broadcast::tx_commit::Response {
let tx_body = tx::Body::new(vec![msg], "", Height::try_from(tip.timeout(100)).unwrap());

let sign_doc = SignDoc::new(
Expand All @@ -148,7 +148,7 @@ pub async fn tx_broadcast_single_signed_msg(
)
.unwrap();

sign_and_tx_tendermint(rpc, sign_doc, signing_key).await;
sign_and_tx_tendermint(rpc, sign_doc, signing_key).await
}

/// simulates tx and ensure fees are within limits
Expand Down

0 comments on commit 96c73ea

Please sign in to comment.