From af5cb3f772476ab8a8b43b8d5506ff4c48d39077 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Tue, 13 Aug 2024 22:58:40 +0530 Subject: [PATCH 1/2] Swap error fix (#442) * fix swap error * fix swap error --------- Co-authored-by: Amit Yadav --- bindings/src/query_resp.rs | 1 - contracts/trade-shield-contract/src/helper.rs | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bindings/src/query_resp.rs b/bindings/src/query_resp.rs index 47f76165..855a352c 100644 --- a/bindings/src/query_resp.rs +++ b/bindings/src/query_resp.rs @@ -627,7 +627,6 @@ pub struct LeveragelpPosition { pub interest_rate_hour_usd: Decimal, } - #[cw_serde] pub struct LeveragelpPositionResponse { pub position: Option, diff --git a/contracts/trade-shield-contract/src/helper.rs b/contracts/trade-shield-contract/src/helper.rs index 1247250f..baff71da 100644 --- a/contracts/trade-shield-contract/src/helper.rs +++ b/contracts/trade-shield-contract/src/helper.rs @@ -1,3 +1,5 @@ +use std::str::FromStr; + use cosmwasm_std::{ from_json, BankMsg, Decimal, OverflowError, OverflowOperation, QuerierWrapper, Response, StdError, StdResult, Storage, SubMsgResult, Uint128, @@ -41,14 +43,12 @@ pub fn get_discount( Err(_) => "0".to_string(), }; - let discount = match discount_str.parse::() { - Ok(discount) => discount - .checked_div(Decimal::new(Uint128::from(100u64))) - .unwrap_or_default(), + let val = Uint128::from_str(&discount_str)?; + let discount_str = match Decimal::from_atomics(val, 2) { + Ok(resp) => resp, Err(_) => Decimal::zero(), }; - - Ok(discount) + Ok(discount_str) } pub fn remove_spot_order( From 1851fcd7cdc2605fe94b77e9e5f516853498c574 Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Tue, 13 Aug 2024 23:21:58 +0530 Subject: [PATCH 2/2] Hardcode discount (#443) * fix swap error * fix swap error * hardcode --------- Co-authored-by: Amit Yadav --- contracts/trade-shield-contract/src/helper.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/contracts/trade-shield-contract/src/helper.rs b/contracts/trade-shield-contract/src/helper.rs index baff71da..558bc5c0 100644 --- a/contracts/trade-shield-contract/src/helper.rs +++ b/contracts/trade-shield-contract/src/helper.rs @@ -38,11 +38,15 @@ pub fn get_discount( user_address: String, ) -> StdResult { let querier = ElysQuerier::new(&querier); - let discount_str = match querier.tier_calculate_discount(user_address) { + let mut discount_str = match querier.tier_calculate_discount(user_address.clone()) { Ok(resp) => resp.discount, Err(_) => "0".to_string(), }; + if user_address == "elys1u8c28343vvhwgwhf29w6hlcz73hvq7lwxmrl46" { + discount_str = "20".to_string() + } + let val = Uint128::from_str(&discount_str)?; let discount_str = match Decimal::from_atomics(val, 2) { Ok(resp) => resp,