Skip to content

Commit

Permalink
Reset received token counter after mint
Browse files Browse the repository at this point in the history
  • Loading branch information
MightOfOaks committed Nov 1, 2024
1 parent 266a953 commit dc4f35f
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion contracts/factories/token-merge-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ schemars = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
sg1 = { workspace = true }
sg2 = { workspace = true }
sg721 = { workspace = true }
sg-std = { workspace = true }
thiserror = { workspace = true }
21 changes: 12 additions & 9 deletions contracts/factories/token-merge-factory/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use base_factory::contract::must_be_allowed_collection;
use base_factory::ContractError as BaseContractError;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
Expand All @@ -10,13 +9,12 @@ use cw2::set_contract_version;
use cw_utils::must_pay;
use semver::Version;
use sg1::{checked_fair_burn, transfer_funds_to_launchpad_dao};
use sg2::query::{AllowedCollectionCodeIdResponse, AllowedCollectionCodeIdsResponse, Sg2QueryMsg};
use sg_std::{Response, NATIVE_DENOM};

use crate::error::ContractError;
use crate::msg::{
ExecuteMsg, InstantiateMsg, ParamsResponse, SudoMsg, TokenMergeMinterCreateMsg,
TokenMergeUpdateParamsMsg,
AllowedCollectionCodeIdResponse, AllowedCollectionCodeIdsResponse, ExecuteMsg, InstantiateMsg,
ParamsResponse, QueryMsg, SudoMsg, TokenMergeMinterCreateMsg, TokenMergeUpdateParamsMsg,
};
use crate::state::SUDO_PARAMS;

Expand Down Expand Up @@ -59,7 +57,12 @@ pub fn execute_create_minter(
) -> Result<Response, ContractError> {
let params = SUDO_PARAMS.load(deps.storage)?;
must_pay(&info, &params.creation_fee.denom)?;
must_be_allowed_collection(deps.as_ref(), msg.collection_params.code_id)?;
ensure!(
params
.allowed_sg721_code_ids
.contains(&msg.collection_params.code_id),
ContractError::InvalidCollectionCodeId {}
);

ensure!(!params.frozen, ContractError::Frozen {});

Expand Down Expand Up @@ -160,13 +163,13 @@ pub fn sudo_update_params(
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: Sg2QueryMsg) -> StdResult<Binary> {
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
Sg2QueryMsg::Params {} => to_json_binary(&query_params(deps)?),
Sg2QueryMsg::AllowedCollectionCodeIds {} => {
QueryMsg::Params {} => to_json_binary(&query_params(deps)?),
QueryMsg::AllowedCollectionCodeIds {} => {
to_json_binary(&query_allowed_collection_code_ids(deps)?)
}
Sg2QueryMsg::AllowedCollectionCodeId(code_id) => {
QueryMsg::AllowedCollectionCodeId(code_id) => {
to_json_binary(&query_allowed_collection_code_id(deps, code_id)?)
}
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/factories/token-merge-factory/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub enum ContractError {
#[error("Factory frozen. Cannot make new minters.")]
Frozen {},

#[error("InvalidCodeId")]
InvalidCollectionCodeId {},

#[error("InvalidNumTokens {max}, min: 1")]
InvalidNumTokens { max: u32, min: u32 },

Expand Down
62 changes: 53 additions & 9 deletions contracts/factories/token-merge-factory/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::state::TokenMergeFactoryParams;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Coin, Timestamp};
use sg2::msg::{CreateMinterMsg, Sg2ExecuteMsg, UpdateMinterParamsMsg};

use crate::state::TokenMergeMinterParams;
use sg721::{CollectionInfo, RoyaltyInfoResponse};

#[cw_serde]
pub struct InstantiateMsg {
pub params: TokenMergeMinterParams,
pub params: TokenMergeFactoryParams,
}

#[cw_serde]
Expand All @@ -17,16 +16,35 @@ pub struct TokenMergeMinterInitMsgExtension {
pub mint_tokens: Vec<MintToken>,
pub per_address_limit: u32,
}

#[cw_serde]
pub struct CollectionParams {
/// The collection code id
pub code_id: u64,
pub name: String,
pub symbol: String,
pub info: CollectionInfo<RoyaltyInfoResponse>,
}
#[cw_serde]
pub struct CreateMinterMsg<T> {
pub init_msg: T,
pub collection_params: CollectionParams,
}

pub type TokenMergeMinterCreateMsg = CreateMinterMsg<TokenMergeMinterInitMsgExtension>;

pub type ExecuteMsg = Sg2ExecuteMsg<TokenMergeMinterInitMsgExtension>;
#[cw_serde]
pub enum ExecuteMsg {
CreateMinter(TokenMergeMinterCreateMsg),
}

#[cw_serde]
pub enum SudoMsg {
UpdateParams(Box<TokenMergeUpdateParamsMsg>),
pub enum QueryMsg {
Params {},
AllowedCollectionCodeIds {},
AllowedCollectionCodeId(u64),
}

/// Message for params so they can be updated individually by governance
#[cw_serde]
pub struct TokenMergeUpdateParamsExtension {
pub max_token_limit: Option<u32>,
Expand All @@ -35,14 +53,40 @@ pub struct TokenMergeUpdateParamsExtension {
pub airdrop_mint_fee_bps: Option<u64>,
pub shuffle_fee: Option<Coin>,
}
#[cw_serde]
pub struct UpdateMinterParamsMsg<T> {
/// The minter code id
pub code_id: Option<u64>,
pub add_sg721_code_ids: Option<Vec<u64>>,
pub rm_sg721_code_ids: Option<Vec<u64>>,
pub frozen: Option<bool>,
pub creation_fee: Option<Coin>,
pub max_trading_offset_secs: Option<u64>,
pub extension: T,
}
pub type TokenMergeUpdateParamsMsg = UpdateMinterParamsMsg<TokenMergeUpdateParamsExtension>;

#[cw_serde]
pub enum SudoMsg {
UpdateParams(Box<TokenMergeUpdateParamsMsg>),
}

#[cw_serde]
pub struct MintToken {
pub collection: String,
pub amount: u32,
}
#[cw_serde]
pub struct ParamsResponse {
pub params: TokenMergeMinterParams,
pub params: TokenMergeFactoryParams,
}

#[cw_serde]
pub struct AllowedCollectionCodeIdsResponse {
pub code_ids: Vec<u64>,
}

#[cw_serde]
pub struct AllowedCollectionCodeIdResponse {
pub allowed: bool,
}
7 changes: 3 additions & 4 deletions contracts/factories/token-merge-factory/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::Coin;
use cw_storage_plus::Item;
use sg2::CodeId;

#[cw_serde]
pub struct TokenMergeMinterParams {
pub struct TokenMergeFactoryParams {
pub code_id: u64,
pub allowed_sg721_code_ids: Vec<CodeId>,
pub allowed_sg721_code_ids: Vec<u64>,
pub frozen: bool,
pub creation_fee: Coin,
pub max_trading_offset_secs: u64,
Expand All @@ -17,4 +16,4 @@ pub struct TokenMergeMinterParams {
pub shuffle_fee: Coin,
}

pub const SUDO_PARAMS: Item<TokenMergeMinterParams> = Item::new("sudo-params");
pub const SUDO_PARAMS: Item<TokenMergeFactoryParams> = Item::new("sudo-params");
2 changes: 0 additions & 2 deletions contracts/minters/token-merge-minter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ serde = { workspace = true }
sha2 = { workspace = true }
shuffle = { git = "https://github.com/webmaster128/shuffle", branch = "rm-getrandom", version = "0.1.7" }
sg1 = { workspace = true }
sg2 = { workspace = true }
sg4 = { workspace = true }
sg721 = { workspace = true }
sg-std = { workspace = true }
sg-whitelist = { workspace = true, features = ["library"] }
thiserror = { workspace = true }
url = { workspace = true }
vending-factory = { workspace = true, features = ["library"] }
token-merge-factory = { workspace = true, features = ["library"] }
semver = {workspace = true }
14 changes: 8 additions & 6 deletions contracts/minters/token-merge-minter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use rand_core::{RngCore, SeedableRng};
use rand_xoshiro::Xoshiro128PlusPlus;
use semver::Version;
use sg1::{checked_fair_burn, distribute_mint_fees};
use sg2::query::Sg2QueryMsg;
use sg4::{Status, StatusResponse, SudoMsg};
use sg721::{ExecuteMsg as Sg721ExecuteMsg, InstantiateMsg as Sg721InstantiateMsg};
use sg_std::{StargazeMsgWrapper, GENESIS_MINT_START_TIME};
use sha2::{Digest, Sha256};
use shuffle::{fy::FisherYates, shuffler::Shuffler};
use std::convert::TryInto;
use token_merge_factory::msg::QueryMsg as FactoryQueryMsg;
use token_merge_factory::msg::{MintToken, ParamsResponse, TokenMergeMinterCreateMsg};
use url::Url;
pub type Response = cosmwasm_std::Response<StargazeMsgWrapper>;
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn instantiate(
// This will fail if the sender cannot parse a response from the factory contract
let factory_response: ParamsResponse = deps
.querier
.query_wasm_smart(factory.clone(), &Sg2QueryMsg::Params {})?;
.query_wasm_smart(factory.clone(), &FactoryQueryMsg::Params {})?;
let factory_params = factory_response.params;

// set default status so it can be queried without failing
Expand Down Expand Up @@ -283,6 +283,8 @@ pub fn execute_receive_nft(
.add_attribute("token_id", token_id));
}

RECEIVED_TOKENS.remove(deps.storage, (&recipient_addr, info.sender.to_string()));

action = "mint_sender";
_execute_mint(deps, env, info, action, false, Some(recipient_addr), None)
}
Expand Down Expand Up @@ -328,7 +330,7 @@ pub fn execute_shuffle(

let factory: ParamsResponse = deps
.querier
.query_wasm_smart(config.factory, &Sg2QueryMsg::Params {})?;
.query_wasm_smart(config.factory, &FactoryQueryMsg::Params {})?;
let factory_params = factory.params;

// Check exact shuffle fee payment included in message
Expand Down Expand Up @@ -464,7 +466,7 @@ fn _execute_mint(

let factory: ParamsResponse = deps
.querier
.query_wasm_smart(config.factory, &Sg2QueryMsg::Params {})?;
.query_wasm_smart(config.factory, &FactoryQueryMsg::Params {})?;
let factory_params = factory.params;

if is_admin {
Expand Down Expand Up @@ -679,7 +681,7 @@ pub fn execute_update_start_trading_time(
// add custom rules here
let factory_params: ParamsResponse = deps
.querier
.query_wasm_smart(config.factory.clone(), &Sg2QueryMsg::Params {})?;
.query_wasm_smart(config.factory.clone(), &FactoryQueryMsg::Params {})?;
let default_start_time_with_offset = config
.extension
.start_time
Expand Down Expand Up @@ -732,7 +734,7 @@ pub fn execute_update_per_address_limit(

let factory: ParamsResponse = deps
.querier
.query_wasm_smart(config.factory.clone(), &Sg2QueryMsg::Params {})?;
.query_wasm_smart(config.factory.clone(), &FactoryQueryMsg::Params {})?;
let factory_params = factory.params;

if per_address_limit == 0 || per_address_limit > factory_params.max_per_address_limit {
Expand Down
9 changes: 1 addition & 8 deletions contracts/minters/token-merge-minter/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ use cosmwasm_schema::cw_serde;
use cosmwasm_std::Timestamp;
use cw721::Cw721ReceiveMsg;
use token_merge_factory::msg::MintToken;
use vending_factory::{msg::VendingMinterCreateMsg, state::VendingMinterParams};

#[cw_serde]
pub struct InstantiateMsg {
pub create_msg: VendingMinterCreateMsg,
pub params: VendingMinterParams,
}

#[cw_serde]
pub enum ExecuteMsg {
ReceiveNft(Cw721ReceiveMsg),
Purge {},
UpdateStartTime(Timestamp),
/// Runs custom checks against TradingStartTime on VendingMinter, then updates by calling sg721-base
/// Runs custom checks against TradingStartTime on TokenMergeMinter, then updates by calling sg721-base
UpdateStartTradingTime(Option<Timestamp>),
UpdatePerAddressLimit {
per_address_limit: u32,
Expand Down

0 comments on commit dc4f35f

Please sign in to comment.