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

Commit

Permalink
feat: remove min collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptokage1996 committed Sep 26, 2024
1 parent 3789f2d commit c181420
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 76 deletions.
6 changes: 3 additions & 3 deletions bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,13 @@ impl Module for ElysModule {
} => {
return Ok(to_json_binary(&PerpetualOpenEstimationRawResponse {
position,
min_collateral: coin(0, &collateral.denom),
available_liquidity: coin(99999999, &trading_asset),
leverage: leverage.to_string(),
collateral,
trading_asset,
discount: discount.to_string(),
valid_collateral: Some(true),
// TODO: Fix
interest_amount: Int128::zero(),
position_size: coin(1, "btc"),
swap_fee: Decimal::zero().to_string(),
open_price: Decimal::zero().to_string(),
Expand All @@ -383,7 +383,7 @@ impl Module for ElysModule {
price_impact: Decimal::zero().to_string(),
borrow_fee: Coin::new(0, ""),
funding_fee: Coin::new(0, ""),
})?)
})?);
}
ElysQuery::AssetProfileEntryAll { .. } => {
let asset_info = ASSET_INFO.load(storage)?;
Expand Down
46 changes: 2 additions & 44 deletions bindings/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,51 +153,9 @@ impl<'a> ElysQuerier<'a> {

let raw_resp: PerpetualOpenEstimationRawResponse = self.querier.query(&request)?;

let resp: PerpetualOpenEstimationResponse = PerpetualOpenEstimationResponse {
position: PerpetualPosition::try_from_i32(raw_resp.position)?,
leverage: SignedDecimal::from_str(&raw_resp.leverage)
.map_or(SignedDecimal::zero(), |leverage| leverage),
trading_asset: raw_resp.trading_asset,
collateral: raw_resp.collateral,
min_collateral: raw_resp.min_collateral,
valid_collateral: raw_resp
.valid_collateral
.map_or(false, |valid_collateral| valid_collateral),
position_size: raw_resp.position_size,
swap_fee: Decimal::from_str(&raw_resp.swap_fee)
.map_or(Decimal::zero(), |swap_fee| swap_fee),
discount: Decimal::from_str(&raw_resp.discount)
.map_or(Decimal::zero(), |discount| discount),
open_price: Decimal::from_str(&raw_resp.open_price)
.map_or(Decimal::zero(), |open_price| open_price),
take_profit_price: SignedDecimal256::from_str(&raw_resp.take_profit_price)
.map_or(SignedDecimal256::zero(), |take_profit_price| {
take_profit_price
}),
liquidation_price: SignedDecimal::from_str(&raw_resp.liquidation_price)
.map_or(SignedDecimal::zero(), |liquidation_price| liquidation_price),
estimated_pnl: raw_resp.estimated_pnl,
estimated_pnl_denom: raw_resp.estimated_pnl_denom,
available_liquidity: raw_resp.available_liquidity,
slippage: Decimal::from_str(&raw_resp.slippage)
.map_or(Decimal::zero(), |slippage| slippage),
weight_balance_ratio: SignedDecimal::from_str(&raw_resp.weight_balance_ratio)
.map_or(SignedDecimal::zero(), |weight_balance_ratio| {
weight_balance_ratio
}),
borrow_interest_rate: SignedDecimal::from_str(&raw_resp.borrow_interest_rate)
.map_or(SignedDecimal::zero(), |borrow_interest_rate| {
borrow_interest_rate
}),
funding_rate: SignedDecimal::from_str(&raw_resp.funding_rate)
.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,
};
let resp: StdResult<PerpetualOpenEstimationResponse> = raw_resp.into();

Ok(resp)
resp
}

pub fn get_all_asset_profile(
Expand Down
52 changes: 47 additions & 5 deletions bindings/src/query_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ pub struct AmmSwapEstimationByDenomResponse {
pub price_impact: SignedDecimal,
pub slippage: Decimal,
}

#[cw_serde]
pub struct PerpetualOpenEstimationRawResponse {
pub position: i32,
pub leverage: String,
pub trading_asset: String,
pub collateral: Coin,
pub min_collateral: Coin,
pub valid_collateral: Option<bool>,
pub interest_amount: Int128,
pub position_size: Coin,
pub swap_fee: String,
pub discount: String,
Expand All @@ -133,8 +131,7 @@ pub struct PerpetualOpenEstimationResponse {
pub leverage: SignedDecimal,
pub trading_asset: String,
pub collateral: Coin,
pub min_collateral: Coin,
pub valid_collateral: bool,
pub interest_amount: Int128,
pub position_size: Coin,
pub swap_fee: Decimal,
pub discount: Decimal,
Expand All @@ -153,6 +150,51 @@ pub struct PerpetualOpenEstimationResponse {
pub funding_fee: Coin,
}

impl Into<StdResult<PerpetualOpenEstimationResponse>> for PerpetualOpenEstimationRawResponse {
fn into(self) -> StdResult<PerpetualOpenEstimationResponse> {
Ok(PerpetualOpenEstimationResponse {
position: PerpetualPosition::try_from_i32(self.position)?,
leverage: SignedDecimal::from_str(&self.leverage)
.map_or(SignedDecimal::zero(), |leverage| leverage),
interest_amount: self.interest_amount,
trading_asset: self.trading_asset,
collateral: self.collateral,
position_size: self.position_size,
swap_fee: Decimal::from_str(&self.swap_fee)
.map_or(Decimal::zero(), |swap_fee| swap_fee),
discount: Decimal::from_str(&self.discount)
.map_or(Decimal::zero(), |discount| discount),
open_price: Decimal::from_str(&self.open_price)
.map_or(Decimal::zero(), |open_price| open_price),
take_profit_price: SignedDecimal256::from_str(&self.take_profit_price)
.map_or(SignedDecimal256::zero(), |take_profit_price| {
take_profit_price
}),
liquidation_price: SignedDecimal::from_str(&self.liquidation_price)
.map_or(SignedDecimal::zero(), |liquidation_price| liquidation_price),
estimated_pnl: self.estimated_pnl,
estimated_pnl_denom: self.estimated_pnl_denom,
available_liquidity: self.available_liquidity,
slippage: Decimal::from_str(&self.slippage)
.map_or(Decimal::zero(), |slippage| slippage),
weight_balance_ratio: SignedDecimal::from_str(&self.weight_balance_ratio)
.map_or(SignedDecimal::zero(), |weight_balance_ratio| {
weight_balance_ratio
}),
borrow_interest_rate: SignedDecimal::from_str(&self.borrow_interest_rate)
.map_or(SignedDecimal::zero(), |borrow_interest_rate| {
borrow_interest_rate
}),
funding_rate: SignedDecimal::from_str(&self.funding_rate)
.map_or(SignedDecimal::zero(), |funding_rate| funding_rate),
price_impact: SignedDecimal::from_str(&self.price_impact)
.map_or(SignedDecimal::zero(), |price_impact| price_impact),
borrow_fee: self.borrow_fee,
funding_fee: self.funding_fee,
})
}
}

#[cw_serde]
pub struct PerpetualGetPositionsForAddressResponseRaw {
pub mtps: Option<Vec<Mtp>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,6 @@ fn create_perpetual_open_order(
get_discount(deps.querier, info.sender.to_string())?,
)?;

if !open_estimation.valid_collateral {
return Err(StdError::generic_err(format!(
"not valid collateral: min collateral: {}",
open_estimation.min_collateral.amount
))
.into());
}

if let Some(price) = &trigger_price {
if price.rate.is_zero() {
return Err(StdError::generic_err("trigger_price: The rate cannot be zero").into());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Int128, SignedDecimal, SignedDecimal256, Uint64};
use cosmwasm_std::{Int128, SignedDecimal, SignedDecimal256};
use elys_bindings::{query_resp::PerpetualGetPositionsForAddressResponse, ElysQuery};

use super::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, Decimal, Int128, SignedDecimal, SignedDecimal256, Uint64};
use cosmwasm_std::{Addr, Decimal, Int128, SignedDecimal, SignedDecimal256};
use elys_bindings::trade_shield::msg::query_resp::GetPerpetualOrderResp;
use std::str::FromStr;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ impl Module for ElysModule {
leverage: leverage.clone().to_string(),
trading_asset: trading_asset.clone(),
collateral: collateral.clone(),
min_collateral: coin(
8333333,
"ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65",
),
valid_collateral: Some(true),
// TODO: Fix
interest_amount: Int128::zero(),
position_size: collateral.clone(),
swap_fee: Decimal::zero().to_string(),
discount: discount.clone().to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::{Addr, SignedDecimal, SignedDecimal256, Uint64};
use cosmwasm_std::{Addr, SignedDecimal, SignedDecimal256};
use std::str::FromStr;

use cosmwasm_std::Int128;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ impl Module for ElysModuleWrapper {
position,
leverage: leverage.to_string(),
trading_asset,
min_collateral: collateral.clone(),
position_size: coin(0, ""),
collateral,
available_liquidity: coin(0, ""),
valid_collateral: Some(true),
// TODO: Fix
interest_amount: Int128::zero(),
swap_fee: Decimal::zero().to_string(),
discount: discount.to_string(),
open_price: Decimal::zero().to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ impl Module for ElysModuleWrapper {
position,
leverage: leverage.to_string(),
trading_asset,
min_collateral: collateral.clone(),
// TODO: Fix
interest_amount: Int128::zero(),
position_size: coin(0, ""),
collateral,
available_liquidity: coin(0, ""),
valid_collateral: Some(true),
swap_fee: Decimal::zero().to_string(),
discount: discount.to_string(),
open_price: Decimal::zero().to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ impl Module for ElysModuleWrapper {
position,
leverage: leverage.to_string(),
trading_asset,
min_collateral: collateral.clone(),
position_size: coin(0, ""),
collateral,
available_liquidity: coin(0, ""),
valid_collateral: Some(true),
// TODO: Fix
interest_amount: Int128::zero(),
swap_fee: Decimal::zero().to_string(),
discount: discount.to_string(),
open_price: Decimal::zero().to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ impl Module for ElysModuleWrapper {
position,
leverage: leverage.to_string(),
trading_asset,
min_collateral: collateral.clone(),
// TODO: Fix
interest_amount: Int128::zero(),
position_size: coin(0, ""),
collateral,
available_liquidity: coin(0, ""),
valid_collateral: Some(true),
swap_fee: Decimal::zero().to_string(),
discount: discount.to_string(),
open_price: Decimal::zero().to_string(),
Expand Down

0 comments on commit c181420

Please sign in to comment.