From 20b34c3ddcd3b0d39904d49dbf0e155bc0279c41 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Wed, 30 Aug 2023 10:28:54 +0300 Subject: [PATCH] Add update_tiers() to program --- Cargo.lock | 1 + contracts/vip/collection/src/contract.rs | 2 +- contracts/vip/program/Cargo.toml | 1 + contracts/vip/program/src/contract.rs | 31 ++++++++++++++++++------ contracts/vip/program/src/msg.rs | 4 ++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08875b1..213c8de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2227,6 +2227,7 @@ dependencies = [ "cosmwasm-std", "cosmwasm-storage", "cw-multi-test", + "cw-ownable", "cw-storage-plus 1.1.0", "cw2 1.1.0", "cw721 0.18.0", diff --git a/contracts/vip/collection/src/contract.rs b/contracts/vip/collection/src/contract.rs index b6e45a1..84b301f 100644 --- a/contracts/vip/collection/src/contract.rs +++ b/contracts/vip/collection/src/contract.rs @@ -73,7 +73,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { /// sum the staked amounts. pub fn query_total_staked(deps: Deps, owner: String) -> StdResult { // 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!() } diff --git a/contracts/vip/program/Cargo.toml b/contracts/vip/program/Cargo.toml index 4ff8ffe..35a9f7a 100644 --- a/contracts/vip/program/Cargo.toml +++ b/contracts/vip/program/Cargo.toml @@ -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 } diff --git a/contracts/vip/program/src/contract.rs b/contracts/vip/program/src/contract.rs index bed29f9..7f8147b 100644 --- a/contracts/vip/program/src/contract.rs +++ b/contracts/vip/program/src/contract.rs @@ -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; @@ -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 { 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)?)?; @@ -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 { + match msg { + ExecuteMsg::UpdateTiers { tiers } => execute_update_tiers(deps, info, tiers), + } +} + +pub fn execute_update_tiers( + deps: DepsMut, + info: MessageInfo, + tiers: Vec, ) -> Result { - 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)] diff --git a/contracts/vip/program/src/msg.rs b/contracts/vip/program/src/msg.rs index 644bc6f..75e45e0 100644 --- a/contracts/vip/program/src/msg.rs +++ b/contracts/vip/program/src/msg.rs @@ -8,7 +8,9 @@ pub struct InstantiateMsg { } #[cw_serde] -pub enum ExecuteMsg {} +pub enum ExecuteMsg { + UpdateTiers { tiers: Vec }, +} #[cw_serde] #[derive(QueryResponses)]