Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contract): update to cairo 2.7.1, OZ 0.15.1 and starknet-foundry 0.28.0 #430

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
97 changes: 92 additions & 5 deletions contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ name = "ark_oz"
version = "0.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
]

[[package]]
Expand All @@ -46,13 +45,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
5 changes: 5 additions & 0 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

members = ["ark_common", "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" }

[workspace.scripts]
test = "snforge test"
6 changes: 4 additions & 2 deletions contracts/ark_common/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ 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

[lib]

Expand Down
2 changes: 1 addition & 1 deletion contracts/ark_common/tests/test_type_data.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use snforge_std::signature::stark_curve::{

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
6 changes: 4 additions & 2 deletions contracts/ark_orderbook/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ version = "0.1.0"

[dependencies]
ark_common = { path = "../ark_common" }
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

[scripts]
test.workspace = true
Expand Down
18 changes: 10 additions & 8 deletions contracts/ark_orderbook/src/orderbook.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! # Orderbook Contract
//!
//! This module defines the structure and functionalities of an orderbook contract. It includes
//! trait definitions, error handling, contract storage, events, constructors, L1 handlers, external functions,
//! and internal functions. The primary functionalities include broker whitelisting, order management
//! (creation, cancellation, fulfillment), and order queries.
//! trait definitions, error handling, contract storage, events, constructors, L1 handlers, external
//! functions, and internal functions. The primary functionalities include broker whitelisting,
//! order management (creation, cancellation, fulfillment), and order queries.

use ark_common::protocol::order_types::{FulfillInfo, OrderType, CancelInfo, OrderStatus};
use ark_common::crypto::signer::{SignInfo, Signer, SignerValidator};
Expand Down Expand Up @@ -104,6 +104,7 @@ mod orderbook {
use core::traits::Into;
use super::{orderbook_errors, Orderbook};
use starknet::ContractAddress;
use starknet::storage::Map;
use ark_common::protocol::order_v1::OrderV1;
use ark_common::protocol::order_database::{
order_read, order_status_read, order_write, order_status_write, order_type_read
Expand All @@ -123,13 +124,13 @@ mod orderbook {
admin: ContractAddress,
/// Mapping of broker addresses to their whitelisted status.
/// Represented as felt252, set to 1 if the broker is registered.
brokers: LegacyMap<felt252, felt252>,
brokers: Map<felt252, felt252>,
/// Mapping of token_hash to order_hash.
token_listings: LegacyMap<felt252, felt252>,
token_listings: Map<felt252, felt252>,
/// Mapping of token_hash to auction details (order_hash and end_date, auction_offer_count).
auctions: LegacyMap<felt252, (felt252, u64, u256)>,
auctions: Map<felt252, (felt252, u64, u256)>,
/// Mapping of auction offer order_hash to auction listing order_hash.
auction_offers: LegacyMap<felt252, felt252>,
auction_offers: Map<felt252, felt252>,
/// The address of the StarkNet executor contract.
starknet_executor_address: ContractAddress,
}
Expand Down Expand Up @@ -834,7 +835,8 @@ mod orderbook {
.read(token_hash);

let current_block_timestamp = starknet::get_block_timestamp();
// Determine if the auction end date has passed, indicating that the auction is still ongoing.
// Determine if the auction end date has passed, indicating that the auction is still
// ongoing.
let auction_is_pending = current_block_timestamp < auction_end_date;

if auction_is_pending {
Expand Down
2 changes: 1 addition & 1 deletion contracts/ark_orderbook/tests/common/setup.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use snforge_std::signature::KeyPairTrait;
use snforge_std::signature::stark_curve::{
StarkCurveKeyPairImpl, StarkCurveSignerImpl, StarkCurveVerifierImpl
};
use snforge_std::test_address;

use snforge_std::{start_prank, stop_prank, test_address, CheatTarget};
use starknet::ContractAddress;

/// Utility function to setup orders for test environment.
Expand Down
41 changes: 24 additions & 17 deletions contracts/ark_orderbook/tests/unit/test_orderbook.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ use ark_orderbook::orderbook::{orderbook, orderbook_errors};
use ark_common::protocol::order_v1::OrderV1;
use core::traits::Into;
use core::traits::TryInto;
use snforge_std::cheatcodes::CheatTarget;
use ark_common::crypto::signer::{SignInfo, Signer, SignerValidator};
use ark_common::protocol::order_types::{OrderTrait, RouteType, OrderType, FulfillInfo, OrderStatus};
use ark_common::protocol::order_database::{
order_read, order_status_read, order_status_write, order_type_read
};
use snforge_std::{
start_warp, declare, ContractClassTrait, spy_events, EventSpy, EventFetcher, EventAssertions,
Event, SpyOn, test_address
ContractClassTrait, spy_events, EventSpyAssertionsTrait, test_address, cheat_block_timestamp,
CheatSpan,
};
use array::ArrayTrait;

Expand All @@ -24,7 +23,7 @@ fn test_create_listing() {
let (order_listing_1, order_hash_1, _) = setup_listing_order(600000000000000000);
let contract_address = test_address();
let mut state = orderbook::contract_state_for_testing();
let mut spy = spy_events(SpyOn::One(contract_address));
let mut spy = spy_events();

let _ = orderbook::InternalFunctions::_create_listing_order(
ref state, order_listing_1, OrderType::Listing, order_hash_1
Expand Down Expand Up @@ -102,8 +101,10 @@ fn test_recreate_listing_different_offerer_fulfilled() {
// check is first order is fulfilled

// assert(order_status.unwrap() == OrderStatus::Fulfilled, 'Order not fulfilled');
// create a second order over the first one same ressource hash different price, different owner but the previous order is only fulfilled, to cover the case of user who just bought a token to list it instantly but the order is not yet executed
// we cannot place & cancel a previous order if it's fulfilled
// create a second order over the first one same ressource hash different price, different owner
// but the previous order is only fulfilled, to cover the case of user who just bought a token
// to list it instantly but the order is not yet executed we cannot place & cancel a previous
// order if it's fulfilled
let (mut order_listing_2, order_hash_2, _) = setup_listing_order(500000000000000000);
order_listing_2
.offerer = 0x2484a6517b487be8114013f277f9e2010ac001a24a93e3c48cdf5f8f345a81b
Expand All @@ -128,8 +129,10 @@ fn test_recreate_listing_same_offerer_fulfilled() {
// check is first order is fulfilled
let order_status = order_status_read(order_hash_1);
assert(order_status.unwrap() == OrderStatus::Fulfilled, 'Order not fulfilled');
// create a second order over the first one same ressource hash different price, different owner but the previous order is only fulfilled, to cover the case of user who just bought a token to list it instantly but the order is not yet executed
// we cannot place & cancel a previous order if it's fulfilled
// create a second order over the first one same ressource hash different price, different owner
// but the previous order is only fulfilled, to cover the case of user who just bought a token
// to list it instantly but the order is not yet executed we cannot place & cancel a previous
// order if it's fulfilled
let (mut order_listing_2, order_hash_2, _) = setup_listing_order(500000000000000000);
let _ = orderbook::InternalFunctions::_create_listing_order(
ref state, order_listing_2, OrderType::Listing, order_hash_2
Expand All @@ -145,7 +148,8 @@ fn test_recreate_listing_new_owner() {
ref state, order_listing_1, OrderType::Listing, order_hash_1
);

// create a second order over the first one same ressource hash different price, different owner it should work and cancel the previous one
// create a second order over the first one same ressource hash different price, different owner
// it should work and cancel the previous one
let (mut order_listing_2, order_hash_2, _) = setup_listing_order(500000000000000000);
order_listing_2
.offerer = 0x2584a6517b487be8114013f277f9e2010ac001a24a93e3c48cdf5f8f345a823
Expand Down Expand Up @@ -180,7 +184,8 @@ fn test_recreate_listing_same_owner_old_order_expired() {
let _ = orderbook::InternalFunctions::_create_listing_order(
ref state, order_listing_1, OrderType::Listing, order_hash_1
);
// create a second order over the first one same ressource hash different price, different owner it should work and cancel the previous one
// create a second order over the first one same ressource hash different price, different owner
// it should work and cancel the previous one
let (order_listing_2, order_hash_2, _) = setup_listing_order(500000000000000000);

let _ = orderbook::InternalFunctions::_create_listing_order(
Expand Down Expand Up @@ -211,7 +216,7 @@ fn test_create_offer() {

let contract_address = test_address();
let mut state = orderbook::contract_state_for_testing();
let mut spy = spy_events(SpyOn::One(contract_address));
let mut spy = spy_events();

orderbook::InternalFunctions::_create_offer(
ref state, offer_order, OrderType::Offer, order_hash
Expand Down Expand Up @@ -244,7 +249,7 @@ fn test_create_offer() {
#[test]
fn test_create_collection_offer() {
let contract_address = test_address();
let mut spy = spy_events(SpyOn::One(contract_address));
let mut spy = spy_events();

let mut offer_order = get_offer_order();
offer_order.token_id = Option::None;
Expand Down Expand Up @@ -346,10 +351,10 @@ fn test_fulfill_classic_token_offer() {
let fulfill_broker_address = test_address();
let mut state = orderbook::contract_state_for_testing();

let mut spy = spy_events(SpyOn::One(contract_address));
let mut spy = spy_events();
let order_hash = order_listing.compute_order_hash();

start_warp(CheatTarget::One(contract_address), order_listing.start_date);
cheat_block_timestamp(contract_address, order_listing.start_date, CheatSpan::TargetCalls(1));

let fulfill_info = FulfillInfo {
order_hash,
Expand Down Expand Up @@ -384,14 +389,14 @@ fn test_fulfill_classic_token_offer() {
fn test_fulfill_classic_collection_offer() {
let (order_listing, mut order_offer, _, _) = setup_orders();
let contract_address = test_address();
let mut spy = spy_events(SpyOn::One(contract_address));
let mut spy = spy_events();
let mut state = orderbook::contract_state_for_testing();

order_offer.token_id = Option::None;
order_offer.start_date = order_listing.start_date + 100;
order_offer.end_date = order_listing.start_date + 100;

start_warp(CheatTarget::One(contract_address), order_offer.start_date);
cheat_block_timestamp(contract_address, order_listing.start_date, CheatSpan::TargetCalls(1));

let fulfill_info = FulfillInfo {
order_hash: order_listing.compute_order_hash(),
Expand Down Expand Up @@ -430,7 +435,9 @@ fn test_fulfill_expired_offer() {
let fulfill_broker_address = test_address();
let mut state = orderbook::contract_state_for_testing();

start_warp(CheatTarget::One(contract_address), order_listing.end_date + 3600); // +1 hour
cheat_block_timestamp(
contract_address, order_listing.end_date + 3600, CheatSpan::TargetCalls(1)
); // +1 hour

let fulfill_info = FulfillInfo {
order_hash: order_listing.compute_order_hash(),
Expand Down
Loading
Loading