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

Safe + whitelisting #48

Merged
merged 47 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1d6fa15
Draft of safe
porkbrain Oct 26, 2022
a301f1e
Merge branch 'beekeeping/removing-white-spaces' into feature/safe
porkbrain Oct 26, 2022
374d729
Merge branch 'main' into feature/safe
porkbrain Oct 26, 2022
290a854
Draft of a heterogenous whitelist
porkbrain Oct 26, 2022
b19d277
Exposing more logic in Safe
porkbrain Oct 26, 2022
db39e3d
Renaming entities to authorities
porkbrain Oct 26, 2022
cf68477
Adding whitelisting errs
porkbrain Oct 26, 2022
c5cb53c
Consistent code styles
porkbrain Oct 26, 2022
278fcf7
Draft of using logical owner and collection in conjunction with white…
porkbrain Oct 26, 2022
f13154b
Fixing a bug where for delisting we only rotate version but not counter
porkbrain Oct 26, 2022
321672e
Removing the store ability
porkbrain Oct 26, 2022
b31e963
Merge remote-tracking branch 'origin/main' into feature/safe
kaizu-xyz Oct 27, 2022
bf13395
Adapted code to new NFT fields
kaizu-xyz Oct 27, 2022
050912b
New Embedded NFTs Flow
kaizu-xyz Oct 27, 2022
8474527
Implementing Safe with ObjectBag
porkbrain Oct 31, 2022
b466939
Merge branch 'main' into feature/safe
porkbrain Oct 31, 2022
a20f330
Renaming rc to ref
porkbrain Oct 31, 2022
7da7133
Using witness for whitelisting which enables us to get rid of colleti…
porkbrain Oct 31, 2022
3c96939
Adding some docs about the 3 witness types
porkbrain Oct 31, 2022
81cd2f5
Renaming generic, using store with Whitelist and creating a struct in…
porkbrain Oct 31, 2022
68d403f
Asserting that tx sender is a collection creator before adding collec…
porkbrain Oct 31, 2022
6ea12b6
Using TypeName instead of String because types can always be referenced
porkbrain Nov 1, 2022
4d13a16
More granular control over what NFTs can be deposited
porkbrain Nov 1, 2022
58ccc98
Deduplicating logic for transfers
porkbrain Nov 1, 2022
0fa8fb1
Adding docs to transfer methods in Nft wrapper module
porkbrain Nov 1, 2022
3d61588
Being consistent with variable naming: target -> recipient
porkbrain Nov 1, 2022
0baa543
Adding docs and renaming some fields
porkbrain Nov 1, 2022
d1f0270
New flow for embedded NFTs
kaizu-xyz Nov 1, 2022
9c693d3
New NFT release flow
kaizu-xyz Nov 1, 2022
6b362fa
Documentation comments
kaizu-xyz Nov 2, 2022
d4b229b
Moving transfer whitelist to trading directory
porkbrain Nov 2, 2022
e0ed26b
Removing NFT ID as input because it's already included in the transfe…
porkbrain Nov 2, 2022
8e32fd9
Merging main into self
porkbrain Nov 3, 2022
f60e001
Merge remote-tracking branch 'origin/main' into feature/safe
kaizu-xyz Nov 4, 2022
50fa532
doc comments
kaizu-xyz Nov 4, 2022
9245e50
Merge remote-tracking branch 'origin/main' into nft-release-flow
kaizu-xyz Nov 4, 2022
b1e9b95
Adapt gutenberg
kaizu-xyz Nov 4, 2022
aabe973
Merge remote-tracking branch 'origin/nft-release-flow' into feature/safe
kaizu-xyz Nov 4, 2022
6ea7402
fix mint functions
kaizu-xyz Nov 4, 2022
6a4d283
Merge branch 'main' into feature/safe
porkbrain Nov 9, 2022
22cd61f
Sorting imports
porkbrain Nov 9, 2022
bdd6126
Merge branch 'main' into feature/safe
porkbrain Nov 14, 2022
d064f95
Co-authored-by: Jakub Łabor <Suficio@users.noreply.github.com>
porkbrain Nov 21, 2022
477b0b9
Fixing merge conflicts
porkbrain Nov 21, 2022
a898a27
Fixing wrong merge to main
porkbrain Nov 21, 2022
1909eda
Simplifying Whitelist by removing a generic
porkbrain Nov 21, 2022
7aa4c99
Merge remote-tracking branch 'origin/develop' into feature/safe
kaizu-xyz Nov 23, 2022
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
17 changes: 9 additions & 8 deletions examples/collectibles.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ module nft_protocol::suinamis {

use sui::tx_context::{Self, TxContext};

use nft_protocol::collection::{MintAuthority};
use nft_protocol::fixed_price;
use nft_protocol::std_collection;
use nft_protocol::collectible;


struct SUINAMIS has drop {}

fun init(witness: SUINAMIS, ctx: &mut TxContext) {
Expand All @@ -22,7 +18,7 @@ module nft_protocol::suinamis {
b"SUIN", // symbol
100, // max_supply
@0x6c86ac4a796204ea09a87b6130db0c38263c1890, // Royalty receiver
tags, // tags
tags,
100, // royalty_fee_bps
true, // is_mutable
b"Some extra data",
Expand All @@ -42,29 +38,34 @@ module nft_protocol::suinamis {
collection_id,
@0x6c86ac4a796204ea09a87b6130db0c38263c1890,
false, // is_embedded
whitelist, prices,
whitelist,
prices,
ctx,
);
}

public entry fun mint_nft<T>(
public entry fun prepare_mint(
name: vector<u8>,
description: vector<u8>,
url: vector<u8>,
attribute_keys: vector<vector<u8>>,
attribute_values: vector<vector<u8>>,
max_supply: u64,
mint: &mut MintAuthority<SUINAMIS>,
sale_outlet: u64,
launchpad: &mut Slingshot<SUINAMIS, FixedPriceMarket>,
ctx: &mut TxContext,
) {
collectible::mint_regulated_nft_data(
collectible::prepare_launchpad_mint<SUINAMIS, FixedPriceMarket>(
name,
description,
url,
attribute_keys,
attribute_values,
max_supply,
mint,
sale_outlet,
launchpad,
ctx,
);
}
Expand Down
10 changes: 5 additions & 5 deletions examples/suimarines.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module nft_protocol::suimarines {

use nft_protocol::collection::{MintAuthority};
use nft_protocol::fixed_price::{Self, FixedPriceMarket};
use nft_protocol::slingshot::Slingshot;
use nft_protocol::std_collection;
use nft_protocol::unique_nft;
use nft_protocol::slingshot::Slingshot;

struct SUIMARINES has drop {}

Expand Down Expand Up @@ -48,25 +48,25 @@ module nft_protocol::suimarines {
);
}

public entry fun mint_nft(
public entry fun prepare_mint(
name: vector<u8>,
description: vector<u8>,
url: vector<u8>,
attribute_keys: vector<vector<u8>>,
attribute_values: vector<vector<u8>>,
mint_authority: &mut MintAuthority<SUIMARINES>,
sale_index: u64,
sale_outlet: u64,
launchpad: &mut Slingshot<SUIMARINES, FixedPriceMarket>,
ctx: &mut TxContext,
) {
unique_nft::mint_regulated_nft(
unique_nft::prepare_launchpad_mint<SUIMARINES, FixedPriceMarket>(
name,
description,
url,
attribute_keys,
attribute_values,
mint_authority,
sale_index,
sale_outlet,
launchpad,
ctx,
);
Expand Down
19 changes: 19 additions & 0 deletions gutenberg/examples/c_nft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
NftType: "CNft"

Collection:
name: "Suricannes"
description: "A Unique NFT collection of Hurricanes on Sui"
symbol: "SURI"
max_supply: 100
receiver: "0x6c86ac4a796204ea09a87b6130db0c38263c1890"
tags:
- "Art"
- "PFP"
royalty_fee_bps: 100
is_mutable: true
data: "Some extra data"

Launchpad:
market_type: "fixed_price"
prices: [1000]
whitelists: [false]
8 changes: 2 additions & 6 deletions gutenberg/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,8 @@ impl Schema {
let define_market_arguments = self.write_define_market_arguments();
let market_arguments = self.write_market_arguments();

let market_module_imports = if is_embedded {
format!("::{{Self, {}}}", market_type)
} else {
"".to_string()
}
.into_boxed_str();
let market_module_imports =
format!("::{{Self, {}}}", market_type).into_boxed_str();

let slingshot_import = if is_embedded {
" use nft_protocol::slingshot::Slingshot;"
Expand Down
41 changes: 26 additions & 15 deletions gutenberg/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,78 +48,89 @@ impl NftType {
// TODO: Need to add support for unregulated collections
let func = match self {
NftType::Unique => format!(
"public entry fun mint_nft(\n \
"public entry fun prepare_mint(\n \
name: vector<u8>,\n \
description: vector<u8>,\n \
url: vector<u8>,\n \
attribute_keys: vector<vector<u8>>,\n \
attribute_values: vector<vector<u8>>,\n \
mint_authority: &mut MintAuthority<{}>,\n \
sale_index: u64,\n \
launchpad: &mut Slingshot<{}, {}>,\n \
mint_authority: &mut MintAuthority<{witness}>,\n \
sale_outlet: u64,\n \
launchpad: &mut Slingshot<{witness}, {market_type}>,\n \
ctx: &mut TxContext,\n \
) {{\n \
unique_nft::mint_regulated_nft(\n \
unique_nft::prepare_launchpad_mint<{witness}, {market_type}>(\n \
name,\n \
description,\n \
url,\n \
attribute_keys,\n \
attribute_values,\n \
mint_authority,\n \
sale_index,\n \
sale_outlet,\n \
launchpad,\n \
ctx,\n \
);\n \
}}",
witness, witness, market_type
witness = witness,
market_type = market_type,
),
NftType::Collectible => format!(
"public entry fun mint_nft<T>(\n \
"public entry fun prepare_mint(\n \
name: vector<u8>,\n \
description: vector<u8>,\n \
url: vector<u8>,\n \
attribute_keys: vector<vector<u8>>,\n \
attribute_values: vector<vector<u8>>,\n \
max_supply: u64,\n \
mint: &mut MintAuthority<{}>,\n \
mint: &mut MintAuthority<{witness}>,\n \
sale_outlet: u64,\n \
launchpad: &mut Slingshot<{witness}, {market_type}>,\n \
ctx: &mut TxContext,\n \
) {{\n \
collectible::mint_regulated_nft_data(\n \
collectible::prepare_launchpad_mint<{witness}, {market_type}>(\n \
name,\n \
description,\n \
url,\n \
attribute_keys,\n \
attribute_values,\n \
max_supply,\n \
mint,\n \
sale_outlet,\n \
launchpad,\n \
ctx,\n \
);\n \
}}",
witness,
witness = witness,
market_type = market_type,
),
NftType::CNft => format!(
"public entry fun mint_nft(\n \
"public entry fun prepare_mint(\n \
name: vector<u8>,\n \
description: vector<u8>,\n \
url: vector<u8>,\n \
attribute_keys: vector<vector<u8>>,\n \
attribute_values: vector<vector<u8>>,\n \
max_supply: u64,\n \
mint: &mut MintAuthority<{}>,\n \
mint: &mut MintAuthority<{witness}>,\n \
sale_outlet: u64,\n \
launchpad: &mut Slingshot<{witness}, {market_type}>,\n \
ctx: &mut TxContext,\n \
) {{\n \
c_nft::mint_regulated_nft_data<{}, c_nft::Data>(\n \
c_nft::prepare_launchpad_mint<{witness}, {market_type}, c_nft::Data>(\n \
name,\n \
description,\n \
url,\n \
attribute_keys,\n \
attribute_values,\n \
max_supply,\n \
mint,\n \
sale_outlet,\n \
launchpad,\n \
ctx,\n \
);\n \
}}",
witness, witness
witness = witness,
market_type = market_type,
),
};
func.into_boxed_str()
Expand Down
4 changes: 1 addition & 3 deletions gutenberg/templates/template.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module nft_protocol::{module_name} {{

use sui::tx_context::{{Self, TxContext}};

use nft_protocol::collection::{{MintAuthority}};
use nft_protocol::{market_module}{market_module_imports};
use nft_protocol::std_collection;
use nft_protocol::{nft_type};
{slingshot_import}

Expand All @@ -19,7 +17,7 @@ module nft_protocol::{module_name} {{
b"{symbol}", // symbol
{max_supply}, // max_supply
@{receiver}, // Royalty receiver
tags, // tags
tags,
{royalty_fee_bps}, // royalty_fee_bps
{is_mutable}, // is_mutable
b"{extra_data}",
Expand Down
89 changes: 37 additions & 52 deletions sources/collection/collection.move
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! frozen, in order to give creators the ability to ammend it prior to
//! the primary sale taking place.
//!
//! TODO: Consider adding a function `destroy_unregulated`?
//! TODO: Consider adding a struct object Collection Proof
//! TODO: Verify creator in function to add creator, and function to post verify
//! TODO: Split field `is_mutable` to `is_mutable` and `frozen` such that
Expand Down Expand Up @@ -121,7 +120,7 @@ module nft_protocol::collection {


/// Initialises a `MintAuthority` and transfers it to `authority` and
/// initialized `Collection` object and returns it. The `MintAuthority`
/// initializes a `Collection` object and returns it. The `MintAuthority`
/// object gives power to the owner to mint objects. There is only one
/// `MintAuthority` per `Collection`. The Mint Authority object contains a
/// `SupplyPolicy` which can be regulated or unregulated.
Expand Down Expand Up @@ -189,52 +188,20 @@ module nft_protocol::collection {
}
}

// TODO: Requires fixing
// /// Burn a Collection with regulated supply object and
// /// returns the Metadata object
// public entry fun burn_regulated<T, M: store>(
// collection: Collection<T, M>,
// mint: MintAuthority<T>,
// ): M {
// assert!(
// supply::current(supply_policy::supply(&mint.supply_policy)) == 0,
// err::supply_is_not_zero()
// );

// let MintAuthority {
// id,
// collection_id: _,
// supply_policy,
// } = mint;

// object::delete(id);

// event::emit(
// BurnEvent {
// collection_id: id(&collection),
// }
// );

// let Collection {
// id,
// name: _,
// description: _,
// symbol: _,
// receiver: _,
// tags: _,
// is_mutable: _,
// royalty_fee_bps: _,
// creators: _,
// mint_authority: _,
// metadata,
// } = collection;

// supply_policy::destroy_regulated(supply_policy);

// object::delete(id);

// metadata
// }
/// Shares the `MintAuthority` object of a given `Collection`. For NFT
/// collections that require users to be the ones to mint the data, one
/// requires the `MintAuthority` to be shared, such that they can access the
/// nft mint functions.
///
/// An example of this could be a Domain Name Service protocol, which
/// relies on users calling the nft mint function themselses and therefore
/// minting their domain name.
public fun share_authority<T, M: store>(
authority: MintAuthority<T>,
_collection: &Collection<T, M>,
) {
transfer::share_object(authority);
}

/// Make Collections immutable
/// WARNING: this is irreversible, use with care
Expand Down Expand Up @@ -537,8 +504,8 @@ module nft_protocol::collection {
/// Get the Collections's `tags`
public fun tags<T, M: store>(
collection: &Collection<T, M>,
): Tags {
collection.tags
): &Tags {
&collection.tags
}

/// Get the Collection's `is_mutable`
Expand All @@ -558,8 +525,8 @@ module nft_protocol::collection {
/// Get the Collection's `creators`
public fun creators<T, M: store>(
collection: &Collection<T, M>,
): vector<Creator> {
collection.creators
): &vector<Creator> {
&collection.creators
}

/// Get an immutable reference to Collections's `cap`
Expand Down Expand Up @@ -602,6 +569,24 @@ module nft_protocol::collection {
mint.collection_id
}

// === Utility Function ===

public fun is_creator(
who: address,
creators: &vector<Creator>,
): bool {
let i = 0;
while (i < vector::length(creators)) {
let creator = vector::borrow(creators, i);
if (creator.creator_address == who) {
return true
};
i = i + 1;
};

false
}

// === Private Functions ===

fun create_mint_authority<T>(
Expand Down
Loading