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

Commit

Permalink
handle negative amount
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptokage1996 committed Sep 27, 2024
1 parent b9518cb commit 31deb54
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 23 deletions.
7 changes: 5 additions & 2 deletions bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use elys_bindings::{
},
query_resp::{
AmmSwapEstimationByDenomResponse, AmmSwapEstimationResponse, AuthAddressesResponse,
BalanceBorrowed, Commitments, Entry, EstakingRewardsResponse,
BalanceBorrowed, CoinNeg, Commitments, Entry, EstakingRewardsResponse,
LeveragelpIsWhitelistedResponse, LeveragelpParams, LeveragelpParamsResponse,
LeveragelpStatusResponse, LeveragelpWhitelistResponse, MasterchefUserPendingRewardResponse,
OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponse, PerpetualMtpResponse,
Expand Down Expand Up @@ -394,7 +394,10 @@ impl Module for ElysModule {
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, "")),
funding_fee: Some(CoinNeg {
amount: Int128::zero(),
denom: "".to_string(),
}),
})?);
}
ElysQuery::AssetProfileEntryAll { .. } => {
Expand Down
25 changes: 22 additions & 3 deletions bindings/src/query_resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ pub struct AmmSwapEstimationByDenomResponse {
pub price_impact: SignedDecimal,
pub slippage: Decimal,
}

#[cw_serde]
pub struct CoinNeg {
pub denom: String,
pub amount: Int128,
}

impl Default for CoinNeg {
fn default() -> Self {
Self {
denom: "".to_string(),
amount: Int128::zero(),
}
}
}

#[cw_serde]
pub struct PerpetualOpenEstimationRawResponse {
pub position: Option<i32>,
Expand All @@ -123,7 +139,7 @@ pub struct PerpetualOpenEstimationRawResponse {
pub funding_rate: Option<String>,
pub price_impact: Option<String>,
pub borrow_fee: Option<Coin>,
pub funding_fee: Option<Coin>,
pub funding_fee: Option<CoinNeg>,
}

#[cw_serde]
Expand All @@ -148,7 +164,7 @@ pub struct PerpetualOpenEstimationResponse {
pub funding_rate: SignedDecimal,
pub price_impact: SignedDecimal,
pub borrow_fee: Coin,
pub funding_fee: Coin,
pub funding_fee: CoinNeg,
}

impl Into<StdResult<PerpetualOpenEstimationResponse>> for PerpetualOpenEstimationRawResponse {
Expand Down Expand Up @@ -193,7 +209,10 @@ impl Into<StdResult<PerpetualOpenEstimationResponse>> for PerpetualOpenEstimatio
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(),
funding_fee: self.funding_fee.unwrap_or(CoinNeg {
denom: "".to_string(),
amount: Int128::zero(),
}),
})
}
}
Expand Down
17 changes: 17 additions & 0 deletions bindings/src/trade_shield/types/fees.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Coin;

use crate::query_resp::CoinNeg;

#[cw_serde]
pub struct Fee {
pub percent: String,
Expand All @@ -15,3 +17,18 @@ impl Default for Fee {
}
}
}

#[cw_serde]
pub struct FeeNeg {
pub percent: String,
pub amount: CoinNeg,
}

impl Default for FeeNeg {
fn default() -> Self {
Self {
percent: "".to_string(),
amount: CoinNeg::default(),
}
}
}
1 change: 1 addition & 0 deletions bindings/src/trade_shield/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use coin_value::CoinValue;
pub use date::Date;
pub use denom::ElysDenom;
pub use fees::Fee;
pub use fees::FeeNeg;
pub use perpetual_assets::{PerpetualAsset, PerpetualAssets};
pub use perpetual_order::PerpetualOrder;
pub use perpetual_order_plus::PerpetualOrderPlus;
Expand Down
8 changes: 4 additions & 4 deletions bindings/src/trade_shield/types/perpetual_order_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cosmwasm_std::{
Storage,
};

use super::{Fee, OrderPrice, PerpetualOrderType, Status};
use super::{fees::FeeNeg, Fee, OrderPrice, PerpetualOrderType, Status};

#[cw_serde]
pub struct PerpetualOrderV2 {
Expand All @@ -25,7 +25,7 @@ pub struct PerpetualOrderV2 {
pub size: Option<DecCoin>,
pub liquidation: Option<SignedDecimal>,
pub borrow_fee: Option<Fee>,
pub funding_fee: Option<Fee>,
pub funding_fee: Option<FeeNeg>,
}

impl PerpetualOrderV2 {
Expand All @@ -42,7 +42,7 @@ impl PerpetualOrderV2 {
size: DecCoin,
liquidation: SignedDecimal,
borrow_fee: Fee,
funding_fee: Fee,
funding_fee: FeeNeg,
) -> StdResult<Self> {
let status = if order_type == &PerpetualOrderType::MarketOpen {
Status::Executed
Expand Down Expand Up @@ -109,7 +109,7 @@ impl PerpetualOrderV2 {
size: Some(DecCoin::new(Decimal256::zero(), "")),
liquidation: Some(SignedDecimal::zero()),
borrow_fee: Some(Fee::default()),
funding_fee: Some(Fee::default()),
funding_fee: Some(FeeNeg::default()),
};

Ok(order)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn create_perpetual_open_order(
percent: open_estimation.borrow_interest_rate.to_string(),
amount: open_estimation.borrow_fee,
},
Fee {
FeeNeg {
percent: open_estimation.funding_rate.to_string(),
amount: open_estimation.funding_fee,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn succesful_cancel_an_order() {
DecCoin::new(Decimal256::zero(), ""),
SignedDecimal::zero(),
Fee::default(),
Fee::default(),
FeeNeg::default(),
)
.unwrap()],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn unauthorize() {
DecCoin::new(Decimal256::zero(), ""),
SignedDecimal::zero(),
Fee::default(),
Fee::default(),
FeeNeg::default(),
)
.unwrap()],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{
use cw_multi_test::{AppResponse, BasicAppBuilder, Module};
use elys_bindings::{
msg_resp::PerpetualOpenResponse,
query_resp::{Entry, PerpetualOpenEstimationRawResponse, QueryGetEntryResponse},
query_resp::{CoinNeg, Entry, PerpetualOpenEstimationRawResponse, QueryGetEntryResponse},
ElysMsg, ElysQuery,
};

Expand Down Expand Up @@ -165,7 +165,7 @@ impl Module for ElysModule {
),
slippage: Some(Decimal::zero().to_string()),
borrow_fee: Some(Coin::default()),
funding_fee: Some(Coin::default()),
funding_fee: Some(CoinNeg::default()),
};

return Ok(to_json_binary(&resp)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn successful_query_message() {
DecCoin::new(Decimal256::zero(), ""),
SignedDecimal::zero(),
Fee::default(),
Fee::default(),
FeeNeg::default(),
)
.unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{
use cw_multi_test::{AppResponse, BasicAppBuilder, ContractWrapper, Executor, Module};
use elys_bindings::msg_resp::PerpetualOpenResponse;
use elys_bindings::query_resp::{
OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
CoinNeg, OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
PerpetualOpenEstimationRawResponse, PerpetualParamsRaw, PerpetualParamsResponseRaw,
QueryGetEntryResponseRaw, QueryGetPriceResponse, RawEntry, TierCalculateDiscountResponse,
};
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Module for ElysModuleWrapper {
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, "")),
funding_fee: Some(CoinNeg::default()),
})?),
//ignoring address here since we only use one user
ElysQuery::PerpetualGetPositionsForAddress { .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{
use cw_multi_test::{AppResponse, BasicAppBuilder, ContractWrapper, Executor, Module};
use elys_bindings::msg_resp::PerpetualOpenResponse;
use elys_bindings::query_resp::{
OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
CoinNeg, OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
PerpetualOpenEstimationRawResponse, PerpetualParamsRaw, PerpetualParamsResponseRaw,
QueryGetEntryResponseRaw, QueryGetPriceResponse, RawEntry, TierCalculateDiscountResponse,
};
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Module for ElysModuleWrapper {
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, "")),
funding_fee: Some(CoinNeg::default()),
})?),
//ignoring address here since we only use one user
ElysQuery::PerpetualGetPositionsForAddress { .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{
use cw_multi_test::{AppResponse, BasicAppBuilder, ContractWrapper, Executor, Module};
use elys_bindings::msg_resp::PerpetualOpenResponse;
use elys_bindings::query_resp::{
OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
CoinNeg, OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
PerpetualOpenEstimationRawResponse, PerpetualParamsRaw, PerpetualParamsResponseRaw,
QueryGetEntryResponseRaw, QueryGetPriceResponse, RawEntry, TierCalculateDiscountResponse,
};
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Module for ElysModuleWrapper {
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, "")),
funding_fee: Some(CoinNeg::default()),
})?),
//ignoring address here since we only use one user
ElysQuery::PerpetualGetPositionsForAddress { .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use cosmwasm_std::{
use cw_multi_test::{AppResponse, BasicAppBuilder, ContractWrapper, Executor, Module};
use elys_bindings::msg_resp::PerpetualOpenResponse;
use elys_bindings::query_resp::{
OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
CoinNeg, OracleAssetInfoResponse, PerpetualGetPositionsForAddressResponseRaw,
PerpetualOpenEstimationRawResponse, PerpetualParamsRaw, PerpetualParamsResponseRaw,
QueryGetEntryResponseRaw, QueryGetPriceResponse, RawEntry, TierCalculateDiscountResponse,
};
Expand Down Expand Up @@ -137,7 +137,7 @@ impl Module for ElysModuleWrapper {
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, "")),
funding_fee: Some(CoinNeg::default()),
})?),
//ignoring address here since we only use one user
ElysQuery::PerpetualGetPositionsForAddress { .. } => {
Expand Down

0 comments on commit 31deb54

Please sign in to comment.