Skip to content

Commit

Permalink
feat: use library calls
Browse files Browse the repository at this point in the history
  • Loading branch information
zarboq committed May 14, 2024
1 parent c092116 commit 1144bb6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
22 changes: 12 additions & 10 deletions src/exchange/base_order_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// Core lib imports.
use core::traits::Into;
use starknet::{ContractAddress, contract_address_const};
use starknet::{ContractAddress, contract_address_const, ClassHash};

use satoru::oracle::oracle_utils::SetPricesParams;
use satoru::order::{order::SecondaryOrderType, base_order_utils::ExecuteOrderParams};
Expand Down Expand Up @@ -34,7 +34,7 @@ trait IBaseOrderHandler<TContractState> {
oracle_address: ContractAddress,
swap_handler_address: ContractAddress,
referral_storage_address: ContractAddress,
order_utils_address: ContractAddress
order_utils_class_hash: ClassHash
);
}

Expand All @@ -48,7 +48,7 @@ mod BaseOrderHandler {
use core::option::OptionTrait;
use core::zeroable::Zeroable;
use core::traits::Into;
use starknet::{get_caller_address, ContractAddress, contract_address_const};
use starknet::{get_caller_address, ContractAddress, contract_address_const, ClassHash};

use result::ResultTrait;

Expand All @@ -70,7 +70,7 @@ mod BaseOrderHandler {
error::OrderError, order::{SecondaryOrderType, OrderType, Order, DecreasePositionSwapType},
order_vault::{IOrderVaultDispatcher, IOrderVaultDispatcherTrait},
base_order_utils::{ExecuteOrderParams, ExecuteOrderParamsContracts},
order_utils::{IOrderUtilsDispatcher, IOrderUtilsDispatcherTrait}
order_utils::IOrderUtilsLibraryDispatcher
};
use satoru::swap::swap_handler::{ISwapHandlerDispatcher, ISwapHandlerDispatcherTrait};
use satoru::exchange::error::ExchangeError;
Expand Down Expand Up @@ -99,8 +99,8 @@ mod BaseOrderHandler {
oracle: IOracleDispatcher,
/// Interface to interact with the `ReferralStorage` contract.
referral_storage: IReferralStorageDispatcher,
/// Interface to interact with the `OrderUtils` contract.
order_utils: IOrderUtilsDispatcher
/// Interface to interact with the `OrderUtils` lib.
order_utils_lib: IOrderUtilsLibraryDispatcher
}

// *************************************************************************
Expand All @@ -126,7 +126,7 @@ mod BaseOrderHandler {
oracle_address: ContractAddress,
swap_handler_address: ContractAddress,
referral_storage_address: ContractAddress,
order_utils_address: ContractAddress
order_utils_class_hash: ClassHash
) {
self
.initialize(
Expand All @@ -137,7 +137,7 @@ mod BaseOrderHandler {
oracle_address,
swap_handler_address,
referral_storage_address,
order_utils_address
order_utils_class_hash
);
}

Expand All @@ -156,7 +156,7 @@ mod BaseOrderHandler {
oracle_address: ContractAddress,
swap_handler_address: ContractAddress,
referral_storage_address: ContractAddress,
order_utils_address: ContractAddress
order_utils_class_hash: ClassHash
) {
// Make sure the contract is not already initialized.
assert(
Expand All @@ -177,7 +177,9 @@ mod BaseOrderHandler {
self
.referral_storage
.write(IReferralStorageDispatcher { contract_address: referral_storage_address });
self.order_utils.write(IOrderUtilsDispatcher { contract_address: order_utils_address });
self
.order_utils_lib
.write(IOrderUtilsLibraryDispatcher { class_hash: order_utils_class_hash });
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/exchange/liquidation_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod LiquidationHandler {

// Core lib imports.

use starknet::{ContractAddress, get_caller_address, get_contract_address};
use starknet::{ContractAddress, get_caller_address, get_contract_address, ClassHash};


// Local imports.
Expand Down Expand Up @@ -109,7 +109,7 @@ mod LiquidationHandler {
oracle_address: ContractAddress,
swap_handler_address: ContractAddress,
referral_storage_address: ContractAddress,
order_utils_address: ContractAddress
order_utils_class_hash: ClassHash
) {
let mut state: BaseOrderHandler::ContractState =
BaseOrderHandler::unsafe_new_contract_state();
Expand All @@ -122,7 +122,7 @@ mod LiquidationHandler {
oracle_address,
swap_handler_address,
referral_storage_address,
order_utils_address
order_utils_class_hash
);
let mut state: RoleModule::ContractState = RoleModule::unsafe_new_contract_state();
IRoleModule::initialize(ref state, role_store_address,);
Expand Down
12 changes: 6 additions & 6 deletions src/exchange/order_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ mod OrderHandler {
// *************************************************************************

// Core lib imports.
use satoru::exchange::base_order_handler::BaseOrderHandler::order_utils_lib::InternalContractMemberStateTrait;
use satoru::order::order_utils::IOrderUtilsDispatcherTrait;
use core::starknet::SyscallResultTrait;
use core::traits::Into;
use starknet::ContractAddress;
use starknet::{get_caller_address, get_contract_address};
use starknet::{get_caller_address, get_contract_address, ClassHash};
use array::ArrayTrait;
use debug::PrintTrait;

Expand Down Expand Up @@ -133,7 +134,6 @@ mod OrderHandler {
order_vault::InternalContractMemberStateTrait as OrderVaultStateTrait,
referral_storage::InternalContractMemberStateTrait as ReferralStorageStateTrait,
oracle::InternalContractMemberStateTrait as OracleStateTrait,
order_utils::InternalContractMemberStateTrait as OrderUtilsTrait,
InternalTrait as BaseOrderHandleInternalTrait,
};
use satoru::feature::feature_utils::{validate_feature};
Expand Down Expand Up @@ -178,7 +178,7 @@ mod OrderHandler {
oracle_address: ContractAddress,
swap_handler_address: ContractAddress,
referral_storage_address: ContractAddress,
order_utils_address: ContractAddress
order_utils_class_hash: ClassHash
) {
let mut state: BaseOrderHandler::ContractState =
BaseOrderHandler::unsafe_new_contract_state();
Expand All @@ -191,7 +191,7 @@ mod OrderHandler {
oracle_address,
swap_handler_address,
referral_storage_address,
order_utils_address
order_utils_class_hash
);
}

Expand Down Expand Up @@ -219,7 +219,7 @@ mod OrderHandler {
create_order_feature_disabled_key(get_contract_address(), params.order_type)
);
let key = base_order_handler_state
.order_utils
.order_utils_lib
.read()
.create_order_utils(
data_store,
Expand Down Expand Up @@ -327,7 +327,7 @@ mod OrderHandler {
execute_order_feature_disabled_key(get_contract_address(), params.order.order_type)
);

base_order_handler_state.order_utils.read().execute_order_utils(params);
base_order_handler_state.order_utils_lib.read().execute_order_utils(params);
}


Expand Down
35 changes: 16 additions & 19 deletions src/order/order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ trait IOrderUtils<TContractState> {
#[starknet::contract]
mod OrderUtils {
// Core lib imports.
use starknet::{ContractAddress, contract_address_const};
use satoru::order::swap_order_utils::ISwapOrderUtilsDispatcherTrait;
use satoru::order::decrease_order_utils::IDecreaseOrderUtilsDispatcherTrait;
use satoru::order::increase_order_utils::IIncreaseOrderUtilsDispatcherTrait;
use starknet::{ContractAddress, contract_address_const, ClassHash};
use clone::Clone;
// Local imports.
use satoru::order::base_order_utils::{ExecuteOrderParams, CreateOrderParams};
Expand All @@ -124,23 +127,17 @@ mod OrderUtils {
use satoru::utils::serializable_dict::{SerializableFelt252Dict, SerializableFelt252DictTrait};
use satoru::order::error::OrderError;

use satoru::order::increase_order_utils::{
IIncreaseOrderUtilsDispatcher, IIncreaseOrderUtilsDispatcherTrait
};
use satoru::order::decrease_order_utils::{
IDecreaseOrderUtilsDispatcher, IDecreaseOrderUtilsDispatcherTrait
};
use satoru::order::swap_order_utils::{
ISwapOrderUtilsDispatcher, ISwapOrderUtilsDispatcherTrait
};
use satoru::order::increase_order_utils::IIncreaseOrderUtilsLibraryDispatcher;
use satoru::order::decrease_order_utils::IDecreaseOrderUtilsLibraryDispatcher;
use satoru::order::swap_order_utils::ISwapOrderUtilsLibraryDispatcher;

use satoru::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};

#[storage]
struct Storage {
increase_order_utils: IIncreaseOrderUtilsDispatcher,
decrease_order_utils: IDecreaseOrderUtilsDispatcher,
swap_order_utils: ISwapOrderUtilsDispatcher,
increase_order_utils: IIncreaseOrderUtilsLibraryDispatcher,
decrease_order_utils: IDecreaseOrderUtilsLibraryDispatcher,
swap_order_utils: ISwapOrderUtilsLibraryDispatcher,
}

// *************************************************************************
Expand All @@ -149,19 +146,19 @@ mod OrderUtils {
#[constructor]
fn constructor(
ref self: ContractState,
increase_order_address: ContractAddress,
decrease_order_address: ContractAddress,
swap_order_address: ContractAddress
increase_order_class_hash: ClassHash,
decrease_order_class_hash: ClassHash,
swap_order_class_hash: ClassHash
) {
self
.increase_order_utils
.write(IIncreaseOrderUtilsDispatcher { contract_address: increase_order_address });
.write(IIncreaseOrderUtilsLibraryDispatcher { class_hash: increase_order_class_hash });
self
.decrease_order_utils
.write(IDecreaseOrderUtilsDispatcher { contract_address: decrease_order_address });
.write(IDecreaseOrderUtilsLibraryDispatcher { class_hash: decrease_order_class_hash });
self
.swap_order_utils
.write(ISwapOrderUtilsDispatcher { contract_address: swap_order_address });
.write(ISwapOrderUtilsLibraryDispatcher { class_hash: swap_order_class_hash });
}

// *************************************************************************
Expand Down

0 comments on commit 1144bb6

Please sign in to comment.