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

Commit

Permalink
feat: add collateral flow (#446)
Browse files Browse the repository at this point in the history
* feat: add cpllateral flow

* fix
  • Loading branch information
cryptokage1996 authored Sep 19, 2024
1 parent 613af4c commit c1bd4dc
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ impl Module for ElysModule {
})
}
ElysMsg::LeveragelpClaimRewards { .. } => todo!(),
ElysMsg::PerpetualAddCollateral { .. } => todo!(),
}
}

Expand Down
21 changes: 21 additions & 0 deletions bindings/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ pub enum ElysMsg {
sender: String,
ids: Vec<u64>,
},

PerpetualAddCollateral {
creator: String,
id: u64,
amount: Uint128,
owner: String,
},
}

impl ElysMsg {
Expand Down Expand Up @@ -397,6 +404,20 @@ impl ElysMsg {
pool_ids,
}
}

pub fn perpetual_add_collateral(
creator: impl Into<String>,
id: u64,
amount: u128,
owner: impl Into<String>,
) -> Self {
Self::PerpetualAddCollateral {
creator: creator.into(),
id,
amount: Uint128::new(amount),
owner: owner.into(),
}
}
}

impl From<ElysMsg> for CosmosMsg<ElysMsg> {
Expand Down
4 changes: 4 additions & 0 deletions bindings/src/trade_shield/msg/execute_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ pub enum ExecuteMsg {
},

ProcessOrders {},

PerpetualAddCollateral {
id: u64,
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use super::*;
use cosmwasm_std::StdError;

pub fn perpetual_add_collateral(
info: MessageInfo,
deps: DepsMut<ElysQuery>,
env: Env,
id: u64,
) -> Result<Response<ElysMsg>, 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)
}
2 changes: 2 additions & 0 deletions contracts/trade-shield-contract/src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions contracts/trade-shield-contract/src/entry_point/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c1bd4dc

Please sign in to comment.