Skip to content

Commit

Permalink
ensure people are aware of
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 15, 2024
1 parent 4ba1f16 commit 3a6b1aa
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
6 changes: 2 additions & 4 deletions contracts/cosmwasm/order/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ Solution has owner per pair as identifier.

If solution requires multiblock tracking for execution its id added with block solution was accepted.

## What is fork join?

A was split into B and C, and then B and C were moved to be D.

D must "summed" from 2 amounts must be 2 separate CVM routes branches.
## References

Run over fork-join tree and product no joins (split rotes).
https://github.com/openbook-dex/openbook-v2/blob/master/programs/openbook-v2/src/lib.rs
10 changes: 9 additions & 1 deletion contracts/cosmwasm/order/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod order {

use crate::prelude::*;
use crate::{prelude::*, TrackedOrderItem};
use cosmwasm_std::Event;

use crate::OrderItem;
Expand Down Expand Up @@ -44,6 +44,14 @@ pub mod order {
.add_attribute("order_id", order.order_id.to_string())
.add_attribute("solver_address", solver_address.clone())
}

pub fn mantis_order_cross_chain_tracked(tracking: &TrackedOrderItem) -> Event {
Event::new("mantis-order-cross-chain-tracked")
.add_attribute("order_id", tracking.order_id.to_string())
.add_attribute("amount_taken", tracking.amount_taken.to_string())
.add_attribute("promised", tracking.promised.to_string())
.add_attribute("meta", "solution is not verified, do not use for big funds".to_string())
}
}

pub mod solution {
Expand Down
8 changes: 7 additions & 1 deletion contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mod constants;
mod errors;
mod events;
pub mod ordered_tuple;
mod prelude;
mod simulator;
mod state;
Expand Down Expand Up @@ -223,8 +224,13 @@ impl OrderContract<'_> {
amount: b_funds,
},
];

let events = cvm_filled
.iter()
.map(|x| mantis_order_cross_chain_tracked(&x.tracking));

let cvm = wasm_execute(contract, &cvm, funds)?;
Ok(Response::default().add_message(cvm))
Ok(Response::default().add_message(cvm).add_events(events))
}

/// Provides solution for set of orders.
Expand Down
44 changes: 44 additions & 0 deletions contracts/cosmwasm/order/src/ordered_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use cosmwasm_schema::cw_serde;
pub use tuples::*;

#[cw_serde]
pub struct OrderedTuple2<T> {
pub a: T,
pub b: T,
}

impl<T> Tuple for OrderedTuple2<T> {
fn arity(&self) -> usize {
2
}
}

impl<T> Tuple2 for OrderedTuple2<T> {
type Item0 = T;
type Item1 = T;
}

impl<T: PartialOrd + Clone + PartialOrd + PartialEq> From<(T, T)> for OrderedTuple2<T> {
fn from(pair: (T, T)) -> Self {
Self::new(pair.0, pair.1)
}
}

impl<T: PartialOrd + Clone + PartialOrd + PartialEq> OrderedTuple2<T> {
pub fn new(a: T, b: T) -> Self {
let mut pair = (a, b);
pair.sort_selection();
Self {
a: pair.0,
b: pair.1,
}
}

pub fn other(&self, denom: &T) -> T {
if &self.a == denom {
self.b.clone()
} else {
self.a.clone()
}
}
}
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! simple operation without constraint checks and calculations
use cw_storage_plus::MultiIndex;
use cw_storage_plus::{KeyDeserialize, MultiIndex, PrimaryKey};

use crate::*;

Expand Down
3 changes: 2 additions & 1 deletion contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ pub struct OrderSubMsg {

#[cw_serde]
pub struct SolutionItem {
pub pair: (String, String),
pub pair: DenomPair,
pub msg: SolutionSubMsg,
/// at which block solution was added
pub block_added: u64,
pub owner: Addr,
}


impl SolutionItem {
pub fn id(&self) -> Vec<u8> {
solution_id(&(self.owner.to_string(), self.pair.clone(), self.block_added))
Expand Down

0 comments on commit 3a6b1aa

Please sign in to comment.