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

Commit 2bdfa8a

Browse files
Dev 1969 v2 bindings fix (#451)
* fix: remove options * feat: remove min collateral
1 parent 02f26c5 commit 2bdfa8a

File tree

12 files changed

+65
-76
lines changed

12 files changed

+65
-76
lines changed

bindings-test/src/multitest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,13 +362,13 @@ impl Module for ElysModule {
362362
} => {
363363
return Ok(to_json_binary(&PerpetualOpenEstimationRawResponse {
364364
position,
365-
min_collateral: coin(0, &collateral.denom),
366365
available_liquidity: coin(99999999, &trading_asset),
367366
leverage: leverage.to_string(),
368367
collateral,
369368
trading_asset,
370369
discount: discount.to_string(),
371-
valid_collateral: Some(true),
370+
// TODO: Fix
371+
interest_amount: Int128::zero(),
372372
position_size: coin(1, "btc"),
373373
swap_fee: Decimal::zero().to_string(),
374374
open_price: Decimal::zero().to_string(),
@@ -383,7 +383,7 @@ impl Module for ElysModule {
383383
price_impact: Decimal::zero().to_string(),
384384
borrow_fee: Coin::new(0, ""),
385385
funding_fee: Coin::new(0, ""),
386-
})?)
386+
})?);
387387
}
388388
ElysQuery::AssetProfileEntryAll { .. } => {
389389
let asset_info = ASSET_INFO.load(storage)?;

bindings/src/querier.rs

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -153,51 +153,9 @@ impl<'a> ElysQuerier<'a> {
153153

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

156-
let resp: PerpetualOpenEstimationResponse = PerpetualOpenEstimationResponse {
157-
position: PerpetualPosition::try_from_i32(raw_resp.position)?,
158-
leverage: SignedDecimal::from_str(&raw_resp.leverage)
159-
.map_or(SignedDecimal::zero(), |leverage| leverage),
160-
trading_asset: raw_resp.trading_asset,
161-
collateral: raw_resp.collateral,
162-
min_collateral: raw_resp.min_collateral,
163-
valid_collateral: raw_resp
164-
.valid_collateral
165-
.map_or(false, |valid_collateral| valid_collateral),
166-
position_size: raw_resp.position_size,
167-
swap_fee: Decimal::from_str(&raw_resp.swap_fee)
168-
.map_or(Decimal::zero(), |swap_fee| swap_fee),
169-
discount: Decimal::from_str(&raw_resp.discount)
170-
.map_or(Decimal::zero(), |discount| discount),
171-
open_price: Decimal::from_str(&raw_resp.open_price)
172-
.map_or(Decimal::zero(), |open_price| open_price),
173-
take_profit_price: SignedDecimal256::from_str(&raw_resp.take_profit_price)
174-
.map_or(SignedDecimal256::zero(), |take_profit_price| {
175-
take_profit_price
176-
}),
177-
liquidation_price: SignedDecimal::from_str(&raw_resp.liquidation_price)
178-
.map_or(SignedDecimal::zero(), |liquidation_price| liquidation_price),
179-
estimated_pnl: raw_resp.estimated_pnl,
180-
estimated_pnl_denom: raw_resp.estimated_pnl_denom,
181-
available_liquidity: raw_resp.available_liquidity,
182-
slippage: Decimal::from_str(&raw_resp.slippage)
183-
.map_or(Decimal::zero(), |slippage| slippage),
184-
weight_balance_ratio: SignedDecimal::from_str(&raw_resp.weight_balance_ratio)
185-
.map_or(SignedDecimal::zero(), |weight_balance_ratio| {
186-
weight_balance_ratio
187-
}),
188-
borrow_interest_rate: SignedDecimal::from_str(&raw_resp.borrow_interest_rate)
189-
.map_or(SignedDecimal::zero(), |borrow_interest_rate| {
190-
borrow_interest_rate
191-
}),
192-
funding_rate: SignedDecimal::from_str(&raw_resp.funding_rate)
193-
.map_or(SignedDecimal::zero(), |funding_rate| funding_rate),
194-
price_impact: SignedDecimal::from_str(&raw_resp.price_impact)
195-
.map_or(SignedDecimal::zero(), |price_impact| price_impact),
196-
borrow_fee: raw_resp.borrow_fee,
197-
funding_fee: raw_resp.funding_fee,
198-
};
156+
let resp: StdResult<PerpetualOpenEstimationResponse> = raw_resp.into();
199157

200-
Ok(resp)
158+
resp
201159
}
202160

203161
pub fn get_all_asset_profile(

bindings/src/query_resp.rs

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,13 @@ pub struct AmmSwapEstimationByDenomResponse {
100100
pub price_impact: SignedDecimal,
101101
pub slippage: Decimal,
102102
}
103-
104103
#[cw_serde]
105104
pub struct PerpetualOpenEstimationRawResponse {
106105
pub position: i32,
107106
pub leverage: String,
108107
pub trading_asset: String,
109108
pub collateral: Coin,
110-
pub min_collateral: Coin,
111-
pub valid_collateral: Option<bool>,
109+
pub interest_amount: Int128,
112110
pub position_size: Coin,
113111
pub swap_fee: String,
114112
pub discount: String,
@@ -133,8 +131,7 @@ pub struct PerpetualOpenEstimationResponse {
133131
pub leverage: SignedDecimal,
134132
pub trading_asset: String,
135133
pub collateral: Coin,
136-
pub min_collateral: Coin,
137-
pub valid_collateral: bool,
134+
pub interest_amount: Int128,
138135
pub position_size: Coin,
139136
pub swap_fee: Decimal,
140137
pub discount: Decimal,
@@ -153,6 +150,51 @@ pub struct PerpetualOpenEstimationResponse {
153150
pub funding_fee: Coin,
154151
}
155152

153+
impl Into<StdResult<PerpetualOpenEstimationResponse>> for PerpetualOpenEstimationRawResponse {
154+
fn into(self) -> StdResult<PerpetualOpenEstimationResponse> {
155+
Ok(PerpetualOpenEstimationResponse {
156+
position: PerpetualPosition::try_from_i32(self.position)?,
157+
leverage: SignedDecimal::from_str(&self.leverage)
158+
.map_or(SignedDecimal::zero(), |leverage| leverage),
159+
interest_amount: self.interest_amount,
160+
trading_asset: self.trading_asset,
161+
collateral: self.collateral,
162+
position_size: self.position_size,
163+
swap_fee: Decimal::from_str(&self.swap_fee)
164+
.map_or(Decimal::zero(), |swap_fee| swap_fee),
165+
discount: Decimal::from_str(&self.discount)
166+
.map_or(Decimal::zero(), |discount| discount),
167+
open_price: Decimal::from_str(&self.open_price)
168+
.map_or(Decimal::zero(), |open_price| open_price),
169+
take_profit_price: SignedDecimal256::from_str(&self.take_profit_price)
170+
.map_or(SignedDecimal256::zero(), |take_profit_price| {
171+
take_profit_price
172+
}),
173+
liquidation_price: SignedDecimal::from_str(&self.liquidation_price)
174+
.map_or(SignedDecimal::zero(), |liquidation_price| liquidation_price),
175+
estimated_pnl: self.estimated_pnl,
176+
estimated_pnl_denom: self.estimated_pnl_denom,
177+
available_liquidity: self.available_liquidity,
178+
slippage: Decimal::from_str(&self.slippage)
179+
.map_or(Decimal::zero(), |slippage| slippage),
180+
weight_balance_ratio: SignedDecimal::from_str(&self.weight_balance_ratio)
181+
.map_or(SignedDecimal::zero(), |weight_balance_ratio| {
182+
weight_balance_ratio
183+
}),
184+
borrow_interest_rate: SignedDecimal::from_str(&self.borrow_interest_rate)
185+
.map_or(SignedDecimal::zero(), |borrow_interest_rate| {
186+
borrow_interest_rate
187+
}),
188+
funding_rate: SignedDecimal::from_str(&self.funding_rate)
189+
.map_or(SignedDecimal::zero(), |funding_rate| funding_rate),
190+
price_impact: SignedDecimal::from_str(&self.price_impact)
191+
.map_or(SignedDecimal::zero(), |price_impact| price_impact),
192+
borrow_fee: self.borrow_fee,
193+
funding_fee: self.funding_fee,
194+
})
195+
}
196+
}
197+
156198
#[cw_serde]
157199
pub struct PerpetualGetPositionsForAddressResponseRaw {
158200
pub mtps: Option<Vec<Mtp>>,

contracts/trade-shield-contract/src/action/execute/create_perpetual_order.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ fn create_perpetual_open_order(
148148
get_discount(deps.querier, info.sender.to_string())?,
149149
)?;
150150

151-
if !open_estimation.valid_collateral {
152-
return Err(StdError::generic_err(format!(
153-
"not valid collateral: min collateral: {}",
154-
open_estimation.min_collateral.amount
155-
))
156-
.into());
157-
}
158-
159151
if let Some(price) = &trigger_price {
160152
if price.rate.is_zero() {
161153
return Err(StdError::generic_err("trigger_price: The rate cannot be zero").into());

contracts/trade-shield-contract/src/tests/close_perpetual_position/closing_a_perpetual_position.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{Int128, SignedDecimal, SignedDecimal256, Uint64};
1+
use cosmwasm_std::{Int128, SignedDecimal, SignedDecimal256};
22
use elys_bindings::{query_resp::PerpetualGetPositionsForAddressResponse, ElysQuery};
33

44
use super::*;

contracts/trade-shield-contract/src/tests/create_perpetual_order/change_trigger_price.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{Addr, Decimal, Int128, SignedDecimal, SignedDecimal256, Uint64};
1+
use cosmwasm_std::{Addr, Decimal, Int128, SignedDecimal, SignedDecimal256};
22
use elys_bindings::trade_shield::msg::query_resp::GetPerpetualOrderResp;
33
use std::str::FromStr;
44

contracts/trade-shield-contract/src/tests/create_perpetual_order/reproduce_testnet_issue_create_perpetual_market_open_order.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,8 @@ impl Module for ElysModule {
116116
leverage: leverage.clone().to_string(),
117117
trading_asset: trading_asset.clone(),
118118
collateral: collateral.clone(),
119-
min_collateral: coin(
120-
8333333,
121-
"ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65",
122-
),
123-
valid_collateral: Some(true),
119+
// TODO: Fix
120+
interest_amount: Int128::zero(),
124121
position_size: collateral.clone(),
125122
swap_fee: Decimal::zero().to_string(),
126123
discount: discount.clone().to_string(),

contracts/trade-shield-contract/src/tests/create_perpetual_order/successful_create_perpetual_market_close.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cosmwasm_std::{Addr, SignedDecimal, SignedDecimal256, Uint64};
1+
use cosmwasm_std::{Addr, SignedDecimal, SignedDecimal256};
22
use std::str::FromStr;
33

44
use cosmwasm_std::Int128;

contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_met.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ impl Module for ElysModuleWrapper {
117117
position,
118118
leverage: leverage.to_string(),
119119
trading_asset,
120-
min_collateral: collateral.clone(),
121120
position_size: coin(0, ""),
122121
collateral,
123122
available_liquidity: coin(0, ""),
124-
valid_collateral: Some(true),
123+
// TODO: Fix
124+
interest_amount: Int128::zero(),
125125
swap_fee: Decimal::zero().to_string(),
126126
discount: discount.to_string(),
127127
open_price: Decimal::zero().to_string(),

contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_not_met.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ impl Module for ElysModuleWrapper {
117117
position,
118118
leverage: leverage.to_string(),
119119
trading_asset,
120-
min_collateral: collateral.clone(),
120+
// TODO: Fix
121+
interest_amount: Int128::zero(),
121122
position_size: coin(0, ""),
122123
collateral,
123124
available_liquidity: coin(0, ""),
124-
valid_collateral: Some(true),
125125
swap_fee: Decimal::zero().to_string(),
126126
discount: discount.to_string(),
127127
open_price: Decimal::zero().to_string(),

0 commit comments

Comments
 (0)