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

Conversation

humanalgorithm
Copy link
Contributor

Please see #585 for previous branch.

Closed previous branch because commit history was causing errors when rebase main.

This PR has several modules to it:

  1. Fungible and Nonfungible msg types in sg2:
pub enum Token {
    Fungible(Coin),
    NonFungible(String),
}
  1. The branching logic to check if receiving fungible or nonfungible token in contracts. All of the use of mint price through contracts and factories had to be changed to support this. Usually this is done implicitly in the .amount() checks. For example:
let config_mint_price = config.mint_price.clone().amount()?;

The amount() function has an implicit check:

    pub fn amount(self) -> Result<Uint128, StdError> {
        let amount = match self {
            Token::Fungible(coin) => coin.amount,
            Token::NonFungible(_) => {
                return Err(StdError::generic_err("non-fungible tokens have no amount"))
            }
        };
        Ok(amount)
    }
}
  1. Refactor of open edition minter tests: The open edition minter tests were in a bad state, so I refactored them to be more consistent. The files changed are the following:
test-suite/src/common_setup/templates.rs
* in test-suite/src/open_edition_factory/
* in test-suite/src/open_edition_minter
* in test-suite/src/common_setup/setup_minter/open_edition_minter/
test-suite/src/common_setup/setup_minter/open_edition_minter.rs
  1. Missing sudo tests: there was not sufficient tests for sudo update params so I added them in the following files:
test-suite/src/base_factory/tests/sudo_tests.rs
test-suite/src/open_edition_factory/tests/sudo_tests.rs
test-suite/src/vending_factory/tests/sudo_tests.rs
  1. Updates to minters: All three minters base-minter, vending-minter and open-edition minter had the following changes:
  • Add a ReceiveNft(Cw721ReceiveMsg) path to execute
  • Add a execute_burn_to_mint function to respond to the receive NFT message
  • Updates to execute_mint functions to accomodate for not paying a mint fee when an NFT is received (collection contract will be calling itself)
  1. check_minter_caller added to s721-base: We need this assertion check because, when an NFT is received, that contract will burn that NFT and then itself call a collection for a mint. The check minter caller, allows an sg721-base collection to call itself.

  2. burn_to_mint tests: burn_to_mint.rs was added to vending-minter, open-edition-minter and base-minter tests. A send nft is sent like so:

    let send_nft = Cw721ExecuteMsg::SendNft {
        contract: minter_addr_2.to_string(),
        token_id: 1.to_string(),
        msg: to_binary("this is a test").unwrap(),
    };
    ```
    The message is sent to collection 1, with instructions to have collection 1 forward that NFT to minter 2. In this way, the functionality of burn to mint is tested end to end. 

@humanalgorithm humanalgorithm mentioned this pull request Aug 29, 2023
@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Patch coverage: 85.03% and project coverage change: +3.83% 🎉

Comparison is base (2861976) 59.20% compared to head (b2137cb) 63.04%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #610      +/-   ##
==========================================
+ Coverage   59.20%   63.04%   +3.83%     
==========================================
  Files          80       84       +4     
  Lines        4246     4662     +416     
==========================================
+ Hits         2514     2939     +425     
+ Misses       1732     1723       -9     
Files Changed Coverage Δ
contracts/collections/sg721-base/src/contract.rs 62.04% <0.00%> (+1.87%) ⬆️
...tracts/collections/sg721-updatable/src/contract.rs 50.56% <ø> (ø)
...cts/minters/vending-minter-wl-flex/src/contract.rs 0.00% <0.00%> (ø)
e2e/src/helpers/helper.rs 0.00% <0.00%> (ø)
e2e/src/helpers/open_edition_minter_helpers.rs 0.00% <0.00%> (ø)
contracts/factories/base-factory/src/contract.rs 84.69% <43.75%> (+0.78%) ⬆️
...up/setup_minter/open_edition_minter/mock_params.rs 46.15% <54.54%> (-53.85%) ⬇️
packages/sg2/src/lib.rs 62.50% <62.50%> (ø)
...cts/factories/open-edition-factory/src/contract.rs 94.44% <71.42%> (+1.38%) ⬆️
...src/common_setup/setup_minter/base_minter/setup.rs 90.27% <72.00%> (-9.73%) ⬇️
... and 14 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link

github-actions bot commented Sep 1, 2023

Cosm-Orc Gas Usage

Contract Op Name Gas Used Old Gas Used Gas Diff File
open_edition_factory Execute__factory_exec_minter_inst_w_trading_time 545174 542350 +0.5207% e2e/src/tests/open_edition_factory_and_mint_tests.rs:405
open_edition_factory Store__Store 3708621 3434360 +7.9858% e2e/src/helpers/chain.rs:78
open_edition_factory Execute__factory_exec_minter_inst 544455 541640 +0.5197% e2e/src/tests/open_edition_minter_executes_tests.rs:59
multiple_contracts Execute__minter_batch_exec_mint_token 1587295 3106975 -48.9119% e2e/src/tests/open_edition_minter_executes_tests.rs:142
multiple_contracts Execute__minter_batch_exec_mint_token_w_trading_time 1944878 3108261 -37.4287% e2e/src/tests/factory_test.rs:314
vending_factory Store__Store 3202063 3044906 +5.1613% e2e/src/helpers/chain.rs:78
base_factory Store__Store 2811686 2665605 +5.4802% e2e/src/helpers/chain.rs:78
base_minter Store__Store 7355993 6995048 +5.1600% e2e/src/helpers/chain.rs:78
open_edition_minter Store__Store 8945659 8493792 +5.3200% e2e/src/helpers/chain.rs:78
vending_minter Store__Store 9236248 8757887 +5.4621% e2e/src/helpers/chain.rs:78
vending_minter_wl_flex Store__Store 9101016 8935500 +1.8523% e2e/src/helpers/chain.rs:78
minter Execute__minter_exec_update_per_addr_limit 210722 209170 +0.7420% e2e/src/tests/open_edition_minter_executes_tests.rs:216
Raw Report for b2137cb
Contract Op Name Gas Used Gas Wanted File
open_edition_factory Instantiate__factory_inst 187539 258192 e2e/src/helpers/open_edition_minter_helpers.rs:39
open_edition_factory Execute__factory_exec_minter_inst_w_trading_time 545174 794636 e2e/src/tests/open_edition_factory_and_mint_tests.rs:405
open_edition_factory Store__Store 3708621 5539791 e2e/src/helpers/chain.rs:78
open_edition_factory Execute__factory_exec_minter_inst 544455 793563 e2e/src/tests/open_edition_minter_executes_tests.rs:59
multiple_contracts Execute__minter_batch_exec_mint_token 1587295 2358092 e2e/src/tests/open_edition_minter_executes_tests.rs:142
multiple_contracts Execute__minter_batch_exec_mint_token_w_trading_time 1944878 2909832 e2e/src/tests/factory_test.rs:314
vending_factory Execute__factory_exec_minter_inst 34040243 51037146 e2e/src/tests/factory_test.rs:98
vending_factory Instantiate__factory_inst 188231 259230 e2e/src/helpers/helper.rs:35
vending_factory Execute__factory_exec_minter_inst_w_trading_time 3860441 5767457 e2e/src/tests/factory_test.rs:244
vending_factory Store__Store 3202063 4779954 e2e/src/helpers/chain.rs:78
base_factory Store__Store 2811686 4194389 e2e/src/helpers/chain.rs:78
base_minter Store__Store 7355993 11010789 e2e/src/helpers/chain.rs:78
open_edition_minter Store__Store 8945659 13395288 e2e/src/helpers/chain.rs:78
sg721_base Store__Store 8384995 12554292 e2e/src/helpers/chain.rs:78
sg721_metadata_onchain Store__Store 8836004 13230806 e2e/src/helpers/chain.rs:78
sg721_nt Store__Store 7784265 11653197 e2e/src/helpers/chain.rs:78
sg721_updatable Store__Store 9160770 13717955 e2e/src/helpers/chain.rs:78
sg_whitelist Store__Store 3582040 5349920 e2e/src/helpers/chain.rs:78
sg_whitelist_flex Store__Store 3519822 5256593 e2e/src/helpers/chain.rs:78
vending_minter Store__Store 9236248 13831172 e2e/src/helpers/chain.rs:78
vending_minter_wl_flex Store__Store 9101016 13628319 e2e/src/helpers/chain.rs:78
whitelist_immutable Store__Store 2195122 3269543 e2e/src/helpers/chain.rs:78
minter Execute__minter_exec_mint_to_token 364509 523647 e2e/src/tests/open_edition_minter_executes_tests.rs:180
minter Execute__minter_exec_purge 139165 185681 e2e/src/tests/open_edition_minter_executes_tests.rs:281
minter Execute__minter_exec_update_per_addr_limit 210722 292967 e2e/src/tests/open_edition_minter_executes_tests.rs:216
minter Execute__minter_exec_update_trading_time 271526 384171 e2e/src/tests/open_edition_minter_executes_tests.rs:99

@shanev
Copy link
Member

shanev commented Sep 7, 2023

Closing in favor of implementing burn-to-mint using mint hooks instead. A lot of this code will make its way into those hooks so will keep this PR around.

@shanev shanev closed this Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants