Skip to content

Commit

Permalink
Open Edition minter update & tests (#629)
Browse files Browse the repository at this point in the history
* Add the option to limit number of tokens instead of end time

* Make linter happy

* Update schema files
  • Loading branch information
MightOfOaks authored Jan 25, 2024
1 parent f3c053f commit 15d2990
Show file tree
Hide file tree
Showing 36 changed files with 651 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"airdrop_mint_fee_bps",
"airdrop_mint_price",
"dev_fee_address",
"max_per_address_limit"
"max_per_address_limit",
"max_token_limit"
],
"properties": {
"airdrop_mint_fee_bps": {
Expand All @@ -104,6 +105,11 @@
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"max_token_limit": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down
5 changes: 5 additions & 0 deletions contracts/factories/open-edition-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ pub fn sudo_update_params(

update_params(&mut params, param_msg.clone())?;

params.extension.max_token_limit = param_msg
.extension
.max_token_limit
.unwrap_or(params.extension.max_token_limit);

params.extension.dev_fee_address = param_msg
.extension
.dev_fee_address
Expand Down
3 changes: 3 additions & 0 deletions contracts/factories/open-edition-factory/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub enum ContractError {
#[error("Unauthorized")]
Unauthorized {},

#[error("LimitOfTimeOrNumTokensRequired")]
LimitOfTimeOrNumTokensRequired {},

#[error("InvalidMintPrice")]
InvalidMintPrice {},

Expand Down
31 changes: 25 additions & 6 deletions contracts/factories/open-edition-factory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ pub struct InstantiateMsg {
pub struct OpenEditionMinterInitMsgExtension {
pub nft_data: NftData,
pub start_time: Timestamp,
pub end_time: Timestamp,
pub end_time: Option<Timestamp>,
pub mint_price: Coin,
pub per_address_limit: u32,
pub num_tokens: Option<u32>,
// If not the admin/init
pub payment_address: Option<String>,
}
Expand All @@ -33,6 +34,16 @@ impl OpenEditionMinterInitMsgExtension {
// Validation of the Minter Params -> need to be in-line with the factory
init_msg.nft_data = NftData::validate(init_msg.nft_data)?;

// Optional: can have a max mint amount
if let Some(max_num_tokens) = init_msg.num_tokens {
if max_num_tokens == 0 || max_num_tokens > params.extension.max_token_limit {
return Err(ContractError::InvalidNumTokens {
min: 1,
max: params.extension.max_token_limit,
});
}
}

let max = params.extension.max_per_address_limit;
let min = 1;
let per_address_limit = init_msg.per_address_limit;
Expand All @@ -51,11 +62,17 @@ impl OpenEditionMinterInitMsgExtension {
));
}

if init_msg.end_time <= init_msg.start_time {
return Err(ContractError::InvalidEndTime(
init_msg.start_time,
init_msg.end_time,
));
// Optional: not time limited
if let Some(end_time) = init_msg.end_time {
if end_time <= init_msg.start_time {
return Err(ContractError::InvalidEndTime(init_msg.start_time, end_time));
}
}

// Need to validate the end time and number of tokens are not both None
// At least 1 constraint is required
if init_msg.end_time.is_none() && init_msg.num_tokens.is_none() {
return Err(ContractError::LimitOfTimeOrNumTokensRequired {});
}

if init_msg.mint_price.amount < params.min_mint_price.amount {
Expand All @@ -68,6 +85,7 @@ impl OpenEditionMinterInitMsgExtension {
end_time: init_msg.end_time,
mint_price: init_msg.mint_price,
per_address_limit,
num_tokens: init_msg.num_tokens,
payment_address: init_msg.payment_address,
})
}
Expand All @@ -85,6 +103,7 @@ pub enum SudoMsg {
/// Message for params so they can be updated individually by governance
#[cw_serde]
pub struct OpenEditionUpdateParamsExtension {
pub max_token_limit: Option<u32>,
pub max_per_address_limit: Option<u32>,
pub min_mint_price: Option<Coin>,
pub airdrop_mint_fee_bps: Option<u64>,
Expand Down
1 change: 1 addition & 0 deletions contracts/factories/open-edition-factory/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use sg2::MinterParams;

#[cw_serde]
pub struct ParamsExtension {
pub max_token_limit: u32,
pub max_per_address_limit: u32,
pub airdrop_mint_fee_bps: u64,
pub airdrop_mint_price: Coin,
Expand Down
18 changes: 16 additions & 2 deletions contracts/minters/open-edition-minter/schema/config_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"type": "object",
"required": [
"admin",
"end_time",
"factory",
"mint_price",
"nft_data",
Expand All @@ -18,7 +17,14 @@
"type": "string"
},
"end_time": {
"$ref": "#/definitions/Timestamp"
"anyOf": [
{
"$ref": "#/definitions/Timestamp"
},
{
"type": "null"
}
]
},
"factory": {
"type": "string"
Expand All @@ -29,6 +35,14 @@
"nft_data": {
"$ref": "#/definitions/NftData"
},
"num_tokens": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"payment_address": {
"anyOf": [
{
Expand Down
13 changes: 13 additions & 0 deletions contracts/minters/open-edition-minter/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"burn_remaining"
],
"properties": {
"burn_remaining": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"definitions": {
Expand Down
26 changes: 23 additions & 3 deletions contracts/minters/open-edition-minter/schema/instantiate_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,36 @@
"OpenEditionMinterInitMsgExtension": {
"type": "object",
"required": [
"end_time",
"mint_price",
"nft_data",
"per_address_limit",
"start_time"
],
"properties": {
"end_time": {
"$ref": "#/definitions/Timestamp"
"anyOf": [
{
"$ref": "#/definitions/Timestamp"
},
{
"type": "null"
}
]
},
"mint_price": {
"$ref": "#/definitions/Coin"
},
"nft_data": {
"$ref": "#/definitions/NftData"
},
"num_tokens": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"payment_address": {
"type": [
"string",
Expand All @@ -333,7 +347,8 @@
"airdrop_mint_fee_bps",
"airdrop_mint_price",
"dev_fee_address",
"max_per_address_limit"
"max_per_address_limit",
"max_token_limit"
],
"properties": {
"airdrop_mint_fee_bps": {
Expand All @@ -351,6 +366,11 @@
"type": "integer",
"format": "uint32",
"minimum": 0.0
},
"max_token_limit": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MintableNumTokensResponse",
"type": "object",
"required": [
"count"
],
"properties": {
"count": {
"type": "integer",
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"type": "object",
"required": [
"admin",
"end_time",
"nft_data",
"per_address_limit",
"start_time"
Expand All @@ -60,11 +59,26 @@
"$ref": "#/definitions/Addr"
},
"end_time": {
"$ref": "#/definitions/Timestamp"
"anyOf": [
{
"$ref": "#/definitions/Timestamp"
},
{
"type": "null"
}
]
},
"nft_data": {
"$ref": "#/definitions/NftData"
},
"num_tokens": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"payment_address": {
"anyOf": [
{
Expand Down
13 changes: 13 additions & 0 deletions contracts/minters/open-edition-minter/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"mintable_num_tokens"
],
"properties": {
"mintable_num_tokens": {
"type": "object",
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
Loading

0 comments on commit 15d2990

Please sign in to comment.