Skip to content

Commit

Permalink
more bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Nov 22, 2023
1 parent 89ec63b commit 4be69b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
23 changes: 16 additions & 7 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impl OrderContract<'_> {
pair: ab.clone(),
msg,
block_added: ctx.env.block.height,
owner: ctx.info.sender.clone(),
};

self.solutions.save(
Expand Down Expand Up @@ -316,11 +317,16 @@ impl OrderContract<'_> {
a_total_in,
b_total_in,
);

ctx.deps.api.debug(&format!(
"mantis::solutions::alternative {:?}",
&alternative_transfers
));
if let Ok(alternative_transfers) = alternative_transfers {
if let Err(err) = alternative_transfers {
if solution.owner == ctx.info.sender {
return Err(err);
}
} else if let Ok(alternative_transfers) = alternative_transfers {
if a_total_in * b_total_in > a_in * b_in {
a_in = a_total_in;
b_in = b_total_in;
Expand Down Expand Up @@ -476,23 +482,26 @@ fn solves_cows_via_bank(
let mut transfers = vec![];
for order in all_orders.iter() {
let cowed = order.solution.cow_amount;
let amount = Coin {
let filled_wanted = Coin {
amount: cowed,
..order.given().clone()
denom: order.wanted_denom().clone(),
};

// so if not enough was deposited as was taken from original orders, it will fails - so
// so if not enough was deposited as was taken from original orders, it will fail - so
// solver cannot rob the bank
if amount.denom == a {
if filled_wanted.denom == a {
a_total_in -= BigRational::from_integer(cowed.u128().into());
} else {
b_total_in -= BigRational::from_integer(cowed.u128().into());
};

transfers.push((amount, order.order.order_id));
transfers.push((filled_wanted, order.order.order_id));
}
if a_total_in < BigRational::default() || b_total_in < BigRational::default() {
return Err(StdError::generic_err("SolutionForCowsViaBankIsNotBalanced"));
return Err(StdError::generic_err(format!(
"SolutionForCowsViaBankIsNotBalanced {} {}",
a_total_in, b_total_in
)));
}
Ok(transfers)
}
13 changes: 11 additions & 2 deletions contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct SolutionItem {
pub msg: SolutionSubMsg,
/// at which block solution was added
pub block_added: u64,
pub owner: Addr,
}

/// price information will not be used on chain or deciding.
Expand Down Expand Up @@ -114,9 +115,9 @@ pub struct RouteSubMsg {
#[cw_serde]
pub struct Cow {
pub order_id: OrderId,
/// how much of order to be solved by from bank for all aggregated cows
/// how much of order to be solved by from bank for all aggregated cows, `want` unit
pub cow_amount: Amount,
/// amount user should get after order executed
/// amount user should get after order executed in `want` unit
pub given: Amount,
}
impl Cow {
Expand Down Expand Up @@ -147,6 +148,14 @@ impl SolvedOrder {
self.order.msg.wants.amount.u128() - self.solution.cow_amount.u128()
}

pub fn filled(&self) -> u128 {
self.solution.cow_amount.u128()
}

pub fn wanted_denom(&self) -> String {
self.order.msg.wants.denom.clone()
}

pub fn given(&self) -> &Coin {
&self.order.given
}
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 "centauri1zanf7k7uxth9js5jw2j4sqdhpllldedq9cl72jn4m2e3ddu23jqqp47cum" --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 "centauri1jmr5uttywk0qgzhcme5z4tfy7kg6aprz9wyrdr9tekx25f0lck2qt2vy4q" --simulate "200000ppica,3ibc/EF48E6B1A1A19F47ECAEA62F5670C37C0580E86A9E88498B7E393EB6F49F33C0"

0 comments on commit 4be69b3

Please sign in to comment.