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 #585

Closed
wants to merge 72 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a4e8671
Update sg2 to take an NFT as a min mint price
shanev Jun 24, 2023
a1b8969
Update contracts
shanev Jun 24, 2023
2306299
Add TODOs
shanev Jun 24, 2023
2cbede1
refactored open edition minter
humanalgorithm Jun 28, 2023
88a22de
moving functions to sg2
humanalgorithm Jun 28, 2023
7882018
moving functions to impl in sg2
humanalgorithm Jun 28, 2023
3b3fcb3
fungible/nonfungible amount retrieval for vending-minter
humanalgorithm Jun 29, 2023
c7cdc04
fix discount mint price vs config mint price
humanalgorithm Jun 29, 2023
9c03c5a
redo open edition minter with discount mint price
humanalgorithm Jun 29, 2023
421b2fb
redo vending minter with mint price discount
humanalgorithm Jun 29, 2023
322b8f9
completed fungible checks for vending-minter-wl-flex
humanalgorithm Jun 29, 2023
47da7f2
fix unit test syntax errors
humanalgorithm Jun 29, 2023
84d5b36
now using fungible_coin function in sg2
humanalgorithm Jun 30, 2023
489480d
Add is_fungible
shanev Jul 1, 2023
ef5922d
Re-wrote in more idomatic Rust
shanev Jul 1, 2023
9c4b762
now using new token impl methods
humanalgorithm Jul 1, 2023
c22b8f2
remove erroneous code
humanalgorithm Jul 4, 2023
c165b4f
all passing unit tests
humanalgorithm Jul 4, 2023
52e0f72
cargo lint
humanalgorithm Jul 4, 2023
508be3b
cargo schema for factories
humanalgorithm Jul 4, 2023
08e47e6
adding schemas
humanalgorithm Jul 4, 2023
794bfa1
fix lint
humanalgorithm Jul 4, 2023
6f69acf
basic working version of check collection in base factory
humanalgorithm Jul 7, 2023
9a5e2f0
basic working version of check collection in base factory
humanalgorithm Jul 7, 2023
17f30d4
move into base factory and lint
humanalgorithm Jul 7, 2023
8c490d0
fix lint
humanalgorithm Jul 7, 2023
7986687
sudo params test for invalid collection
humanalgorithm Jul 7, 2023
f7a01e6
add sudo_params_update_creation_fee
humanalgorithm Jul 7, 2023
3c0ab9c
before attempting to refactor open edition minter test code
humanalgorithm Jul 7, 2023
3867f1e
working refactor v1
humanalgorithm Jul 8, 2023
d569f1f
working address limit and invalid code id tests
humanalgorithm Jul 8, 2023
365c616
working complete mint all outcomes
humanalgorithm Jul 8, 2023
0adf708
factory create minter
humanalgorithm Jul 8, 2023
cee33d6
working frozen factory and update mint price
humanalgorithm Jul 8, 2023
2b2c858
working all unit tests
humanalgorithm Jul 8, 2023
5a7e26b
sudo tests for open edition factory
humanalgorithm Jul 9, 2023
171f9d7
update base factory sudo test
humanalgorithm Jul 9, 2023
5c47aaf
working burn test
humanalgorithm Jul 9, 2023
e86b2c7
rebase main
humanalgorithm Aug 20, 2023
52a415f
some refactoring of payments and address checks
humanalgorithm Jul 10, 2023
5822833
assert minter caller
humanalgorithm Jul 10, 2023
026d329
remove clippy cargo
humanalgorithm Jul 10, 2023
63f21a8
remove clippy cargo
humanalgorithm Jul 10, 2023
5a90e8c
fix clippy
humanalgorithm Jul 10, 2023
d487c1e
fix minter vcaller
humanalgorithm Jul 10, 2023
b258e8d
working unit tests for open edition minter
humanalgorithm Jul 11, 2023
7919599
cargo schema
humanalgorithm Jul 11, 2023
f9c87cb
working vending minter tests
humanalgorithm Jul 12, 2023
27caf8a
cargo schema vending minter
humanalgorithm Jul 12, 2023
c87a6fc
min mint price check in open edition factory
humanalgorithm Jul 12, 2023
dacfd0e
remove printlines
humanalgorithm Jul 12, 2023
6dd6fe8
rebase main
humanalgorithm Aug 20, 2023
4a3edaa
respond shane comments part 1
humanalgorithm Aug 16, 2023
92aea0c
put collection or contract check back
humanalgorithm Aug 16, 2023
87a5290
rebase main
humanalgorithm Aug 20, 2023
1f35da3
fix after rebase
humanalgorithm Aug 20, 2023
646c8e0
fix some lint
humanalgorithm Aug 20, 2023
33e1ea3
refactor into burn-to-mint package
humanalgorithm Aug 22, 2023
2472e6c
working v1 for allowed_burn_collections
humanalgorithm Aug 26, 2023
b2c4e90
using utility functions in burn to mint package
humanalgorithm Aug 26, 2023
3a967e4
working version for open edition minter with allowed burn addresses
humanalgorithm Aug 26, 2023
79c425b
working allowed collections for base,vending and open edition minter
humanalgorithm Aug 27, 2023
f9557f5
remove unnecesary check
humanalgorithm Aug 27, 2023
863301f
refactor utility functions
humanalgorithm Aug 27, 2023
44fed17
refactor utility functions and cargo schema
humanalgorithm Aug 27, 2023
1d68e29
merge main and overwrite open edition minter tests
humanalgorithm Aug 27, 2023
99c7706
refactoring burn and mint function for message ordering
humanalgorithm Aug 27, 2023
3d9ed09
adding event attributes to burn message
humanalgorithm Aug 28, 2023
46d482a
using controllers/mint package
humanalgorithm Aug 28, 2023
e623416
working 1 test for ibc minter
humanalgorithm Aug 29, 2023
a0c5e1b
working tests for ibc_asset_mint.rs
humanalgorithm Aug 29, 2023
5d2c5b8
consolidate response message in burn package
humanalgorithm Aug 29, 2023
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: 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"] }
shanev marked this conversation as resolved.
Show resolved Hide resolved
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