From ab31199d0fd84355a93b455393d0441bbc7ce879 Mon Sep 17 00:00:00 2001 From: Brian Date: Thu, 14 Mar 2024 15:39:26 +0700 Subject: [PATCH 1/2] Update openedition --- .gitignore | 4 +- .../interfaces/nft_transfer_manager.cairo | 8 +-- .../src/marketplace/marketplace.cairo | 8 ++- .../openedition/ERC721_open_edition.cairo | 18 ++++-- .../marketplace/openedition/FlexDrop.cairo | 56 ++++++++++++++----- .../erc721_metadata/ERC721_metadata.cairo | 11 +++- .../marketplace/transfer_manager_ERC721.cairo | 4 +- 7 files changed, 75 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 653a781..e6ecf77 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ flex_marketplace/.snfoundry_cache/ tool-versions .vscode/ -target \ No newline at end of file +target + +deployment \ No newline at end of file diff --git a/flex_marketplace/src/marketplace/interfaces/nft_transfer_manager.cairo b/flex_marketplace/src/marketplace/interfaces/nft_transfer_manager.cairo index 5d64b23..2758af6 100644 --- a/flex_marketplace/src/marketplace/interfaces/nft_transfer_manager.cairo +++ b/flex_marketplace/src/marketplace/interfaces/nft_transfer_manager.cairo @@ -2,11 +2,7 @@ use starknet::ContractAddress; #[starknet::interface] trait ITransferManagerNFT { - fn initializer( - ref self: TState, - marketplace: ContractAddress, - owner: ContractAddress, - ); + fn initializer(ref self: TState, marketplace: ContractAddress, owner: ContractAddress,); fn transfer_non_fungible_token( ref self: TState, collection: ContractAddress, @@ -18,4 +14,4 @@ trait ITransferManagerNFT { ); fn update_marketplace(ref self: TState, new_address: ContractAddress); fn get_marketplace(self: @TState) -> ContractAddress; -} \ No newline at end of file +} diff --git a/flex_marketplace/src/marketplace/marketplace.cairo b/flex_marketplace/src/marketplace/marketplace.cairo index d5ed973..4c46fa4 100644 --- a/flex_marketplace/src/marketplace/marketplace.cairo +++ b/flex_marketplace/src/marketplace/marketplace.cairo @@ -97,7 +97,9 @@ mod MarketPlace { transfer_selector_NFT::{ ITransferSelectorNFTDispatcher, ITransferSelectorNFTDispatcherTrait }, - interfaces::nft_transfer_manager::{ITransferManagerNFTDispatcher, ITransferManagerNFTDispatcherTrait} + interfaces::nft_transfer_manager::{ + ITransferManagerNFTDispatcher, ITransferManagerNFTDispatcherTrait + } }; use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder}; @@ -698,7 +700,9 @@ mod MarketPlace { .check_transfer_manager_for_token(collection); assert!(!manager.is_zero(), "MarketPlace: invalid tranfer manager {}", manager); ITransferManagerNFTDispatcher { contract_address: manager } - .transfer_non_fungible_token(collection, from, to, token_id, amount, ArrayTrait::::new().span()); + .transfer_non_fungible_token( + collection, from, to, token_id, amount, ArrayTrait::::new().span() + ); } fn calculate_protocol_fee( diff --git a/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo b/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo index 59da6fa..0eec833 100644 --- a/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo +++ b/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo @@ -81,9 +81,11 @@ mod ERC721 { owner: ContractAddress, name: felt252, symbol: felt252, + token_base_uri: felt252, allowed_flex_drop: Array::, ) { - self.erc721_metadata.initializer(owner); + self.ownable.initializer(owner); + self.erc721_metadata.initializer(owner, token_base_uri); self.erc721.initializer(name, symbol); self.current_token_id.write(1); @@ -240,13 +242,17 @@ mod ERC721 { self.ownable.assert_only_owner(); let mut max_supply = config.max_supply; - if max_supply == 0 { - max_supply = BoundedU64::max(); + if max_supply != 0 { + self.set_max_supply(max_supply); } - self.set_max_supply(max_supply); - self.set_base_uri(config.base_uri); - self.set_contract_uri(config.contract_uri); + if config.base_uri.into() > 0_u256 { + self.set_base_uri(config.base_uri); + } + + if config.contract_uri.into() > 0_u256 { + self.set_contract_uri(config.contract_uri); + } let public_drop = config.public_drop; if public_drop.start_time != 0 && public_drop.end_time != 0 { diff --git a/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo b/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo index c1c0158..ae20aa7 100644 --- a/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo +++ b/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo @@ -1,7 +1,5 @@ #[starknet::contract] mod FlexDrop { - use core::box::BoxTrait; -use core::option::OptionTrait; use flex::marketplace::utils::openedition::PublicDrop; use flex::marketplace::openedition::interfaces::IFlexDrop::IFlexDrop; use flex::marketplace::openedition::interfaces::INonFungibleFlexDropToken::{ @@ -226,7 +224,7 @@ use core::option::OptionTrait; let nft_address = get_caller_address(); if allowed { assert( - self.allowed_fee_recipients.read((nft_address, fee_recipient)), + !self.allowed_fee_recipients.read((nft_address, fee_recipient)), 'Duplicate Fee Recipient' ); self.allowed_fee_recipients.write((nft_address, fee_recipient), true); @@ -239,14 +237,14 @@ use core::option::OptionTrait; .write(nft_address, enumerated_allowed_fee_recipients); } else { assert( - !self.allowed_fee_recipients.read((nft_address, fee_recipient)), + self.allowed_fee_recipients.read((nft_address, fee_recipient)), 'Fee Recipient not present' ); self.allowed_fee_recipients.write((nft_address, fee_recipient), false); self.remove_enumerated_allowed_fee_recipient(nft_address, fee_recipient); } - self.emit(FeeRecipientUpdated {nft_address, fee_recipient, allowed}); + self.emit(FeeRecipientUpdated { nft_address, fee_recipient, allowed }); } fn update_payer(ref self: ContractState, payer: ContractAddress, allowed: bool) { @@ -256,19 +254,19 @@ use core::option::OptionTrait; let nft_address = get_caller_address(); if allowed { - assert(self.allowed_payer.read((nft_address, payer)), 'Duplicate payer'); + assert(!self.allowed_payer.read((nft_address, payer)), 'Duplicate payer'); self.allowed_payer.write((nft_address, payer), true); let mut enumerated_allowed_payer = self.enumerated_allowed_payer.read(nft_address); enumerated_allowed_payer.append(payer); self.enumerated_allowed_payer.write(nft_address, enumerated_allowed_payer); } else { - assert(!self.allowed_payer.read((nft_address, payer)), 'Payer not present'); + assert(self.allowed_payer.read((nft_address, payer)), 'Payer not present'); self.allowed_payer.write((nft_address, payer), false); self.remove_enumerated_allowed_payer(nft_address, payer); } - self.emit(PayerUpdated {nft_address, payer, allowed}); + self.emit(PayerUpdated { nft_address, payer, allowed }); } } @@ -311,6 +309,37 @@ use core::option::OptionTrait; self.fee_bps.read() } + #[external(v0)] + fn get_public_drop(self: @ContractState, nft_address: ContractAddress) -> PublicDrop { + self.public_drops.read(nft_address) + } + + #[external(v0)] + fn get_currency_manager(self: @ContractState) -> ContractAddress { + self.currency_manager.read().contract_address + } + + #[external(v0)] + fn get_creator_payout_address( + self: @ContractState, nft_address: ContractAddress + ) -> ContractAddress { + self.creator_payout_address.read(nft_address) + } + + #[external(v0)] + fn get_enumerated_allowed_fee_recipients( + self: @ContractState, nft_address: ContractAddress + ) -> Span:: { + self.enumerated_allowed_fee_recipients.read(nft_address).array().span() + } + + #[external(v0)] + fn get_enumerated_allowed_payer( + self: @ContractState, nft_address: ContractAddress + ) -> Span:: { + self.enumerated_allowed_payer.read(nft_address).array().span() + } + fn assert_only_non_fungible_flex_drop_token(self: @ContractState) { let nft_address = get_caller_address(); let is_supported_interface = ISRC5Dispatcher { contract_address: nft_address } @@ -464,20 +493,21 @@ use core::option::OptionTrait; } if *cp_enumerated.get(index).unwrap().unbox() != to_remove { - new_enumerated_allowed_fee_recipients.append(*cp_enumerated.get(index).unwrap().unbox()); + new_enumerated_allowed_fee_recipients + .append(*cp_enumerated.get(index).unwrap().unbox()); } index += 1; }; enumerated_allowed_fee_recipients.from_array(@new_enumerated_allowed_fee_recipients); - self.enumerated_allowed_fee_recipients.write(nft_address, enumerated_allowed_fee_recipients); + self + .enumerated_allowed_fee_recipients + .write(nft_address, enumerated_allowed_fee_recipients); } fn remove_enumerated_allowed_payer( ref self: ContractState, nft_address: ContractAddress, to_remove: ContractAddress ) { - let mut enumerated_allowed_payer = self - .enumerated_allowed_payer - .read(nft_address); + let mut enumerated_allowed_payer = self.enumerated_allowed_payer.read(nft_address); let mut index = 0; let enumerated_allowed_payer_length = enumerated_allowed_payer.len(); diff --git a/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo b/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo index ba84c44..90ee62c 100644 --- a/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo +++ b/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo @@ -24,7 +24,7 @@ mod ERC721MetadataComponent { > of IFlexDropContractMetadata> { fn set_base_uri(ref self: ComponentState, new_token_uri: felt252) { self.assert_only_owner(); - self._set_base_uri(new_token_uri); + self._set_token_base_uri(new_token_uri); } fn set_contract_uri(ref self: ComponentState, new_contract_uri: felt252) { @@ -57,11 +57,16 @@ mod ERC721MetadataComponent { /// Sets the contract's initial owner. /// /// This function should be called at construction time. - fn initializer(ref self: ComponentState, owner: ContractAddress,) { + fn initializer( + ref self: ComponentState, + owner: ContractAddress, + token_base_uri: felt252 + ) { self.owner.write(owner); + self._set_token_base_uri(token_base_uri); } - fn _set_base_uri(ref self: ComponentState, new_token_uri: felt252) { + fn _set_token_base_uri(ref self: ComponentState, new_token_uri: felt252) { self.token_base_uri.write(new_token_uri); } diff --git a/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo b/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo index 038ff2c..11905ea 100644 --- a/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo +++ b/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo @@ -35,9 +35,7 @@ mod TransferManagerNFT { #[external(v0)] impl TransferManagerNFTImpl of ITransferManagerNFT { fn initializer( - ref self: ContractState, - marketplace: ContractAddress, - owner: ContractAddress, + ref self: ContractState, marketplace: ContractAddress, owner: ContractAddress, ) { // TODO: verify the role of Proxy here. self.marketplace.write(marketplace); From db2116b1828752223e66ff4623af151315e9abde Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 15 Mar 2024 11:29:53 +0700 Subject: [PATCH 2/2] add update total minted per minter --- .../src/marketplace/openedition/ERC721_open_edition.cairo | 1 + 1 file changed, 1 insertion(+) diff --git a/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo b/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo index 0eec833..41f9cbb 100644 --- a/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo +++ b/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo @@ -339,6 +339,7 @@ mod ERC721 { self.current_token_id.write(current_token_id + quantity.into()); self.total_minted.write(self.get_total_minted() + quantity); + self.total_minted_per_wallet.write(to, self.total_minted_per_wallet.read(to) + quantity); let mut index: u64 = 0; loop {