diff --git a/contracts/cosmwasm/order/README.md b/contracts/cosmwasm/order/README.md index 6704a83a..6dcb3e3b 100644 --- a/contracts/cosmwasm/order/README.md +++ b/contracts/cosmwasm/order/README.md @@ -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). \ No newline at end of file +https://github.com/openbook-dex/openbook-v2/blob/master/programs/openbook-v2/src/lib.rs \ No newline at end of file diff --git a/contracts/cosmwasm/order/src/events.rs b/contracts/cosmwasm/order/src/events.rs index dc43d7ca..a488a17c 100644 --- a/contracts/cosmwasm/order/src/events.rs +++ b/contracts/cosmwasm/order/src/events.rs @@ -1,6 +1,6 @@ pub mod order { - use crate::prelude::*; + use crate::{prelude::*, TrackedOrderItem}; use cosmwasm_std::Event; use crate::OrderItem; @@ -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 { diff --git a/contracts/cosmwasm/order/src/lib.rs b/contracts/cosmwasm/order/src/lib.rs index 7972843b..0de1fba4 100644 --- a/contracts/cosmwasm/order/src/lib.rs +++ b/contracts/cosmwasm/order/src/lib.rs @@ -4,6 +4,7 @@ mod constants; mod errors; mod events; +pub mod ordered_tuple; mod prelude; mod simulator; mod state; @@ -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. diff --git a/contracts/cosmwasm/order/src/ordered_tuple.rs b/contracts/cosmwasm/order/src/ordered_tuple.rs new file mode 100644 index 00000000..dcbcf359 --- /dev/null +++ b/contracts/cosmwasm/order/src/ordered_tuple.rs @@ -0,0 +1,44 @@ +use cosmwasm_schema::cw_serde; +pub use tuples::*; + +#[cw_serde] +pub struct OrderedTuple2 { + pub a: T, + pub b: T, +} + +impl Tuple for OrderedTuple2 { + fn arity(&self) -> usize { + 2 + } +} + +impl Tuple2 for OrderedTuple2 { + type Item0 = T; + type Item1 = T; +} + +impl From<(T, T)> for OrderedTuple2 { + fn from(pair: (T, T)) -> Self { + Self::new(pair.0, pair.1) + } +} + +impl OrderedTuple2 { + 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() + } + } +} diff --git a/contracts/cosmwasm/order/src/state.rs b/contracts/cosmwasm/order/src/state.rs index 26d98d26..fb07b317 100644 --- a/contracts/cosmwasm/order/src/state.rs +++ b/contracts/cosmwasm/order/src/state.rs @@ -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::*; diff --git a/contracts/cosmwasm/order/src/types.rs b/contracts/cosmwasm/order/src/types.rs index 657f6695..d1a518d5 100644 --- a/contracts/cosmwasm/order/src/types.rs +++ b/contracts/cosmwasm/order/src/types.rs @@ -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 { solution_id(&(self.owner.to_string(), self.pair.clone(), self.block_added))