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

Commit 250d49d

Browse files
Dev 1969 v3 bindings fix (#452)
* fix: remove options * feat: remove min collateral * feat: update interfaces
1 parent 2bdfa8a commit 250d49d

File tree

8 files changed

+239
-228
lines changed

8 files changed

+239
-228
lines changed

bindings-test/src/multitest.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -361,28 +361,28 @@ impl Module for ElysModule {
361361
discount,
362362
} => {
363363
return Ok(to_json_binary(&PerpetualOpenEstimationRawResponse {
364-
position,
365-
available_liquidity: coin(99999999, &trading_asset),
366-
leverage: leverage.to_string(),
367-
collateral,
368-
trading_asset,
369-
discount: discount.to_string(),
370-
// TODO: Fix
371-
interest_amount: Int128::zero(),
372-
position_size: coin(1, "btc"),
373-
swap_fee: Decimal::zero().to_string(),
374-
open_price: Decimal::zero().to_string(),
375-
take_profit_price: take_profit_price.to_string(),
376-
liquidation_price: Decimal::zero().to_string(),
377-
estimated_pnl: Int128::zero(),
378-
estimated_pnl_denom: "uelys".to_string(),
379-
slippage: Decimal::zero().to_string(),
380-
weight_balance_ratio: Decimal::zero().to_string(),
381-
borrow_interest_rate: Decimal::zero().to_string(),
382-
funding_rate: Decimal::zero().to_string(),
383-
price_impact: Decimal::zero().to_string(),
384-
borrow_fee: Coin::new(0, ""),
385-
funding_fee: Coin::new(0, ""),
364+
position: Some(position),
365+
available_liquidity: Some(coin(99999999, &trading_asset)),
366+
leverage: Some(leverage.to_string()),
367+
collateral: Some(collateral),
368+
trading_asset: Some(trading_asset),
369+
discount: Some(discount.to_string()),
370+
// TODO:Fix
371+
interest_amount: Some(Int128::zero()),
372+
position_size: Some(coin(1, "btc")),
373+
swap_fee: Some(Decimal::zero().to_string()),
374+
open_price: Some(Decimal::zero().to_string()),
375+
take_profit_price: Some(take_profit_price.to_string()),
376+
liquidation_price: Some(Decimal::zero().to_string()),
377+
estimated_pnl: Some(Int128::zero()),
378+
estimated_pnl_denom: Some("uelys".to_string()),
379+
slippage: Some(Decimal::zero().to_string()),
380+
weight_balance_ratio: Some(Decimal::zero().to_string()),
381+
borrow_interest_rate: Some(Decimal::zero().to_string()),
382+
funding_rate: Some(Decimal::zero().to_string()),
383+
price_impact: Some(Decimal::zero().to_string()),
384+
borrow_fee: Some(Coin::new(0, "")),
385+
funding_fee: Some(Coin::new(0, "")),
386386
})?);
387387
}
388388
ElysQuery::AssetProfileEntryAll { .. } => {

bindings/src/query_resp.rs

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,27 @@ pub struct AmmSwapEstimationByDenomResponse {
102102
}
103103
#[cw_serde]
104104
pub struct PerpetualOpenEstimationRawResponse {
105-
pub position: i32,
106-
pub leverage: String,
107-
pub trading_asset: String,
108-
pub collateral: Coin,
109-
pub interest_amount: Int128,
110-
pub position_size: Coin,
111-
pub swap_fee: String,
112-
pub discount: String,
113-
pub open_price: String,
114-
pub take_profit_price: String,
115-
pub liquidation_price: String,
116-
pub estimated_pnl: Int128,
117-
pub estimated_pnl_denom: String,
118-
pub available_liquidity: Coin,
119-
pub slippage: String,
120-
pub weight_balance_ratio: String,
121-
pub borrow_interest_rate: String,
122-
pub funding_rate: String,
123-
pub price_impact: String,
124-
pub borrow_fee: Coin,
125-
pub funding_fee: Coin,
105+
pub position: Option<i32>,
106+
pub leverage: Option<String>,
107+
pub trading_asset: Option<String>,
108+
pub collateral: Option<Coin>,
109+
pub interest_amount: Option<Int128>,
110+
pub position_size: Option<Coin>,
111+
pub swap_fee: Option<String>,
112+
pub discount: Option<String>,
113+
pub open_price: Option<String>,
114+
pub take_profit_price: Option<String>,
115+
pub liquidation_price: Option<String>,
116+
pub estimated_pnl: Option<Int128>,
117+
pub estimated_pnl_denom: Option<String>,
118+
pub available_liquidity: Option<Coin>,
119+
pub slippage: Option<String>,
120+
pub weight_balance_ratio: Option<String>,
121+
pub borrow_interest_rate: Option<String>,
122+
pub funding_rate: Option<String>,
123+
pub price_impact: Option<String>,
124+
pub borrow_fee: Option<Coin>,
125+
pub funding_fee: Option<Coin>,
126126
}
127127

128128
#[cw_serde]
@@ -153,44 +153,46 @@ pub struct PerpetualOpenEstimationResponse {
153153
impl Into<StdResult<PerpetualOpenEstimationResponse>> for PerpetualOpenEstimationRawResponse {
154154
fn into(self) -> StdResult<PerpetualOpenEstimationResponse> {
155155
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,
156+
position: PerpetualPosition::try_from_i32(self.position.unwrap_or_default())?,
157+
leverage: SignedDecimal::from_str(self.leverage.unwrap_or_default().as_str())
158+
.unwrap_or_default(),
159+
trading_asset: self.trading_asset.unwrap_or_default(),
160+
collateral: self.collateral.unwrap_or_default(),
161+
interest_amount: self.interest_amount.unwrap_or_default(),
162+
position_size: self.position_size.unwrap_or_default(),
163+
swap_fee: Decimal::from_str(self.swap_fee.unwrap_or_default().as_str())
164+
.unwrap_or_default(),
165+
discount: Decimal::from_str(self.discount.unwrap_or_default().as_str())
166+
.unwrap_or_default(),
167+
open_price: Decimal::from_str(self.open_price.unwrap_or_default().as_str())
168+
.unwrap_or_default(),
169+
take_profit_price: SignedDecimal256::from_str(
170+
self.take_profit_price.unwrap_or_default().as_str(),
171+
)
172+
.unwrap_or_default(),
173+
liquidation_price: SignedDecimal::from_str(
174+
self.liquidation_price.unwrap_or_default().as_str(),
175+
)
176+
.unwrap_or_default(),
177+
estimated_pnl: self.estimated_pnl.unwrap_or_default(),
178+
estimated_pnl_denom: self.estimated_pnl_denom.unwrap_or_default(),
179+
available_liquidity: self.available_liquidity.unwrap_or_default(),
180+
slippage: Decimal::from_str(self.slippage.unwrap_or_default().as_str())
181+
.unwrap_or_default(),
182+
weight_balance_ratio: SignedDecimal::from_str(
183+
self.weight_balance_ratio.unwrap_or_default().as_str(),
184+
)
185+
.unwrap_or_default(),
186+
borrow_interest_rate: SignedDecimal::from_str(
187+
self.borrow_interest_rate.unwrap_or_default().as_str(),
188+
)
189+
.unwrap_or_default(),
190+
funding_rate: SignedDecimal::from_str(self.funding_rate.unwrap_or_default().as_str())
191+
.unwrap_or_default(),
192+
price_impact: SignedDecimal::from_str(self.price_impact.unwrap_or_default().as_str())
193+
.unwrap_or_default(),
194+
borrow_fee: self.borrow_fee.unwrap_or_default(),
195+
funding_fee: self.funding_fee.unwrap_or_default(),
194196
})
195197
}
196198
}
@@ -646,10 +648,10 @@ pub struct LeveragelpParams {
646648
#[cw_serde]
647649
#[derive(Default)]
648650
pub struct PerpetualParamsRaw {
649-
pub option: Option<bool>,
650651
pub leverage_max: Option<Decimal>,
651652
pub borrow_interest_rate_max: Option<Decimal>,
652653
pub borrow_interest_rate_min: Option<Decimal>,
654+
pub min_borrow_interest_amount: Option<Uint128>,
653655
pub borrow_interest_rate_increase: Option<Decimal>,
654656
pub borrow_interest_rate_decrease: Option<Decimal>,
655657
pub health_gain_factor: Option<Decimal>,
@@ -675,10 +677,10 @@ pub struct PerpetualParamsRaw {
675677

676678
#[cw_serde]
677679
pub struct PerpetualParams {
678-
pub option: bool,
679680
pub leverage_max: Decimal,
680681
pub borrow_interest_rate_max: Decimal,
681682
pub borrow_interest_rate_min: Decimal,
683+
pub min_borrow_interest_amount: Uint128,
682684
pub borrow_interest_rate_increase: Decimal,
683685
pub borrow_interest_rate_decrease: Decimal,
684686
pub health_gain_factor: Decimal,
@@ -1264,7 +1266,7 @@ pub struct ParameterParamsResponse {
12641266
impl Into<PerpetualParams> for PerpetualParamsRaw {
12651267
fn into(self) -> PerpetualParams {
12661268
PerpetualParams {
1267-
option: self.option.unwrap_or_default(),
1269+
min_borrow_interest_amount: self.min_borrow_interest_amount.unwrap_or_default(),
12681270
leverage_max: self.leverage_max.unwrap_or_default(),
12691271
borrow_interest_rate_max: self.borrow_interest_rate_max.unwrap_or_default(),
12701272
borrow_interest_rate_min: self.borrow_interest_rate_min.unwrap_or_default(),

bindings/src/types.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -256,36 +256,35 @@ impl FromStr for PerpetualPosition {
256256
})
257257
}
258258
}
259-
260259
#[cw_serde]
261260
pub struct Mtp {
262261
pub address: String,
263-
pub amm_pool_id: u64,
262+
pub collateral_asset: String,
263+
pub trading_asset: String,
264+
pub liabilities_asset: String,
265+
pub custody_asset: String,
266+
pub collateral: Int128,
267+
pub liabilities: Int128,
264268
pub borrow_interest_paid_collateral: Int128,
265269
pub borrow_interest_paid_custody: Int128,
266270
pub borrow_interest_unpaid_collateral: Int128,
267-
pub collateral_asset: String,
268-
pub collateral: Int128,
269-
pub consolidate_leverage: SignedDecimal,
270271
pub custody: Int128,
271-
pub custody_asset: String,
272+
pub take_profit_liabilities: Int128,
273+
pub take_profit_custody: Int128,
274+
pub leverage: SignedDecimal,
275+
pub mtp_health: SignedDecimal,
276+
pub position: i32, // Assuming Position is an enum or struct defined elsewhere
277+
pub id: u64,
278+
pub amm_pool_id: u64,
279+
pub consolidate_leverage: SignedDecimal,
280+
pub sum_collateral: Int128,
281+
pub take_profit_price: SignedDecimal256,
282+
pub take_profit_borrow_rate: SignedDecimal,
272283
pub funding_fee_paid_collateral: Int128,
273284
pub funding_fee_paid_custody: Int128,
274285
pub funding_fee_received_collateral: Int128,
275286
pub funding_fee_received_custody: Int128,
276-
pub id: u64,
277-
pub leverage: SignedDecimal,
278-
pub liabilities: Int128,
279-
pub liabilities_asset: String,
280-
pub mtp_health: SignedDecimal,
281287
pub open_price: SignedDecimal,
282-
pub position: i32,
283-
pub sum_collateral: Int128,
284-
pub take_profit_borrow_rate: SignedDecimal,
285-
pub take_profit_custody: Int128,
286-
pub take_profit_liabilities: Int128,
287-
pub take_profit_price: SignedDecimal256,
288-
pub trading_asset: String,
289288
pub stop_loss_price: SignedDecimal,
290289
pub last_interest_calc_time: Option<u64>,
291290
pub last_interest_calc_block: Option<u64>,

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

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -112,50 +112,60 @@ impl Module for ElysModule {
112112
discount,
113113
} => {
114114
let resp = PerpetualOpenEstimationRawResponse {
115-
position,
116-
leverage: leverage.clone().to_string(),
117-
trading_asset: trading_asset.clone(),
118-
collateral: collateral.clone(),
115+
position: Some(position),
116+
leverage: Some(leverage.clone().to_string()),
117+
trading_asset: Some(trading_asset.clone()),
118+
collateral: Some(collateral.clone()),
119119
// TODO: Fix
120-
interest_amount: Int128::zero(),
121-
position_size: collateral.clone(),
122-
swap_fee: Decimal::zero().to_string(),
123-
discount: discount.clone().to_string(),
124-
open_price: Decimal::from_atomics(Uint128::new(9_440_848_026_817_446_325), 18)
125-
.unwrap()
126-
.to_string(),
127-
take_profit_price: take_profit_price.clone().to_string(),
128-
liquidation_price: Decimal::from_atomics(
129-
Uint128::new(9_240_848_026_817_446_325),
130-
18,
131-
)
132-
.unwrap()
133-
.to_string(),
134-
estimated_pnl: Int128::from_str(
135-
// "4_999_999_999_999_999_999_999_999_999_999_999_999_527_957_598_6",
136-
"4999999999999999999999999999999999999",
137-
)
138-
.unwrap(),
139-
estimated_pnl_denom:
120+
interest_amount: Some(Int128::zero()),
121+
position_size: Some(collateral.clone()),
122+
swap_fee: Some(Decimal::zero().to_string()),
123+
discount: Some(discount.clone().to_string()),
124+
open_price: Some(
125+
Decimal::from_atomics(Uint128::new(9_440_848_026_817_446_325), 18)
126+
.unwrap()
127+
.to_string(),
128+
),
129+
take_profit_price: Some(take_profit_price.clone().to_string()),
130+
liquidation_price: Some(
131+
Decimal::from_atomics(Uint128::new(9_240_848_026_817_446_325), 18)
132+
.unwrap()
133+
.to_string(),
134+
),
135+
estimated_pnl: Some(
136+
Int128::from_str(
137+
// "4_999_999_999_999_999_999_999_999_999_999_999_999_527_957_598_6",
138+
"4999999999999999999999999999999999999",
139+
)
140+
.unwrap(),
141+
),
142+
estimated_pnl_denom: Some(
140143
"ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
141144
.to_string(),
142-
available_liquidity: coin(
145+
),
146+
available_liquidity: Some(coin(
143147
7705931608,
144148
"ibc/E2D2F6ADCC68AA3384B2F5DFACCA437923D137C14E86FB8A10207CF3BED0C8D4",
149+
)),
150+
weight_balance_ratio: Some(Decimal::zero().to_string()),
151+
borrow_interest_rate: Some(
152+
Decimal::from_atomics(Uint128::new(323_793_793_684), 18)
153+
.unwrap()
154+
.to_string(),
155+
),
156+
funding_rate: Some(
157+
Decimal::from_atomics(Uint128::new(1_000_000_000_000_000), 18)
158+
.unwrap()
159+
.to_string(),
160+
),
161+
price_impact: Some(
162+
Decimal::from_atomics(Uint128::new(6_495_303_442_450), 18)
163+
.unwrap()
164+
.to_string(),
145165
),
146-
weight_balance_ratio: Decimal::zero().to_string(),
147-
borrow_interest_rate: Decimal::from_atomics(Uint128::new(323_793_793_684), 18)
148-
.unwrap()
149-
.to_string(),
150-
funding_rate: Decimal::from_atomics(Uint128::new(1_000_000_000_000_000), 18)
151-
.unwrap()
152-
.to_string(),
153-
price_impact: Decimal::from_atomics(Uint128::new(6_495_303_442_450), 18)
154-
.unwrap()
155-
.to_string(),
156-
slippage: Decimal::zero().to_string(),
157-
borrow_fee: Coin::default(),
158-
funding_fee: Coin::default(),
166+
slippage: Some(Decimal::zero().to_string()),
167+
borrow_fee: Some(Coin::default()),
168+
funding_fee: Some(Coin::default()),
159169
};
160170

161171
return Ok(to_json_binary(&resp)?);

0 commit comments

Comments
 (0)