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/deployer v2 #442

Closed
wants to merge 17 commits into from
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
2 changes: 1 addition & 1 deletion contracts/ark_component/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ snforge_std.workspace = true
assert_macros.workspace = true

[scripts]
test.workspace = true


[tool]
fmt.workspace = true
Expand Down
106 changes: 40 additions & 66 deletions contracts/ark_component/src/orderbook/orderbook.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ pub mod OrderbookComponent {
OrderFulfilled: OrderFulfilled,
}

// must be increased when `OrderPlaced` content change
const ORDER_PLACED_EVENT_VERSION: u8 = 1;
/// Event for when an order is placed.
#[derive(Drop, starknet::Event)]
struct OrderPlaced {
Expand All @@ -61,63 +59,45 @@ pub mod OrderbookComponent {
order_version: felt252,
#[key]
order_type: OrderType,
///
version: u8,
// The order that was cancelled by this order.
cancelled_order_hash: Option<felt252>,
// The full order serialized.
order: OrderV1,
}

// must be increased when `OrderExecuted` content change
const ORDER_EXECUTED_EVENT_VERSION: u8 = 2;
const ORDER_EXECUTED_EVENT_VERSION: u8 = 1;
/// Event for when an order is executed.
#[derive(Drop, starknet::Event)]
struct OrderExecuted {
#[key]
order_hash: felt252,
#[key]
order_status: OrderStatus,
#[key]
order_type: OrderType,
///
version: u8,
transaction_hash: felt252,
from: ContractAddress,
to: ContractAddress,
}

// must be increased when `OrderPlaced` content change
const ORDER_CANCELLED_EVENT_VERSION: u8 = 1;
/// Event for when an order is cancelled.
#[derive(Drop, starknet::Event)]
struct OrderCancelled {
#[key]
order_hash: felt252,
#[key]
reason: felt252,
#[key]
order_type: OrderType,
version: u8,
}

// must be increased when `RollbackStatus` content change
const ROLLBACK_STATUS_EVENT_VERSION: u8 = 1;
/// Event for when an order has been rollbacked to placed.
#[derive(Drop, starknet::Event)]
struct RollbackStatus {
#[key]
order_hash: felt252,
#[key]
reason: felt252,
#[key]
order_type: OrderType,
///
version: u8,
reason: felt252
}

// must be increased when `OrderFulfilled` content change
const ORDER_FULFILLED_EVENT_VERSION: u8 = 1;
/// Event for when an order is fulfilled.
#[derive(Drop, starknet::Event)]
struct OrderFulfilled {
Expand All @@ -127,10 +107,6 @@ pub mod OrderbookComponent {
fulfiller: ContractAddress,
#[key]
related_order_hash: Option<felt252>,
#[key]
order_type: OrderType,
///
version: u8,
}

pub trait OrderbookHooksCreateOrderTrait<TContractState> {
Expand Down Expand Up @@ -236,13 +212,11 @@ pub mod OrderbookComponent {
HooksValidateOrder::before_validate_order_execution(ref self, info);
order_status_write(info.order_hash, OrderStatus::Executed);
let order_status = order_status_read(info.order_hash).unwrap();
let order_type = order_type_read(info.order_hash).unwrap();
self
.emit(
OrderExecuted {
order_hash: info.order_hash,
order_status,
order_type,
order_status: order_status,
transaction_hash: info.transaction_hash,
from: info.from,
to: info.to,
Expand Down Expand Up @@ -302,7 +276,7 @@ pub mod OrderbookComponent {
Option::None => panic_with_felt252(orderbook_errors::ORDER_NOT_FOUND),
};
let block_ts = starknet::get_block_timestamp();
let order_type = match order_type_read(order_hash) {
match order_type_read(order_hash) {
Option::Some(order_type) => {
if order_type == OrderType::Auction {
let auction_token_hash = order.compute_token_hash();
Expand All @@ -317,22 +291,13 @@ pub mod OrderbookComponent {
self.token_listings.write(order.compute_token_hash(), 0);
}
}
order_type
},
Option::None => panic_with_felt252(orderbook_errors::ORDER_NOT_FOUND),
};

// Cancel order
order_status_write(order_hash, OrderStatus::CancelledUser);
self
.emit(
OrderCancelled {
order_hash,
reason: OrderStatus::CancelledUser.into(),
order_type,
version: ORDER_CANCELLED_EVENT_VERSION,
}
);
self.emit(OrderCancelled { order_hash, reason: OrderStatus::CancelledUser.into() });

HooksCancelOrder::after_cancel_order(ref self, cancel_info);
}
Expand All @@ -356,24 +321,13 @@ pub mod OrderbookComponent {
Option::Some(s) => s,
Option::None => panic_with_felt252(orderbook_errors::ORDER_NOT_FOUND),
};
let (execution_info, related_order_hash) = match order_type {
let execution_info = match order_type {
OrderType::Listing => self._fulfill_listing_order(fulfill_info, order),
OrderType::Auction => self._fulfill_auction_order(fulfill_info, order),
OrderType::Offer => self._fulfill_offer(fulfill_info, order),
OrderType::CollectionOffer => self._fulfill_offer(fulfill_info, order),
};

self
.emit(
OrderFulfilled {
order_hash: fulfill_info.order_hash,
fulfiller: fulfill_info.fulfiller,
related_order_hash,
order_type,
version: ORDER_FULFILLED_EVENT_VERSION,
}
);

HooksFulfillOrder::after_fulfill_order(ref self, fulfill_info);
execution_info
}
Expand All @@ -394,7 +348,7 @@ pub mod OrderbookComponent {
///
fn _fulfill_auction_order(
ref self: ComponentState<TContractState>, fulfill_info: FulfillInfo, order: OrderV1
) -> (Option<ExecutionInfo>, Option<felt252>) {
) -> Option<ExecutionInfo> {
let block_timestamp = starknet::get_block_timestamp();
assert(
order.offerer == fulfill_info.fulfiller, orderbook_errors::ORDER_NOT_SAME_OFFERER
Expand Down Expand Up @@ -455,6 +409,14 @@ pub mod OrderbookComponent {

order_status_write(related_order_hash, OrderStatus::Fulfilled);
order_status_write(fulfill_info.order_hash, OrderStatus::Fulfilled);
self
.emit(
OrderFulfilled {
order_hash: fulfill_info.order_hash,
fulfiller: fulfill_info.fulfiller,
related_order_hash: Option::Some(related_order_hash)
}
);

if order.token_id.is_some() {
let execute_info = ExecutionInfo {
Expand All @@ -471,9 +433,9 @@ pub mod OrderbookComponent {
listing_broker_address: order.broker_id,
fulfill_broker_address: fulfill_info.fulfill_broker_address
};
(Option::Some(execute_info), Option::Some(related_order_hash))
Option::Some(execute_info)
} else {
(Option::None, Option::Some(related_order_hash))
Option::None
}
}

Expand All @@ -485,7 +447,7 @@ pub mod OrderbookComponent {
///
fn _fulfill_offer(
ref self: ComponentState<TContractState>, fulfill_info: FulfillInfo, order: OrderV1
) -> (Option<ExecutionInfo>, Option<felt252>) {
) -> Option<ExecutionInfo> {
if order.token_id.is_some() {
let (auction_order_hash, _, _) = self.auctions.read(order.compute_token_hash());

Expand All @@ -496,13 +458,21 @@ pub mod OrderbookComponent {

let current_date = starknet::get_block_timestamp();
assert(order.end_date > current_date, orderbook_errors::ORDER_EXPIRED);

order_status_write(fulfill_info.order_hash, OrderStatus::Fulfilled);
self
.emit(
OrderFulfilled {
order_hash: fulfill_info.order_hash,
fulfiller: fulfill_info.fulfiller,
related_order_hash: Option::None
}
);

if order.token_id.is_some() {
// remove token from listed tokens
self.token_listings.write(order.compute_token_hash(), 0);
}

let execute_info = ExecutionInfo {
order_hash: order.compute_order_hash(),
nft_address: order.token_address,
Expand All @@ -517,7 +487,7 @@ pub mod OrderbookComponent {
listing_broker_address: order.broker_id,
fulfill_broker_address: fulfill_info.fulfill_broker_address
};
(Option::Some(execute_info), Option::None)
Option::Some(execute_info)
}

/// Fulfill listing order
Expand All @@ -528,12 +498,20 @@ pub mod OrderbookComponent {
///
fn _fulfill_listing_order(
ref self: ComponentState<TContractState>, fulfill_info: FulfillInfo, order: OrderV1
) -> (Option<ExecutionInfo>, Option<felt252>) {
) -> Option<ExecutionInfo> {
assert(order.offerer != fulfill_info.fulfiller, orderbook_errors::ORDER_SAME_OFFERER);
assert(
order.end_date > starknet::get_block_timestamp(), orderbook_errors::ORDER_EXPIRED
);
order_status_write(fulfill_info.order_hash, OrderStatus::Fulfilled);
self
.emit(
OrderFulfilled {
order_hash: fulfill_info.order_hash,
fulfiller: fulfill_info.fulfiller,
related_order_hash: Option::None
}
);

if order.token_id.is_some() {
let execute_info = ExecutionInfo {
Expand All @@ -550,9 +528,9 @@ pub mod OrderbookComponent {
listing_broker_address: order.broker_id,
fulfill_broker_address: fulfill_info.fulfill_broker_address
};
(Option::Some(execute_info), Option::None)
Option::Some(execute_info)
} else {
(Option::None, Option::None)
Option::None
}
}

Expand Down Expand Up @@ -678,7 +656,6 @@ pub mod OrderbookComponent {
order_hash: order_hash,
order_version: order.get_version(),
order_type: order_type,
version: ORDER_PLACED_EVENT_VERSION,
cancelled_order_hash,
order: order
}
Expand Down Expand Up @@ -722,7 +699,6 @@ pub mod OrderbookComponent {
order_hash: order_hash,
order_version: order.get_version(),
order_type: order_type,
version: ORDER_PLACED_EVENT_VERSION,
cancelled_order_hash,
order: order,
}
Expand Down Expand Up @@ -786,7 +762,6 @@ pub mod OrderbookComponent {
order_hash: order_hash,
order_version: order.get_version(),
order_type: order_type,
version: ORDER_PLACED_EVENT_VERSION,
cancelled_order_hash: Option::None,
order: order,
}
Expand All @@ -806,8 +781,7 @@ pub mod OrderbookComponent {
OrderPlaced {
order_hash: order_hash,
order_version: order.get_version(),
order_type,
version: ORDER_PLACED_EVENT_VERSION,
order_type: order_type,
cancelled_order_hash: Option::None,
order: order,
}
Expand Down
9 changes: 3 additions & 6 deletions contracts/ark_orderbook/src/orderbook.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ mod orderbook {
fn _fulfill_auction_order(
ref self: ContractState, fulfill_info: FulfillInfo, order: OrderV1
) {
let (execute_info, _) = self.orderbook._fulfill_auction_order(fulfill_info, order);
match execute_info {
match self.orderbook._fulfill_auction_order(fulfill_info, order) {
Option::Some(execute_info) => {
let execute_order_selector = selector!("execute_order");
let starknet_executor_address: ContractAddress = self
Expand All @@ -221,8 +220,7 @@ mod orderbook {
/// * `order` - The order.
///
fn _fulfill_offer(ref self: ContractState, fulfill_info: FulfillInfo, order: OrderV1) {
let (execute_info, _) = self.orderbook._fulfill_offer(fulfill_info, order);
match execute_info {
match self.orderbook._fulfill_offer(fulfill_info, order) {
Option::Some(execute_info) => {
let execute_order_selector = selector!("execute_order");
let starknet_executor_address: ContractAddress = self
Expand All @@ -248,8 +246,7 @@ mod orderbook {
fn _fulfill_listing_order(
ref self: ContractState, fulfill_info: FulfillInfo, order: OrderV1
) {
let (execute_info, _) = self.orderbook._fulfill_listing_order(fulfill_info, order);
match execute_info {
match self.orderbook._fulfill_listing_order(fulfill_info, order) {
Option::Some(execute_info) => {
let execute_order_selector = selector!("execute_order");
let starknet_executor_address: ContractAddress = self
Expand Down
Loading
Loading