|
| 1 | +use cosmwasm_std::{ |
| 2 | + entry_point, to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Response, |
| 3 | + StdResult, |
| 4 | +}; |
| 5 | +use cw_storage_plus::Item; |
| 6 | +use schemars::JsonSchema; |
| 7 | +use serde::{Deserialize, Serialize}; |
| 8 | + |
| 9 | +use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg}; |
| 10 | + |
| 11 | +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] |
| 12 | +pub struct State { |
| 13 | + pub redemption_rate: Decimal, |
| 14 | + pub lst_asset_denom: String, |
| 15 | +} |
| 16 | + |
| 17 | +pub const STATE: Item<State> = Item::new("state"); |
| 18 | + |
| 19 | +#[entry_point] |
| 20 | +pub fn instantiate( |
| 21 | + deps: DepsMut, |
| 22 | + _env: Env, |
| 23 | + _info: MessageInfo, |
| 24 | + msg: InstantiateMsg, |
| 25 | +) -> StdResult<Response> { |
| 26 | + let state = State { |
| 27 | + redemption_rate: msg.redemption_rate, |
| 28 | + lst_asset_denom: msg.lst_asset_denom, |
| 29 | + }; |
| 30 | + STATE.save(deps.storage, &state)?; |
| 31 | + Ok(Response::default()) |
| 32 | +} |
| 33 | + |
| 34 | +#[entry_point] |
| 35 | +pub fn execute( |
| 36 | + deps: DepsMut, |
| 37 | + _env: Env, |
| 38 | + _info: MessageInfo, |
| 39 | + msg: ExecuteMsg, |
| 40 | +) -> StdResult<Response> { |
| 41 | + match msg { |
| 42 | + ExecuteMsg::SetRedemptionRate { |
| 43 | + redemption_rate, |
| 44 | + } => { |
| 45 | + STATE.update(deps.storage, |mut state| -> StdResult<_> { |
| 46 | + state.redemption_rate = redemption_rate; |
| 47 | + Ok(state) |
| 48 | + })?; |
| 49 | + Ok(Response::default()) |
| 50 | + } |
| 51 | + ExecuteMsg::SetLstAssetDenom { |
| 52 | + denom, |
| 53 | + } => { |
| 54 | + STATE.update(deps.storage, |mut state| -> StdResult<_> { |
| 55 | + state.lst_asset_denom = denom; |
| 56 | + Ok(state) |
| 57 | + })?; |
| 58 | + Ok(Response::default()) |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +#[entry_point] |
| 64 | +pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> { |
| 65 | + match msg { |
| 66 | + QueryMsg::RedemptionRate {} => { |
| 67 | + let state = STATE.load(deps.storage)?; |
| 68 | + to_json_binary(&state.redemption_rate) |
| 69 | + } |
| 70 | + QueryMsg::GetLstAssetDenom {} => { |
| 71 | + let state = STATE.load(deps.storage)?; |
| 72 | + to_json_binary(&state.lst_asset_denom) |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments