From e619e420407b930cbdb1c17ffd2f061fe11d6aec Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 19:10:22 -0500 Subject: [PATCH 01/16] Remove duplicate members --- contracts/whitelist/src/contract.rs | 29 ++++++++++++++++++++++++++++- contracts/whitelist/src/msg.rs | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 63c1dca1a..97137ad28 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -32,7 +32,7 @@ pub fn instantiate( deps: DepsMut, env: Env, info: MessageInfo, - msg: InstantiateMsg, + mut msg: InstantiateMsg, ) -> Result { set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; @@ -57,6 +57,10 @@ pub fn instantiate( }); } + // remove duplicate members + msg.members.sort_unstable(); + msg.members.dedup(); + let config = Config { admin: info.sender.clone(), start_time: msg.start_time, @@ -67,6 +71,8 @@ pub fn instantiate( }; CONFIG.save(deps.storage, &config)?; + println!("{:?}", config); + if msg.start_time > msg.end_time { return Err(ContractError::InvalidStartTime( msg.start_time, @@ -296,6 +302,7 @@ fn query_has_member(deps: Deps, member: String) -> StdResult fn query_config(deps: Deps, env: Env) -> StdResult { let config = CONFIG.load(deps.storage)?; Ok(ConfigResponse { + num_members: config.num_members, per_address_limit: config.per_address_limit, start_time: config.start_time, end_time: config.end_time, @@ -353,6 +360,26 @@ mod tests { instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err(); } + #[test] + fn improper_initialization_dedup() { + let mut deps = mock_dependencies(); + let msg = InstantiateMsg { + members: vec![ + "adsfsa".to_string(), + "adsfsa".to_string(), + "adsfsa".to_string(), + ], + start_time: NON_EXPIRED_HEIGHT, + end_time: NON_EXPIRED_HEIGHT, + unit_price: coin(UNIT_AMOUNT, NATIVE_DENOM), + per_address_limit: 1, + }; + let info = mock_info(ADMIN, &[coin(100_000_000, "ustars")]); + let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); + let res = query_config(deps.as_ref(), mock_env()).unwrap(); + assert_eq!(1, res.num_members); + } + #[test] fn check_start_time_after_end_time() { let msg = InstantiateMsg { diff --git a/contracts/whitelist/src/msg.rs b/contracts/whitelist/src/msg.rs index 8f1b92197..e92b96a24 100644 --- a/contracts/whitelist/src/msg.rs +++ b/contracts/whitelist/src/msg.rs @@ -78,6 +78,7 @@ pub struct UnitPriceResponse { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] pub struct ConfigResponse { + pub num_members: u32, pub per_address_limit: u32, pub start_time: Expiration, pub end_time: Expiration, From 99691f47cb5cefe1c280ba0043542588e8f4cef9 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 19:33:37 -0500 Subject: [PATCH 02/16] Consolidate whitelist queries --- contracts/whitelist/src/contract.rs | 41 +++++------------------------ contracts/whitelist/src/msg.rs | 4 --- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 97137ad28..192bc1334 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -10,8 +10,7 @@ use sg_std::StargazeMsgWrapper; use crate::error::ContractError; use crate::msg::{ ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, HasStartedResponse, - InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg, TimeResponse, UnitPriceResponse, - UpdateMembersMsg, + InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg, UpdateMembersMsg, }; use crate::state::{Config, CONFIG, WHITELIST}; @@ -227,39 +226,15 @@ pub fn execute_update_per_address_limit( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::StartTime {} => to_binary(&query_start_time(deps)?), - QueryMsg::EndTime {} => to_binary(&query_end_time(deps)?), QueryMsg::Members {} => to_binary(&query_members(deps)?), QueryMsg::HasStarted {} => to_binary(&query_has_started(deps, env)?), QueryMsg::HasEnded {} => to_binary(&query_has_ended(deps, env)?), QueryMsg::IsActive {} => to_binary(&query_is_active(deps, env)?), QueryMsg::HasMember { member } => to_binary(&query_has_member(deps, member)?), - QueryMsg::UnitPrice {} => to_binary(&query_unit_price(deps)?), - QueryMsg::Config {} => to_binary(&query_config(deps, env)?), + QueryMsg::Config {} => to_binary(&query_config(deps)?), } } -fn query_unit_price(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; - Ok(UnitPriceResponse { - unit_price: config.unit_price, - }) -} - -fn query_start_time(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; - Ok(TimeResponse { - time: config.start_time, - }) -} - -fn query_end_time(deps: Deps) -> StdResult { - let config = CONFIG.load(deps.storage)?; - Ok(TimeResponse { - time: config.end_time, - }) -} - fn query_has_started(deps: Deps, env: Env) -> StdResult { let config = CONFIG.load(deps.storage)?; Ok(HasStartedResponse { @@ -299,7 +274,7 @@ fn query_has_member(deps: Deps, member: String) -> StdResult }) } -fn query_config(deps: Deps, env: Env) -> StdResult { +fn query_config(deps: Deps) -> StdResult { let config = CONFIG.load(deps.storage)?; Ok(ConfigResponse { num_members: config.num_members, @@ -307,8 +282,6 @@ fn query_config(deps: Deps, env: Env) -> StdResult { start_time: config.start_time, end_time: config.end_time, unit_price: config.unit_price, - is_active: config.start_time.is_expired(&env.block) - && !config.end_time.is_expired(&env.block), }) } @@ -376,7 +349,7 @@ mod tests { }; let info = mock_info(ADMIN, &[coin(100_000_000, "ustars")]); let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - let res = query_config(deps.as_ref(), mock_env()).unwrap(); + let res = query_config(deps.as_ref()).unwrap(); assert_eq!(1, res.num_members); } @@ -403,8 +376,8 @@ mod tests { let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); assert_eq!(res.attributes.len(), 3); - let res = query_end_time(deps.as_ref()).unwrap(); - assert_eq!(res.time, Expiration::AtHeight(10)); + let res = query_config(deps.as_ref()).unwrap(); + assert_eq!(res.end_time, Expiration::AtHeight(10)); } #[test] @@ -471,7 +444,7 @@ mod tests { let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); assert_eq!(res.attributes.len(), 2); - let wl_config: ConfigResponse = query_config(deps.as_ref(), mock_env()).unwrap(); + let wl_config: ConfigResponse = query_config(deps.as_ref()).unwrap(); assert_eq!(wl_config.per_address_limit, per_address_limit); } } diff --git a/contracts/whitelist/src/msg.rs b/contracts/whitelist/src/msg.rs index e92b96a24..dda361b41 100644 --- a/contracts/whitelist/src/msg.rs +++ b/contracts/whitelist/src/msg.rs @@ -30,14 +30,11 @@ pub struct UpdateMembersMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - StartTime {}, - EndTime {}, HasStarted {}, HasEnded {}, IsActive {}, Members {}, HasMember { member: String }, - UnitPrice {}, Config {}, } @@ -83,5 +80,4 @@ pub struct ConfigResponse { pub start_time: Expiration, pub end_time: Expiration, pub unit_price: Coin, - pub is_active: bool, } From 07cad038c2bcdc38c5d2c1349b9399bb4f663459 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 19:42:54 -0500 Subject: [PATCH 03/16] Fixed minter tests --- contracts/minter/src/contract.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/contracts/minter/src/contract.rs b/contracts/minter/src/contract.rs index 7cd20271f..c4915a2f1 100644 --- a/contracts/minter/src/contract.rs +++ b/contracts/minter/src/contract.rs @@ -20,8 +20,8 @@ use crate::state::{ }; use sg_std::{burn_and_distribute_fee, StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM}; use whitelist::msg::{ - ConfigResponse as WhitelistConfigResponse, HasMemberResponse, QueryMsg as WhitelistQueryMsg, - UnitPriceResponse, + ConfigResponse as WhitelistConfigResponse, HasMemberResponse, IsActiveResponse, + QueryMsg as WhitelistQueryMsg, }; pub type Response = cosmwasm_std::Response; @@ -202,7 +202,11 @@ pub fn execute_mint_sender( .querier .query_wasm_smart(whitelist.clone(), &WhitelistQueryMsg::Config {})?; - if wl_config.is_active { + let is_active_res: IsActiveResponse = deps + .querier + .query_wasm_smart(whitelist.clone(), &WhitelistQueryMsg::IsActive {})?; + + if is_active_res.is_active { let res: HasMemberResponse = deps.querier.query_wasm_smart( whitelist, &WhitelistQueryMsg::HasMember { @@ -483,8 +487,13 @@ pub fn mint_price(deps: Deps, admin_no_fee: bool) -> Result { } else if let Some(whitelist) = config.whitelist { let wl_config: WhitelistConfigResponse = deps .querier - .query_wasm_smart(whitelist, &WhitelistQueryMsg::Config {})?; - if wl_config.is_active { + .query_wasm_smart(whitelist.clone(), &WhitelistQueryMsg::Config {})?; + + let is_active_res: IsActiveResponse = deps + .querier + .query_wasm_smart(whitelist, &WhitelistQueryMsg::IsActive {})?; + + if is_active_res.is_active { wl_config.unit_price } else { config.unit_price.clone() @@ -554,10 +563,10 @@ fn query_mint_price(deps: Deps) -> StdResult { let current_price = mint_price(deps, false)?; let public_price = config.unit_price; let whitelist_price: Option = if let Some(whitelist) = config.whitelist { - let unit_price: UnitPriceResponse = deps + let wl_config: WhitelistConfigResponse = deps .querier - .query_wasm_smart(whitelist, &WhitelistQueryMsg::UnitPrice {})?; - Some(unit_price.unit_price) + .query_wasm_smart(whitelist, &WhitelistQueryMsg::Config {})?; + Some(wl_config.unit_price) } else { None }; From b6aa94a76ddb5ca35072cd4c482cdda8f8a34a52 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 19:54:07 -0500 Subject: [PATCH 04/16] Checks for invalid start and end times --- contracts/whitelist/src/contract.rs | 8 ++++++++ contracts/whitelist/src/error.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 192bc1334..72a258106 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -136,6 +136,10 @@ pub fn execute_update_start_time( return Err(ContractError::Unauthorized {}); } + if start_time > config.end_time { + return Err(ContractError::InvalidStartTime(start_time, config.end_time)); + } + config.start_time = start_time; CONFIG.save(deps.storage, &config)?; Ok(Response::new() @@ -154,6 +158,10 @@ pub fn execute_update_end_time( return Err(ContractError::Unauthorized {}); } + if end_time > config.start_time { + return Err(ContractError::InvalidEndTime(end_time, config.start_time)); + } + config.end_time = end_time; CONFIG.save(deps.storage, &config)?; Ok(Response::new() diff --git a/contracts/whitelist/src/error.rs b/contracts/whitelist/src/error.rs index 859376237..5f732db88 100644 --- a/contracts/whitelist/src/error.rs +++ b/contracts/whitelist/src/error.rs @@ -14,6 +14,9 @@ pub enum ContractError { #[error("InvalidStartTime {0} > {1}")] InvalidStartTime(Expiration, Expiration), + #[error("InvalidEndTime {0} > {1}")] + InvalidEndTime(Expiration, Expiration), + #[error("MembersExceeded: {expected} got {actual}")] MembersExceeded { expected: u32, actual: u32 }, From f1071739ca7f26653724398f917e874c76c76d35 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:04:47 -0500 Subject: [PATCH 05/16] Already started error when updating end time --- contracts/whitelist/src/contract.rs | 7 ++++++- contracts/whitelist/src/error.rs | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 72a258106..8c8ba1a72 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -149,7 +149,7 @@ pub fn execute_update_start_time( pub fn execute_update_end_time( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, end_time: Expiration, ) -> Result { @@ -158,6 +158,11 @@ pub fn execute_update_end_time( return Err(ContractError::Unauthorized {}); } + // don't allow updating end time if whitelist is active + if config.start_time.is_expired(&env.block) { + return Err(ContractError::AlreadyStarted {}); + } + if end_time > config.start_time { return Err(ContractError::InvalidEndTime(end_time, config.start_time)); } diff --git a/contracts/whitelist/src/error.rs b/contracts/whitelist/src/error.rs index 5f732db88..dbb66aa30 100644 --- a/contracts/whitelist/src/error.rs +++ b/contracts/whitelist/src/error.rs @@ -11,6 +11,9 @@ pub enum ContractError { #[error("Unauthorized")] Unauthorized {}, + #[error("AlreadyStarted")] + AlreadyStarted {}, + #[error("InvalidStartTime {0} > {1}")] InvalidStartTime(Expiration, Expiration), From f669da916a01077164fe6c153d24afd714f8364f Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:06:30 -0500 Subject: [PATCH 06/16] Already started error when updating start time --- contracts/whitelist/src/contract.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 8c8ba1a72..7d7e7c23e 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -127,7 +127,7 @@ pub fn execute( pub fn execute_update_start_time( deps: DepsMut, - _env: Env, + env: Env, info: MessageInfo, start_time: Expiration, ) -> Result { @@ -136,6 +136,11 @@ pub fn execute_update_start_time( return Err(ContractError::Unauthorized {}); } + // don't allow updating start time if whitelist is active + if config.start_time.is_expired(&env.block) { + return Err(ContractError::AlreadyStarted {}); + } + if start_time > config.end_time { return Err(ContractError::InvalidStartTime(start_time, config.end_time)); } From 369e9e8f82bff63cc01f1c565417d3c8c3a94474 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:16:24 -0500 Subject: [PATCH 07/16] Remove removing members to simplify --- contracts/minter/src/contract_tests.rs | 12 ++++------- contracts/whitelist/src/contract.rs | 28 +++++++++----------------- contracts/whitelist/src/msg.rs | 7 +++---- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/contracts/minter/src/contract_tests.rs b/contracts/minter/src/contract_tests.rs index 73c4e9144..0903b9768 100644 --- a/contracts/minter/src/contract_tests.rs +++ b/contracts/minter/src/contract_tests.rs @@ -10,7 +10,7 @@ use sg721::msg::{InstantiateMsg as Sg721InstantiateMsg, RoyaltyInfoResponse}; use sg721::state::CollectionInfo; use sg_std::{StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM}; use whitelist::msg::InstantiateMsg as WhitelistInstantiateMsg; -use whitelist::msg::{ExecuteMsg as WhitelistExecuteMsg, UpdateMembersMsg}; +use whitelist::msg::{AddMembersMsg, ExecuteMsg as WhitelistExecuteMsg}; use crate::contract::instantiate; use crate::msg::{ @@ -786,9 +786,8 @@ fn whitelist_access_len_add_remove_expiration() { ); assert!(res.is_err()); - let inner_msg = UpdateMembersMsg { - add: vec![buyer.to_string()], - remove: vec![], + let inner_msg = AddMembersMsg { + to_add: vec![buyer.to_string()], }; let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg); let res = router.execute_contract( @@ -882,10 +881,7 @@ fn whitelist_access_len_add_remove_expiration() { ); // remove buyer from whitelist - let inner_msg = UpdateMembersMsg { - add: vec![], - remove: vec![buyer.to_string()], - }; + let inner_msg = AddMembersMsg { to_add: vec![] }; let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg); let res = router.execute_contract( creator.clone(), diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 7d7e7c23e..62a8a57fc 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -9,8 +9,8 @@ use sg_std::StargazeMsgWrapper; use crate::error::ContractError; use crate::msg::{ - ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, HasStartedResponse, - InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg, UpdateMembersMsg, + AddMembersMsg, ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, + HasStartedResponse, InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg, }; use crate::state::{Config, CONFIG, WHITELIST}; @@ -118,7 +118,7 @@ pub fn execute( match msg { ExecuteMsg::UpdateStartTime(time) => execute_update_start_time(deps, env, info, time), ExecuteMsg::UpdateEndTime(time) => execute_update_end_time(deps, env, info, time), - ExecuteMsg::UpdateMembers(msg) => execute_update_members(deps, env, info, msg), + ExecuteMsg::UpdateMembers(msg) => execute_add_members(deps, env, info, msg), ExecuteMsg::UpdatePerAddressLimit(per_address_limit) => { execute_update_per_address_limit(deps, env, info, per_address_limit) } @@ -180,18 +180,18 @@ pub fn execute_update_end_time( .add_attribute("sender", info.sender)) } -pub fn execute_update_members( +pub fn execute_add_members( deps: DepsMut, _env: Env, info: MessageInfo, - msg: UpdateMembersMsg, + msg: AddMembersMsg, ) -> Result { let mut config = CONFIG.load(deps.storage)?; if info.sender != config.admin { return Err(ContractError::Unauthorized {}); } - for add in msg.add.into_iter() { + for add in msg.to_add.into_iter() { if config.num_members >= MAX_MEMBERS { return Err(ContractError::MembersExceeded { expected: MAX_MEMBERS, @@ -203,12 +203,6 @@ pub fn execute_update_members( config.num_members += 1; } - for remove in msg.remove.into_iter() { - let addr = deps.api.addr_validate(&remove)?; - WHITELIST.remove(deps.storage, addr); - config.num_members -= 1; - } - CONFIG.save(deps.storage, &config)?; Ok(Response::new() @@ -403,9 +397,8 @@ mod tests { let mut deps = mock_dependencies(); setup_contract(deps.as_mut()); - let inner_msg = UpdateMembersMsg { - add: vec!["adsfsa1".to_string()], - remove: vec![], + let inner_msg = AddMembersMsg { + to_add: vec!["adsfsa1".to_string()], }; let msg = ExecuteMsg::UpdateMembers(inner_msg); let info = mock_info(ADMIN, &[]); @@ -420,9 +413,8 @@ mod tests { let mut deps = mock_dependencies(); setup_contract(deps.as_mut()); - let inner_msg = UpdateMembersMsg { - add: vec!["asdf".to_string(); MAX_MEMBERS as usize], - remove: vec![], + let inner_msg = AddMembersMsg { + to_add: vec!["asdf".to_string(); MAX_MEMBERS as usize], }; let msg = ExecuteMsg::UpdateMembers(inner_msg); let info = mock_info(ADMIN, &[]); diff --git a/contracts/whitelist/src/msg.rs b/contracts/whitelist/src/msg.rs index dda361b41..1dea6b52a 100644 --- a/contracts/whitelist/src/msg.rs +++ b/contracts/whitelist/src/msg.rs @@ -17,14 +17,13 @@ pub struct InstantiateMsg { pub enum ExecuteMsg { UpdateStartTime(Expiration), UpdateEndTime(Expiration), - UpdateMembers(UpdateMembersMsg), + UpdateMembers(AddMembersMsg), UpdatePerAddressLimit(u32), } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -pub struct UpdateMembersMsg { - pub add: Vec, - pub remove: Vec, +pub struct AddMembersMsg { + pub to_add: Vec, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] From caaf974e26d39dc51deb55a21e0516da13723958 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:21:45 -0500 Subject: [PATCH 08/16] Refactored tests --- contracts/minter/src/contract_tests.rs | 16 +++++----------- contracts/whitelist/src/contract.rs | 8 ++++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/contracts/minter/src/contract_tests.rs b/contracts/minter/src/contract_tests.rs index 0903b9768..830b6e61d 100644 --- a/contracts/minter/src/contract_tests.rs +++ b/contracts/minter/src/contract_tests.rs @@ -227,9 +227,7 @@ fn initialization() { }, }, }; - let res = instantiate(deps.as_mut(), mock_env(), info, msg); - println!("{:?}", res); - assert!(res.is_err()); + instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err(); // Invalid uri returns error let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM)); @@ -257,8 +255,7 @@ fn initialization() { }, }, }; - let res = instantiate(deps.as_mut(), mock_env(), info, msg); - assert!(res.is_err()); + instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err(); // invalid denom returns error let wrong_denom = "uosmo"; @@ -287,8 +284,7 @@ fn initialization() { }, }, }; - let res = instantiate(deps.as_mut(), mock_env(), info, msg); - assert!(res.is_err()); + instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err(); // insufficient mint price returns error let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM)); @@ -316,8 +312,7 @@ fn initialization() { }, }, }; - let res = instantiate(deps.as_mut(), mock_env(), info, msg); - assert!(res.is_err()); + instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err(); // over max token limit let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM)); @@ -345,8 +340,7 @@ fn initialization() { }, }, }; - let res = instantiate(deps.as_mut(), mock_env(), info, msg); - assert!(res.is_err()); + instantiate(deps.as_mut(), mock_env(), info, msg).unwrap_err(); // under min token limit let info = mock_info("creator", &coins(INITIAL_BALANCE, NATIVE_DENOM)); diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 62a8a57fc..9bc91f059 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -70,8 +70,6 @@ pub fn instantiate( }; CONFIG.save(deps.storage, &config)?; - println!("{:?}", config); - if msg.start_time > msg.end_time { return Err(ContractError::InvalidStartTime( msg.start_time, @@ -199,8 +197,10 @@ pub fn execute_add_members( }); } let addr = deps.api.addr_validate(&add)?; - WHITELIST.save(deps.storage, addr, &true)?; - config.num_members += 1; + if !WHITELIST.has(deps.storage, addr.clone()) { + WHITELIST.save(deps.storage, addr, &true)?; + config.num_members += 1; + } } CONFIG.save(deps.storage, &config)?; From 1655fe709773bf2a65b6a453fc14a0991016edad Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:30:21 -0500 Subject: [PATCH 09/16] Fix tests --- contracts/whitelist/src/contract.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 9bc91f059..353f81970 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -413,9 +413,12 @@ mod tests { let mut deps = mock_dependencies(); setup_contract(deps.as_mut()); - let inner_msg = AddMembersMsg { - to_add: vec!["asdf".to_string(); MAX_MEMBERS as usize], - }; + let mut members = vec![]; + for i in 0..MAX_MEMBERS { + members.push(format!("adsfsa{}", i)); + } + + let inner_msg = AddMembersMsg { to_add: members }; let msg = ExecuteMsg::UpdateMembers(inner_msg); let info = mock_info(ADMIN, &[]); let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err(); From ff32c422c6dfdea422a23781b0582a94c0b44e60 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:38:20 -0500 Subject: [PATCH 10/16] Duplicate member error --- contracts/whitelist/src/contract.rs | 11 +++++++---- contracts/whitelist/src/error.rs | 3 +++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 353f81970..99d2a9671 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -197,10 +197,11 @@ pub fn execute_add_members( }); } let addr = deps.api.addr_validate(&add)?; - if !WHITELIST.has(deps.storage, addr.clone()) { - WHITELIST.save(deps.storage, addr, &true)?; - config.num_members += 1; + if WHITELIST.has(deps.storage, addr.clone()) { + return Err(ContractError::DuplicateMember(addr.to_string())); } + WHITELIST.save(deps.storage, addr, &true)?; + config.num_members += 1; } CONFIG.save(deps.storage, &config)?; @@ -402,10 +403,12 @@ mod tests { }; let msg = ExecuteMsg::UpdateMembers(inner_msg); let info = mock_info(ADMIN, &[]); - let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + let res = execute(deps.as_mut(), mock_env(), info.clone(), msg.clone()).unwrap(); assert_eq!(res.attributes.len(), 2); let res = query_members(deps.as_ref()).unwrap(); assert_eq!(res.members.len(), 2); + + execute(deps.as_mut(), mock_env(), info, msg).unwrap_err(); } #[test] diff --git a/contracts/whitelist/src/error.rs b/contracts/whitelist/src/error.rs index dbb66aa30..4f9229a7f 100644 --- a/contracts/whitelist/src/error.rs +++ b/contracts/whitelist/src/error.rs @@ -14,6 +14,9 @@ pub enum ContractError { #[error("AlreadyStarted")] AlreadyStarted {}, + #[error("DuplicateMember: {0}")] + DuplicateMember(String), + #[error("InvalidStartTime {0} > {1}")] InvalidStartTime(Expiration, Expiration), From 2f40b001315a3c4149b1f0b139364549486c9a33 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Thu, 3 Mar 2022 20:44:16 -0500 Subject: [PATCH 11/16] Update schema --- contracts/whitelist/schema/execute_msg.json | 37 +++++++++------------ contracts/whitelist/schema/query_msg.json | 36 -------------------- 2 files changed, 15 insertions(+), 58 deletions(-) diff --git a/contracts/whitelist/schema/execute_msg.json b/contracts/whitelist/schema/execute_msg.json index 0f8d51bf6..b52a11aeb 100644 --- a/contracts/whitelist/schema/execute_msg.json +++ b/contracts/whitelist/schema/execute_msg.json @@ -33,7 +33,7 @@ ], "properties": { "update_members": { - "$ref": "#/definitions/UpdateMembersMsg" + "$ref": "#/definitions/AddMembersMsg" } }, "additionalProperties": false @@ -54,6 +54,20 @@ } ], "definitions": { + "AddMembersMsg": { + "type": "object", + "required": [ + "to_add" + ], + "properties": { + "to_add": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "Expiration": { "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", "oneOf": [ @@ -111,27 +125,6 @@ "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" - }, - "UpdateMembersMsg": { - "type": "object", - "required": [ - "add", - "remove" - ], - "properties": { - "add": { - "type": "array", - "items": { - "type": "string" - } - }, - "remove": { - "type": "array", - "items": { - "type": "string" - } - } - } } } } diff --git a/contracts/whitelist/schema/query_msg.json b/contracts/whitelist/schema/query_msg.json index df19095b2..1aa4b57f6 100644 --- a/contracts/whitelist/schema/query_msg.json +++ b/contracts/whitelist/schema/query_msg.json @@ -2,30 +2,6 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "QueryMsg", "oneOf": [ - { - "type": "object", - "required": [ - "start_time" - ], - "properties": { - "start_time": { - "type": "object" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "end_time" - ], - "properties": { - "end_time": { - "type": "object" - } - }, - "additionalProperties": false - }, { "type": "object", "required": [ @@ -94,18 +70,6 @@ }, "additionalProperties": false }, - { - "type": "object", - "required": [ - "unit_price" - ], - "properties": { - "unit_price": { - "type": "object" - } - }, - "additionalProperties": false - }, { "type": "object", "required": [ From 530792dc26286bb7686a21e27cc75aad38058b8f Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Fri, 4 Mar 2022 11:44:41 -0500 Subject: [PATCH 12/16] Fix test --- contracts/minter/src/contract_tests.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contracts/minter/src/contract_tests.rs b/contracts/minter/src/contract_tests.rs index 830b6e61d..ef197a72f 100644 --- a/contracts/minter/src/contract_tests.rs +++ b/contracts/minter/src/contract_tests.rs @@ -582,9 +582,8 @@ fn mint_count_query() { ); assert!(res.is_ok()); - let inner_msg = UpdateMembersMsg { - add: vec![buyer.to_string()], - remove: vec![], + let inner_msg = AddMembersMsg { + to_add: vec![buyer.to_string()], }; let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg); let res = router.execute_contract( From d82e07144322b5cad97164a5acd375a8c1fe9be1 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Fri, 4 Mar 2022 11:46:44 -0500 Subject: [PATCH 13/16] Refactor add and remove members --- contracts/minter/src/contract_tests.rs | 6 +++--- contracts/whitelist/src/contract.rs | 6 +++--- contracts/whitelist/src/msg.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/minter/src/contract_tests.rs b/contracts/minter/src/contract_tests.rs index ef197a72f..694e2f88c 100644 --- a/contracts/minter/src/contract_tests.rs +++ b/contracts/minter/src/contract_tests.rs @@ -585,7 +585,7 @@ fn mint_count_query() { let inner_msg = AddMembersMsg { to_add: vec![buyer.to_string()], }; - let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg); + let wasm_msg = WhitelistExecuteMsg::AddMembers(inner_msg); let res = router.execute_contract( creator.clone(), whitelist_addr, @@ -782,7 +782,7 @@ fn whitelist_access_len_add_remove_expiration() { let inner_msg = AddMembersMsg { to_add: vec![buyer.to_string()], }; - let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg); + let wasm_msg = WhitelistExecuteMsg::AddMembers(inner_msg); let res = router.execute_contract( creator.clone(), whitelist_addr.clone(), @@ -875,7 +875,7 @@ fn whitelist_access_len_add_remove_expiration() { // remove buyer from whitelist let inner_msg = AddMembersMsg { to_add: vec![] }; - let wasm_msg = WhitelistExecuteMsg::UpdateMembers(inner_msg); + let wasm_msg = WhitelistExecuteMsg::AddMembers(inner_msg); let res = router.execute_contract( creator.clone(), whitelist_addr, diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 99d2a9671..0cf079c3d 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -116,7 +116,7 @@ pub fn execute( match msg { ExecuteMsg::UpdateStartTime(time) => execute_update_start_time(deps, env, info, time), ExecuteMsg::UpdateEndTime(time) => execute_update_end_time(deps, env, info, time), - ExecuteMsg::UpdateMembers(msg) => execute_add_members(deps, env, info, msg), + ExecuteMsg::AddMembers(msg) => execute_add_members(deps, env, info, msg), ExecuteMsg::UpdatePerAddressLimit(per_address_limit) => { execute_update_per_address_limit(deps, env, info, per_address_limit) } @@ -401,7 +401,7 @@ mod tests { let inner_msg = AddMembersMsg { to_add: vec!["adsfsa1".to_string()], }; - let msg = ExecuteMsg::UpdateMembers(inner_msg); + let msg = ExecuteMsg::AddMembers(inner_msg); let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info.clone(), msg.clone()).unwrap(); assert_eq!(res.attributes.len(), 2); @@ -422,7 +422,7 @@ mod tests { } let inner_msg = AddMembersMsg { to_add: members }; - let msg = ExecuteMsg::UpdateMembers(inner_msg); + let msg = ExecuteMsg::AddMembers(inner_msg); let info = mock_info(ADMIN, &[]); let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err(); assert_eq!( diff --git a/contracts/whitelist/src/msg.rs b/contracts/whitelist/src/msg.rs index 1dea6b52a..47a03ca4d 100644 --- a/contracts/whitelist/src/msg.rs +++ b/contracts/whitelist/src/msg.rs @@ -17,7 +17,7 @@ pub struct InstantiateMsg { pub enum ExecuteMsg { UpdateStartTime(Expiration), UpdateEndTime(Expiration), - UpdateMembers(AddMembersMsg), + AddMembers(AddMembersMsg), UpdatePerAddressLimit(u32), } From 584aed89200f7ba4c6eacd39955b00e512530fad Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Fri, 4 Mar 2022 13:43:09 -0500 Subject: [PATCH 14/16] Add remove members --- contracts/whitelist/src/contract.rs | 46 ++++++++++++++++++++++++++--- contracts/whitelist/src/error.rs | 3 ++ contracts/whitelist/src/msg.rs | 6 ++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 0cf079c3d..85f757553 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -11,6 +11,7 @@ use crate::error::ContractError; use crate::msg::{ AddMembersMsg, ConfigResponse, ExecuteMsg, HasEndedResponse, HasMemberResponse, HasStartedResponse, InstantiateMsg, IsActiveResponse, MembersResponse, QueryMsg, + RemoveMembersMsg, }; use crate::state::{Config, CONFIG, WHITELIST}; @@ -117,6 +118,7 @@ pub fn execute( ExecuteMsg::UpdateStartTime(time) => execute_update_start_time(deps, env, info, time), ExecuteMsg::UpdateEndTime(time) => execute_update_end_time(deps, env, info, time), ExecuteMsg::AddMembers(msg) => execute_add_members(deps, env, info, msg), + ExecuteMsg::RemoveMembers(msg) => execute_remove_members(deps, env, info, msg), ExecuteMsg::UpdatePerAddressLimit(per_address_limit) => { execute_update_per_address_limit(deps, env, info, per_address_limit) } @@ -207,7 +209,34 @@ pub fn execute_add_members( CONFIG.save(deps.storage, &config)?; Ok(Response::new() - .add_attribute("action", "update_whitelist_members") + .add_attribute("action", "add_members") + .add_attribute("sender", info.sender)) +} + +pub fn execute_remove_members( + deps: DepsMut, + _env: Env, + info: MessageInfo, + msg: RemoveMembersMsg, +) -> Result { + let mut config = CONFIG.load(deps.storage)?; + if info.sender != config.admin { + return Err(ContractError::Unauthorized {}); + } + + for remove in msg.to_remove.into_iter() { + let addr = deps.api.addr_validate(&remove)?; + if !WHITELIST.has(deps.storage, addr.clone()) { + return Err(ContractError::NoMemberFound(addr.to_string())); + } + WHITELIST.remove(deps.storage, addr); + config.num_members -= 1; + } + + CONFIG.save(deps.storage, &config)?; + + Ok(Response::new() + .add_attribute("action", "remove_members") .add_attribute("sender", info.sender)) } @@ -398,17 +427,26 @@ mod tests { let mut deps = mock_dependencies(); setup_contract(deps.as_mut()); - let inner_msg = AddMembersMsg { + let add_msg = AddMembersMsg { to_add: vec!["adsfsa1".to_string()], }; - let msg = ExecuteMsg::AddMembers(inner_msg); + let msg = ExecuteMsg::AddMembers(add_msg); let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info.clone(), msg.clone()).unwrap(); assert_eq!(res.attributes.len(), 2); let res = query_members(deps.as_ref()).unwrap(); assert_eq!(res.members.len(), 2); - execute(deps.as_mut(), mock_env(), info, msg).unwrap_err(); + execute(deps.as_mut(), mock_env(), info.clone(), msg).unwrap_err(); + + let remove_msg = RemoveMembersMsg { + to_remove: vec!["adsfsa1".to_string()], + }; + let msg = ExecuteMsg::RemoveMembers(remove_msg); + let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); + assert_eq!(res.attributes.len(), 2); + let res = query_members(deps.as_ref()).unwrap(); + assert_eq!(res.members.len(), 1); } #[test] diff --git a/contracts/whitelist/src/error.rs b/contracts/whitelist/src/error.rs index 4f9229a7f..ee0d3a2a8 100644 --- a/contracts/whitelist/src/error.rs +++ b/contracts/whitelist/src/error.rs @@ -17,6 +17,9 @@ pub enum ContractError { #[error("DuplicateMember: {0}")] DuplicateMember(String), + #[error("NoMemberFound: {0}")] + NoMemberFound(String), + #[error("InvalidStartTime {0} > {1}")] InvalidStartTime(Expiration, Expiration), diff --git a/contracts/whitelist/src/msg.rs b/contracts/whitelist/src/msg.rs index 47a03ca4d..08a47a04e 100644 --- a/contracts/whitelist/src/msg.rs +++ b/contracts/whitelist/src/msg.rs @@ -18,6 +18,7 @@ pub enum ExecuteMsg { UpdateStartTime(Expiration), UpdateEndTime(Expiration), AddMembers(AddMembersMsg), + RemoveMembers(RemoveMembersMsg), UpdatePerAddressLimit(u32), } @@ -26,6 +27,11 @@ pub struct AddMembersMsg { pub to_add: Vec, } +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct RemoveMembersMsg { + pub to_remove: Vec, +} + #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { From 7d90626640b36177b7154fb65dad1663116ec821 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Fri, 4 Mar 2022 13:57:58 -0500 Subject: [PATCH 15/16] Added back is_active --- contracts/minter/src/contract.rs | 17 ++++------------- contracts/whitelist/src/contract.rs | 12 +++++++----- contracts/whitelist/src/msg.rs | 1 + 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/contracts/minter/src/contract.rs b/contracts/minter/src/contract.rs index c4915a2f1..39908a829 100644 --- a/contracts/minter/src/contract.rs +++ b/contracts/minter/src/contract.rs @@ -20,8 +20,7 @@ use crate::state::{ }; use sg_std::{burn_and_distribute_fee, StargazeMsgWrapper, GENESIS_MINT_START_TIME, NATIVE_DENOM}; use whitelist::msg::{ - ConfigResponse as WhitelistConfigResponse, HasMemberResponse, IsActiveResponse, - QueryMsg as WhitelistQueryMsg, + ConfigResponse as WhitelistConfigResponse, HasMemberResponse, QueryMsg as WhitelistQueryMsg, }; pub type Response = cosmwasm_std::Response; @@ -202,11 +201,7 @@ pub fn execute_mint_sender( .querier .query_wasm_smart(whitelist.clone(), &WhitelistQueryMsg::Config {})?; - let is_active_res: IsActiveResponse = deps - .querier - .query_wasm_smart(whitelist.clone(), &WhitelistQueryMsg::IsActive {})?; - - if is_active_res.is_active { + if wl_config.is_active { let res: HasMemberResponse = deps.querier.query_wasm_smart( whitelist, &WhitelistQueryMsg::HasMember { @@ -487,13 +482,9 @@ pub fn mint_price(deps: Deps, admin_no_fee: bool) -> Result { } else if let Some(whitelist) = config.whitelist { let wl_config: WhitelistConfigResponse = deps .querier - .query_wasm_smart(whitelist.clone(), &WhitelistQueryMsg::Config {})?; - - let is_active_res: IsActiveResponse = deps - .querier - .query_wasm_smart(whitelist, &WhitelistQueryMsg::IsActive {})?; + .query_wasm_smart(whitelist, &WhitelistQueryMsg::Config {})?; - if is_active_res.is_active { + if wl_config.is_active { wl_config.unit_price } else { config.unit_price.clone() diff --git a/contracts/whitelist/src/contract.rs b/contracts/whitelist/src/contract.rs index 85f757553..e8c30af1d 100644 --- a/contracts/whitelist/src/contract.rs +++ b/contracts/whitelist/src/contract.rs @@ -273,7 +273,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { QueryMsg::HasEnded {} => to_binary(&query_has_ended(deps, env)?), QueryMsg::IsActive {} => to_binary(&query_is_active(deps, env)?), QueryMsg::HasMember { member } => to_binary(&query_has_member(deps, member)?), - QueryMsg::Config {} => to_binary(&query_config(deps)?), + QueryMsg::Config {} => to_binary(&query_config(deps, env)?), } } @@ -316,7 +316,7 @@ fn query_has_member(deps: Deps, member: String) -> StdResult }) } -fn query_config(deps: Deps) -> StdResult { +fn query_config(deps: Deps, env: Env) -> StdResult { let config = CONFIG.load(deps.storage)?; Ok(ConfigResponse { num_members: config.num_members, @@ -324,6 +324,8 @@ fn query_config(deps: Deps) -> StdResult { start_time: config.start_time, end_time: config.end_time, unit_price: config.unit_price, + is_active: config.start_time.is_expired(&env.block) + && !config.end_time.is_expired(&env.block), }) } @@ -391,7 +393,7 @@ mod tests { }; let info = mock_info(ADMIN, &[coin(100_000_000, "ustars")]); let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); - let res = query_config(deps.as_ref()).unwrap(); + let res = query_config(deps.as_ref(), mock_env()).unwrap(); assert_eq!(1, res.num_members); } @@ -418,7 +420,7 @@ mod tests { let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); assert_eq!(res.attributes.len(), 3); - let res = query_config(deps.as_ref()).unwrap(); + let res = query_config(deps.as_ref(), mock_env()).unwrap(); assert_eq!(res.end_time, Expiration::AtHeight(10)); } @@ -498,7 +500,7 @@ mod tests { let info = mock_info(ADMIN, &[]); let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap(); assert_eq!(res.attributes.len(), 2); - let wl_config: ConfigResponse = query_config(deps.as_ref()).unwrap(); + let wl_config: ConfigResponse = query_config(deps.as_ref(), mock_env()).unwrap(); assert_eq!(wl_config.per_address_limit, per_address_limit); } } diff --git a/contracts/whitelist/src/msg.rs b/contracts/whitelist/src/msg.rs index 08a47a04e..a64a62a42 100644 --- a/contracts/whitelist/src/msg.rs +++ b/contracts/whitelist/src/msg.rs @@ -85,4 +85,5 @@ pub struct ConfigResponse { pub start_time: Expiration, pub end_time: Expiration, pub unit_price: Coin, + pub is_active: bool, } From 0d3a8aa5a9620bd6d647f67e5d2ac3b47c38b2d3 Mon Sep 17 00:00:00 2001 From: Shane Vitarana Date: Fri, 4 Mar 2022 14:02:01 -0500 Subject: [PATCH 16/16] Updated schema and types --- contracts/whitelist/schema/execute_msg.json | 30 +++++++++++++++++++-- types/contracts/whitelist/execute_msg.d.ts | 13 ++++++--- types/contracts/whitelist/query_msg.d.ts | 12 --------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/contracts/whitelist/schema/execute_msg.json b/contracts/whitelist/schema/execute_msg.json index b52a11aeb..34f013a5e 100644 --- a/contracts/whitelist/schema/execute_msg.json +++ b/contracts/whitelist/schema/execute_msg.json @@ -29,15 +29,27 @@ { "type": "object", "required": [ - "update_members" + "add_members" ], "properties": { - "update_members": { + "add_members": { "$ref": "#/definitions/AddMembersMsg" } }, "additionalProperties": false }, + { + "type": "object", + "required": [ + "remove_members" + ], + "properties": { + "remove_members": { + "$ref": "#/definitions/RemoveMembersMsg" + } + }, + "additionalProperties": false + }, { "type": "object", "required": [ @@ -114,6 +126,20 @@ } ] }, + "RemoveMembersMsg": { + "type": "object", + "required": [ + "to_remove" + ], + "properties": { + "to_remove": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, "Timestamp": { "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", "allOf": [ diff --git a/types/contracts/whitelist/execute_msg.d.ts b/types/contracts/whitelist/execute_msg.d.ts index fe2cd535f..a0381586f 100644 --- a/types/contracts/whitelist/execute_msg.d.ts +++ b/types/contracts/whitelist/execute_msg.d.ts @@ -5,13 +5,18 @@ update_start_time: Expiration } | { update_end_time: Expiration } | { -update_members: UpdateMembersMsg +add_members: AddMembersMsg +} | { +remove_members: RemoveMembersMsg } | { update_per_address_limit: number }) -export interface UpdateMembersMsg { -add: string[] -remove: string[] +export interface AddMembersMsg { +to_add: string[] +[k: string]: unknown +} +export interface RemoveMembersMsg { +to_remove: string[] [k: string]: unknown } diff --git a/types/contracts/whitelist/query_msg.d.ts b/types/contracts/whitelist/query_msg.d.ts index 9ef8b9243..011603481 100644 --- a/types/contracts/whitelist/query_msg.d.ts +++ b/types/contracts/whitelist/query_msg.d.ts @@ -1,12 +1,4 @@ export type QueryMsg = ({ -start_time: { -[k: string]: unknown -} -} | { -end_time: { -[k: string]: unknown -} -} | { has_started: { [k: string]: unknown } @@ -28,10 +20,6 @@ member: string [k: string]: unknown } } | { -unit_price: { -[k: string]: unknown -} -} | { config: { [k: string]: unknown }