diff --git a/contracts/cosmwasm/order/src/auth.rs b/contracts/cosmwasm/order/src/auth.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/contracts/cosmwasm/order/src/lib.rs b/contracts/cosmwasm/order/src/lib.rs index 85db541d..827e80c5 100644 --- a/contracts/cosmwasm/order/src/lib.rs +++ b/contracts/cosmwasm/order/src/lib.rs @@ -9,6 +9,7 @@ mod prelude; mod simulator; mod state; mod types; +mod validation; use events::order::*; use events::solution::*; @@ -233,6 +234,26 @@ impl OrderContract<'_> { Ok(Response::default().add_message(cvm).add_events(events)) } + /// Executes single order via CVM without use of CoW + #[msg(exec)] + pub fn execute( + &self, + ctx: ExecCtx, + order_id: OrderId, + mut cvm_program: CvmProgram, + ) -> StdResult { + let order: OrderItem = self.orders.load(ctx.deps.storage, order_id.u128())?; + validation::validate_solver(ctx.deps.as_ref(), &ctx.info.sender, &order)?; + self.orders.remove(ctx.deps.storage, order_id.u128()); + validation::validate_program(ctx.deps.as_ref(), &cvm_program, &order)?; + let cvm = wasm_execute( + self.cvm_address.load(ctx.deps.storage)?, + &cvm_program, + vec![order.given], + )?; + Ok(Response::default().add_message(cvm)) + } + /// Provides solution for set of orders. /// All fully #[msg(exec)] @@ -299,6 +320,12 @@ impl OrderContract<'_> { let mut solution_item: SolutionItem = possible_solution; let mut volume = 0u128; for solution in all_solutions { + if validation::validate_solvers(&ctx.deps, &solution, &all_orders).is_err() { + continue; + } + if validation::validate_routes(&ctx.deps, &solution, &all_orders).is_err() { + continue; + } let solution_orders = join_solution_with_orders(&self.orders, &solution.msg, &ctx)?; let a_total_from_orders_in_solution: u128 = solution_orders .iter() diff --git a/contracts/cosmwasm/order/src/validation.rs b/contracts/cosmwasm/order/src/validation.rs new file mode 100644 index 00000000..0876a668 --- /dev/null +++ b/contracts/cosmwasm/order/src/validation.rs @@ -0,0 +1,27 @@ +//! AAA, collateral(stake)<->order, CVM route validation + +use cosmwasm_std::{Addr, StdResult}; + +use crate::{OrderItem, SolvedOrder}; + +/// Validate solver can solve order he tells. +/// Minimal requirement is that CVM salt is unique to solver +pub fn validate_solver(as_ref: cosmwasm_std::Deps<'_>, sender: &Addr, order: &OrderItem) -> StdResult<()> { + Ok(()) +} + +/// Validate program is sane +pub(crate) fn validate_program(as_ref: cosmwasm_std::Deps<'_>, cvm_program: &cvm_runtime::Program, cvm_runtime::shared::XcAddr, cvm_runtime::Funds>>>, order: &OrderItem) -> StdResult<()> { + Ok(()) +} + +/// Validate solver can solver amount he claimed +pub(crate) fn validate_solvers(deps: &cosmwasm_std::DepsMut<'_>, solution: &crate::SolutionItem, all_orders: &[SolvedOrder]) -> StdResult<()> { + Ok(()) +} + +/// Validate solver program is sane +/// Minimal requirement is that CVM salt is unique to solver +pub(crate) fn validate_routes(deps: &cosmwasm_std::DepsMut<'_>, solution: &crate::SolutionItem, all_orders: &[SolvedOrder]) -> StdResult<()> { + Ok(()) +} diff --git a/docs/cvm/lowering-routing.md b/docs/cvm/lowering-routing.md index fe429f8b..1eaf9efe 100644 --- a/docs/cvm/lowering-routing.md +++ b/docs/cvm/lowering-routing.md @@ -181,6 +181,15 @@ Because B to C will be single hop transfer. Other cases rejected. +## 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. + +Run over fork-join tree and product no joins (split rotes). + + ## Solution constraints and questions Given CVM program(tree) and Registry data(graph) on chain, solution to provide annotated CVM program with hints on transports and payloads to use on each hop.