Skip to content

Commit

Permalink
getting last spawn'
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 12, 2024
1 parent 59e8a6a commit df3aadb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions contracts/cosmwasm/order/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ num-integer = { workspace = true, default-features = false, features = ["std"] }

cvm-runtime = { path = "../../../crates/cvm-runtime", default-features = false, features = [
"cosmwasm",
"std",
] }

cvm-route = { path = "../../../crates/cvm-route", default-features = false, features = [
"cosmwasm",
"std",
] }


Expand Down
7 changes: 5 additions & 2 deletions contracts/cosmwasm/order/src/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ use cvm_runtime::AssetId;
use crate::prelude::*;
use crate::CowFilledOrder;
use crate::CowSolutionCalculation;
use crate::Filling;
use crate::SolvedOrder;


/// given expected output amount and list of orders and CVM program, produce fill in of orders
/// return filling amounts for all orders from program, which may or may not lead to full fill
pub fn verify(route: CvmProgram, out_asset: &AssetItem, out_asset:&AssetItem, orders: Vec<SolvedOrder>) -> Result<Vec<int>, StdError> {

pub fn verify(route: CvmProgram, out_asset: &AssetItem, out_asset:&AssetItem, orders: Vec<SolvedOrder>) -> Result<Vec<Filling>, StdError> {
match route.instructions[0] {

}
}

/// All orders amounts aggregated into common pool.
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ impl OrderItem {
}
}

/// simple stucture which can be applied to order to fill or partial fill it
pub struct Filling{
/// simple structure which can be applied to order to fill or partial fill it
pub struct Filling {
order_id: u64,
amount: Uint128,
}
Expand Down
1 change: 1 addition & 0 deletions crates/cvm-runtime/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ pub struct Program<Instructions> {
/// list of instructions to be executed
pub instructions: Instructions,
}

20 changes: 16 additions & 4 deletions crates/cvm-runtime/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ pub type CvmPacket = crate::Packet<CvmProgram>;
pub type CvmProgram = crate::Program<Vec<CvmInstruction>>;

impl CvmProgram {
fn new(instructions: Vec<CvmInstruction>) -> Self {
pub fn new(instructions: Vec<CvmInstruction>) -> Self {
Self {
tag: vec![0],
instructions,
}
}
}
}
}

pub fn last_spawns(&self) -> Vec<&CvmInstruction> {
self.instructions
.iter()
.filter_map(|i|
if let CvmInstruction::Spawn { program, .. } = i {
Some(program.last_spawns())
} else {
None
}
)
.collect()
}
}

impl CvmInstruction {
pub fn transfer_absolute_to_account(to: &str, asset_id: u128, amount: u128) -> Self {
Expand Down

0 comments on commit df3aadb

Please sign in to comment.