Skip to content

Commit

Permalink
Merge pull request #19 from gear-foundation/tm-update-contract
Browse files Browse the repository at this point in the history
Update contract
  • Loading branch information
MedovTimur authored Jul 30, 2024
2 parents 1eb9587 + e94a85e commit 7b0d514
Show file tree
Hide file tree
Showing 22 changed files with 4,343 additions and 3,448 deletions.
17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"nft",
"composable-nft",
"music-nft",

]

[package]
Expand All @@ -16,7 +15,7 @@ license.workspace = true
authors.workspace = true

[dependencies]
gstd.workspace = true
gstd = { workspace = true, features = ["debug"] }
hashbrown = "0.13"
parity-scale-codec.workspace = true
scale-info.workspace = true
Expand Down Expand Up @@ -55,13 +54,13 @@ license = "MIT"
authors = ["Gear Technologies"]

[workspace.dependencies]
gstd = { git = "https://github.com/gear-tech/gear", tag = "v1.0.2" }
gear-wasm-builder = { git = "https://github.com/gear-tech/gear", tag = "v1.0.2" }
gmeta = { git = "https://github.com/gear-tech/gear", tag = "v1.0.2" }
gclient = { git = "https://github.com/gear-tech/gear", tag = "v1.0.2" }
gtest = { git = "https://github.com/gear-tech/gear"}
gear-core = { git = "https://github.com/gear-tech/gear", tag = "v1.0.2" }
gcore = { git = "https://github.com/gear-tech/gear", tag = "v1.0.2" }
gstd = "1.1.0"
gear-wasm-builder = "1.1.0"
gmeta = "1.1.0"
gclient = "1.1.0"
gtest = { git = "https://github.com/gear-tech/gear", tag = "v1.1.0" }
gear-core = "1.1.0"
gcore = "1.1.0"
primitive-types = { version = "0.12", default-features = false }
nft-marketplace-io = { path = "io" }
nft-io = { path = "nft/io" }
Expand Down
139 changes: 120 additions & 19 deletions io/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![no_std]
use gmeta::{In, InOut, Metadata};
use gstd::{prelude::*, ActorId, CodeId};

pub struct NftMarketplaceMetadata;
impl Metadata for NftMarketplaceMetadata {
type Init = In<NftMarketplaceInit>;
Expand All @@ -16,25 +15,29 @@ impl Metadata for NftMarketplaceMetadata {
/// * gas_for_transfer_token - gas that is needed to transfer nft tokens (in case of sale, auction or offer)
/// * gas_for_close_auction - gas which is needed to send a delayed message to close the auction
/// (this action includes a transfer, so gas_for_close_auction must be greater than gas_for_transfer_token)
/// * gas_for_delete_collection - gas that is needed to delete a collection
/// * gas_for_delete_collection - gas that is needed to delete a collection
/// (a message is sent to the collection contract to see if the collection can be deleted)
/// * gas_for_get_token_info - gas which is needed to get information from the collection about the token
/// * gas_for_get_info - gas which is needed to get information from the collection
/// (used for sale, auction and offers)
/// * time_between_create_collections - time between collection creation
/// * time_between_create_collections - time between collection creation
/// (to avoid regular users from creating collections too often)
/// * minimum_transfer_value - minimum allowable transfer value
/// * ms_in_block - number of milliseconds in one block
/// (this variable is needed to correctly calculate the time for the delayed message in the auction)
#[derive(Encode, Decode, TypeInfo)]
pub struct NftMarketplaceInit {
pub gas_for_creation: u64,
pub gas_for_transfer_token: u64,
pub gas_for_transfer_token: u64,
pub gas_for_mint: u64,
pub gas_for_close_auction: u64,
pub gas_for_delete_collection: u64,
pub gas_for_get_token_info: u64,
pub gas_for_get_info: u64,
pub time_between_create_collections: u64,
pub minimum_transfer_value: u128,
pub royalty_to_marketplace_for_trade: u16,
pub royalty_to_marketplace_for_mint: u16,
pub ms_in_block: u32,
pub fee_per_uploaded_file: u128,
pub max_creator_royalty: u16,
pub max_number_of_images: u64,
}

#[derive(Encode, Decode, TypeInfo)]
Expand All @@ -44,11 +47,15 @@ pub enum NftMarketplaceAction {
meta_link: String,
type_name: String,
type_description: String,
allow_create: bool,
},
CreateCollection {
type_name: String,
payload: Vec<u8>,
},
Mint {
collection_address: ActorId,
},
SaleNft {
collection_address: ActorId,
token_id: u64,
Expand All @@ -66,7 +73,7 @@ pub enum NftMarketplaceAction {
collection_address: ActorId,
token_id: u64,
min_price: u128,
duration_ms: u32,
duration: u32,
},
AddBid {
collection_address: ActorId,
Expand Down Expand Up @@ -102,18 +109,38 @@ pub enum NftMarketplaceAction {
},
UpdateConfig {
gas_for_creation: Option<u64>,
gas_for_mint: Option<u64>,
gas_for_transfer_token: Option<u64>,
gas_for_close_auction: Option<u64>,
gas_for_delete_collection: Option<u64>,
gas_for_get_token_info: Option<u64>,
gas_for_get_info: Option<u64>,
time_between_create_collections: Option<u64>,
minimum_transfer_value: Option<u128>,
royalty_to_marketplace_for_trade: Option<u16>,
royalty_to_marketplace_for_mint: Option<u16>,
ms_in_block: Option<u32>,
fee_per_uploaded_file: Option<u128>,
max_creator_royalty: Option<u16>,
max_number_of_images: Option<u64>,
},
AllowMessage(bool),
AllowCreateCollection(bool),
AddExternalCollection {
collection_address: ActorId,
type_name: String,
},
}

#[derive(Encode, Decode, Debug, TypeInfo)]
pub enum NftMarketplaceEvent {
Initialized {
time_between_create_collections: u64,
royalty_to_marketplace_for_trade: u16,
royalty_to_marketplace_for_mint: u16,
minimum_value_for_trade: u128,
fee_per_uploaded_file: u128,
max_creator_royalty: u16,
max_number_of_images: u64,
},
NewCollectionAdded {
code_id: CodeId,
meta_link: String,
Expand All @@ -124,6 +151,10 @@ pub enum NftMarketplaceEvent {
type_name: String,
collection_address: ActorId,
},
Minted {
collection_address: ActorId,
minter: ActorId,
},
SaleNft {
collection_address: ActorId,
token_id: u64,
Expand Down Expand Up @@ -184,18 +215,54 @@ pub enum NftMarketplaceEvent {
},
ConfigUpdated {
gas_for_creation: Option<u64>,
gas_for_mint: Option<u64>,
gas_for_transfer_token: Option<u64>,
gas_for_close_auction: Option<u64>,
gas_for_delete_collection: Option<u64>,
gas_for_get_token_info: Option<u64>,
gas_for_get_info: Option<u64>,
time_between_create_collections: Option<u64>,
minimum_transfer_value: Option<u128>,
royalty_to_marketplace_for_trade: Option<u16>,
royalty_to_marketplace_for_mint: Option<u16>,
ms_in_block: Option<u32>,
minimum_value_for_trade: Option<u128>,
fee_per_uploaded_file: Option<u128>,
max_creator_royalty: Option<u16>,
max_number_of_images: Option<u64>,
},
BalanceHasBeenWithdrawn {
value: u128,
},
ValueSent,
AllowMessageChanged,
AllowCreateCollectionChanged,
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo)]
pub struct NftMarketplaceError(pub String);
pub enum NftMarketplaceError {
WrongCollectionAddress,
AlreadyOnAuction,
AuctionClosed,
AlreadyOnSale,
WrongReply,
WrongCollectionName,
AccessDenied,
DeadlineError,
ThereIsNoSuchAuction,
LessOrEqualThanBid,
NotSellable,
NoApproveToMarketplace,
ErrorFromCollection,
WrongDataOffer,
OfferDoesNotExist,
SaleDoesNotExist,
ValueIsLessThanPrice,
CreationError,
ErrorGetInfo,
WrongValue,
MintError,
InsufficientBalance,
LessThanMinimumValueForTrade,
}

#[derive(Encode, Decode, TypeInfo)]
pub enum StateQuery {
Expand Down Expand Up @@ -227,9 +294,12 @@ pub struct State {
pub auctions: Vec<((ActorId, u64), Auction)>,
pub offers: Vec<(Offer, u128)>,
pub config: Config,
pub minimum_value_for_trade: u128,
pub allow_message: bool,
pub allow_create_collection: bool,
}

/// * code_id - code_id is used to create a collection by that CodeId,
/// * code_id - code_id is used to create a collection by that CodeId,
/// the admin should preload the NFT contract and specify in the marketplace so that regular users can use it
/// * meta_link - it is necessary to set a reference where the meta of this collection type will be stored for further interaction with the contract
/// * type_description - description of this type of collection
Expand All @@ -238,6 +308,7 @@ pub struct TypeCollectionInfo {
pub code_id: CodeId,
pub meta_link: String,
pub type_description: String,
pub allow_create: bool,
}

#[derive(Debug, Encode, Decode, TypeInfo, Clone)]
Expand All @@ -247,17 +318,21 @@ pub struct CollectionInfo {
pub meta_link: String,
}


#[derive(Default, Debug, Encode, Decode, TypeInfo, Clone)]
pub struct Config {
pub gas_for_creation: u64,
pub gas_for_mint: u64,
pub gas_for_transfer_token: u64,
pub gas_for_close_auction: u64,
pub gas_for_delete_collection: u64,
pub gas_for_get_token_info: u64,
pub gas_for_get_info: u64,
pub time_between_create_collections: u64,
pub minimum_transfer_value: u128,
pub royalty_to_marketplace_for_trade: u16,
pub royalty_to_marketplace_for_mint: u16,
pub ms_in_block: u32,
pub fee_per_uploaded_file: u128,
pub max_creator_royalty: u16,
pub max_number_of_images: u64,
}

#[derive(Debug, Encode, Decode, TypeInfo, Clone)]
Expand Down Expand Up @@ -299,6 +374,10 @@ pub enum NftAction {
token_id: u64,
},
CanDelete,
GetPaymentForMint,
Mint {
minter: ActorId,
},
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo)]
Expand All @@ -316,7 +395,29 @@ pub enum NftEvent {
royalty: u16,
},
CanDelete(bool),
PaymentForMintReceived {
payment_for_mint: u128,
},
SuccessfullyMinted,
}

#[derive(Debug, Clone, Encode, Decode, TypeInfo)]
pub struct NftError(pub String);
pub enum NftError {
MathOverflow,
ErrorGettingRandom,
TokenDoesNotExist,
AllTokensMinted,
OwnerDoesNotHaveNft,
AccessDenied,
NoApproval,
ThereIsApproval,
LimitIsZero,
ConfigCannotBeChanged,
WrongRoyalty,
NotTransferable,
UserRestrictionCannotBeChanged,
NoListOfRestriction,
ThereIsNoSuchUser,
ExhaustedLimit,
WrongValue,
}
Loading

0 comments on commit 7b0d514

Please sign in to comment.