Skip to content

Commit

Permalink
happier
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 15, 2024
1 parent c3bc234 commit c3dd528
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Empty file.
27 changes: 27 additions & 0 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod prelude;
mod simulator;
mod state;
mod types;
mod validation;

use events::order::*;
use events::solution::*;
Expand Down Expand Up @@ -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<Response> {
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)]
Expand Down Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions contracts/cosmwasm/order/src/validation.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<cvm_runtime::Instruction<Vec<u8>, 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(())
}
9 changes: 9 additions & 0 deletions docs/cvm/lowering-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c3dd528

Please sign in to comment.