Skip to content

Commit

Permalink
Impl SetLiquiditySourcesMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
hu55a1n1 committed Jun 20, 2024
1 parent fcad39e commit 6f5d72e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 10 additions & 6 deletions apps/mtcs/contracts/cw-tee-mtcs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
error::ContractError,
msg::{
execute::{
Cw20Transfer, FaucetMintMsg, SubmitObligationMsg, SubmitObligationsMsg,
SubmitSetoffsMsg,
Cw20Transfer, FaucetMintMsg, SetLiquiditySourcesMsg, SubmitObligationMsg,
SubmitObligationsMsg, SubmitSetoffsMsg,
},
ExecuteMsg, InstantiateMsg, QueryMsg,
},
Expand Down Expand Up @@ -96,7 +96,7 @@ pub fn execute(
for o in obligations {
execute::submit_obligation(deps.branch(), o.ciphertext, o.digest)?;
}
execute::append_liquidity_sources(deps, liquidity_sources)?;
execute::set_liquidity_sources(deps, liquidity_sources)?;
Ok(Response::new())
}
ExecuteMsg::SubmitSetoffs(attested_msg) => {
Expand All @@ -107,6 +107,9 @@ pub fn execute(
execute::submit_setoffs(deps, env, setoffs_enc)
}
ExecuteMsg::InitClearing => execute::init_clearing(deps),
ExecuteMsg::SetLiquiditySources(SetLiquiditySourcesMsg { liquidity_sources }) => {
execute::set_liquidity_sources(deps, liquidity_sources)
}
}
}

Expand Down Expand Up @@ -172,10 +175,10 @@ pub mod execute {
.add_attribute("ciphertext", ciphertext.to_string()))
}

pub fn append_liquidity_sources(
pub fn set_liquidity_sources(
deps: DepsMut,
liquidity_sources: Vec<HexBinary>,
) -> Result<(), ContractError> {
) -> Result<Response, ContractError> {
// validate liquidity sources as public keys
liquidity_sources
.iter()
Expand All @@ -184,11 +187,12 @@ pub mod execute {
// store the liquidity sources
LiquiditySourcesItem::new(&current_epoch_key(LIQUIDITY_SOURCES_KEY, deps.storage)?)
.update(deps.storage, |mut ls| {
ls.clear();
ls.extend(liquidity_sources);
Ok::<_, ContractError>(ls)
})?;

Ok(())
Ok(Response::default())
}

pub fn submit_setoffs(
Expand Down
6 changes: 6 additions & 0 deletions apps/mtcs/contracts/cw-tee-mtcs/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum ExecuteMsg {
SubmitObligations(execute::SubmitObligationsMsg),
SubmitSetoffs(AttestedMsg<execute::SubmitSetoffsMsg>),
InitClearing,
SetLiquiditySources(execute::SetLiquiditySourcesMsg),
}

pub mod execute {
Expand Down Expand Up @@ -82,6 +83,11 @@ pub mod execute {
user_data
}
}

#[cw_serde]
pub struct SetLiquiditySourcesMsg {
pub liquidity_sources: Vec<HexBinary>,
}
}

#[cw_serde]
Expand Down

0 comments on commit 6f5d72e

Please sign in to comment.