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

Commit

Permalink
Merge branch 'main' of github.com:elys-network/bindings into DEV-1969…
Browse files Browse the repository at this point in the history
…-bindings-fixings
  • Loading branch information
cryptokage1996 committed Sep 26, 2024
2 parents 8bc8109 + 7b3d674 commit 8779175
Show file tree
Hide file tree
Showing 34 changed files with 456 additions and 96 deletions.
2 changes: 2 additions & 0 deletions bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ impl Module for ElysModule {
borrow_interest_rate: Decimal::zero().to_string(),
funding_rate: Decimal::zero().to_string(),
price_impact: Decimal::zero().to_string(),
borrow_fee: Coin::new(0, ""),
funding_fee: Coin::new(0, ""),
})?)
}
ElysQuery::AssetProfileEntryAll { .. } => {
Expand Down
2 changes: 2 additions & 0 deletions bindings/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ impl<'a> ElysQuerier<'a> {
.map_or(SignedDecimal::zero(), |funding_rate| funding_rate),
price_impact: SignedDecimal::from_str(&raw_resp.price_impact)
.map_or(SignedDecimal::zero(), |price_impact| price_impact),
borrow_fee: raw_resp.borrow_fee,
funding_fee: raw_resp.funding_fee,
};

Ok(resp)
Expand Down
4 changes: 4 additions & 0 deletions bindings/src/query_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ pub struct PerpetualOpenEstimationRawResponse {
pub borrow_interest_rate: String,
pub funding_rate: String,
pub price_impact: String,
pub borrow_fee: Coin,
pub funding_fee: Coin,
}

#[cw_serde]
Expand All @@ -147,6 +149,8 @@ pub struct PerpetualOpenEstimationResponse {
pub borrow_interest_rate: SignedDecimal,
pub funding_rate: SignedDecimal,
pub price_impact: SignedDecimal,
pub borrow_fee: Coin,
pub funding_fee: Coin,
}

#[cw_serde]
Expand Down
2 changes: 2 additions & 0 deletions bindings/src/trade_shield/states/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod limit_order;
mod number_of_order;
mod params;
mod perpetual_order;
mod perpetual_order_v2;
mod reply_info;
mod spot_order;

Expand All @@ -14,6 +15,7 @@ pub use params::{
pub use perpetual_order::{
PENDING_PERPETUAL_ORDER, PERPETUAL_ORDER, SORTED_PENDING_PERPETUAL_ORDER, USER_PERPETUAL_ORDER,
};
pub use perpetual_order_v2::{PENDING_PERPETUAL_ORDER_V2, PERPETUAL_ORDER_V2};
pub use reply_info::{MAX_REPLY_ID, REPLY_INFO};
pub use spot_order::{
PENDING_SPOT_ORDER, SORTED_PENDING_SPOT_ORDER, SPOT_ORDER, SPOT_ORDER_MAX_ID, USER_SPOT_ORDER,
Expand Down
7 changes: 7 additions & 0 deletions bindings/src/trade_shield/states/perpetual_order_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::trade_shield::types::PerpetualOrderV2;
use cw_storage_plus::Map;

pub const PERPETUAL_ORDER_V2: Map<u64, PerpetualOrderV2> = Map::new("perpetual order2_v2");

pub const PENDING_PERPETUAL_ORDER_V2: Map<u64, PerpetualOrderV2> =
Map::new("unprocess perpetual order_v2");
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(),
}
}
}
23 changes: 23 additions & 0 deletions bindings/src/trade_shield/types/from_perpetual_order_to_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::{PerpetualOrder, PerpetualOrderV2};

impl Into<PerpetualOrderV2> for PerpetualOrder {
fn into(self) -> PerpetualOrderV2 {
PerpetualOrderV2 {
order_id: self.order_id,
owner: self.owner,
order_type: self.order_type,
position: self.position,
trigger_price: self.trigger_price,
collateral: self.collateral,
trading_asset: self.trading_asset,
leverage: self.leverage,
take_profit_price: self.take_profit_price,
position_id: self.position_id,
status: self.status,
size: None,
liquidation: None,
borrow_fee: None,
funding_fee: None,
}
}
}
5 changes: 5 additions & 0 deletions bindings/src/trade_shield/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ mod spot_order {
mod coin_value;
mod date;
mod denom;
mod fees;
mod from_perpetual_order_to_v2;
mod perpetual_assets;
mod perpetual_order;
mod perpetual_order_plus;
mod perpetual_order_type;
mod perpetual_order_v2;
mod perpetual_position_plus;
mod reply_info;
mod status;
Expand All @@ -25,10 +28,12 @@ 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;
pub use perpetual_order_type::PerpetualOrderType;
pub use perpetual_order_v2::PerpetualOrderV2;
pub use perpetual_position_plus::PerpetualPositionPlus;
pub use reply_info::ReplyInfo;
pub use spot_order::spot_order::SpotOrder;
Expand Down
17 changes: 6 additions & 11 deletions bindings/src/trade_shield/types/perpetual_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use crate::ElysQuerier;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{DecCoin, Decimal, Decimal256, SignedDecimal, StdError, StdResult, Uint128};

use super::Fee;

#[cw_serde]
pub struct PerpetualAssets {
pub total_perpetual_asset_balance: DecCoin,
Expand All @@ -24,7 +26,8 @@ pub struct PerpetualAsset {
pub health: SignedDecimal,
pub profit_price: DecCoin,
pub stop_loss: Option<DecCoin>,
pub fees: Decimal,
pub borrow_fee: Fee,
pub funding_fee: Fee,
}

impl PerpetualAsset {
Expand Down Expand Up @@ -91,16 +94,8 @@ impl PerpetualAsset {
}),
None => None,
},
fees: Decimal::from_atomics(
Uint128::new(mtp.mtp.borrow_interest_paid_collateral.i128() as u128),
collateral_info.asset_info.decimal as u32,
)
.map_err(|e| {
StdError::generic_err(format!(
"failed to convert borrow_interest_paid_collateral to Decimal256: {}",
e
))
})?,
borrow_fee: Fee::default(),
funding_fee: Fee::default(),
})
}
}
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
6 changes: 3 additions & 3 deletions bindings/src/trade_shield/types/perpetual_order_plus.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{coin, Coin, Decimal, SignedDecimal, StdError, StdResult};

use super::{OrderPrice, PerpetualOrder};
use super::{OrderPrice, PerpetualOrderV2};

#[cw_serde]
pub struct PerpetualOrderPlus {
pub order: PerpetualOrder,
pub order: PerpetualOrderV2,
pub order_price: Option<Decimal>,
pub custody: Coin,
}
Expand Down Expand Up @@ -38,7 +38,7 @@ impl PerpetualOrderPlus {
Ok(coin(custody_value.to_uint_floor().u128(), trading_asset))
}

pub fn new(order: PerpetualOrder) -> StdResult<Self> {
pub fn new(order: PerpetualOrderV2) -> StdResult<Self> {
if order.trigger_price.is_none() {
return Ok(Self {
custody: coin(0, &order.trading_asset),
Expand Down
Loading

0 comments on commit 8779175

Please sign in to comment.