Skip to content

Commit

Permalink
feat(contract): explore the possibility to use a fully onchain orderb…
Browse files Browse the repository at this point in the history
…ook on (ArkProjectNFTs#439)

## Description

1. Orderbook is now a component
2. Remove messaging in Starknet part
3. Add `version` and `order_type` in Orderbook component events
4. Move dependencies version to workspace Scarb.toml
5. Update to cairo 2.7.1, snforge 0.28 & OZ 0.15.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 ArkProjectNFTs#123` will close issue 123 when the PR is merged.
- `Closes ArkProjectNFTs#123` will also close issue 123 when the PR is merged.
- `Resolves ArkProjectNFTs#123` will also close issue 123 when the PR is merged.

You can also use multiple keywords in one comment:
- `Fixes ArkProjectNFTs#123, Resolves ArkProjectNFTs#456`

More info:
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->
  • Loading branch information
ptisserand authored Sep 10, 2024
1 parent ab724d6 commit f083deb
Show file tree
Hide file tree
Showing 47 changed files with 1,811 additions and 1,307 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/arkproject-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: 2.5.4
scarb-version: 2.7.1
- name: Check Scarb Formatting
run: cd contracts && scarb fmt --check
test:
Expand All @@ -36,12 +36,12 @@ jobs:
- name: Setup Scarb
uses: software-mansion/setup-scarb@v1
with:
scarb-version: 2.5.4
scarb-version: 2.7.1

- name: Setup Starknet Foundry
uses: foundry-rs/setup-snfoundry@v2
with:
starknet-foundry-version: 0.18.0
starknet-foundry-version: 0.28.0

- name: Test ark_common contracts
run: cd contracts/ark_common && snforge test
Expand Down
4 changes: 2 additions & 2 deletions contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.5.4
starknet-foundry 0.18.0
scarb 2.7.1
starknet-foundry 0.28.0
107 changes: 102 additions & 5 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "ark_component"
version = "0.1.0"
dependencies = [
"ark_common",
"snforge_std",
]

[[package]]
name = "ark_orderbook"
version = "0.1.0"
dependencies = [
"ark_common",
"ark_component",
"snforge_std",
]

Expand All @@ -21,14 +30,14 @@ name = "ark_oz"
version = "0.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
]

[[package]]
name = "ark_starknet"
version = "0.1.0"
dependencies = [
"ark_common",
"ark_component",
"ark_oz",
"ark_tokens",
"openzeppelin",
Expand All @@ -46,13 +55,101 @@ dependencies = [

[[package]]
name = "openzeppelin"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_governance"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"
dependencies = [
"openzeppelin_access",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_introspection"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"

[[package]]
name = "openzeppelin_presets"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
]

[[package]]
name = "openzeppelin_security"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"

[[package]]
name = "openzeppelin_token"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"
dependencies = [
"openzeppelin_account",
"openzeppelin_governance",
"openzeppelin_introspection",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"

[[package]]
name = "openzeppelin_utils"
version = "0.15.1"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.15.1#2f8a93d762858714095a1d391afffa9e21df6983"

[[package]]
name = "snforge_scarb_plugin"
version = "0.1.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"

[[package]]
name = "snforge_std"
version = "0.18.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.18.0#48f909a56b08cbdc5ca6a21a836b0fbc6c36d55b"
version = "0.28.0"
source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.28.0#4dfe39d96690ed6b3d56971512700de3f58288ea"
dependencies = [
"snforge_scarb_plugin",
]

[[package]]
name = "solis"
Expand Down
18 changes: 17 additions & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
[workspace]

members = ["ark_common", "ark_orderbook", "ark_starknet", "ark_tokens", "solis"]
members = [
"ark_common",
"ark_component",
"ark_orderbook",
"ark_starknet",
"ark_tokens",
"solis",
]

[workspace.dependencies]
starknet = "2.7.1"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.1" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.28.0" }
assert_macros = "0.1.0"

[workspace.scripts]
test = "snforge test"

[workspace.tool.fmt]
sort-module-level-items = true
9 changes: 7 additions & 2 deletions contracts/ark_common/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ version = "0.1.0"
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.5.4"
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.18.0" }
starknet.workspace = true

[dev-dependencies]
snforge_std.workspace = true

[tool]
fmt.workspace = true

[lib]

Expand Down
3 changes: 1 addition & 2 deletions contracts/ark_common/src/crypto/common.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use traits::Into;

// locals
use super::constants;
use traits::Into;

fn hash_u256(n: u256) -> felt252 {
let mut hash = pedersen::pedersen(0, constants::U256_TYPE_HASH);
Expand Down
2 changes: 1 addition & 1 deletion contracts/ark_common/src/crypto/typed_data.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use traits::Into;
use box::BoxTrait;
use super::constants;
use traits::Into;

const ORDER_TYPE_HASH: felt252 = 0x3749634CC837ADA5AF76B97FC3197F05DFC376CF4B73199E76107754E39CA1D;

Expand Down
6 changes: 3 additions & 3 deletions contracts/ark_common/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod protocol {
mod order_database;
mod order_types;
mod order_v1;
mod order_database;
}

mod crypto {
mod common;
mod constants;
mod hash;
mod signer;
mod typed_data;
mod constants;
mod common;
}
5 changes: 2 additions & 3 deletions contracts/ark_common/src/protocol/order_database.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ark_common::protocol::order_types::OrderStatus;
use ark_common::protocol::order_types::OrderType;
use core::result::ResultTrait;
//! Orders database.
//!
Expand All @@ -20,9 +22,6 @@ use core::result::ResultTrait;
//! 4. At base addresss + offset 2 => First felt of the serialized order.
use starknet::SyscallResultTrait;

use ark_common::protocol::order_types::OrderStatus;
use ark_common::protocol::order_types::OrderType;

/// Must remain equal to 0 for now.
const ADDRESS_DOMAIN: u32 = 0;
/// A constant value used in the base key hash.
Expand Down
4 changes: 2 additions & 2 deletions contracts/ark_common/src/protocol/order_types.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_common::protocol::order_v1::OrderV1;
use poseidon::poseidon_hash_span;
//! Order generic variables.
use starknet::ContractAddress;
use poseidon::poseidon_hash_span;
use ark_common::protocol::order_v1::OrderV1;

/// Order types.
#[derive(Serde, Drop, PartialEq, Copy, Debug, starknet::Store)]
Expand Down
10 changes: 5 additions & 5 deletions contracts/ark_common/src/protocol/order_v1.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use ark_common::protocol::order_types::FulfillInfo;
use ark_common::protocol::order_types::{OrderTrait, OrderValidationError, OrderType, RouteType};
use core::array::ArrayTrait;
use core::option::OptionTrait;
use core::traits::Into;
use core::traits::TryInto;
use core::option::OptionTrait;
use poseidon::poseidon_hash_span;

//! Order v1 supported by the Orderbook.
//!
use starknet::ContractAddress;
use starknet::contract_address_to_felt252;
use ark_common::protocol::order_types::{OrderTrait, OrderValidationError, OrderType, RouteType};
use ark_common::protocol::order_types::FulfillInfo;
use poseidon::poseidon_hash_span;
use starknet::SyscallResultTrait;
use starknet::contract_address_to_felt252;

const ORDER_VERSION_V1: felt252 = 'v1';
// Auction -> end_amount (reserve price) > start_amount (starting price).
Expand Down
10 changes: 5 additions & 5 deletions contracts/ark_common/tests/test_type_data.cairo
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use core::traits::TryInto;
use traits::Into;
use box::BoxTrait;
use ark_common::crypto::signer::{Signer, SignInfo};

use ark_common::crypto::typed_data::{OrderSign, TypedDataTrait};
use box::BoxTrait;

use core::option::OptionTrait;
use ark_common::crypto::signer::{Signer, SignInfo};
use core::traits::TryInto;
use snforge_std::signature::KeyPairTrait;
use snforge_std::signature::stark_curve::{
StarkCurveKeyPairImpl, StarkCurveSignerImpl, StarkCurveVerifierImpl
};
use traits::Into;

fn sign_mock(message_hash: felt252) -> Signer {
let key_pair = KeyPairTrait::<felt252, felt252>::generate();
let (r, s): (felt252, felt252) = key_pair.sign(message_hash);
let (r, s): (felt252, felt252) = key_pair.sign(message_hash).unwrap();
Signer::WEIERSTRESS_STARKNET(
SignInfo { user_pubkey: key_pair.public_key, user_sig_r: r, user_sig_s: s, }
)
Expand Down
19 changes: 19 additions & 0 deletions contracts/ark_component/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "ark_component"
version = "0.1.0"

[dependencies]
ark_common = { path = "../ark_common" }
starknet.workspace = true

[dev-dependencies]
snforge_std.workspace = true
assert_macros.workspace = true

[scripts]
test.workspace = true

[tool]
fmt.workspace = true

[lib]
1 change: 1 addition & 0 deletions contracts/ark_component/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod orderbook;
9 changes: 9 additions & 0 deletions contracts/ark_component/src/orderbook.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod interface;
pub mod orderbook;
pub use interface::{IOrderbook, IOrderbookAction, orderbook_errors};

pub use orderbook::OrderbookComponent;
pub use orderbook::{
OrderbookHooksCreateOrderEmptyImpl, OrderbookHooksCancelOrderEmptyImpl,
OrderbookHooksFulfillOrderEmptyImpl, OrderbookHooksValidateOrderExecutionEmptyImpl,
};
Loading

0 comments on commit f083deb

Please sign in to comment.