Skip to content

Commit

Permalink
change handle contract by exchange router
Browse files Browse the repository at this point in the history
  • Loading branch information
sparqet committed Jun 24, 2024
1 parent 22c97f7 commit 5d046cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/exchange/order_handler.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ mod OrderHandler {
ref self: ContractState, account: ContractAddress, params: CreateOrderParams
) -> felt252 {
// Check only controller.
let role_module_state = RoleModule::unsafe_new_contract_state();
role_module_state.only_controller();
// let role_module_state = RoleModule::unsafe_new_contract_state(); // TODO uncomment role
// role_module_state.only_controller();
// Fetch data store.
let base_order_handler_state = BaseOrderHandler::unsafe_new_contract_state();
let data_store = base_order_handler_state.data_store.read();
Expand Down
4 changes: 2 additions & 2 deletions src/router/exchange_router.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ mod ExchangeRouter {

fn create_order(ref self: ContractState, params: CreateOrderParams) -> felt252 {
let data_store = self.data_store.read();
global_reentrancy_guard::non_reentrant_before(data_store);
// global_reentrancy_guard::non_reentrant_before(data_store);

let account = get_caller_address();

let key = self.order_handler.read().create_order(account, params);

global_reentrancy_guard::non_reentrant_after(data_store);
// global_reentrancy_guard::non_reentrant_after(data_store);

key
}
Expand Down
32 changes: 19 additions & 13 deletions tests/integration/test_long_integration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,8 @@ fn test_long_18_decrease_close_integration() {
keys::open_interest_reserve_factor_key(market.market_token, true), 1000000000000000000
);

data_store.set_bool('REENTRANCY_GUARD_STATUS', false);

'fill the pool'.print();
// Fill the pool.
IERC20Dispatcher { contract_address: market.long_token }
Expand Down Expand Up @@ -1271,7 +1273,7 @@ fn test_long_18_decrease_close_integration() {

role_store.grant_role(caller_address, role::ORDER_KEEPER);
role_store.grant_role(caller_address, role::ROLE_ADMIN);
role_store.grant_role(caller_address, role::CONTROLLER);
role_store.grant_role(exchange_router.contract_address, role::CONTROLLER);
role_store.grant_role(caller_address, role::MARKET_KEEPER);

'execute deposit'.print();
Expand Down Expand Up @@ -1366,10 +1368,11 @@ fn test_long_18_decrease_close_integration() {
referral_code: 0
};
// Create the swap order.
start_roll(order_handler.contract_address, 1930);
role_store.grant_role(exchange_router.contract_address, role::CONTROLLER);
start_roll(exchange_router.contract_address, 1930);
'try to create prder'.print();
start_prank(order_handler.contract_address, caller_address);
let key_long = order_handler.create_order(caller_address, order_params_long);
start_prank(exchange_router.contract_address, caller_address);
let key_long = exchange_router.create_order(order_params_long);
'long created'.print();
let got_order_long = data_store.get_order(key_long);

Expand Down Expand Up @@ -1453,10 +1456,11 @@ fn test_long_18_decrease_close_integration() {
referral_code: 0
};
// Create the long order.
start_roll(order_handler.contract_address, 1940);
role_store.grant_role(exchange_router.contract_address, role::CONTROLLER);
start_roll(exchange_router.contract_address, 1940);
'try to create order'.print();
start_prank(order_handler.contract_address, caller_address);
let key_long_inc = order_handler.create_order(caller_address, order_params_long_inc);
start_prank(exchange_router.contract_address, caller_address);
let key_long_inc = exchange_router.create_order(order_params_long_inc);
'Long increase created'.print();

// Execute the swap order.
Expand Down Expand Up @@ -1549,10 +1553,11 @@ fn test_long_18_decrease_close_integration() {
referral_code: 0
};
// Create the long order.
start_roll(order_handler.contract_address, 1950);
role_store.grant_role(exchange_router.contract_address, role::CONTROLLER);
start_roll(exchange_router.contract_address, 1950);
'try to create order'.print();
start_prank(order_handler.contract_address, caller_address);
let key_long_dec = order_handler.create_order(caller_address, order_params_long_dec);
start_prank(exchange_router.contract_address, caller_address);
let key_long_dec = exchange_router.create_order(order_params_long_dec);
'long decrease created'.print();
let got_order_long_dec = data_store.get_order(key_long_dec);

Expand Down Expand Up @@ -1669,10 +1674,11 @@ fn test_long_18_decrease_close_integration() {
referral_code: 0
};
// Create the long order.
start_roll(order_handler.contract_address, 1960);
role_store.grant_role(exchange_router.contract_address, role::CONTROLLER);
start_roll(exchange_router.contract_address, 1960);
'try to create order'.print();
start_prank(order_handler.contract_address, caller_address);
let key_long_dec_2 = order_handler.create_order(caller_address, order_params_long_dec_2);
start_prank(exchange_router.contract_address, caller_address);
let key_long_dec_2 = exchange_router.create_order(order_params_long_dec_2);
'long decrease created'.print();
let got_order_long_dec = data_store.get_order(key_long_dec_2);
// data_store.set_u256(keys::pool_amount_key(market.market_token, contract_address_const::<'USDC'>()), );
Expand Down

0 comments on commit 5d046cf

Please sign in to comment.