diff --git a/bindings-test/src/multitest.rs b/bindings-test/src/multitest.rs index ced0e14c..6ca7ee29 100644 --- a/bindings-test/src/multitest.rs +++ b/bindings-test/src/multitest.rs @@ -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, @@ -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 { .. } => { diff --git a/bindings/src/query_resp.rs b/bindings/src/query_resp.rs index b822a3e1..1caeffff 100644 --- a/bindings/src/query_resp.rs +++ b/bindings/src/query_resp.rs @@ -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, @@ -123,7 +139,7 @@ pub struct PerpetualOpenEstimationRawResponse { pub funding_rate: Option, pub price_impact: Option, pub borrow_fee: Option, - pub funding_fee: Option, + pub funding_fee: Option, } #[cw_serde] @@ -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> for PerpetualOpenEstimationRawResponse { @@ -193,7 +209,10 @@ impl Into> 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(), + }), }) } } diff --git a/bindings/src/trade_shield/types/fees.rs b/bindings/src/trade_shield/types/fees.rs index 2cf7f930..5020c2e8 100644 --- a/bindings/src/trade_shield/types/fees.rs +++ b/bindings/src/trade_shield/types/fees.rs @@ -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, @@ -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(), + } + } +} diff --git a/bindings/src/trade_shield/types/mod.rs b/bindings/src/trade_shield/types/mod.rs index 5899ef54..db4025f0 100644 --- a/bindings/src/trade_shield/types/mod.rs +++ b/bindings/src/trade_shield/types/mod.rs @@ -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; diff --git a/bindings/src/trade_shield/types/perpetual_order_v2.rs b/bindings/src/trade_shield/types/perpetual_order_v2.rs index e35fe646..898ffb54 100644 --- a/bindings/src/trade_shield/types/perpetual_order_v2.rs +++ b/bindings/src/trade_shield/types/perpetual_order_v2.rs @@ -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 { @@ -25,7 +25,7 @@ pub struct PerpetualOrderV2 { pub size: Option, pub liquidation: Option, pub borrow_fee: Option, - pub funding_fee: Option, + pub funding_fee: Option, } impl PerpetualOrderV2 { @@ -42,7 +42,7 @@ impl PerpetualOrderV2 { size: DecCoin, liquidation: SignedDecimal, borrow_fee: Fee, - funding_fee: Fee, + funding_fee: FeeNeg, ) -> StdResult { let status = if order_type == &PerpetualOrderType::MarketOpen { Status::Executed @@ -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) diff --git a/contracts/trade-shield-contract/src/action/execute/create_perpetual_order.rs b/contracts/trade-shield-contract/src/action/execute/create_perpetual_order.rs index a66e1428..06aef798 100644 --- a/contracts/trade-shield-contract/src/action/execute/create_perpetual_order.rs +++ b/contracts/trade-shield-contract/src/action/execute/create_perpetual_order.rs @@ -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, }, diff --git a/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/succesful_cancel_an_order.rs b/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/succesful_cancel_an_order.rs index 2108b1fd..683581d8 100644 --- a/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/succesful_cancel_an_order.rs +++ b/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/succesful_cancel_an_order.rs @@ -28,7 +28,7 @@ fn succesful_cancel_an_order() { DecCoin::new(Decimal256::zero(), ""), SignedDecimal::zero(), Fee::default(), - Fee::default(), + FeeNeg::default(), ) .unwrap()], }; diff --git a/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/unauthorize.rs b/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/unauthorize.rs index cc311d8f..22a9a8ec 100644 --- a/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/unauthorize.rs +++ b/contracts/trade-shield-contract/src/tests/cancel_perpetual_order/unauthorize.rs @@ -27,7 +27,7 @@ fn unauthorize() { DecCoin::new(Decimal256::zero(), ""), SignedDecimal::zero(), Fee::default(), - Fee::default(), + FeeNeg::default(), ) .unwrap()], }; diff --git a/contracts/trade-shield-contract/src/tests/create_perpetual_order/reproduce_testnet_issue_create_perpetual_market_open_order.rs b/contracts/trade-shield-contract/src/tests/create_perpetual_order/reproduce_testnet_issue_create_perpetual_market_open_order.rs index c1dde3fc..79435e94 100644 --- a/contracts/trade-shield-contract/src/tests/create_perpetual_order/reproduce_testnet_issue_create_perpetual_market_open_order.rs +++ b/contracts/trade-shield-contract/src/tests/create_perpetual_order/reproduce_testnet_issue_create_perpetual_market_open_order.rs @@ -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, }; @@ -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)?); diff --git a/contracts/trade-shield-contract/src/tests/get_perpetual_order/successful_query_message.rs b/contracts/trade-shield-contract/src/tests/get_perpetual_order/successful_query_message.rs index 4f63ad3d..f1b3c560 100644 --- a/contracts/trade-shield-contract/src/tests/get_perpetual_order/successful_query_message.rs +++ b/contracts/trade-shield-contract/src/tests/get_perpetual_order/successful_query_message.rs @@ -25,7 +25,7 @@ fn successful_query_message() { DecCoin::new(Decimal256::zero(), ""), SignedDecimal::zero(), Fee::default(), - Fee::default(), + FeeNeg::default(), ) .unwrap(); diff --git a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_met.rs b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_met.rs index 312ada87..a5e03d89 100644 --- a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_met.rs +++ b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_met.rs @@ -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, }; @@ -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 { .. } => { diff --git a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_not_met.rs b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_not_met.rs index 4e37d389..8d5bf7a9 100644 --- a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_not_met.rs +++ b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_long_with_price_not_met.rs @@ -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, }; @@ -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 { .. } => { diff --git a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_met.rs b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_met.rs index 99e6c150..4b8f359d 100644 --- a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_met.rs +++ b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_met.rs @@ -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, }; @@ -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 { .. } => { diff --git a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_not_met.rs b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_not_met.rs index 6d095dcc..261460cd 100644 --- a/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_not_met.rs +++ b/contracts/trade-shield-contract/src/tests/process_perpetual_order/pending_limit_open_short_with_price_not_met.rs @@ -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, }; @@ -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 { .. } => {