Skip to content

Commit

Permalink
Use new Claims controller in cw4-stake
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Dec 21, 2020
1 parent 610932f commit ec45a73
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
12 changes: 5 additions & 7 deletions contracts/cw4-stake/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use cw_storage_plus::Bound;

use crate::error::ContractError;
use crate::msg::{ClaimsResponse, HandleMsg, InitMsg, QueryMsg, StakedResponse};
use crate::state::{Config, ADMIN, CONFIG, HOOKS, MEMBERS, STAKE, TOTAL};
use cw0::claim::{claim_tokens, create_claim, CLAIMS};
use crate::state::{Config, ADMIN, CLAIMS, CONFIG, HOOKS, MEMBERS, STAKE, TOTAL};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:cw4-stake";
Expand Down Expand Up @@ -126,7 +125,7 @@ pub fn handle_unbond(

// provide them a claim
let cfg = CONFIG.load(deps.storage)?;
create_claim(
CLAIMS.create_claim(
deps.storage,
&sender_raw,
amount,
Expand Down Expand Up @@ -198,7 +197,7 @@ pub fn handle_claim(
info: MessageInfo,
) -> Result<HandleResponse, ContractError> {
let sender_raw = deps.api.canonical_address(&info.sender)?;
let release = claim_tokens(deps.storage, &sender_raw, &env.block, None)?;
let release = CLAIMS.claim_tokens(deps.storage, &sender_raw, &env.block, None)?;
if release.is_zero() {
return Err(ContractError::NothingToClaim {});
}
Expand Down Expand Up @@ -230,7 +229,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
to_binary(&list_members(deps, start_after, limit)?)
}
QueryMsg::TotalWeight {} => to_binary(&query_total_weight(deps)?),
QueryMsg::Claims { address } => to_binary(&query_claims(deps, address)?),
QueryMsg::Claims { address } => to_binary(&CLAIMS.query_claims(deps, address)?),
QueryMsg::Staked { address } => to_binary(&query_staked(deps, address)?),
QueryMsg::Admin {} => to_binary(&ADMIN.query_admin(deps)?),
QueryMsg::Hooks {} => to_binary(&HOOKS.query_hooks(deps)?),
Expand Down Expand Up @@ -304,10 +303,9 @@ mod tests {
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{from_slice, Api, StdError, Storage};
use cw0::claim::Claim;
use cw0::Duration;
use cw4::{member_key, TOTAL_KEY};
use cw_controllers::{AdminError, HookError};
use cw_controllers::{AdminError, Claim, HookError};

const INIT_ADMIN: &str = "juan";
const USER1: &str = "somebody";
Expand Down
7 changes: 1 addition & 6 deletions contracts/cw4-stake/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_std::{Coin, HumanAddr, Uint128};
use cw0::claim::Claim;
use cw0::Duration;
pub use cw_controllers::ClaimsResponse;

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct InitMsg {
Expand Down Expand Up @@ -68,11 +68,6 @@ pub enum QueryMsg {
Hooks {},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ClaimsResponse {
pub claims: Vec<Claim>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct StakedResponse {
pub stake: Coin,
Expand Down
4 changes: 3 additions & 1 deletion contracts/cw4-stake/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use serde::{Deserialize, Serialize};
use cosmwasm_std::Uint128;
use cw0::Duration;
use cw4::TOTAL_KEY;
use cw_controllers::{Admin, Hooks};
use cw_controllers::{Admin, Claims, Hooks};
use cw_storage_plus::{Item, Map, SnapshotMap, Strategy};

pub const CLAIMS: Claims = Claims::new("claims");

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Config {
/// denom of the token to stake
Expand Down

0 comments on commit ec45a73

Please sign in to comment.