Skip to content

Commit

Permalink
Merge branch 'open-edition-minter' into 'main'
Browse files Browse the repository at this point in the history
Open edition minter

See merge request adnan/omniflix-launchpad!10
  • Loading branch information
Adnan Deniz committed Jan 22, 2024
2 parents 61defc7 + f5ff885 commit b18ee69
Show file tree
Hide file tree
Showing 36 changed files with 2,610 additions and 151 deletions.
57 changes: 57 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ cw-ownable = "0.5.1"
cosmwasm-storage = "1.5.0"
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
whitelist-types = { version = "0.0.1", path = "packages/whitelist-types" }
minter-types = { version = "0.0.1", path = "packages/minter-types" }
minter-types = { version = "0.0.1", path = "packages/minter-types" }
open-edition-minter-types = { version = "0.0.1", path = "packages/open-edition-minter-types" }
128 changes: 73 additions & 55 deletions contracts/factories/minter-factory/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use crate::error::ContractError;
use crate::msg::{ExecuteMsg, InstantiateMsg, ParamsResponse, QueryMsg};
use crate::msg::{CreateMinterMsg, ExecuteMsg, InstantiateMsg, ParamsResponse, QueryMsg};
use crate::state::{Params, PARAMS};
use crate::utils::check_payment;
#[cfg(not(feature = "library"))]
Expand All @@ -11,7 +11,6 @@ use cosmwasm_std::{
StdResult, Uint128, WasmMsg,
};
use cw_utils::maybe_addr;
use minter_types::InstantiateMsg as MinterInstantiateMsg;
use omniflix_std::types::omniflix::onft::v1beta1::OnftQuerier;
#[cfg(not(test))]
const CREATION_FEE: Uint128 = Uint128::new(0);
Expand Down Expand Up @@ -75,7 +74,7 @@ fn create_minter(
deps: DepsMut,
_env: Env,
info: MessageInfo,
msg: MinterInstantiateMsg,
msg: CreateMinterMsg,
) -> Result<Response, ContractError> {
let params = PARAMS.load(deps.storage)?;
let nft_creation_fee: Coin = if CREATION_FEE == Uint128::new(0) {
Expand All @@ -97,7 +96,10 @@ fn create_minter(
&[nft_creation_fee.clone(), params.minter_creation_fee.clone()],
)?;

if !params.allowed_minter_mint_denoms.contains(&msg.mint_denom) {
if !params
.allowed_minter_mint_denoms
.contains(&msg.init.mint_denom)
{
return Err(ContractError::MintDenomNotAllowed {});
}

Expand Down Expand Up @@ -222,6 +224,8 @@ fn query_params(deps: Deps) -> StdResult<ParamsResponse> {

#[cfg(test)]
mod tests {
use crate::msg::MinterInitExtention;

use super::*;
use cosmwasm_std::{
testing::{mock_dependencies, mock_env, mock_info},
Expand Down Expand Up @@ -286,25 +290,27 @@ mod tests {
id: "collection_id".to_string(),
extensible: true,
nsfw: false,
num_tokens: 10,
base_uri: "https://example.com/base".to_string(),
uri: "https://example.com/collection".to_string(),
uri_hash: "hash123".to_string(),
data: "Additional data for the collection".to_string(),
};
// Non allowed mint denom
let msg = ExecuteMsg::CreateMinter {
msg: MinterInstantiateMsg {
admin: None,
whitelist_address: None,
mint_denom: "non_allowed".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
msg: CreateMinterMsg {
collection_details: collection_details.clone(),
end_time: None,
init: MinterInitExtention {
admin: None,
whitelist_address: None,
mint_denom: "non_allowed".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
end_time: None,
num_tokens: 100,
},
},
};

Expand All @@ -325,17 +331,20 @@ mod tests {
assert_eq!(res, ContractError::MintDenomNotAllowed {});
// Send additional funds
let msg = ExecuteMsg::CreateMinter {
msg: MinterInstantiateMsg {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
msg: CreateMinterMsg {
collection_details: collection_details.clone(),
end_time: None,
init: MinterInitExtention {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
end_time: None,
num_tokens: 100,
},
},
};

Expand Down Expand Up @@ -389,17 +398,20 @@ mod tests {

// Missing funds
let msg = ExecuteMsg::CreateMinter {
msg: MinterInstantiateMsg {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
msg: CreateMinterMsg {
collection_details: collection_details.clone(),
end_time: None,
init: MinterInitExtention {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
end_time: None,
num_tokens: 100,
},
},
};

Expand Down Expand Up @@ -433,17 +445,20 @@ mod tests {

// Happy path
let msg = ExecuteMsg::CreateMinter {
msg: MinterInstantiateMsg {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
msg: CreateMinterMsg {
collection_details: collection_details.clone(),
end_time: None,
init: MinterInitExtention {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
end_time: None,
num_tokens: 100,
},
},
};

Expand All @@ -468,17 +483,20 @@ mod tests {
CosmosMsg::Wasm(WasmMsg::Instantiate {
admin: Some("creator".to_string()),
code_id: 1,
msg: to_json_binary(&MinterInstantiateMsg {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
msg: to_json_binary(&CreateMinterMsg {
collection_details: collection_details.clone(),
end_time: None,
init: MinterInitExtention {
admin: None,
whitelist_address: None,
mint_denom: "uusd".to_string(),
mint_price: Uint128::new(100),
start_time: Timestamp::from_seconds(0),
royalty_ratio: Decimal::percent(10).to_string(),
payment_collector: None,
per_address_limit: 3,
end_time: None,
num_tokens: 100,
},
})
.unwrap(),
funds: vec![Coin {
Expand Down
28 changes: 25 additions & 3 deletions contracts/factories/minter-factory/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Coin;
use minter_types::InstantiateMsg as MinterInstantiateMsg;
use cosmwasm_std::{Coin, Timestamp, Uint128};
use minter_types::MinterInstantiateMsg;

use crate::state::Params;
#[cw_serde]
Expand All @@ -11,10 +11,32 @@ pub struct InstantiateMsg {
pub minter_code_id: u64,
pub minter_creation_fee: Coin,
}

#[cw_serde]
pub struct MinterInitExtention {
pub admin: Option<String>,
pub mint_price: Uint128,
// Factory sould check denom against the params if denoms is valid and whitelisted.
pub mint_denom: String,
// Public minting start time
pub start_time: Timestamp,
pub end_time: Option<Timestamp>,
pub per_address_limit: u32,
// We expect user to send a string between 0 and 1
// FE "0.1"
pub royalty_ratio: String,
pub payment_collector: Option<String>,
// Whitelist address if any
pub whitelist_address: Option<String>,
pub num_tokens: u32,
}

pub type CreateMinterMsg = MinterInstantiateMsg<MinterInitExtention>;

#[cw_serde]
pub enum ExecuteMsg {
CreateMinter {
msg: MinterInstantiateMsg,
msg: CreateMinterMsg,
},
UpdateAdmin {
admin: String,
Expand Down
55 changes: 55 additions & 0 deletions contracts/factories/open-edition-minter-factory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[package]
authors = ["Adnan Deniz Corlu <[email protected]>"]
name = "omniflix-open-edition-minter-factory"
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"]

[[bin]]
name = "schema"
path = "src/bin/schema.rs"
doc = false

[profile.release]
codegen-units = 1
debug = false
debug-assertions = false
incremental = false
lto = true
opt-level = 3
overflow-checks = true
panic = 'abort'
rpath = false

[features]
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cosmwasm-storage = { workspace = true }
omniflix-std = { workspace = true }
thiserror = { workspace = true }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-controllers = { workspace = true }
cw2 = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
serde = { workspace = true }
open-edition-minter-types = {workspace = true}
minter-types = {workspace = true}

Loading

0 comments on commit b18ee69

Please sign in to comment.