Skip to content

Commit

Permalink
feat(dispatcher): Added sudo message for changing "TVL to APR"
Browse files Browse the repository at this point in the history
  • Loading branch information
KirilMihaylov authored and Gancho Manev committed May 25, 2023
1 parent 12910dc commit 65aff6a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
6 changes: 3 additions & 3 deletions contracts/dispatcher/examples/dispatcher_schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rewards_dispatcher::{
msg::{ConfigResponse, ExecuteMsg, InstantiateMsg, QueryMsg},
state::{Config, DispatchLog},
msg::{ConfigResponse, ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg},
state::DispatchLog,
};
use sdk::cosmwasm_schema::{export_schema, schema_for};

Expand All @@ -10,7 +10,7 @@ fn main() {
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(Config), &out_dir);
export_schema(&schema_for!(SudoMsg), &out_dir);
export_schema(&schema_for!(ConfigResponse), &out_dir);
export_schema(&schema_for!(DispatchLog), &out_dir);
}
9 changes: 6 additions & 3 deletions contracts/dispatcher/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ use sdk::{
use timealarms::stub::TimeAlarmsRef;
use versioning::{version, VersionSegment};

use crate::cmd::RewardCalculator;
use crate::{
cmd::Dispatch,
cmd::{Dispatch, RewardCalculator},
msg::{ConfigResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg},
result::ContractResult,
state::{Config, DispatchLog},
Expand Down Expand Up @@ -100,7 +99,11 @@ pub fn execute(
pub fn sudo(deps: DepsMut<'_>, _env: Env, msg: SudoMsg) -> ContractResult<CwResponse> {
match msg {
SudoMsg::Config { cadence_hours } => {
Config::update(deps.storage, cadence_hours).map(|()| response::empty_response())
Config::update_cadence_hours(deps.storage, cadence_hours)
.map(|()| response::empty_response())
}
SudoMsg::Rewards { tvl_to_apr } => {
Config::update_tvl_to_apr(deps.storage, tvl_to_apr).map(|()| response::empty_response())
}
}
}
Expand Down
1 change: 1 addition & 0 deletions contracts/dispatcher/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum ExecuteMsg {
#[serde(rename_all = "snake_case")]
pub enum SudoMsg {
Config { cadence_hours: u16 },
Rewards { tvl_to_apr: RewardScale },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
Expand Down
29 changes: 23 additions & 6 deletions contracts/dispatcher/src/state/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,31 @@ impl Config {
Self::STORAGE.load(storage)
}

pub fn update(storage: &mut dyn Storage, cadence_hours: u16) -> ContractResult<()> {
Self::load(storage)?;

pub fn update_cadence_hours(
storage: &mut dyn Storage,
cadence_hours: u16,
) -> ContractResult<()> {
Self::STORAGE
.update(storage, |mut c| -> Result<Config, ContractError> {
c.cadence_hours = cadence_hours;
.update(storage, |config| -> Result<Config, ContractError> {
Ok(Self {
cadence_hours,
..config
})
})
.map(|_| ())
.map_err(Into::into)
}

Ok(c)
pub fn update_tvl_to_apr(
storage: &mut dyn Storage,
tvl_to_apr: RewardScale,
) -> ContractResult<()> {
Self::STORAGE
.update(storage, |config| -> Result<Config, ContractError> {
Ok(Self {
tvl_to_apr,
..config
})
})
.map(|_| ())
.map_err(Into::into)
Expand Down

0 comments on commit 65aff6a

Please sign in to comment.