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

Update minter and collection ownership #603

Closed
wants to merge 4 commits 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
39 changes: 10 additions & 29 deletions contracts/collections/sg721-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,14 @@ where
info: MessageInfo,
collection_msg: UpdateCollectionInfoMsg<RoyaltyInfoResponse>,
) -> Result<Response, ContractError> {
only_minter(deps.storage, &info.sender)?;

let mut collection = self.collection_info.load(deps.storage)?;

if self.frozen_collection_info.load(deps.storage)? {
return Err(ContractError::CollectionInfoFrozen {});
}

// only creator can update collection info
if collection.creator != info.sender {
return Err(ContractError::Unauthorized {});
}

collection.description = collection_msg
.description
.unwrap_or_else(|| collection.description.to_string());
Expand Down Expand Up @@ -246,14 +243,12 @@ where

if share_delta > Decimal::percent(MAX_SHARE_DELTA_PCT) {
return Err(ContractError::InvalidRoyalties(format!(
"Share increase cannot be greater than {}%",
MAX_SHARE_DELTA_PCT
"Share increase cannot be greater than {MAX_SHARE_DELTA_PCT}%"
)));
}
if new_royalty_info.share > Decimal::percent(MAX_ROYALTY_SHARE_PCT) {
return Err(ContractError::InvalidRoyalties(format!(
"Share cannot be greater than {}%",
MAX_ROYALTY_SHARE_PCT
"Share cannot be greater than {MAX_ROYALTY_SHARE_PCT}%"
)));
}
}
Expand All @@ -279,7 +274,7 @@ where
info: MessageInfo,
start_time: Option<Timestamp>,
) -> Result<Response, ContractError> {
assert_minter_owner(deps.storage, &info.sender)?;
only_minter(deps.storage, &info.sender)?;

let mut collection_info = self.collection_info.load(deps.storage)?;
collection_info.start_trading_time = start_time;
Expand All @@ -295,10 +290,7 @@ where
_env: Env,
info: MessageInfo,
) -> Result<Response, ContractError> {
let collection = self.query_collection_info(deps.as_ref())?;
if collection.creator != info.sender {
return Err(ContractError::Unauthorized {});
}
only_minter(deps.storage, &info.sender)?;

let frozen = true;
self.frozen_collection_info.save(deps.storage, &frozen)?;
Expand All @@ -313,7 +305,8 @@ where
info: MessageInfo,
nft_data: NftParams<T>,
) -> Result<Response, ContractError> {
assert_minter_owner(deps.storage, &info.sender)?;
only_minter(deps.storage, &info.sender)?;

let (token_id, owner, token_uri, extension) = match nft_data {
NftParams::NftData {
token_id,
Expand Down Expand Up @@ -428,18 +421,6 @@ pub fn share_validate(share: Decimal) -> Result<Decimal, ContractError> {
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 {
Ok(_) => Ok(()),
Err(_) => Err(ContractError::UnauthorizedOwner {}),
}
pub fn only_minter(storage: &mut dyn Storage, sender: &Addr) -> Result<(), ContractError> {
cw_ownable::assert_owner(storage, sender).map_err(ContractError::Ownership)
}
3 changes: 3 additions & 0 deletions contracts/collections/sg721-base/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub enum ContractError {
#[error("{0}")]
Base(#[from] cw721_base::ContractError),

#[error("{0}")]
Ownership(#[from] cw_ownable::OwnershipError),

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

Expand Down
37 changes: 13 additions & 24 deletions contracts/collections/sg721-updatable/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
use crate::error::ContractError;
use crate::msg::{EnableUpdatableResponse, FrozenTokenMetadataResponse};
use crate::state::ENABLE_UPDATABLE;
use crate::state::FROZEN_TOKEN_METADATA;
use cosmwasm_std::{Empty, StdError, Uint128};

use cosmwasm_std::{Deps, StdResult};

#[cfg(not(feature = "library"))]
use cosmwasm_std::{DepsMut, Env, Event, MessageInfo};
use cosmwasm_std::{Empty, StdError, Uint128};
use cw2::set_contract_version;
use semver::Version;
use sg721::InstantiateMsg;
use sg721_base::msg::CollectionInfoResponse;

use crate::msg::{EnableUpdatableResponse, FrozenTokenMetadataResponse};
use crate::state::ENABLE_UPDATABLE;

use cw721_base::Extension;
use cw_utils::nonpayable;
use semver::Version;
use sg1::checked_fair_burn;
use sg721_base::ContractError::Unauthorized;
use sg721::InstantiateMsg;
use sg721_base::contract::only_minter;
use sg721_base::msg::CollectionInfoResponse;
use sg721_base::Sg721Contract;
pub type Sg721UpdatableContract<'a> = Sg721Contract<'a, Extension>;
use sg721_base::ContractError::Unauthorized;
use sg_std::Response;

const CONTRACT_NAME: &str = "crates.io:sg721-updatable";
Expand Down Expand Up @@ -54,6 +51,8 @@ pub fn execute_enable_updatable(
_env: Env,
info: MessageInfo,
) -> Result<Response, ContractError> {
only_minter(deps.storage, &info.sender)?;

let enable_updates = ENABLE_UPDATABLE.load(deps.storage)?;
let mut res = Response::new();
if enable_updates {
Expand Down Expand Up @@ -83,12 +82,7 @@ pub fn execute_freeze_token_metadata(
info: MessageInfo,
) -> Result<Response, ContractError> {
nonpayable(&info)?;
// Check if sender is creator
let collection_info: CollectionInfoResponse =
Sg721UpdatableContract::default().query_collection_info(deps.as_ref())?;
if info.sender != collection_info.creator {
return Err(ContractError::Base(Unauthorized {}));
}
only_minter(deps.storage, &info.sender)?;

FROZEN_TOKEN_METADATA.save(deps.storage, &true)?;

Expand All @@ -105,13 +99,7 @@ pub fn execute_update_token_metadata(
token_uri: Option<String>,
) -> Result<Response, ContractError> {
nonpayable(&info)?;
// Check if sender is creator
let owner = deps.api.addr_validate(info.sender.as_ref())?;
let collection_info: CollectionInfoResponse =
Sg721UpdatableContract::default().query_collection_info(deps.as_ref())?;
if owner != collection_info.creator {
return Err(ContractError::Base(Unauthorized {}));
}
only_minter(deps.storage, &info.sender)?;

// Check if token metadata is frozen
let frozen = FROZEN_TOKEN_METADATA.load(deps.storage)?;
Expand Down Expand Up @@ -240,6 +228,7 @@ mod tests {
};
use cw721::Cw721Query;
use sg721::{CollectionInfo, InstantiateMsg};
use sg721_base::ContractError::Unauthorized;
use std::marker::PhantomData;

const CREATOR: &str = "creator";
Expand Down
Loading