Skip to content

Commit

Permalink
Add update_tiers() to program
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Aug 30, 2023
1 parent 589afbf commit 20b34c3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/vip/collection/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
/// sum the staked amounts.
pub fn query_total_staked(deps: Deps, owner: String) -> StdResult<Binary> {
// TODO: get all tokens by owner of `address` (token_id)
// TODO: iterate through metdata to get total stake weight
// TODO: iterate through metadata to get total stake weight

todo!()
}
Expand Down
1 change: 1 addition & 0 deletions contracts/vip/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ library = []
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["staking"] }
cosmwasm-storage = { workspace = true }
cw-ownable = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
cw721 = { workspace = true }
Expand Down
31 changes: 23 additions & 8 deletions contracts/vip/program/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128,
};
use cw2::set_contract_version;
use stargaze_vip_collection::state::Metadata;

Expand All @@ -16,12 +18,11 @@ const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

// TODO: add cw_ownable so an admin can update tier limits
cw_ownable::initialize_owner(deps.storage, deps.api, Some(&info.sender.as_str()))?;

COLLECTION.save(deps.storage, &deps.api.addr_validate(&msg.collection)?)?;

Expand All @@ -32,12 +33,26 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut,
deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: ExecuteMsg,
info: MessageInfo,
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::UpdateTiers { tiers } => execute_update_tiers(deps, info, tiers),
}
}

pub fn execute_update_tiers(
deps: DepsMut,
info: MessageInfo,
tiers: Vec<Uint128>,
) -> Result<Response, ContractError> {
unimplemented!()
cw_ownable::assert_owner(deps.storage, &info.sender)
.map_err(|_| ContractError::Unauthorized {})?;
TIERS.save(deps.storage, &tiers)?;

Ok(Response::new())
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
4 changes: 3 additions & 1 deletion contracts/vip/program/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ pub struct InstantiateMsg {
}

#[cw_serde]
pub enum ExecuteMsg {}
pub enum ExecuteMsg {
UpdateTiers { tiers: Vec<Uint128> },
}

#[cw_serde]
#[derive(QueryResponses)]
Expand Down

0 comments on commit 20b34c3

Please sign in to comment.