From c1bd4dc8535f22afd07264222cde26c79bc0973d Mon Sep 17 00:00:00 2001 From: cryptokage <26vivek06@gmail.com> Date: Thu, 19 Sep 2024 19:30:09 +0530 Subject: [PATCH] feat: add collateral flow (#446) * feat: add cpllateral flow * fix --- bindings-test/src/multitest.rs | 1 + bindings/src/msg.rs | 21 ++++++++++++++++ bindings/src/trade_shield/msg/execute_msg.rs | 4 ++++ .../execute/add_collateral_perpetual.rs | 24 +++++++++++++++++++ .../trade-shield-contract/src/action/mod.rs | 2 ++ .../src/entry_point/execute.rs | 4 ++++ 6 files changed, 56 insertions(+) create mode 100644 contracts/trade-shield-contract/src/action/execute/add_collateral_perpetual.rs diff --git a/bindings-test/src/multitest.rs b/bindings-test/src/multitest.rs index 93b6623f..9b37ea50 100644 --- a/bindings-test/src/multitest.rs +++ b/bindings-test/src/multitest.rs @@ -1073,6 +1073,7 @@ impl Module for ElysModule { }) } ElysMsg::LeveragelpClaimRewards { .. } => todo!(), + ElysMsg::PerpetualAddCollateral { .. } => todo!(), } } diff --git a/bindings/src/msg.rs b/bindings/src/msg.rs index 4ffa63cd..2757c37d 100644 --- a/bindings/src/msg.rs +++ b/bindings/src/msg.rs @@ -145,6 +145,13 @@ pub enum ElysMsg { sender: String, ids: Vec, }, + + PerpetualAddCollateral { + creator: String, + id: u64, + amount: Uint128, + owner: String, + }, } impl ElysMsg { @@ -397,6 +404,20 @@ impl ElysMsg { pool_ids, } } + + pub fn perpetual_add_collateral( + creator: impl Into, + id: u64, + amount: u128, + owner: impl Into, + ) -> Self { + Self::PerpetualAddCollateral { + creator: creator.into(), + id, + amount: Uint128::new(amount), + owner: owner.into(), + } + } } impl From for CosmosMsg { diff --git a/bindings/src/trade_shield/msg/execute_msg.rs b/bindings/src/trade_shield/msg/execute_msg.rs index 68c3735d..ae51be4a 100644 --- a/bindings/src/trade_shield/msg/execute_msg.rs +++ b/bindings/src/trade_shield/msg/execute_msg.rs @@ -125,4 +125,8 @@ pub enum ExecuteMsg { }, ProcessOrders {}, + + PerpetualAddCollateral { + id: u64, + }, } diff --git a/contracts/trade-shield-contract/src/action/execute/add_collateral_perpetual.rs b/contracts/trade-shield-contract/src/action/execute/add_collateral_perpetual.rs new file mode 100644 index 00000000..27d5fb92 --- /dev/null +++ b/contracts/trade-shield-contract/src/action/execute/add_collateral_perpetual.rs @@ -0,0 +1,24 @@ +use super::*; +use cosmwasm_std::StdError; + +pub fn perpetual_add_collateral( + info: MessageInfo, + deps: DepsMut, + env: Env, + id: u64, +) -> Result, ContractError> { + let collateral = cw_utils::one_coin(&info)?; + if PERPETUAL_ENABLED.load(deps.storage)? == false { + return Err(StdError::generic_err("perpetual endpoint are disable").into()); + } + let msg = ElysMsg::perpetual_add_collateral( + env.contract.address.as_str(), + id, + collateral.amount.into(), + info.sender.as_str(), + ); + + let resp = Response::new().add_message(CosmosMsg::Custom(msg)); + + Ok(resp) +} diff --git a/contracts/trade-shield-contract/src/action/mod.rs b/contracts/trade-shield-contract/src/action/mod.rs index 55184507..fbda863b 100644 --- a/contracts/trade-shield-contract/src/action/mod.rs +++ b/contracts/trade-shield-contract/src/action/mod.rs @@ -42,6 +42,7 @@ pub mod query { } pub mod execute { + mod add_collateral_perpetual; mod cancel_perpetual_order; mod cancel_perpetual_orders; mod cancel_spot_order; @@ -72,6 +73,7 @@ pub mod execute { use super::*; + pub use add_collateral_perpetual::perpetual_add_collateral; pub use cancel_perpetual_order::cancel_perpetual_order; pub use cancel_perpetual_orders::cancel_perpetual_orders; pub use cancel_spot_order::cancel_spot_order; diff --git a/contracts/trade-shield-contract/src/entry_point/execute.rs b/contracts/trade-shield-contract/src/entry_point/execute.rs index b9260026..fb258e65 100644 --- a/contracts/trade-shield-contract/src/entry_point/execute.rs +++ b/contracts/trade-shield-contract/src/entry_point/execute.rs @@ -223,6 +223,10 @@ pub fn execute( let resp = process_orders(deps, env)?; Ok(resp) } + PerpetualAddCollateral { id } => { + let resp = perpetual_add_collateral(info, deps, env, id); + resp + } }?; Ok(resp)