Skip to content

Commit

Permalink
fix: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zarboq committed May 9, 2024
1 parent cee446f commit 02d0cf9
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 40 deletions.
53 changes: 39 additions & 14 deletions src/data/data_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,27 @@ use satoru::utils::i256::i256;
// *************************************************************************
#[starknet::interface]
trait IDataStore<TContractState> {
fn get_max_pool_amount_key(self: @TContractState, market_token: ContractAddress, token: ContractAddress) -> felt252;
fn get_open_interest_key(self: @TContractState, market: ContractAddress, collateral_token: ContractAddress, is_long: bool) -> felt252;
fn get_max_open_interest_key(self: @TContractState, market: ContractAddress, is_long: bool) -> felt252;
fn get_pool_amount_key(self: @TContractState, market: ContractAddress, token: ContractAddress) -> felt252;
fn get_max_pnl_factor_key(self: @TContractState, pnl_factor_type: felt252, market: ContractAddress, is_long: bool) -> felt252;
fn get_max_pool_amount_key(
self: @TContractState, market_token: ContractAddress, token: ContractAddress
) -> felt252;
fn get_open_interest_key(
self: @TContractState,
market: ContractAddress,
collateral_token: ContractAddress,
is_long: bool
) -> felt252;
fn get_max_open_interest_key(
self: @TContractState, market: ContractAddress, is_long: bool
) -> felt252;
fn get_pool_amount_key(
self: @TContractState, market: ContractAddress, token: ContractAddress
) -> felt252;
fn get_max_pnl_factor_key(
self: @TContractState, pnl_factor_type: felt252, market: ContractAddress, is_long: bool
) -> felt252;
fn get_max_pnl_factor_for_deposit_key(self: @TContractState) -> felt252;
fn get_max_pnl_factor_for_withdrawals_key(self: @TContractState) -> felt252;

// *************************************************************************
// Felt252 related functions.
// *************************************************************************
Expand Down Expand Up @@ -523,35 +536,47 @@ mod DataStore {
// *************************************************************************
#[abi(embed_v0)]
impl DataStore of super::IDataStore<ContractState> {

fn get_max_pool_amount_key(self: @ContractState, market_token: ContractAddress, token: ContractAddress) -> felt252 {
fn get_max_pool_amount_key(
self: @ContractState, market_token: ContractAddress, token: ContractAddress
) -> felt252 {
keys::max_pool_amount_key(market_token, token)
}

fn get_open_interest_key(self: @ContractState, market: ContractAddress, collateral_token: ContractAddress, is_long: bool) -> felt252 {
fn get_open_interest_key(
self: @ContractState,
market: ContractAddress,
collateral_token: ContractAddress,
is_long: bool
) -> felt252 {
keys::open_interest_key(market, collateral_token, is_long)
}

fn get_max_open_interest_key(self: @ContractState, market: ContractAddress, is_long: bool) -> felt252 {
fn get_max_open_interest_key(
self: @ContractState, market: ContractAddress, is_long: bool
) -> felt252 {
keys::max_open_interest_key(market, is_long)
}

fn get_pool_amount_key(self: @ContractState, market: ContractAddress, token: ContractAddress) -> felt252 {
fn get_pool_amount_key(
self: @ContractState, market: ContractAddress, token: ContractAddress
) -> felt252 {
keys::pool_amount_key(market, token)
}

fn get_max_pnl_factor_key(self: @ContractState, pnl_factor_type: felt252, market: ContractAddress, is_long: bool) -> felt252 {
fn get_max_pnl_factor_key(
self: @ContractState, pnl_factor_type: felt252, market: ContractAddress, is_long: bool
) -> felt252 {
keys::max_pnl_factor_key(pnl_factor_type, market, is_long)
}

fn get_max_pnl_factor_for_deposit_key(self: @ContractState) -> felt252 {
keys::max_pnl_factor_for_deposits()
}

fn get_max_pnl_factor_for_withdrawals_key(self: @ContractState) -> felt252 {
keys::max_pnl_factor_for_withdrawals()
}


// *************************************************************************
// Felt252 related functions.
Expand Down
5 changes: 1 addition & 4 deletions src/oracle/oracle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ trait IOracle<TContractState> {
fn set_primary_price(ref self: TContractState, token: ContractAddress, price: u256);

fn set_price_testing_eth(ref self: TContractState, new_price: u256);

}

/// A price that has been validated in validate_prices().
Expand Down Expand Up @@ -238,17 +237,15 @@ mod Oracle {

fn set_primary_price(ref self: ContractState, token: ContractAddress, price: u256) {
// TODO add security check keeper
self.primary_prices.write(token, Price { min: price, max: price});
self.primary_prices.write(token, Price { min: price, max: price });
}

}

// *************************************************************************
// INTERNAL FUNCTIONS
// *************************************************************************
#[generate_trait]
impl InternalImpl of InternalTrait {

/// Emits an `OraclePriceUpdated` event for a specific token.
/// # Parameters
/// * `event_emitter`: Dispatcher used for emitting events.
Expand Down
2 changes: 1 addition & 1 deletion src/order/order.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ impl OrderTypeInto of Into<OrderType, felt252> {
}
}
}

// impl OrderTypePrintImpl of PrintTrait<OrderType> {
// fn print(self: OrderType) {
// match self {
Expand All @@ -184,3 +183,4 @@ impl OrderTypeInto of Into<OrderType, felt252> {
// }
// }
// }

7 changes: 3 additions & 4 deletions src/order/swap_order_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ mod SwapOrderUtils {
ui_fee_receiver: params.order.ui_fee_receiver,
}
);
// let mut log_data: LogData = Default::default();

// let mut log_data: LogData = Default::default();

// log_data.address_dict.insert_single('output_token', output_token);
// log_data.uint_dict.insert_single('output_amount', output_amount);
// log_data.address_dict.insert_single('output_token', output_token);
// log_data.uint_dict.insert_single('output_amount', output_amount);

// log_data
}
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 @@ -96,7 +96,6 @@ fn process_collateral(
// );
let (price_impact_usd_, price_impact_diff_usd_, execution_price_) = (i256_new(0, false), 0, 0);


values.price_impact_usd = price_impact_usd_;
values.price_impact_diff_usd = price_impact_diff_usd_;
values.execution_price = execution_price_;
Expand Down
2 changes: 0 additions & 2 deletions src/swap/swap_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ fn _swap(params: @SwapParams, _params: @_SwapParams) -> (ContractAddress, u256)
);

cache.amount_out += calc::to_unsigned(price_impact_amount);

} else {
// when there is a negative price impact factor,
// less of the input amount is sent to the pool
Expand All @@ -293,7 +292,6 @@ fn _swap(params: @SwapParams, _params: @_SwapParams) -> (ContractAddress, u256)
);
}


cache.amount_in = fees.amount_after_fees - calc::to_unsigned(i256_neg(price_impact_amount));
cache.amount_out = cache.amount_in * cache.token_in_price.min / cache.token_out_price.max;
cache.pool_amount_out = cache.amount_out;
Expand Down
4 changes: 0 additions & 4 deletions tests/integration/swap_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ fn test_deposit_market_integration() {
let balance_deposit_vault_before = IERC20Dispatcher { contract_address: market.short_token }
.balance_of(deposit_vault.contract_address);


// Create Deposit
let user1: ContractAddress = contract_address_const::<'user1'>();
let user2: ContractAddress = contract_address_const::<'user2'>();
Expand Down Expand Up @@ -213,7 +212,6 @@ fn test_deposit_market_integration() {
true,
);


// // --------------------------------------------------SWAP TEST ETH->USDC --------------------------------------------------
let balance_ETH_before_swap = IERC20Dispatcher {
contract_address: contract_address_const::<'ETH'>()
Expand All @@ -227,7 +225,6 @@ fn test_deposit_market_integration() {
.balance_of(caller_address);
assert(balance_USDC_before_swap == 1000000, 'wrong balance USDC before swap');


start_prank(contract_address_const::<'ETH'>(), caller_address); //change to switch swap
// Send token to order_vault in multicall with create_order
IERC20Dispatcher { contract_address: contract_address_const::<'ETH'>() } //change to switch swap
Expand All @@ -238,7 +235,6 @@ fn test_deposit_market_integration() {
}
.balance_of(caller_address);


let balance_USDC_before = IERC20Dispatcher {
contract_address: contract_address_const::<'USDC'>()
}
Expand Down
15 changes: 5 additions & 10 deletions tests/integration/test_long_integration.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ const INITIAL_TOKENS_MINTED: felt252 = 1000;
// balance_of_mkt_before.print();
// oracle.set_primary_prices(market.long_token, 6000);


// start_prank(market.market_token, caller_address);
// start_prank(market.long_token, caller_address);
// let order_params_long_dec = CreateOrderParams {
Expand Down Expand Up @@ -702,7 +701,10 @@ fn test_long_decimals_market_integration() {
);
data_store.set_u256(key_open_interest, 1);
let max_key_open_interest = keys::max_open_interest_key(market.market_token, true);
data_store.set_u256(max_key_open_interest, 1000000000000000000000000000000000000000000000000000); // 1 000 000
data_store
.set_u256(
max_key_open_interest, 1000000000000000000000000000000000000000000000000000
); // 1 000 000

// Send token to order_vault in multicall with create_order
start_prank(contract_address_const::<'ETH'>(), caller_address);
Expand Down Expand Up @@ -805,13 +807,7 @@ fn test_long_decimals_market_integration() {

let position_info = reader
.get_position_info(
data_store,
referal_storage,
position_key_1,
market_prices,
0,
contract_address,
true
data_store, referal_storage, position_key_1, market_prices, 0, contract_address, true
);
'pnl'.print();
position_info.base_pnl_usd.mag.print();
Expand Down Expand Up @@ -905,7 +901,6 @@ fn test_long_decimals_market_integration() {
order_handler.execute_order_keeper(key_long_dec, set_price_params_dec, keeper_address);
'long pos dec SUCCEEDED'.print();


let first_position_dec = data_store.get_position(position_key_1);

'size tokens before'.print();
Expand Down

0 comments on commit 02d0cf9

Please sign in to comment.