Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tiered whitelist support #692

Open
wants to merge 14 commits into
base: release/v3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Cargo.lock

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

17 changes: 12 additions & 5 deletions contracts/minters/open-edition-minter-merkle-wl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ pub fn execute(
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::Mint {
stage,
proof_hashes,
allocation,
} => execute_mint_sender(deps, env, info, proof_hashes, allocation),
} => execute_mint_sender(deps, env, info, stage, proof_hashes, allocation),
ExecuteMsg::Purge {} => execute_purge(deps, env, info),
ExecuteMsg::UpdateMintPrice { price } => execute_update_mint_price(deps, env, info, price),
ExecuteMsg::UpdateStartTime(time) => execute_update_start_time(deps, env, info, time),
Expand Down Expand Up @@ -352,14 +353,15 @@ pub fn execute_mint_sender(
deps: DepsMut,
env: Env,
info: MessageInfo,
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
let action = "mint_sender";

// If there is no active whitelist right now, check public mint
let is_public_mint = is_public_mint(deps.as_ref(), &info, proof_hashes, allocation)?;
let is_public_mint = is_public_mint(deps.as_ref(), &info, stage, proof_hashes, allocation)?;
// Check start and end time (if not optional)
if is_public_mint && (env.block.time < config.extension.start_time) {
return Err(ContractError::BeforeMintStartTime {});
Expand All @@ -384,6 +386,7 @@ pub fn execute_mint_sender(
fn is_public_mint(
deps: Deps,
info: &MessageInfo,
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
) -> Result<bool, ContractError> {
Expand All @@ -408,9 +411,13 @@ fn is_public_mint(
deps.querier.query_wasm_smart(
whitelist,
&WhitelistQueryMsg::HasMember {
member: match allocation {
Some(allocation) => format!("{}{}", info.sender, allocation),
None => info.sender.to_string(),
member: match (stage, allocation) {
(None, Some(allocation)) => format!("{}{}", info.sender, allocation),
(Some(stage), None) => format!("{}{}", stage, info.sender),
(Some(stage), Some(allocation)) => {
format!("{}{}{}", stage, info.sender, allocation)
}
(None, None) => info.sender.to_string(),
},
proof_hashes: proof_hashes.unwrap(),
},
Expand Down
1 change: 1 addition & 0 deletions contracts/minters/open-edition-minter-merkle-wl/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct InstantiateMsg {
#[cw_serde]
pub enum ExecuteMsg {
Mint {
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ pub fn execute(
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::Mint {
stage,
proof_hashes,
allocation,
} => execute_mint_sender(deps, env, info, proof_hashes, allocation),
} => execute_mint_sender(deps, env, info, stage, proof_hashes, allocation),
ExecuteMsg::Purge {} => execute_purge(deps, env, info),
ExecuteMsg::UpdateMintPrice { price } => execute_update_mint_price(deps, env, info, price),
ExecuteMsg::UpdateStartTime(time) => execute_update_start_time(deps, env, info, time),
Expand Down Expand Up @@ -498,14 +499,15 @@ pub fn execute_mint_sender(
deps: DepsMut,
env: Env,
info: MessageInfo,
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
let action = "mint_sender";

// If there is no active whitelist right now, check public mint
let is_public_mint = is_public_mint(deps.as_ref(), &info, proof_hashes, allocation)?;
let is_public_mint = is_public_mint(deps.as_ref(), &info, stage, proof_hashes, allocation)?;
// Check if after start_time
if is_public_mint && (env.block.time < config.extension.start_time) {
return Err(ContractError::BeforeMintStartTime {});
Expand All @@ -530,6 +532,7 @@ pub fn execute_mint_sender(
fn is_public_mint(
deps: Deps,
info: &MessageInfo,
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
) -> Result<bool, ContractError> {
Expand All @@ -554,9 +557,13 @@ fn is_public_mint(
deps.querier.query_wasm_smart(
whitelist,
&WhitelistMtreeQueryMsg::HasMember {
member: match allocation {
Some(allocation) => format!("{}{}", info.sender, allocation),
None => info.sender.to_string(),
member: match (stage, allocation) {
(None, Some(allocation)) => format!("{}{}", info.sender, allocation),
(Some(stage), None) => format!("{}{}", stage, info.sender),
(Some(stage), Some(allocation)) => {
format!("{}{}{}", stage, info.sender, allocation)
}
(None, None) => info.sender.to_string(),
},
proof_hashes: proof_hashes.unwrap(),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct InstantiateMsg {
#[cw_serde]
pub enum ExecuteMsg {
Mint {
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
},
Expand Down
17 changes: 12 additions & 5 deletions contracts/minters/vending-minter-merkle-wl/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ pub fn execute(
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::Mint {
stage,
proof_hashes,
allocation,
} => execute_mint_sender(deps, env, info, proof_hashes, allocation),
} => execute_mint_sender(deps, env, info, stage, proof_hashes, allocation),
ExecuteMsg::Purge {} => execute_purge(deps, env, info),
ExecuteMsg::UpdateMintPrice { price } => execute_update_mint_price(deps, env, info, price),
ExecuteMsg::UpdateStartTime(time) => execute_update_start_time(deps, env, info, time),
Expand Down Expand Up @@ -498,14 +499,15 @@ pub fn execute_mint_sender(
deps: DepsMut,
env: Env,
info: MessageInfo,
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
) -> Result<Response, ContractError> {
let config = CONFIG.load(deps.storage)?;
let action = "mint_sender";

// If there is no active whitelist right now, check public mint
let is_public_mint = is_public_mint(deps.as_ref(), &info, proof_hashes, allocation)?;
let is_public_mint = is_public_mint(deps.as_ref(), &info, stage, proof_hashes, allocation)?;
// Check if after start_time
if is_public_mint && (env.block.time < config.extension.start_time) {
return Err(ContractError::BeforeMintStartTime {});
Expand All @@ -530,6 +532,7 @@ pub fn execute_mint_sender(
fn is_public_mint(
deps: Deps,
info: &MessageInfo,
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
) -> Result<bool, ContractError> {
Expand All @@ -554,9 +557,13 @@ fn is_public_mint(
deps.querier.query_wasm_smart(
whitelist,
&WhitelistMtreeQueryMsg::HasMember {
member: match allocation {
Some(allocation) => format!("{}{}", info.sender, allocation),
None => info.sender.to_string(),
member: match (stage, allocation) {
(None, Some(allocation)) => format!("{}{}", info.sender, allocation),
(Some(stage), None) => format!("{}{}", stage, info.sender),
(Some(stage), Some(allocation)) => {
format!("{}{}{}", stage, info.sender, allocation)
}
(None, None) => info.sender.to_string(),
},
proof_hashes: proof_hashes.unwrap(),
},
Expand Down
1 change: 1 addition & 0 deletions contracts/minters/vending-minter-merkle-wl/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct InstantiateMsg {
#[cw_serde]
pub enum ExecuteMsg {
Mint {
stage: Option<u32>,
proof_hashes: Option<Vec<String>>,
allocation: Option<u32>,
},
Expand Down
4 changes: 4 additions & 0 deletions contracts/whitelists/tiered-whitelist-flex/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
11 changes: 11 additions & 0 deletions contracts/whitelists/tiered-whitelist-flex/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.rs]
indent_size = 4
15 changes: 15 additions & 0 deletions contracts/whitelists/tiered-whitelist-flex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build results
/target

# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327)
.cargo-ok

# Text file backups
**/*.rs.bk

# macOS
.DS_Store

# IDEs
*.iml
.idea
39 changes: 39 additions & 0 deletions contracts/whitelists/tiered-whitelist-flex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "sg-tiered-whitelist-flex"
authors = ["Shane Vitarana <[email protected]>"]
description = "Stargaze NFT tiered whitelist contract"
version = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
license = { workspace = true }

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
rust_decimal = { version = "1.14.3" }
schemars = { workspace = true }
serde = { workspace = true }
sg1 = { workspace = true }
sg-std = { workspace = true }
thiserror = { workspace = true }
1 change: 1 addition & 0 deletions contracts/whitelists/tiered-whitelist-flex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Tiered Whitelist contract
31 changes: 31 additions & 0 deletions contracts/whitelists/tiered-whitelist-flex/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

use sg_tiered_whitelist_flex::msg::{
AdminListResponse, CanExecuteResponse, ConfigResponse, ExecuteMsg, HasEndedResponse,
HasMemberResponse, HasStartedResponse, InstantiateMsg, IsActiveResponse, MembersResponse,
QueryMsg,
};
use sg_tiered_whitelist_flex::state::Config;

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(Config), &out_dir);
export_schema(&schema_for!(ConfigResponse), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(HasEndedResponse), &out_dir);
export_schema(&schema_for!(HasMemberResponse), &out_dir);
export_schema(&schema_for!(HasStartedResponse), &out_dir);
export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(IsActiveResponse), &out_dir);
export_schema(&schema_for!(MembersResponse), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(AdminListResponse), &out_dir);
export_schema(&schema_for!(CanExecuteResponse), &out_dir);
}
15 changes: 15 additions & 0 deletions contracts/whitelists/tiered-whitelist-flex/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# stable
newline_style = "unix"
hard_tabs = false
tab_spaces = 4

# unstable... should we require `rustup run nightly cargo fmt` ?
# or just update the style guide when they are stable?
#fn_single_line = true
#format_code_in_doc_comments = true
#overflow_delimited_expr = true
#reorder_impl_items = true
#struct_field_align_threshold = 20
#struct_lit_single_line = true
#report_todo = "Always"

Loading
Loading