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

Burn to Mint [rebase main] #610

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 34 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ open-edition-minter = { version = "3.1.0", path = "contracts/minters/open-editi
whitelist-immutable = { version = "3.1.0", path = "contracts/whitelists/whitelist-immutable" }
sg-whitelist-flex = { version = "3.1.0", path = "contracts/whitelists/whitelist-flex" }
ethereum-verify = { version = "3.1.0", path = "packages/ethereum-verify" }
burn-to-mint = { version = "3.1.0", path = "packages/burn-to-mint" }
sg-eth-airdrop = { version = "3.1.0", path = "contracts/sg-eth-airdrop" }
test-suite = { version = "3.1.0", path = "test-suite" }
semver = "1"
Expand Down
24 changes: 11 additions & 13 deletions contracts/collections/sg721-base/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use cw721_base::state::TokenInfo;
use cw721_base::MinterResponse;

use url::Url;

use cosmwasm_std::{
to_binary, Addr, Binary, ContractInfoResponse, Decimal, Deps, DepsMut, Empty, Env, Event,
MessageInfo, StdError, StdResult, Storage, Timestamp, WasmQuery,
from_binary, to_binary, Addr, Binary, ContractInfoResponse, Decimal, Deps, DepsMut, Empty, Env,
Event, MessageInfo, StdError, StdResult, Storage, Timestamp, WasmQuery,
};

use cw721::{ContractInfoResponse as CW721ContractInfoResponse, Cw721Execute};
Expand All @@ -16,7 +18,7 @@
};
use sg_std::Response;

use crate::msg::{CollectionInfoResponse, NftParams, QueryMsg};
use crate::msg::{self, CollectionInfoResponse, NftParams, QueryMsg};
use crate::{ContractError, Sg721Contract};

use crate::entry::{CONTRACT_NAME, CONTRACT_VERSION};
Expand Down Expand Up @@ -322,7 +324,6 @@
extension,
} => (token_id, owner, token_uri, extension),
};

// create the token
let token = TokenInfo {
owner: deps.api.addr_validate(&owner)?,
Expand All @@ -336,7 +337,6 @@
Some(_) => Err(ContractError::Claimed {}),
None => Ok(token),
})?;

self.parent.increment_tokens(deps.storage)?;

let mut res = Response::new()
Expand Down Expand Up @@ -416,6 +416,12 @@

Ok(response)
}

pub fn get_minter_owner_parent(&self, deps: Deps, env: Env) -> StdResult<MinterResponse> {
let msg = msg::QueryMsg::Minter {};
let minter: MinterResponse = from_binary(&self.parent.query(deps, env, msg.into())?)?;
Ok(minter)

Check warning on line 423 in contracts/collections/sg721-base/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/collections/sg721-base/src/contract.rs#L420-L423

Added lines #L420 - L423 were not covered by tests
}
}

pub fn share_validate(share: Decimal) -> Result<Decimal, ContractError> {
Expand All @@ -428,14 +434,6 @@
Ok(share)
}

pub fn get_owner_minter(storage: &mut dyn Storage) -> Result<Addr, ContractError> {
let ownership = cw_ownable::get_ownership(storage)?;
match ownership.owner {
Some(owner_value) => Ok(owner_value),
None => Err(ContractError::MinterNotFound {}),
}
}

pub fn assert_minter_owner(storage: &mut dyn Storage, sender: &Addr) -> Result<(), ContractError> {
let res = cw_ownable::assert_owner(storage, sender);
match res {
Expand Down
6 changes: 6 additions & 0 deletions contracts/collections/sg721-base/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ pub enum ContractError {

#[error("Error while migrating: ({0}) ")]
MigrationError(String),

#[error("Contract ownership has been renounced")]
NoOwner,

#[error("Caller is not the contract's current owner")]
NotOwner,
}
2 changes: 1 addition & 1 deletion contracts/collections/sg721-updatable/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sg721_base::Sg721Contract;
pub type Sg721UpdatableContract<'a> = Sg721Contract<'a, Extension>;
use sg_std::Response;

const CONTRACT_NAME: &str = "crates.io:sg721-updatable";
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
const EARLIEST_COMPATIBLE_VERSION: &str = "0.16.0";
const COMPATIBLE_CONTRACT_NAMES_FOR_MIGRATION: [&str; 4] = [
Expand Down
2 changes: 2 additions & 0 deletions contracts/factories/base-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ schemars = { workspace = true }
serde = { workspace = true }
sg1 = { workspace = true }
sg2 = { workspace = true }
cw721-base = { workspace = true, features = ["library"] }
sg721-base = { workspace = true, features = ["library"]}
sg-std = { workspace = true }
thiserror = { workspace = true }
30 changes: 22 additions & 8 deletions contracts/factories/base-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
ParamsResponse, SudoMsg,
};
use crate::state::SUDO_PARAMS;

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:sg-base-factory";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -123,7 +122,7 @@
) -> Result<Response, ContractError> {
let mut params = SUDO_PARAMS.load(deps.storage)?;

update_params(&mut params, param_msg)?;
update_params(&mut params, param_msg, deps.as_ref())?;

SUDO_PARAMS.save(deps.storage, &params)?;

Expand All @@ -134,6 +133,7 @@
pub fn update_params<T, C>(
params: &mut MinterParams<C>,
param_msg: UpdateMinterParamsMsg<T>,
deps: Deps,
) -> Result<(), ContractError> {
params.code_id = param_msg.code_id.unwrap_or(params.code_id);

Expand All @@ -149,13 +149,27 @@
);
params.creation_fee = creation_fee;
}

if let Some(min_mint_price) = param_msg.min_mint_price {
ensure_eq!(
&min_mint_price.denom,
&NATIVE_DENOM,
ContractError::InvalidDenom {}
);
match min_mint_price.clone() {
sg2::Token::Fungible(mint_price) => {
ensure_eq!(
&mint_price.denom,
&NATIVE_DENOM,
ContractError::InvalidDenom {}

Check warning on line 158 in contracts/factories/base-factory/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/factories/base-factory/src/contract.rs#L154-L158

Added lines #L154 - L158 were not covered by tests
);
}
sg2::Token::NonFungible(collection) => {
let minter_response: Result<
cw721_base::msg::MinterResponse,
cosmwasm_std::StdError,
> = deps
.querier

Check warning on line 166 in contracts/factories/base-factory/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/factories/base-factory/src/contract.rs#L163-L166

Added lines #L163 - L166 were not covered by tests
.query_wasm_smart(collection, &sg721_base::QueryMsg::Minter {});
if minter_response.is_err() {
return Err(ContractError::InvalidCollectionAddress {});
}
}
}
params.min_mint_price = min_mint_price;
}

Expand Down
6 changes: 6 additions & 0 deletions contracts/factories/base-factory/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ pub enum ContractError {

#[error("InvalidCollectionCodeId {code_id}")]
InvalidCollectionCodeId { code_id: u64 },

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

#[error("NoMinterForNonfungibleToken")]
NoMinterForNonfungibleToken {},
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"minimum": 0.0
},
"min_mint_price": {
"$ref": "#/definitions/Coin"
"$ref": "#/definitions/Token"
},
"mint_fee_bps": {
"type": "integer",
Expand Down Expand Up @@ -108,6 +108,34 @@
},
"additionalProperties": false
},
"Token": {
"oneOf": [
{
"type": "object",
"required": [
"fungible"
],
"properties": {
"fungible": {
"$ref": "#/definitions/Coin"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"non_fungible"
],
"properties": {
"non_fungible": {
"type": "string"
}
},
"additionalProperties": false
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 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 `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
Expand Down
37 changes: 23 additions & 14 deletions contracts/factories/open-edition-factory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
let params = msg.params;

ensure!(
params.extension.airdrop_mint_price.denom == params.min_mint_price.denom,
params.extension.airdrop_mint_price.denom == params.clone().min_mint_price.denom()?,
BaseContractError::InvalidDenom {}
);

ensure!(
params.creation_fee.denom == NATIVE_DENOM,
BaseContractError::InvalidDenom {}
);

SUDO_PARAMS.save(deps.storage, &params)?;

Ok(Response::new())
Expand Down Expand Up @@ -85,19 +82,31 @@
deps.as_ref(),
&params,
)?;

ensure!(
params.min_mint_price.denom == msg.init_msg.mint_price.denom,
params.min_mint_price.clone().denom()? == msg.init_msg.mint_price.denom,
BaseContractError::InvalidDenom {}
);

ensure!(
params.min_mint_price.amount <= msg.init_msg.mint_price.amount,
ContractError::InsufficientMintPrice {
expected: params.min_mint_price.amount.u128(),
let min_mint_price = params.min_mint_price.amount()?;
if min_mint_price > msg.init_msg.mint_price.amount {
return Err(ContractError::InsufficientMintPrice {
expected: min_mint_price.into(),

Check warning on line 92 in contracts/factories/open-edition-factory/src/contract.rs

View check run for this annotation

Codecov / codecov/patch

contracts/factories/open-edition-factory/src/contract.rs#L91-L92

Added lines #L91 - L92 were not covered by tests
got: msg.init_msg.mint_price.amount.into(),
}
);
});
}
// =======
// ensure!(
// params.min_mint_price.denom == msg.init_msg.mint_price.denom,
// BaseContractError::InvalidDenom {}
// );

// ensure!(
// params.min_mint_price.amount <= msg.init_msg.mint_price.amount,
// ContractError::InsufficientMintPrice {
// expected: params.min_mint_price.amount.u128(),
// >>>>>>> main
// got: msg.init_msg.mint_price.amount.into(),
// }
// );

let wasm_msg = WasmMsg::Instantiate {
admin: Some(info.sender.to_string()),
Expand Down Expand Up @@ -127,7 +136,7 @@
) -> Result<Response, ContractError> {
let mut params = SUDO_PARAMS.load(deps.storage)?;

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

params.extension.dev_fee_address = param_msg
.extension
Expand Down
3 changes: 2 additions & 1 deletion contracts/factories/open-edition-factory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ impl OpenEditionMinterInitMsgExtension {
));
}

if init_msg.mint_price.amount < params.min_mint_price.amount {
let min_mint_price = params.min_mint_price.clone().amount()?;
if init_msg.mint_price.amount < min_mint_price {
return Err(ContractError::InvalidMintPrice {});
}

Expand Down
Loading
Loading