Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
feat: add missing fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptokage1996 committed Sep 21, 2024
1 parent c1bd4dc commit 75d0df1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
17 changes: 17 additions & 0 deletions bindings/src/trade_shield/types/fees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Coin;

#[cw_serde]
pub struct Fee {
pub percent: String,
pub amount: Coin,
}

impl Default for Fee {
fn default() -> Self {
Self {
percent: "".to_string(),
amount: Coin::default(),
}
}
}
2 changes: 2 additions & 0 deletions bindings/src/trade_shield/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod spot_order {
mod coin_value;
mod date;
mod denom;
mod fees;
mod perpetual_assets;
mod perpetual_order;
mod perpetual_order_plus;
Expand All @@ -25,6 +26,7 @@ pub use crate::types::*;
pub use coin_value::CoinValue;
pub use date::Date;
pub use denom::ElysDenom;
pub use fees::Fee;
pub use perpetual_assets::{PerpetualAsset, PerpetualAssets};
pub use perpetual_order::PerpetualOrder;
pub use perpetual_order_plus::PerpetualOrderPlus;
Expand Down
24 changes: 22 additions & 2 deletions bindings/src/trade_shield/types/perpetual_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::str::FromStr;
use crate::{trade_shield::states::PENDING_PERPETUAL_ORDER, types::PerpetualPosition};
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{
Coin, OverflowError, SignedDecimal, SignedDecimal256, StdError, StdResult, Storage,
Coin, DecCoin, OverflowError, SignedDecimal, SignedDecimal256, StdError, StdResult, Storage,
};

use super::{OrderPrice, PerpetualOrderType, Status};
use super::{Fee, OrderPrice, PerpetualOrderType, Status};

#[cw_serde]
pub struct PerpetualOrder {
Expand All @@ -21,6 +21,10 @@ pub struct PerpetualOrder {
pub take_profit_price: Option<SignedDecimal256>,
pub position_id: Option<u64>,
pub status: Status,
pub size: DecCoin,
pub liquidation: SignedDecimal,
pub borrow_fee: Fee,
pub funding_fee: Fee,
}

impl PerpetualOrder {
Expand All @@ -34,6 +38,10 @@ impl PerpetualOrder {
take_profit_price: &Option<SignedDecimal256>,
trigger_price: &Option<OrderPrice>,
order_vec: &Vec<PerpetualOrder>,
size: DecCoin,
liquidation: SignedDecimal,
borrow_fee: Fee,
funding_fee: Fee,
) -> StdResult<Self> {
let status = if order_type == &PerpetualOrderType::MarketOpen {
Status::Executed
Expand All @@ -55,6 +63,10 @@ impl PerpetualOrder {
trigger_price: trigger_price.to_owned(),
status,
position_id: None,
size,
liquidation,
borrow_fee,
funding_fee,
};

return Ok(order);
Expand All @@ -70,6 +82,10 @@ impl PerpetualOrder {
trigger_price: &Option<OrderPrice>,
take_profit_price: &Option<SignedDecimal256>,
order_vec: &Vec<PerpetualOrder>,
size: DecCoin,
liquidation: SignedDecimal,
borrow_fee: Fee,
funding_fee: Fee,
) -> StdResult<Self> {
let order_id: u64 = get_new_id(&order_vec)?;

Expand All @@ -93,6 +109,10 @@ impl PerpetualOrder {
position_id: Some(position_id),
leverage: leverage.to_owned(),
take_profit_price: take_profit_price.to_owned(),
size,
liquidation,
borrow_fee,
funding_fee,
};

Ok(order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::{helper::get_discount, msg::ReplyType};

use super::*;
use cosmwasm_std::{
coin, to_json_binary, OverflowError, OverflowOperation, SignedDecimal, SignedDecimal256,
StdError, StdResult, SubMsg,
coin, to_json_binary, Coin, DecCoin, Decimal256, OverflowError, OverflowOperation,
SignedDecimal, SignedDecimal256, StdError, StdResult, SubMsg,
};
use cw_utils;
use elys_bindings::query_resp::{Entry, QueryGetEntryResponse};
Expand Down Expand Up @@ -175,6 +175,8 @@ fn create_perpetual_open_order(
}
}

let amount = Decimal256::new(open_estimation.position_size.amount.into());

let order = PerpetualOrder::new_open(
&info.sender,
&position,
Expand All @@ -185,6 +187,25 @@ fn create_perpetual_open_order(
&take_profit_price,
&trigger_price,
&orders,
DecCoin {
denom: open_estimation.position_size.denom,
amount,
},
open_estimation.liquidation_price,
Fee {
percent: open_estimation.borrow_interest_rate.to_string(),
amount: Coin {
denom: open_estimation.collateral.denom,
amount: todo!(),
},
},
Fee {
percent: open_estimation.funding_rate.to_string(),
amount: Coin {
denom: open_estimation.trading_asset,
amount: todo!(),
},
},
)?;

let order_id = order.order_id;
Expand Down Expand Up @@ -360,6 +381,10 @@ fn create_perpetual_close_order(
&trigger_price,
&Some(mtp.take_profit_price),
&orders,
DecCoin::new(Decimal256::zero(), ""),
SignedDecimal::zero(),
Fee::default(),
Fee::default(),
)?;

let order_id = order.order_id;
Expand Down

0 comments on commit 75d0df1

Please sign in to comment.