diff --git a/.github/workflows/arkproject-rs.yml b/.github/workflows/arkproject-rs.yml index 8d85514e2..4c4efe521 100644 --- a/.github/workflows/arkproject-rs.yml +++ b/.github/workflows/arkproject-rs.yml @@ -46,7 +46,6 @@ jobs: with: profile: minimal toolchain: stable - override: true - name: Run cargo check uses: actions-rs/cargo@v1 with: @@ -79,7 +78,6 @@ jobs: with: profile: minimal toolchain: stable - override: true components: rustfmt, clippy - name: Run cargo fmt uses: actions-rs/cargo@v1 diff --git a/Cargo.lock b/Cargo.lock index 3b8dd0278..cdd1ffde8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1211,11 +1211,11 @@ checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" [[package]] name = "cainome" version = "0.1.5" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.7#2d4b52b2e79796f76fba9e3a1b1027e8e63292b8" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.8#e79deabeb989f73100c0b2e6a1fe5427858e40a8" dependencies = [ - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.7)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.7)", - "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.7)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.8)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.8)", + "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.8)", ] [[package]] @@ -1245,7 +1245,7 @@ dependencies = [ [[package]] name = "cainome-cairo-serde" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.7#2d4b52b2e79796f76fba9e3a1b1027e8e63292b8" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.8#e79deabeb989f73100c0b2e6a1fe5427858e40a8" dependencies = [ "starknet 0.8.0", "thiserror", @@ -1263,7 +1263,7 @@ dependencies = [ [[package]] name = "cainome-parser" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.7#2d4b52b2e79796f76fba9e3a1b1027e8e63292b8" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.8#e79deabeb989f73100c0b2e6a1fe5427858e40a8" dependencies = [ "quote", "serde_json", @@ -1288,11 +1288,11 @@ dependencies = [ [[package]] name = "cainome-rs" version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.7#2d4b52b2e79796f76fba9e3a1b1027e8e63292b8" +source = "git+https://github.com/cartridge-gg/cainome?tag=v0.1.8#e79deabeb989f73100c0b2e6a1fe5427858e40a8" dependencies = [ "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.7)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.7)", + "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.8)", + "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.1.8)", "proc-macro2", "quote", "serde_json", diff --git a/contracts/Scarb.toml b/contracts/Scarb.toml index 132ebcb44..83a37c9de 100644 --- a/contracts/Scarb.toml +++ b/contracts/Scarb.toml @@ -1,3 +1,6 @@ [workspace] members = ["ark_common", "ark_orderbook", "ark_starknet", "ark_tokens", "solis"] + +[workspace.scripts] +test = "snforge test" diff --git a/contracts/ark_common/src/protocol/order_types.cairo b/contracts/ark_common/src/protocol/order_types.cairo index 536d8ef6e..cd903c157 100644 --- a/contracts/ark_common/src/protocol/order_types.cairo +++ b/contracts/ark_common/src/protocol/order_types.cairo @@ -251,6 +251,8 @@ struct ExecutionValidationInfo { order_hash: felt252, transaction_hash: felt252, starknet_block_timestamp: u64, + from: ContractAddress, + to: ContractAddress, } /// Type of an route, that may be defined from diff --git a/contracts/ark_orderbook/Scarb.toml b/contracts/ark_orderbook/Scarb.toml index c712c590a..bfa59fd0d 100644 --- a/contracts/ark_orderbook/Scarb.toml +++ b/contracts/ark_orderbook/Scarb.toml @@ -7,6 +7,9 @@ ark_common = { path = "../ark_common" } starknet = "2.5.4" snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.18.0" } +[scripts] +test.workspace = true + [[target.starknet-contract]] sierra = true casm = true diff --git a/contracts/ark_orderbook/src/orderbook.cairo b/contracts/ark_orderbook/src/orderbook.cairo index f717f6c45..3db6318de 100644 --- a/contracts/ark_orderbook/src/orderbook.cairo +++ b/contracts/ark_orderbook/src/orderbook.cairo @@ -165,6 +165,8 @@ mod orderbook { order: OrderV1, } + // must be increased when `OrderExecuted` content change + const ORDER_EXECUTED_EVENT_VERSION: u8 = 1; /// Event for when an order is executed. #[derive(Drop, starknet::Event)] struct OrderExecuted { @@ -172,7 +174,10 @@ mod orderbook { order_hash: felt252, #[key] order_status: OrderStatus, - // info: ExecutionInfo, + version: u8, + transaction_hash: felt252, + from: ContractAddress, + to: ContractAddress, } /// Event for when an order is cancelled. @@ -235,7 +240,17 @@ mod orderbook { // TODO: anyway, it can be useful to have an extra check here. order_status_write(info.order_hash, OrderStatus::Executed); let order_status = order_status_read(info.order_hash).unwrap(); - self.emit(OrderExecuted { order_hash: info.order_hash, order_status: order_status }); + self + .emit( + OrderExecuted { + order_hash: info.order_hash, + order_status: order_status, + transaction_hash: info.transaction_hash, + from: info.from, + to: info.to, + version: ORDER_EXECUTED_EVENT_VERSION, + } + ); } /// Update status : only from solis. diff --git a/contracts/ark_starknet/Scarb.toml b/contracts/ark_starknet/Scarb.toml index 2d28cb5dd..7aa7af24b 100644 --- a/contracts/ark_starknet/Scarb.toml +++ b/contracts/ark_starknet/Scarb.toml @@ -10,6 +10,9 @@ ark_common = { path = "../ark_common" } ark_tokens = { path = "../ark_tokens" } ark_oz = { path = "../ark_oz" } +[scripts] +test.workspace = true + [[target.starknet-contract]] sierra = true casm = true diff --git a/contracts/ark_starknet/src/executor.cairo b/contracts/ark_starknet/src/executor.cairo index 54656b57c..08f8652b9 100644 --- a/contracts/ark_starknet/src/executor.cairo +++ b/contracts/ark_starknet/src/executor.cairo @@ -457,6 +457,8 @@ mod executor { order_hash: execution_info.order_hash, transaction_hash, starknet_block_timestamp: block_timestamp, + from: execution_info.nft_from, + to: execution_info.nft_to, }; let mut vinfo_buf = array![]; diff --git a/crates/ark-metadata/Cargo.toml b/crates/ark-metadata/Cargo.toml index 65bc89929..1055aa74a 100644 --- a/crates/ark-metadata/Cargo.toml +++ b/crates/ark-metadata/Cargo.toml @@ -24,3 +24,6 @@ num-bigint = "0.4.4" [dev-dependencies] ark-starknet = { path = "../ark-starknet", features = ["mock"] } mockall = "0.12.1" + +[features] +mock = [] diff --git a/crates/diri/Cargo.toml b/crates/diri/Cargo.toml index 74a82f5bd..093d45848 100644 --- a/crates/diri/Cargo.toml +++ b/crates/diri/Cargo.toml @@ -27,7 +27,7 @@ tracing = "0.1" num-bigint = "0.4.4" num-traits = "0.2.17" -cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.1.7", features = [ +cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.1.8", features = [ "abigen-rs", ] } diff --git a/crates/diri/src/orderbook.rs b/crates/diri/src/orderbook.rs index 41f4a6d4c..52d5a302f 100644 --- a/crates/diri/src/orderbook.rs +++ b/crates/diri/src/orderbook.rs @@ -1,5 +1,136 @@ use cainome::rs::abigen; +use starknet::{ + core::types::{EmittedEvent, FieldElement}, + macros::selector, +}; // TODO: check a way to fix the path... because when compiled from // ark-services, the path is not valid as it's relative to Cargo manifest file. -abigen!(Orderbook, "./artifacts/orderbook.abi.json"); +abigen!( + Orderbook, + "./artifacts/orderbook.abi.json", + type_aliases { + ark_orderbook::orderbook::orderbook::Event as EventV0; + ark_orderbook::orderbook::orderbook::OrderExecuted as OrderExecutedV0; + } +); + +abigen!( + OrderBook, + r#" + [ + { + "type": "event", + "name": "ark_orderbook::orderbook::orderbook::Event", + "kind": "enum", + "variants": [ + { + "name": "OrderExecuted", + "type": "ark_orderbook::orderbook::orderbook::OrderExecuted", + "kind": "nested" + } + ] + }, + { + "type": "event", + "name": "ark_orderbook::orderbook::orderbook::OrderExecuted", + "kind": "struct", + "members": [ + { + "name": "order_hash", + "type": "core::felt252", + "kind": "key" + }, + { + "name": "order_status", + "type": "ark_common::protocol::order_types::OrderStatus", + "kind": "key" + }, + { + "name": "version", + "type": "core::integer::u8", + "kind": "data" + }, + { + "name": "transaction_hash", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "from", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + } + ] + "# +, type_aliases { + ark_orderbook::orderbook::orderbook::Event as EventV1; + ark_orderbook::orderbook::orderbook::OrderExecuted as OrderExecutedV1; + } +); + +#[derive(Debug)] +pub(crate) enum OrderExecuted { + V0(OrderExecutedV0), + V1(OrderExecutedV1), +} + +#[derive(Debug)] +pub(crate) enum Event { + OrderPlaced(OrderPlaced), + OrderExecuted(OrderExecuted), + OrderCancelled(OrderCancelled), + RollbackStatus(RollbackStatus), + OrderFulfilled(OrderFulfilled), + Upgraded(Upgraded), + Unknown, +} + +impl From for Event { + fn from(ev: EmittedEvent) -> Self { + if ev.keys[0] == selector!("OrderExecuted") { + if ev.data.len() > 0 { + let version = ev.data[0]; + if version == FieldElement::ONE {} + // Version 1 + TryInto::::try_into(ev).unwrap().into() + } else { + // Version 0 + TryInto::::try_into(ev).unwrap().into() + } + } else { + match TryInto::::try_into(ev) { + Ok(ev) => ev.into(), + Err(_) => Event::Unknown, + } + } + } +} + +impl From for Event { + fn from(ev: EventV0) -> Self { + match ev { + EventV0::OrderCancelled(ev) => Event::OrderCancelled(ev), + EventV0::OrderPlaced(ev) => Event::OrderPlaced(ev), + EventV0::OrderFulfilled(ev) => Event::OrderFulfilled(ev), + EventV0::RollbackStatus(ev) => Event::RollbackStatus(ev), + EventV0::Upgraded(ev) => Event::Upgraded(ev), + EventV0::OrderExecuted(ev) => Event::OrderExecuted(OrderExecuted::V0(ev)), + } + } +} + +impl From for Event { + fn from(ev: EventV1) -> Self { + match ev { + EventV1::OrderExecuted(ev) => Event::OrderExecuted(OrderExecuted::V1(ev)), + } + } +} diff --git a/crates/diri/src/storage/types.rs b/crates/diri/src/storage/types.rs index a3a8751c7..030591954 100644 --- a/crates/diri/src/storage/types.rs +++ b/crates/diri/src/storage/types.rs @@ -107,13 +107,30 @@ impl From for FulfilledData { #[derive(Debug, Clone)] pub struct ExecutedData { + pub version: u8, pub order_hash: String, + pub transaction_hash: Option, + pub from: Option, + pub to: Option, } impl From for ExecutedData { fn from(value: OrderExecuted) -> Self { - Self { - order_hash: to_hex_str(&value.order_hash), + match value { + OrderExecuted::V0(v) => Self { + version: 0, + order_hash: to_hex_str(&v.order_hash), + transaction_hash: None, + from: None, + to: None, + }, + OrderExecuted::V1(v) => Self { + version: 1, + order_hash: to_hex_str(&v.order_hash), + transaction_hash: Some(to_hex_str(&FieldElement::from(v.transaction_hash))), + from: Some(to_hex_str(&FieldElement::from(v.from))), + to: Some(to_hex_str(&FieldElement::from(v.to))), + }, } } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 87d6531ee..a56a283d2 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.77.1" +channel = "1.80.1"