Skip to content

Commit

Permalink
native calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 5, 2024
1 parent 78331b9 commit f74d71a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
20 changes: 20 additions & 0 deletions crates/mantis-cw/src/ordered_coin_pair.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use cosmwasm_std::{Coin, Uint128};

use crate::{Denom, OrderedTuple2};

/// CosmWasm Coin pair ordered by denom
Expand All @@ -14,6 +16,24 @@ impl OrderCoinPair {
b: cosmwasm_std::Coin { denom : ab.b, ..Default::default()},
}
}

pub fn add_a(&mut self, amount: Uint128) {
self.a.amount += amount;
}

pub fn add_b(&mut self, amount: Uint128) {
self.b.amount += amount;
}

pub fn add(&mut self, coin: Coin) {
if coin.denom == self.a.denom {
self.a.amount += coin.amount;
} else if coin.denom == self.b.denom {
self.b.amount += coin.amount;
} else {
panic!("invalid coin denom");
}
}
}

impl From<(Denom, Denom)> for OrderCoinPair {
Expand Down
18 changes: 15 additions & 3 deletions mantis/node/src/mantis/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,30 @@ impl IntentBankInput {

/// given CoW solution and total amount of assets, aggregate remaining to bank for two sides
pub fn find_intent_amount(cows: &[OrderSolution], orders: &[OrderItem], optimal_ratio: Ratio<u64>, cvm_glt: &GetConfigResponse, pair: DenomPair ) -> (IntentBankInput, IntentBankInput) {
let pair = OrderCoinPair::from(pair);
// native calculations
let mut pair = OrderCoinPair::from(pair);
let mut a_to_b = Vec::new();
let mut b_to_a = Vec::new();

for cow in cows {
match cow.cross_chain_part {
Some(OrderAmount::All) => {
let order = orders.iter().find(|x| x.order_id == cow.order_id).expect("order").clone();
let remaining = order.remaining(cow.cow_out_amount, optimal_ratio);

order.fill(cow.cow_out_amount, optimal_ratio).expect("off chain");
pair.add(order.given);

if order.given.denom == pair.a.denom {
a_to_b.push((order.owner, order.given.amount));
} else {
b_to_a.push((order.owner, order.given.amount));
}
},
None => {},
_ => panic!("unsupported cross chain part")
}
}

// making MANTIS route request in CVM form
}
}

Expand Down

0 comments on commit f74d71a

Please sign in to comment.