Skip to content

Commit

Permalink
diri: add new event
Browse files Browse the repository at this point in the history
  • Loading branch information
ybensacq committed Mar 20, 2024
1 parent 4cf91b8 commit ccb8bbc
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
17 changes: 17 additions & 0 deletions artifacts/orderbook.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,18 @@
}
]
},
{
"type": "event",
"name": "ark_orderbook::orderbook::orderbook::OrderBackToOpen",
"kind": "struct",
"members": [
{
"name": "order_hash",
"type": "core::felt252",
"kind": "key"
}
]
},
{
"type": "event",
"name": "ark_orderbook::orderbook::orderbook::Event",
Expand Down Expand Up @@ -643,6 +655,11 @@
"name": "Upgraded",
"type": "ark_orderbook::orderbook::orderbook::Upgraded",
"kind": "nested"
},
{
"name": "OrderBackToOpen",
"type": "ark_orderbook::orderbook::orderbook::OrderBackToOpen",
"kind": "nested"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions crates/diri/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ which is the one state among the following: 0. The order is created and open (`O
1. The order is cancelled (`OrderCancelled`).
2. The order is fulfilled (`OrderFulfilled`).
3. The order is executed (`OrderExecuted`).
4. The order can be rollbacked and status back to placed (`OrderBackToOpen`).

The concept of `expiry` does not apply to Diri logic. We only care about the
lifecycle of an order through the events.
Expand Down
17 changes: 17 additions & 0 deletions crates/diri/artifacts/orderbook.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@
}
]
},
{
"type": "event",
"name": "ark_orderbook::orderbook::orderbook::OrderBackToOpen",
"kind": "struct",
"members": [
{
"name": "order_hash",
"type": "core::felt252",
"kind": "key"
}
]
},
{
"type": "event",
"name": "ark_orderbook::orderbook::orderbook::Event",
Expand Down Expand Up @@ -639,6 +651,11 @@
"name": "Upgraded",
"type": "ark_orderbook::orderbook::orderbook::Upgraded",
"kind": "nested"
},
{
"name": "OrderBackToOpen",
"type": "ark_orderbook::orderbook::orderbook::OrderBackToOpen",
"kind": "nested"
}
]
}
Expand Down
6 changes: 6 additions & 0 deletions crates/diri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ impl<S: Storage, E: EventHandler> Diri<S, E> {
.register_executed(block_number, block_timestamp, &ev.into())
.await?;
}
Event::OrderBackToOpen(ev) => {
trace!("OrderBackToOpen found: {:?}", ev);
self.storage
.order_back_to_open(block_number, block_timestamp, &ev.into())
.await?;
}
_ => warn!("Orderbook event not handled: {:?}", orderbook_event),
};
}
Expand Down
9 changes: 8 additions & 1 deletion crates/diri/src/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use async_trait::async_trait;

pub mod types;
use types::{CancelledData, ExecutedData, FulfilledData, PlacedData};
use types::{BackToOpenData, CancelledData, ExecutedData, FulfilledData, PlacedData};

pub type StorageResult<T> = Result<T, StorageError>;

Expand Down Expand Up @@ -42,4 +42,11 @@ pub trait Storage {
block_timestamp: u64,
order: &ExecutedData,
) -> StorageResult<()>;

async fn order_back_to_open(
&self,
block_id: u64,
block_timestamp: u64,
order: &BackToOpenData,
) -> StorageResult<()>;
}
17 changes: 16 additions & 1 deletion crates/diri/src/storage/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use starknet::core::types::FieldElement;
use starknet::core::utils::parse_cairo_short_string;
use std::fmt::LowerHex;

use crate::orderbook::{OrderCancelled, OrderExecuted, OrderFulfilled, OrderPlaced, U256};
use crate::orderbook::{
OrderBackToOpen, OrderCancelled, OrderExecuted, OrderFulfilled, OrderPlaced, U256,
};

#[derive(Debug, Clone)]
pub struct PlacedData {
Expand Down Expand Up @@ -70,6 +72,19 @@ impl From<OrderCancelled> for CancelledData {
}
}

#[derive(Debug, Clone)]
pub struct BackToOpenData {
pub order_hash: String,
}

impl From<OrderBackToOpen> for BackToOpenData {
fn from(value: OrderBackToOpen) -> Self {
Self {
order_hash: to_hex_str(&value.order_hash),
}
}
}

#[derive(Debug, Clone)]
pub struct FulfilledData {
pub order_hash: String,
Expand Down

0 comments on commit ccb8bbc

Please sign in to comment.