Skip to content

Commit

Permalink
remove inlines
Browse files Browse the repository at this point in the history
  • Loading branch information
sparqet committed Nov 2, 2023
1 parent 282539e commit 146b977
Show file tree
Hide file tree
Showing 19 changed files with 4 additions and 83 deletions.
2 changes: 0 additions & 2 deletions src/deposit/execute_deposit_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ fn execute_deposit(params: ExecuteDepositParams) {
/// # Arguments
/// * `params` - @ExecuteDepositParams.
/// * `_params` - @_ExecuteDepositParams.
#[inline(always)]
fn execute_deposit_helper(
params: @ExecuteDepositParams, ref _params: _ExecuteDepositParams
) -> u128 {
Expand Down Expand Up @@ -460,7 +459,6 @@ fn execute_deposit_helper(
mint_amount
}

#[inline(always)]
fn swap(
params: @ExecuteDepositParams,
swap_path: Span32<ContractAddress>,
Expand Down
14 changes: 0 additions & 14 deletions src/event/event_emitter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `DepositCreated` event.
#[inline(always)]
fn emit_deposit_created(ref self: TContractState, key: felt252, deposit: Deposit);

/// Emits the `DepositExecuted` event.
Expand All @@ -140,7 +139,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `WithdrawalCreated` event.
#[inline(always)]
fn emit_withdrawal_created(ref self: TContractState, key: felt252, withdrawal: Withdrawal);

/// Emits the `WithdrawalExecuted` event.
Expand All @@ -152,11 +150,9 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `PositionIncrease` event.
#[inline(always)]
fn emit_position_increase(ref self: TContractState, params: PositionIncreaseParams);

/// Emits the `PositionDecrease` event.
#[inline(always)]
fn emit_position_decrease(
ref self: TContractState,
order_key: felt252,
Expand Down Expand Up @@ -190,7 +186,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `PositionFeesCollected` event.
#[inline(always)]
fn emit_position_fees_collected(
ref self: TContractState,
order_key: felt252,
Expand All @@ -203,7 +198,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `PositionFeesInfo` event.
#[inline(always)]
fn emit_position_fees_info(
ref self: TContractState,
order_key: felt252,
Expand All @@ -216,7 +210,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `OrderCreated` event.
#[inline(always)]
fn emit_order_created(ref self: TContractState, key: felt252, order: Order);

/// Emits the `OrderExecuted` event.
Expand Down Expand Up @@ -434,7 +427,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `MarketPoolValueInfo` event.
#[inline(always)]
fn emit_market_pool_value_info(
ref self: TContractState,
market: ContractAddress,
Expand Down Expand Up @@ -592,7 +584,6 @@ trait IEventEmitter<TContractState> {
);

/// Emits the `SwapFeesCollected` event.
#[inline(always)]
fn emit_swap_fees_collected(
ref self: TContractState,
market: ContractAddress,
Expand Down Expand Up @@ -1700,7 +1691,6 @@ mod EventEmitter {
}

/// Emits the `DepositCreated` event.
#[inline(always)]
fn emit_deposit_created(ref self: ContractState, key: felt252, deposit: Deposit) {
self
.emit(
Expand Down Expand Up @@ -1782,7 +1772,6 @@ mod EventEmitter {
/// Emits the `PositionIncrease` event.
/// # Arguments
/// * `params` - The position increase parameters.
#[inline(always)]
fn emit_position_increase(ref self: ContractState, params: PositionIncreaseParams) {
self
.emit(
Expand Down Expand Up @@ -1830,7 +1819,6 @@ mod EventEmitter {
/// * `values` - The parameters linked to the decrease of collateral.
/// * `index_token_price` - The price of the index token.
/// * `collateral_token_price` - The price of the collateral token.
#[inline(always)]
fn emit_position_decrease(
ref self: ContractState,
order_key: felt252,
Expand Down Expand Up @@ -2427,7 +2415,6 @@ mod EventEmitter {
}

/// Emits the `MarketPoolValueInfo` event.
#[inline(always)]
fn emit_market_pool_value_info(
ref self: ContractState,
market: ContractAddress,
Expand Down Expand Up @@ -2680,7 +2667,6 @@ mod EventEmitter {
}

/// Emits the `SwapFeesCollected` event.
#[inline(always)]
fn emit_swap_fees_collected(
ref self: ContractState,
market: ContractAddress,
Expand Down
6 changes: 0 additions & 6 deletions src/event/event_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,37 @@ use alexandria_data_structures::array_ext::SpanTraitExt;
//

impl Felt252IntoBool of Into<felt252, bool> {
#[inline(always)]
fn into(self: felt252) -> bool {
let as_u128: u128 = self.try_into().expect('u128 Overflow');
as_u128 > 0
}
}

impl Felt252IntoU128 of Into<felt252, u128> {
#[inline(always)]
fn into(self: felt252) -> u128 {
self.try_into().expect('u128 Overflow')
}
}

impl Felt252IntoI128 of Into<felt252, i128> {
#[inline(always)]
fn into(self: felt252) -> i128 {
self.try_into().expect('i128 Overflow')
}
}

impl Felt252IntoContractAddress of Into<felt252, ContractAddress> {
#[inline(always)]
fn into(self: felt252) -> ContractAddress {
Felt252TryIntoContractAddress::try_into(self).expect('contractaddress overflow')
}
}

impl I128252DictValue of Felt252DictValue<i128> {
#[inline(always)]
fn zero_default() -> i128 nopanic {
i128 { mag: 0, sign: false }
}
}

impl ContractAddressDictValue of Felt252DictValue<ContractAddress> {
#[inline(always)]
fn zero_default() -> ContractAddress nopanic {
contract_address_const::<0>()
}
Expand Down
3 changes: 0 additions & 3 deletions src/oracle/oracle_modules.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use satoru::oracle::error::OracleError;
/// * `dataStore` - `DataStore` contract dispatcher
/// * `eventEmitter` - `EventEmitter` contract dispatcher
/// * `params` - parameters used to set oracle price
#[inline(always)]
fn with_oracle_prices_before(
oracle: IOracleDispatcher,
data_store: IDataStoreDispatcher,
Expand All @@ -39,7 +38,6 @@ fn with_oracle_prices_before(
oracle.set_prices(data_store, event_emitter, params.clone());
}

#[inline(always)]
fn with_oracle_prices_after(oracle: IOracleDispatcher) {
oracle.clear_all_prices();
}
Expand Down Expand Up @@ -73,7 +71,6 @@ fn with_simulated_oracle_prices_before(oracle: IOracleDispatcher, params: Simula
};
}

#[inline(always)]
fn with_simulated_oracle_prices_after() {
OracleError::END_OF_ORACLE_SIMULATION();
}
10 changes: 0 additions & 10 deletions src/order/base_order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ struct GetExecutionPriceCache {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is a market order
#[inline(always)]
fn is_market_order(order_type: OrderType) -> bool {
// a liquidation order is not considered as a market order
order_type == OrderType::MarketSwap
Expand All @@ -157,7 +156,6 @@ fn is_market_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is a limit order
#[inline(always)]
fn is_limit_order(order_type: OrderType) -> bool {
order_type == OrderType::LimitSwap
|| order_type == OrderType::LimitIncrease
Expand All @@ -169,7 +167,6 @@ fn is_limit_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is a swap order
#[inline(always)]
fn is_swap_order(order_type: OrderType) -> bool {
order_type == OrderType::MarketSwap || order_type == OrderType::LimitSwap
}
Expand All @@ -179,7 +176,6 @@ fn is_swap_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is a position order
#[inline(always)]
fn is_position_order(order_type: OrderType) -> bool {
is_increase_order(order_type) || is_decrease_order(order_type)
}
Expand All @@ -189,7 +185,6 @@ fn is_position_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is an increase order
#[inline(always)]
fn is_increase_order(order_type: OrderType) -> bool {
order_type == OrderType::MarketIncrease || order_type == OrderType::LimitIncrease
}
Expand All @@ -199,7 +194,6 @@ fn is_increase_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is a decrease order
#[inline(always)]
fn is_decrease_order(order_type: OrderType) -> bool {
order_type == OrderType::MarketDecrease
|| order_type == OrderType::LimitDecrease
Expand All @@ -212,7 +206,6 @@ fn is_decrease_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// # Return
/// Return whether an order_type is a liquidation order
#[inline(always)]
fn is_liquidation_order(order_type: OrderType) -> bool {
order_type == OrderType::Liquidation
}
Expand All @@ -227,7 +220,6 @@ fn is_liquidation_order(order_type: OrderType) -> bool {
/// * `order_type` - The order type.
/// * `trigger_price` - the order's trigger_price.
/// * `is_long` - Whether the order is for a long or short.
#[inline(always)]
fn validate_order_trigger_price(
oracle: IOracleDispatcher,
index_token: ContractAddress,
Expand Down Expand Up @@ -345,7 +337,6 @@ fn get_execution_price_for_increase(
0 // doesn't compile otherwise
}

#[inline(always)]
fn get_execution_price_for_decrease(
index_token_price: Price,
position_size_in_usd: u128,
Expand Down Expand Up @@ -480,7 +471,6 @@ fn get_execution_price_for_decrease(
/// Validates that an order exists.
/// # Arguments
/// * `order` - The order to check.
#[inline(always)]
fn validate_non_empty_order(order: @Order) {
assert((*order.account).is_non_zero(), OrderError::EMPTY_ORDER);
assert(
Expand Down
3 changes: 0 additions & 3 deletions src/order/decrease_order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use satoru::swap::swap_handler::{ISwapHandlerDispatcher, ISwapHandlerDispatcherT

// This function should return an EventLogData cause the callback_utils
// needs it. We need to find a solution for that case.
#[inline(always)]
fn process_order(
params: ExecuteOrderParams
) -> LogData { //TODO check with refactor with callback_utils
Expand Down Expand Up @@ -136,7 +135,6 @@ fn process_order(
/// * `order_updated_at_block` - The block at which the order was last updated.
/// * `position_increased_at_block` - The block at which the position was last increased.
/// * `position_decrease_at_block` - The block at which the position was last decreased.
#[inline(always)]
fn validate_oracle_block_numbers(
min_oracle_block_numbers: Span<u64>,
max_oracle_block_numbers: Span<u64>,
Expand Down Expand Up @@ -216,7 +214,6 @@ fn validate_output_amount_secondary(
}
}

#[inline(always)]
fn handle_swap_error(
oracle: IOracleDispatcher,
order: Order,
Expand Down
1 change: 0 additions & 1 deletion src/order/increase_order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use alexandria_data_structures::array_ext::SpanTraitExt;
/// * `EventLogData` - The event log data.
/// This function should return an EventLogData cause the callback_utils
/// needs it. We need to find a solution for that case.
#[inline(always)]
fn process_order(params: ExecuteOrderParams) -> event_utils::LogData {
market_utils::validate_position_market(params.contracts.data_store, params.market.market_token);

Expand Down
1 change: 0 additions & 1 deletion src/order/order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ fn create_order( //TODO and fix when fee_token is implememted
/// Executes an order.
/// # Arguments
/// * `params` - The parameters used to execute the order.
#[inline(always)]
fn execute_order(params: ExecuteOrderParams) {
// 63/64 gas is forwarded to external calls, reduce the startingGas to account for this
// TODO GAS NOT AVAILABLE params.startingGas -= gasleft() / 63;
Expand Down
2 changes: 0 additions & 2 deletions src/order/swap_order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use satoru::bank::bank::{IBankDispatcher, IBankDispatcherTrait};
use satoru::utils::span32::{Span32, DefaultSpan32};
use satoru::oracle::error::OracleError;

#[inline(always)]
fn process_order(params: ExecuteOrderParams) -> LogData {
if (params.order.market.is_non_zero()) {
panic(array![OrderError::UNEXPECTED_MARKET]);
Expand Down Expand Up @@ -63,7 +62,6 @@ fn process_order(params: ExecuteOrderParams) -> LogData {
/// * `max_oracle_block_numbers` - The max oracle block numbers.
/// * `order_type` - The order type.
/// * `order_updated_at_block` - the block at which the order was last updated.
#[inline(always)]
fn validate_oracle_block_numbers(
min_oracle_block_numbers: Span<u64>,
max_oracle_block_numbers: Span<u64>,
Expand Down
1 change: 0 additions & 1 deletion src/position/decrease_position_collateral_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ struct GetExecutionPriceCache {
/// Handle the collateral changes of the position.
/// # Returns
/// The values linked to the process of a decrease of collateral and position fees.
#[inline(always)]
fn process_collateral(
mut params: position_utils::UpdatePositionParams, cache: position_utils::DecreasePositionCache
) -> (position_utils::DecreasePositionCollateralValues, position_pricing_utils::PositionFees) {
Expand Down
1 change: 0 additions & 1 deletion src/position/decrease_position_swap_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ fn swap_withdrawn_collateral_to_pnl_token(
/// * `pnl_amount` - The amount of profit in usd.
/// # Returns
/// DecreasePositionCollateralValues
#[inline(always)]
fn swap_profit_to_collateral_token(
params: UpdatePositionParams, pnl_token: ContractAddress, profit_amount: u128
) -> (bool, u128) {
Expand Down
2 changes: 0 additions & 2 deletions src/price/price.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ impl PriceZeroable of Zeroable<Price> {
fn zero() -> Price {
Price { min: 0, max: 0 }
}
#[inline(always)]
fn is_zero(self: Price) -> bool {
self.min == 0 && self.max == 0
}
#[inline(always)]
fn is_non_zero(self: Price) -> bool {
!self.is_zero()
}
Expand Down
1 change: 0 additions & 1 deletion src/referral/referral_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use satoru::referral::referral_tier::ReferralTier;
/// * `referral_storage` - The referral storage instance to use.
/// * `account` - The account of the trader.
/// * `referral_code` - The referral code.
#[inline(always)]
fn set_trader_referral_code(
referral_storage: IReferralStorageDispatcher, account: ContractAddress, referral_code: felt252
) {
Expand Down
2 changes: 0 additions & 2 deletions src/role/role_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ mod RoleStore {
// *************************************************************************
#[generate_trait]
impl InternalFunctions of InternalFunctionsTrait {
#[inline(always)]
fn _has_role(self: @ContractState, account: ContractAddress, role_key: felt252) -> bool {
self.has_role.read((role_key, account))
}

#[inline(always)]
fn _assert_only_role(self: @ContractState, account: ContractAddress, role_key: felt252) {
assert(self._has_role(account, role_key), RoleError::UNAUTHORIZED_ACCESS);
}
Expand Down
Loading

0 comments on commit 146b977

Please sign in to comment.