Skip to content

Commit

Permalink
feat(minor-rewards)!: set params per pool (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcobb23 authored Aug 16, 2024
1 parent ff214c3 commit 45df3df
Show file tree
Hide file tree
Showing 11 changed files with 993 additions and 357 deletions.
42 changes: 23 additions & 19 deletions contracts/rewards/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use itertools::Itertools;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{self, Config, Epoch, ParamsSnapshot, PoolId, CONFIG, PARAMS};
use crate::state::{self, Config, PoolId, CONFIG};

mod execute;
mod migrations;
Expand All @@ -24,7 +24,7 @@ pub fn migrate(
_env: Env,
_msg: Empty,
) -> Result<Response, axelar_wasm_std::error::ContractError> {
migrations::v0_4_0::migrate(deps.storage)?;
migrations::v1_0_0::migrate(deps.storage)?;

// any version checks should be done before here

Expand All @@ -36,7 +36,7 @@ pub fn migrate(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
env: Env,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, axelar_wasm_std::error::ContractError> {
Expand All @@ -52,17 +52,6 @@ pub fn instantiate(
},
)?;

PARAMS.save(
deps.storage,
&ParamsSnapshot {
params: msg.params,
created_at: Epoch {
epoch_num: 0,
block_height_started: env.block.height,
},
},
)?;

Ok(Response::new())
}

Expand Down Expand Up @@ -135,11 +124,15 @@ pub fn execute(

Ok(Response::new().add_messages(msgs))
}
ExecuteMsg::UpdateParams { params } => {
execute::update_params(deps.storage, params, env.block.height)?;
ExecuteMsg::UpdatePoolParams { params, pool_id } => {
execute::update_pool_params(deps.storage, &pool_id, params, env.block.height)?;

Ok(Response::new())
}
ExecuteMsg::CreatePool { params, pool_id } => {
execute::create_pool(deps.storage, params, env.block.height, &pool_id)?;
Ok(Response::new())
}
}
}

Expand Down Expand Up @@ -181,7 +174,7 @@ mod tests {
let mut deps = mock_dependencies();

#[allow(deprecated)]
migrations::v0_4_0::tests::instantiate_contract(deps.as_mut(), "denom");
migrations::v1_0_0::tests::instantiate_contract(deps.as_mut(), "denom");

migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();

Expand Down Expand Up @@ -224,7 +217,6 @@ mod tests {
&InstantiateMsg {
governance_address: governance_address.to_string(),
rewards_denom: AXL_DENOMINATION.to_string(),
params: initial_params.clone(),
},
&[],
"Contract",
Expand All @@ -237,6 +229,17 @@ mod tests {
contract: pool_contract.clone(),
};

let res = app.execute_contract(
governance_address.clone(),
contract_address.clone(),
&ExecuteMsg::CreatePool {
params: initial_params.clone(),
pool_id: pool_id.clone(),
},
&[],
);
assert!(res.is_ok());

let rewards = 200;
let res = app.execute_contract(
user.clone(),
Expand All @@ -255,8 +258,9 @@ mod tests {
let res = app.execute_contract(
governance_address,
contract_address.clone(),
&ExecuteMsg::UpdateParams {
&ExecuteMsg::UpdatePoolParams {
params: updated_params.clone(),
pool_id: pool_id.clone(),
},
&[],
);
Expand Down
Loading

0 comments on commit 45df3df

Please sign in to comment.