-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orderbook): implement new executed event (#419)
## Description 1. Update `orderbook::OrderExecuted` event with the following data: ```cairo #[derive(Drop, starknet::Event)] struct OrderExecuted { #[key] order_hash: felt252, #[key] order_status: OrderStatus, version: u8, transaction_hash: felt252, from: ContractAddress, to: ContractAddress, } ``` 2. Update diri to handle `OrderExecuted` version 0 and version 1 <!-- Please do not leave this blank. Describe the changes in this PR. What does it [add/remove/fix/replace]? For crafting a good description, consider using ChatGPT to help articulate your changes. --> ## What type of PR is this? (check all applicable) - [x] 🍕 Feature (`feat:`) - [ ] 🐛 Bug Fix (`fix:`) - [ ] 📝 Documentation Update (`docs:`) - [ ] 🎨 Style (`style:`) - [ ] 🧑💻 Code Refactor (`refactor:`) - [ ] 🔥 Performance Improvements (`perf:`) - [ ] ✅ Test (`test:`) - [ ] 🤖 Build (`build:`) - [ ] 🔁 CI (`ci:`) - [ ] 📦 Chore (`chore:`) - [ ] ⏩ Revert (`revert:`) - [ ] 🚀 Breaking Changes (`BREAKING CHANGE:`) ## Related Tickets & Documents <!-- Please use this format to link related issues: Fixes #<issue_number> More info: https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword --> ## Added tests? - [ ] 👍 yes - [ ] 🙅 no, because they aren't needed - [ ] 🙋 no, because I need help ## Added to documentation? - [ ] 📜 README.md - [ ] 📓 Documentation - [ ] 🙅 no documentation needed ## [optional] Are there any post-deployment tasks we need to perform? <!-- Describe any additional tasks, if any, and provide steps. --> ## [optional] What gif best describes this PR or how it makes you feel? <!-- Share a fun gif related to your PR! --> ### PR Title and Description Guidelines: - Ensure your PR title follows semantic versioning standards. This helps automate releases and changelogs. - Use types like `feat:`, `fix:`, `chore:`, `BREAKING CHANGE:` etc. in your PR title. - Your PR title will be used as a commit message when merging. Make sure it adheres to [Conventional Commits standards](https://www.conventionalcommits.org/). ## Closing Issues <!-- Use keywords to close related issues. This ensures that the associated issues will automatically close when the PR is merged. - `Fixes #123` will close issue 123 when the PR is merged. - `Closes #123` will also close issue 123 when the PR is merged. - `Resolves #123` will also close issue 123 when the PR is merged. You can also use multiple keywords in one comment: - `Fixes #123, Resolves #456` More info: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue -->
- Loading branch information
1 parent
fae88ab
commit 9fdf559
Showing
13 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[workspace] | ||
|
||
members = ["ark_common", "ark_orderbook", "ark_starknet", "ark_tokens", "solis"] | ||
|
||
[workspace.scripts] | ||
test = "snforge test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<EmittedEvent> 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::<EventV1>::try_into(ev).unwrap().into() | ||
} else { | ||
// Version 0 | ||
TryInto::<EventV0>::try_into(ev).unwrap().into() | ||
} | ||
} else { | ||
match TryInto::<EventV0>::try_into(ev) { | ||
Ok(ev) => ev.into(), | ||
Err(_) => Event::Unknown, | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl From<EventV0> 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<EventV1> for Event { | ||
fn from(ev: EventV1) -> Self { | ||
match ev { | ||
EventV1::OrderExecuted(ev) => Event::OrderExecuted(OrderExecuted::V1(ev)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[toolchain] | ||
channel = "1.77.1" | ||
channel = "1.80.1" |