Skip to content

Commit

Permalink
more fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
darainj committed Jan 21, 2022
1 parent 171454e commit 2af152b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 19 deletions.
47 changes: 39 additions & 8 deletions contracts/maker/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,22 @@ pub fn instantiate(deps: DepsMut<InjectiveQueryWrapper>, _env: Env, info: Messag

#[entry_point]
pub fn execute(
deps: DepsMut<InjectiveQueryWrapper>, env: Env, info: MessageInfo, msg: ExecuteMsg,
deps: DepsMut<InjectiveQueryWrapper>,
env: Env,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response<InjectiveMsgWrapper>, ContractError> {
match msg {
ExecuteMsg::Subscribe { subaccount_id, amount } => subscribe(deps, env, info.sender, subaccount_id, amount),
}
}

pub fn subscribe(
_deps: DepsMut<InjectiveQueryWrapper>, env: Env, sender: Addr, subaccount_id: String, amount: Coin,
_deps: DepsMut<InjectiveQueryWrapper>,
env: Env,
sender: Addr,
subaccount_id: String,
amount: Coin,
) -> Result<Response<InjectiveMsgWrapper>, ContractError> {
let contract = env.contract.address;

Expand Down Expand Up @@ -91,8 +98,14 @@ pub fn query(deps: Deps<InjectiveQueryWrapper>, _env: Env, msg: QueryMsg) -> Std
}

fn get_action(
deps: Deps<InjectiveQueryWrapper>, is_deriv: bool, open_orders: Vec<OpenOrder>, position: Option<Position>, inv_base_val: String,
inv_val: String, std_dev: String, mid_price: String,
deps: Deps<InjectiveQueryWrapper>,
is_deriv: bool,
open_orders: Vec<OpenOrder>,
position: Option<Position>,
inv_base_val: String,
inv_val: String,
std_dev: String,
mid_price: String,
) -> StdResult<WrappedGetActionResponse> {
// Wrap everything
let open_orders: Vec<WrappedOpenOrder> = open_orders.into_iter().map(|o| o.wrap(deps).unwrap()).collect();
Expand Down Expand Up @@ -193,7 +206,11 @@ fn get_action(
}
}
fn orders_to_cancel(
open_orders: Vec<WrappedOpenOrder>, new_head: Decimal, new_tail: Decimal, is_buy: bool, is_deriv: bool,
open_orders: Vec<WrappedOpenOrder>,
new_head: Decimal,
new_tail: Decimal,
is_buy: bool,
is_deriv: bool,
) -> (Vec<String>, Vec<WrappedOpenOrder>, Decimal, bool) {
if is_deriv {
orders_to_cancel_deriv(open_orders, new_head, new_tail, is_buy)
Expand All @@ -203,8 +220,17 @@ fn orders_to_cancel(
}

fn create_orders(
new_head: Decimal, new_tail: Decimal, inv_val: Decimal, orders_to_keep: Vec<WrappedOpenOrder>, orders_remaining_val: Decimal,
position: Option<WrappedPosition>, append_to_new_head: bool, hashes_to_cancel: &mut Vec<String>, is_deriv: bool, is_buy: bool, state: &State,
new_head: Decimal,
new_tail: Decimal,
inv_val: Decimal,
orders_to_keep: Vec<WrappedOpenOrder>,
orders_remaining_val: Decimal,
position: Option<WrappedPosition>,
append_to_new_head: bool,
hashes_to_cancel: &mut Vec<String>,
is_deriv: bool,
is_buy: bool,
state: &State,
) -> Vec<WrappedOrderResponse> {
if is_deriv {
let position_qty = match position {
Expand Down Expand Up @@ -256,7 +282,12 @@ fn create_orders(
}

fn reservation_price(
mid_price: Decimal, inv_imbal: Decimal, varience: Decimal, risk_aversion: Decimal, manual_offset_perct: Decimal, imbal_is_long: bool,
mid_price: Decimal,
inv_imbal: Decimal,
varience: Decimal,
risk_aversion: Decimal,
manual_offset_perct: Decimal,
imbal_is_long: bool,
) -> Decimal {
if inv_imbal == Decimal::zero() {
mid_price
Expand Down
32 changes: 26 additions & 6 deletions contracts/maker/src/derivative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ pub fn inv_imbalance_deriv(position: &Option<WrappedPosition>, inv_val: Decimal)
/// * `append_to_new_head` - An indication of whether we should append new orders to the new head
/// or to the back of the orders_to_keep block
pub fn orders_to_cancel_deriv(
open_orders: Vec<WrappedOpenOrder>, new_head: Decimal, new_tail: Decimal, is_buy: bool,
open_orders: Vec<WrappedOpenOrder>,
new_head: Decimal,
new_tail: Decimal,
is_buy: bool,
) -> (Vec<String>, Vec<WrappedOpenOrder>, Decimal, bool) {
let mut orders_remaining_val = Decimal::zero();
let mut hashes_to_cancel: Vec<String> = Vec::new();
Expand Down Expand Up @@ -61,8 +64,15 @@ pub fn orders_to_cancel_deriv(
}

pub fn base_deriv(
new_head: Decimal, new_tail: Decimal, inv_val: Decimal, orders_to_keep: Vec<WrappedOpenOrder>, orders_remaining_val: Decimal,
mut position_qty: Decimal, touch_head: bool, is_buy: bool, state: &State,
new_head: Decimal,
new_tail: Decimal,
inv_val: Decimal,
orders_to_keep: Vec<WrappedOpenOrder>,
orders_remaining_val: Decimal,
mut position_qty: Decimal,
touch_head: bool,
is_buy: bool,
state: &State,
) -> (Vec<WrappedOrderResponse>, Decimal) {
let num_open_orders = Uint256::from_str(&orders_to_keep.len().to_string()).unwrap();
let mut orders_to_open: Vec<WrappedOrderResponse> = Vec::new();
Expand Down Expand Up @@ -117,7 +127,12 @@ pub fn base_deriv(
}

pub fn tail_to_head_deriv(
new_head: Decimal, inv_val: Decimal, orders_to_keep: Vec<WrappedOpenOrder>, orders_remaining_val: Decimal, position_qty: Decimal, is_buy: bool,
new_head: Decimal,
inv_val: Decimal,
orders_to_keep: Vec<WrappedOpenOrder>,
orders_remaining_val: Decimal,
position_qty: Decimal,
is_buy: bool,
state: &State,
) -> (Vec<WrappedOrderResponse>, Vec<String>) {
let (mut orders_to_open, mut position_qty) = base_deriv(
Expand Down Expand Up @@ -165,8 +180,13 @@ pub fn tail_to_head_deriv(
}

pub fn head_to_tail_deriv(
new_tail: Decimal, inv_val: Decimal, orders_to_keep: Vec<WrappedOpenOrder>, orders_remaining_val: Decimal, mut position_qty: Decimal,
is_buy: bool, state: &State,
new_tail: Decimal,
inv_val: Decimal,
orders_to_keep: Vec<WrappedOpenOrder>,
orders_remaining_val: Decimal,
mut position_qty: Decimal,
is_buy: bool,
state: &State,
) -> (Vec<WrappedOrderResponse>, Vec<String>) {
let mut orders_to_open: Vec<WrappedOrderResponse> = Vec::new();
let mut additional_hashes_to_cancel: Vec<String> = Vec::new();
Expand Down
15 changes: 12 additions & 3 deletions contracts/maker/src/spot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ pub fn inv_imbalance_spot(inv_base_val: Decimal, inv_val: Decimal) -> (Decimal,
/// * `append_to_new_head` - An indication of whether we should append new orders to the new head
/// or to the back of the orders_to_keep block
pub fn orders_to_cancel_spot(
open_orders: Vec<WrappedOpenOrder>, new_head: Decimal, new_tail: Decimal, is_buy: bool,
open_orders: Vec<WrappedOpenOrder>,
new_head: Decimal,
new_tail: Decimal,
is_buy: bool,
) -> (Vec<String>, Vec<WrappedOpenOrder>, Decimal, bool) {
let mut orders_remaining_val = Decimal::zero();
let mut hashes_to_cancel: Vec<String> = Vec::new();
Expand Down Expand Up @@ -76,8 +79,14 @@ pub fn orders_to_cancel_spot(
/// # Returns
/// * `orders_to_open` - A list of all the new orders that we would like to place
pub fn create_new_orders_spot(
new_head: Decimal, new_tail: Decimal, inv_val: Decimal, orders_to_keep: Vec<WrappedOpenOrder>, orders_remaining_val: Decimal,
append_to_new_head: bool, is_buy: bool, state: &State,
new_head: Decimal,
new_tail: Decimal,
inv_val: Decimal,
orders_to_keep: Vec<WrappedOpenOrder>,
orders_remaining_val: Decimal,
append_to_new_head: bool,
is_buy: bool,
state: &State,
) -> Vec<WrappedOrderResponse> {
let num_open_orders = Uint256::from_str(&orders_to_keep.len().to_string()).unwrap();
let mut orders_to_open: Vec<WrappedOrderResponse> = Vec::new();
Expand Down
5 changes: 4 additions & 1 deletion packages/bindings/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ pub enum InjectiveMsg {
}

pub fn create_subaccount_transfer_msg(
sender: Addr, source_subaccount_id: String, destination_subaccount_id: String, amount: Coin,
sender: Addr,
source_subaccount_id: String,
destination_subaccount_id: String,
amount: Coin,
) -> CosmosMsg<InjectiveMsgWrapper> {
InjectiveMsgWrapper {
route: InjectiveRoute::Exchange,
Expand Down
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
newline_style = "unix"
hard_tabs = false
tab_spaces = 4
fn_args_layout = "Compressed"
max_width = 150

# unstable... should we require `rustup run nightly cargo fmt` ?
Expand Down

0 comments on commit 2af152b

Please sign in to comment.