diff --git a/src/exchange/base_order_handler.cairo b/src/exchange/base_order_handler.cairo index df738a14..e8c26667 100644 --- a/src/exchange/base_order_handler.cairo +++ b/src/exchange/base_order_handler.cairo @@ -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}; @@ -34,7 +34,7 @@ trait IBaseOrderHandler { oracle_address: ContractAddress, swap_handler_address: ContractAddress, referral_storage_address: ContractAddress, - order_utils_address: ContractAddress + order_utils_class_hash: ClassHash ); } @@ -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; @@ -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; @@ -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 } // ************************************************************************* @@ -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( @@ -137,7 +137,7 @@ mod BaseOrderHandler { oracle_address, swap_handler_address, referral_storage_address, - order_utils_address + order_utils_class_hash ); } @@ -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( @@ -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 }); } } diff --git a/src/exchange/liquidation_handler.cairo b/src/exchange/liquidation_handler.cairo index 063c384d..2061674a 100644 --- a/src/exchange/liquidation_handler.cairo +++ b/src/exchange/liquidation_handler.cairo @@ -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. @@ -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(); @@ -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,); diff --git a/src/exchange/order_handler.cairo b/src/exchange/order_handler.cairo index 829e80de..6db49907 100644 --- a/src/exchange/order_handler.cairo +++ b/src/exchange/order_handler.cairo @@ -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; @@ -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}; @@ -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(); @@ -191,7 +191,7 @@ mod OrderHandler { oracle_address, swap_handler_address, referral_storage_address, - order_utils_address + order_utils_class_hash ); } @@ -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, @@ -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); } diff --git a/src/order/order_utils.cairo b/src/order/order_utils.cairo index e8bdba76..eeb112a2 100644 --- a/src/order/order_utils.cairo +++ b/src/order/order_utils.cairo @@ -99,7 +99,10 @@ trait IOrderUtils { #[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}; @@ -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, } // ************************************************************************* @@ -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 }); } // *************************************************************************