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

Dev 1969 v3 bindings fix #452

Merged
merged 4 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,28 +361,28 @@ impl Module for ElysModule {
discount,
} => {
return Ok(to_json_binary(&PerpetualOpenEstimationRawResponse {
position,
available_liquidity: coin(99999999, &trading_asset),
leverage: leverage.to_string(),
collateral,
trading_asset,
discount: discount.to_string(),
// TODO: Fix
interest_amount: Int128::zero(),
position_size: coin(1, "btc"),
swap_fee: Decimal::zero().to_string(),
open_price: Decimal::zero().to_string(),
take_profit_price: take_profit_price.to_string(),
liquidation_price: Decimal::zero().to_string(),
estimated_pnl: Int128::zero(),
estimated_pnl_denom: "uelys".to_string(),
slippage: Decimal::zero().to_string(),
weight_balance_ratio: Decimal::zero().to_string(),
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, ""),
position: Some(position),
available_liquidity: Some(coin(99999999, &trading_asset)),
leverage: Some(leverage.to_string()),
collateral: Some(collateral),
trading_asset: Some(trading_asset),
discount: Some(discount.to_string()),
// TODO:Fix
interest_amount: Some(Int128::zero()),
position_size: Some(coin(1, "btc")),
swap_fee: Some(Decimal::zero().to_string()),
open_price: Some(Decimal::zero().to_string()),
take_profit_price: Some(take_profit_price.to_string()),
liquidation_price: Some(Decimal::zero().to_string()),
estimated_pnl: Some(Int128::zero()),
estimated_pnl_denom: Some("uelys".to_string()),
slippage: Some(Decimal::zero().to_string()),
weight_balance_ratio: Some(Decimal::zero().to_string()),
borrow_interest_rate: Some(Decimal::zero().to_string()),
funding_rate: Some(Decimal::zero().to_string()),
price_impact: Some(Decimal::zero().to_string()),
borrow_fee: Some(Coin::new(0, "")),
funding_fee: Some(Coin::new(0, "")),
})?);
}
ElysQuery::AssetProfileEntryAll { .. } => {
Expand Down
126 changes: 64 additions & 62 deletions bindings/src/query_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,27 @@ pub struct AmmSwapEstimationByDenomResponse {
}
#[cw_serde]
pub struct PerpetualOpenEstimationRawResponse {
pub position: i32,
pub leverage: String,
pub trading_asset: String,
pub collateral: Coin,
pub interest_amount: Int128,
pub position_size: Coin,
pub swap_fee: String,
pub discount: String,
pub open_price: String,
pub take_profit_price: String,
pub liquidation_price: String,
pub estimated_pnl: Int128,
pub estimated_pnl_denom: String,
pub available_liquidity: Coin,
pub slippage: String,
pub weight_balance_ratio: String,
pub borrow_interest_rate: String,
pub funding_rate: String,
pub price_impact: String,
pub borrow_fee: Coin,
pub funding_fee: Coin,
pub position: Option<i32>,
pub leverage: Option<String>,
pub trading_asset: Option<String>,
pub collateral: Option<Coin>,
pub interest_amount: Option<Int128>,
pub position_size: Option<Coin>,
pub swap_fee: Option<String>,
pub discount: Option<String>,
pub open_price: Option<String>,
pub take_profit_price: Option<String>,
pub liquidation_price: Option<String>,
pub estimated_pnl: Option<Int128>,
pub estimated_pnl_denom: Option<String>,
pub available_liquidity: Option<Coin>,
pub slippage: Option<String>,
pub weight_balance_ratio: Option<String>,
pub borrow_interest_rate: Option<String>,
pub funding_rate: Option<String>,
pub price_impact: Option<String>,
pub borrow_fee: Option<Coin>,
pub funding_fee: Option<Coin>,
}

#[cw_serde]
Expand Down Expand Up @@ -153,44 +153,46 @@ pub struct PerpetualOpenEstimationResponse {
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,
position: PerpetualPosition::try_from_i32(self.position.unwrap_or_default())?,
leverage: SignedDecimal::from_str(self.leverage.unwrap_or_default().as_str())
.unwrap_or_default(),
trading_asset: self.trading_asset.unwrap_or_default(),
collateral: self.collateral.unwrap_or_default(),
interest_amount: self.interest_amount.unwrap_or_default(),
position_size: self.position_size.unwrap_or_default(),
swap_fee: Decimal::from_str(self.swap_fee.unwrap_or_default().as_str())
.unwrap_or_default(),
discount: Decimal::from_str(self.discount.unwrap_or_default().as_str())
.unwrap_or_default(),
open_price: Decimal::from_str(self.open_price.unwrap_or_default().as_str())
.unwrap_or_default(),
take_profit_price: SignedDecimal256::from_str(
self.take_profit_price.unwrap_or_default().as_str(),
)
.unwrap_or_default(),
liquidation_price: SignedDecimal::from_str(
self.liquidation_price.unwrap_or_default().as_str(),
)
.unwrap_or_default(),
estimated_pnl: self.estimated_pnl.unwrap_or_default(),
estimated_pnl_denom: self.estimated_pnl_denom.unwrap_or_default(),
available_liquidity: self.available_liquidity.unwrap_or_default(),
slippage: Decimal::from_str(self.slippage.unwrap_or_default().as_str())
.unwrap_or_default(),
weight_balance_ratio: SignedDecimal::from_str(
self.weight_balance_ratio.unwrap_or_default().as_str(),
)
.unwrap_or_default(),
borrow_interest_rate: SignedDecimal::from_str(
self.borrow_interest_rate.unwrap_or_default().as_str(),
)
.unwrap_or_default(),
funding_rate: SignedDecimal::from_str(self.funding_rate.unwrap_or_default().as_str())
.unwrap_or_default(),
price_impact: SignedDecimal::from_str(self.price_impact.unwrap_or_default().as_str())
.unwrap_or_default(),
borrow_fee: self.borrow_fee.unwrap_or_default(),
funding_fee: self.funding_fee.unwrap_or_default(),
})
}
}
Expand Down Expand Up @@ -646,10 +648,10 @@ pub struct LeveragelpParams {
#[cw_serde]
#[derive(Default)]
pub struct PerpetualParamsRaw {
pub option: Option<bool>,
pub leverage_max: Option<Decimal>,
pub borrow_interest_rate_max: Option<Decimal>,
pub borrow_interest_rate_min: Option<Decimal>,
pub min_borrow_interest_amount: Option<Uint128>,
pub borrow_interest_rate_increase: Option<Decimal>,
pub borrow_interest_rate_decrease: Option<Decimal>,
pub health_gain_factor: Option<Decimal>,
Expand All @@ -675,10 +677,10 @@ pub struct PerpetualParamsRaw {

#[cw_serde]
pub struct PerpetualParams {
pub option: bool,
pub leverage_max: Decimal,
pub borrow_interest_rate_max: Decimal,
pub borrow_interest_rate_min: Decimal,
pub min_borrow_interest_amount: Uint128,
pub borrow_interest_rate_increase: Decimal,
pub borrow_interest_rate_decrease: Decimal,
pub health_gain_factor: Decimal,
Expand Down Expand Up @@ -1264,7 +1266,7 @@ pub struct ParameterParamsResponse {
impl Into<PerpetualParams> for PerpetualParamsRaw {
fn into(self) -> PerpetualParams {
PerpetualParams {
option: self.option.unwrap_or_default(),
min_borrow_interest_amount: self.min_borrow_interest_amount.unwrap_or_default(),
leverage_max: self.leverage_max.unwrap_or_default(),
borrow_interest_rate_max: self.borrow_interest_rate_max.unwrap_or_default(),
borrow_interest_rate_min: self.borrow_interest_rate_min.unwrap_or_default(),
Expand Down
35 changes: 17 additions & 18 deletions bindings/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,36 +256,35 @@ impl FromStr for PerpetualPosition {
})
}
}

#[cw_serde]
pub struct Mtp {
pub address: String,
pub amm_pool_id: u64,
pub collateral_asset: String,
pub trading_asset: String,
pub liabilities_asset: String,
pub custody_asset: String,
pub collateral: Int128,
pub liabilities: Int128,
pub borrow_interest_paid_collateral: Int128,
pub borrow_interest_paid_custody: Int128,
pub borrow_interest_unpaid_collateral: Int128,
pub collateral_asset: String,
pub collateral: Int128,
pub consolidate_leverage: SignedDecimal,
pub custody: Int128,
pub custody_asset: String,
pub take_profit_liabilities: Int128,
pub take_profit_custody: Int128,
pub leverage: SignedDecimal,
pub mtp_health: SignedDecimal,
pub position: i32, // Assuming Position is an enum or struct defined elsewhere
pub id: u64,
pub amm_pool_id: u64,
pub consolidate_leverage: SignedDecimal,
pub sum_collateral: Int128,
pub take_profit_price: SignedDecimal256,
pub take_profit_borrow_rate: SignedDecimal,
pub funding_fee_paid_collateral: Int128,
pub funding_fee_paid_custody: Int128,
pub funding_fee_received_collateral: Int128,
pub funding_fee_received_custody: Int128,
pub id: u64,
pub leverage: SignedDecimal,
pub liabilities: Int128,
pub liabilities_asset: String,
pub mtp_health: SignedDecimal,
pub open_price: SignedDecimal,
pub position: i32,
pub sum_collateral: Int128,
pub take_profit_borrow_rate: SignedDecimal,
pub take_profit_custody: Int128,
pub take_profit_liabilities: Int128,
pub take_profit_price: SignedDecimal256,
pub trading_asset: String,
pub stop_loss_price: SignedDecimal,
pub last_interest_calc_time: Option<u64>,
pub last_interest_calc_block: Option<u64>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,50 +112,60 @@ impl Module for ElysModule {
discount,
} => {
let resp = PerpetualOpenEstimationRawResponse {
position,
leverage: leverage.clone().to_string(),
trading_asset: trading_asset.clone(),
collateral: collateral.clone(),
position: Some(position),
leverage: Some(leverage.clone().to_string()),
trading_asset: Some(trading_asset.clone()),
collateral: Some(collateral.clone()),
// TODO: Fix
interest_amount: Int128::zero(),
position_size: collateral.clone(),
swap_fee: Decimal::zero().to_string(),
discount: discount.clone().to_string(),
open_price: Decimal::from_atomics(Uint128::new(9_440_848_026_817_446_325), 18)
.unwrap()
.to_string(),
take_profit_price: take_profit_price.clone().to_string(),
liquidation_price: Decimal::from_atomics(
Uint128::new(9_240_848_026_817_446_325),
18,
)
.unwrap()
.to_string(),
estimated_pnl: Int128::from_str(
// "4_999_999_999_999_999_999_999_999_999_999_999_999_527_957_598_6",
"4999999999999999999999999999999999999",
)
.unwrap(),
estimated_pnl_denom:
interest_amount: Some(Int128::zero()),
position_size: Some(collateral.clone()),
swap_fee: Some(Decimal::zero().to_string()),
discount: Some(discount.clone().to_string()),
open_price: Some(
Decimal::from_atomics(Uint128::new(9_440_848_026_817_446_325), 18)
.unwrap()
.to_string(),
),
take_profit_price: Some(take_profit_price.clone().to_string()),
liquidation_price: Some(
Decimal::from_atomics(Uint128::new(9_240_848_026_817_446_325), 18)
.unwrap()
.to_string(),
),
estimated_pnl: Some(
Int128::from_str(
// "4_999_999_999_999_999_999_999_999_999_999_999_999_527_957_598_6",
"4999999999999999999999999999999999999",
)
.unwrap(),
),
estimated_pnl_denom: Some(
"ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
.to_string(),
available_liquidity: coin(
),
available_liquidity: Some(coin(
7705931608,
"ibc/E2D2F6ADCC68AA3384B2F5DFACCA437923D137C14E86FB8A10207CF3BED0C8D4",
)),
weight_balance_ratio: Some(Decimal::zero().to_string()),
borrow_interest_rate: Some(
Decimal::from_atomics(Uint128::new(323_793_793_684), 18)
.unwrap()
.to_string(),
),
funding_rate: Some(
Decimal::from_atomics(Uint128::new(1_000_000_000_000_000), 18)
.unwrap()
.to_string(),
),
price_impact: Some(
Decimal::from_atomics(Uint128::new(6_495_303_442_450), 18)
.unwrap()
.to_string(),
),
weight_balance_ratio: Decimal::zero().to_string(),
borrow_interest_rate: Decimal::from_atomics(Uint128::new(323_793_793_684), 18)
.unwrap()
.to_string(),
funding_rate: Decimal::from_atomics(Uint128::new(1_000_000_000_000_000), 18)
.unwrap()
.to_string(),
price_impact: Decimal::from_atomics(Uint128::new(6_495_303_442_450), 18)
.unwrap()
.to_string(),
slippage: Decimal::zero().to_string(),
borrow_fee: Coin::default(),
funding_fee: Coin::default(),
slippage: Some(Decimal::zero().to_string()),
borrow_fee: Some(Coin::default()),
funding_fee: Some(Coin::default()),
};

return Ok(to_json_binary(&resp)?);
Expand Down
Loading
Loading