Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JoE11-y committed Oct 8, 2024
1 parent 67f86f3 commit b4a5fd7
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 192 deletions.
14 changes: 7 additions & 7 deletions contracts/ark_common/src/protocol/order_types.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl Felt252TryIntoOrderType of TryInto<felt252, OrderType> {
Option::Some(OrderType::Offer)
} else if self == 'COLLECTION_OFFER' {
Option::Some(OrderType::CollectionOffer)
} else if self == 'LIMIT_BUY'{
} else if self == 'LIMIT_BUY' {
Option::Some(OrderType::LimitBuy)
}else if self == 'LIMIT_SELL'{
} else if self == 'LIMIT_SELL' {
Option::Some(OrderType::LimitSell)
} else {
Option::None
Expand Down Expand Up @@ -292,9 +292,9 @@ impl Felt252TryIntoRoute of TryInto<felt252, RouteType> {
Option::Some(RouteType::Erc20ToErc721)
} else if self == 'ERC721TOERC20' {
Option::Some(RouteType::Erc721ToErc20)
} else if self == 'ERC20TOERC20BUY'{
} else if self == 'ERC20TOERC20BUY' {
Option::Some(RouteType::Erc20ToErc20Buy)
} else if self == 'ERC20TOERC20SELL'{
} else if self == 'ERC20TOERC20SELL' {
Option::Some(RouteType::Erc20ToErc20Sell)
} else {
Option::None
Expand All @@ -304,8 +304,8 @@ impl Felt252TryIntoRoute of TryInto<felt252, RouteType> {

#[derive(starknet::Store, Serde, Drop, PartialEq, Copy, Debug)]
struct OptionU256 {
is_some: felt252,
value: u256,
is_some: felt252,
value: u256,
}

trait OptionU256Trait<T, +Serde<T>, +Drop<T>> {
Expand All @@ -319,7 +319,7 @@ impl OptionU256Impl of OptionU256Trait<OptionU256> {
}
fn is_some(self: @OptionU256) -> bool {
if *self.is_some == 1 {
true
true
} else {
false
}
Expand Down
34 changes: 18 additions & 16 deletions contracts/ark_common/src/protocol/order_v1.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ impl OrderTraitOrderV1 of OrderTrait<OrderV1> {
}

// check for expiry only if not erc20 buys or sells
if (*self.route != RouteType::Erc20ToErc20Buy && *self.route != RouteType::Erc20ToErc20Sell) {
if (*self.route != RouteType::Erc20ToErc20Buy
&& *self.route != RouteType::Erc20ToErc20Sell) {
let end_date = *self.end_date;

if end_date < block_timestamp {
return Result::Err(OrderValidationError::EndDateInThePast);
}

// End date -> block_timestamp + 30 days.
let max_end_date = block_timestamp + (30 * 24 * 60 * 60);
if end_date > max_end_date {
Expand All @@ -79,12 +80,12 @@ impl OrderTraitOrderV1 of OrderTrait<OrderV1> {
}

// check that the start amount is not zero for sell erc20 orders
if(*self.route != RouteType::Erc20ToErc20Sell){
if (*self.start_amount).is_zero(){
if (*self.route != RouteType::Erc20ToErc20Sell) {
if (*self.start_amount).is_zero() {
return Result::Err(OrderValidationError::InvalidContent);
}
}else{
if (*self.end_amount).is_zero(){
} else {
if (*self.end_amount).is_zero() {
return Result::Err(OrderValidationError::InvalidContent);
}
}
Expand All @@ -98,9 +99,9 @@ impl OrderTraitOrderV1 of OrderTrait<OrderV1> {
}

if (*self.offerer).is_zero()
|| (*self.token_address).is_zero()
|| (*self.salt).is_zero()
|| (*self.quantity).is_zero() {
|| (*self.token_address).is_zero()
|| (*self.salt).is_zero()
|| (*self.quantity).is_zero() {
return Result::Err(OrderValidationError::InvalidContent);
}

Expand Down Expand Up @@ -135,16 +136,16 @@ impl OrderTraitOrderV1 of OrderTrait<OrderV1> {
return Result::Ok(OrderType::CollectionOffer);
}

// Limit Buy Order
if(*self.quantity) > 0
// Limit Buy Order
if (*self.quantity) > 0
&& (*self.start_amount) > 0 // amount to pay
&& (*self.end_amount).is_zero()
&& (*self.route == RouteType::Erc20ToErc20Buy) {
return Result::Ok(OrderType::LimitBuy);
}

// Limit Sell Order
if(*self.quantity) > 0
// Limit Sell Order
if (*self.quantity) > 0
&& (*self.start_amount).is_zero()
&& (*self.end_amount) > 0 // amount to receive
&& (*self.route == RouteType::Erc20ToErc20Sell) {
Expand All @@ -161,13 +162,14 @@ impl OrderTraitOrderV1 of OrderTrait<OrderV1> {
}

fn compute_token_hash(self: @OrderV1) -> felt252 {
if (*self.route == RouteType::Erc20ToErc20Buy || *self.route == RouteType::Erc20ToErc20Sell) {
if (*self.route == RouteType::Erc20ToErc20Buy
|| *self.route == RouteType::Erc20ToErc20Sell) {
let mut buf: Array<felt252> = array![];
// used quantity, start_date and the offerer as the identifiers
buf.append((*self.token_address).into());
buf.append(*self.token_chain_id);
poseidon_hash_span(buf.span())
}else{
} else {
assert(OptionTrait::is_some(self.token_id), 'Token ID expected');
let token_id = (*self.token_id).unwrap();
let mut buf: Array<felt252> = array![];
Expand All @@ -184,4 +186,4 @@ impl OrderTraitOrderV1 of OrderTrait<OrderV1> {
self.serialize(ref buf);
poseidon_hash_span(buf.span())
}
}
}
Loading

0 comments on commit b4a5fd7

Please sign in to comment.