From 95111ec3bd49371225c8b4c3b9743ba266b81f11 Mon Sep 17 00:00:00 2001 From: Brian Sin Date: Mon, 6 May 2024 13:34:32 +0700 Subject: [PATCH] update nonFungibleFlexDropToken contract, upgrade to cairo ver 2.5.3 --- flex_marketplace/Scarb.lock | 4 +- flex_marketplace/Scarb.toml | 4 +- flex_marketplace/src/lib.cairo | 2 +- .../src/marketplace/currency_manager.cairo | 2 +- .../src/marketplace/execution_manager.cairo | 2 +- .../src/marketplace/marketplace.cairo | 10 +- .../src/marketplace/openedition.cairo | 9 +- .../openedition/ERC721_open_edition.cairo | 40 +- .../marketplace/openedition/FlexDrop.cairo | 3 +- .../openedition/erc721/ERC721.cairo | 629 ++++++++++++++++++ .../erc721_metadata/ERC721_metadata.cairo | 93 --- .../openedition/interfaces/IERC721.cairo | 157 +++++ .../IFlexDropContractMetadata.cairo | 11 +- flex_marketplace/src/marketplace/proxy.cairo | 2 +- .../src/marketplace/royalty_fee_manager.cairo | 2 +- .../marketplace/royalty_fee_registry.cairo | 2 +- .../src/marketplace/signature_checker2.cairo | 2 +- ...rategy_standard_sale_for_fixed_price.cairo | 2 +- .../transfer_manager_ERC1155.cairo | 2 +- .../marketplace/transfer_manager_ERC721.cairo | 2 +- .../marketplace/transfer_selector_NFT.cairo | 2 +- .../src/marketplace/utils/openedition.cairo | 4 +- flex_marketplace/src/mocks/account.cairo | 1 + flex_marketplace/src/mocks/erc1155.cairo | 2 +- flex_marketplace/src/mocks/erc20.cairo | 4 +- flex_marketplace/src/mocks/erc721.cairo | 10 +- flex_marketplace/src/mocks/strategy.cairo | 4 +- 27 files changed, 847 insertions(+), 160 deletions(-) create mode 100644 flex_marketplace/src/marketplace/openedition/erc721/ERC721.cairo delete mode 100644 flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo create mode 100644 flex_marketplace/src/marketplace/openedition/interfaces/IERC721.cairo diff --git a/flex_marketplace/Scarb.lock b/flex_marketplace/Scarb.lock index 08e907a..95b3dbf 100644 --- a/flex_marketplace/Scarb.lock +++ b/flex_marketplace/Scarb.lock @@ -17,8 +17,8 @@ dependencies = [ [[package]] name = "openzeppelin" -version = "0.8.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.8.0#c23e8e96de60e6e3159b1ff8591a1187269c0eb7" +version = "0.10.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3" [[package]] name = "snforge_std" diff --git a/flex_marketplace/Scarb.toml b/flex_marketplace/Scarb.toml index 7ef55d1..22e6063 100644 --- a/flex_marketplace/Scarb.toml +++ b/flex_marketplace/Scarb.toml @@ -4,9 +4,9 @@ version = "0.1.0" edition = "2023_01" [dependencies] -starknet = "2.4.3" +starknet = ">=2.4.3" snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.14.0" } -openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.8.0" } +openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.10.0" } alexandria_storage = { git = "https://github.com/keep-starknet-strange/alexandria.git", tag = "cairo-v2.3.0-rc0" } [scripts] diff --git a/flex_marketplace/src/lib.cairo b/flex_marketplace/src/lib.cairo index 661cd64..1290d61 100644 --- a/flex_marketplace/src/lib.cairo +++ b/flex_marketplace/src/lib.cairo @@ -61,7 +61,6 @@ mod marketplace { mod transfer_manager_ERC1155; mod transfer_selector_NFT; } - mod mocks { mod account; mod erc20; @@ -69,3 +68,4 @@ mod mocks { mod erc721; mod strategy; } + diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index b3d56ca..56eb633 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -54,7 +54,7 @@ mod CurrencyManager { timestamp: u64, } - #[external(v0)] + #[abi(embed_v0)] impl CurrencyManagerImpl of super::ICurrencyManager { fn initializer( ref self: ContractState, owner: ContractAddress, proxy_admin: ContractAddress diff --git a/flex_marketplace/src/marketplace/execution_manager.cairo b/flex_marketplace/src/marketplace/execution_manager.cairo index 041eddd..be91fa3 100644 --- a/flex_marketplace/src/marketplace/execution_manager.cairo +++ b/flex_marketplace/src/marketplace/execution_manager.cairo @@ -54,7 +54,7 @@ mod ExecutionManager { timestamp: u64 } - #[external(v0)] + #[abi(embed_v0)] impl ExecutionManagerImpl of super::IExecutionManager { fn initializer(ref self: ContractState, owner: ContractAddress) { assert!(!self.initialized.read(), "ExecutionManager: already initialized"); diff --git a/flex_marketplace/src/marketplace/marketplace.cairo b/flex_marketplace/src/marketplace/marketplace.cairo index 4c46fa4..6c50f28 100644 --- a/flex_marketplace/src/marketplace/marketplace.cairo +++ b/flex_marketplace/src/marketplace/marketplace.cairo @@ -82,13 +82,11 @@ trait IAuctionStrategy { mod MarketPlace { use super::{ IExecutionStrategyDispatcher, IExecutionStrategyDispatcherTrait, IAuctionStrategyDispatcher, - IAuctionStrategyDispatcherTrait - }; - use starknet::{ - ContractAddress, ClassHash, contract_address_const, get_block_timestamp, get_caller_address + IAuctionStrategyDispatcherTrait, ContractAddress, ClassHash }; + use starknet::{contract_address_const, get_block_timestamp, get_caller_address}; - use flex::{DebugContractAddress, DisplayContractAddress}; + use flex::{DisplayContractAddress}; use flex::marketplace::{ currency_manager::{ICurrencyManagerDispatcher, ICurrencyManagerDispatcherTrait}, execution_manager::{IExecutionManagerDispatcher, IExecutionManagerDispatcherTrait}, @@ -266,7 +264,7 @@ mod MarketPlace { timestamp: u64, } - #[external(v0)] + #[abi(embed_v0)] impl MarketPlaceImpl of super::IMarketPlace { fn initializer( ref self: ContractState, diff --git a/flex_marketplace/src/marketplace/openedition.cairo b/flex_marketplace/src/marketplace/openedition.cairo index daf437f..e58fe95 100644 --- a/flex_marketplace/src/marketplace/openedition.cairo +++ b/flex_marketplace/src/marketplace/openedition.cairo @@ -1,4 +1,5 @@ mod interfaces { + mod IERC721; mod IFlexDrop; mod IFlexDropContractMetadata; mod INonFungibleFlexDropToken; @@ -8,7 +9,11 @@ mod ERC721_open_edition; mod FlexDrop; -mod erc721_metadata { - mod ERC721_metadata; +mod erc721 { + mod ERC721; } +use erc721::ERC721; +use interfaces::IFlexDrop::IFlexDrop; +use interfaces::INonFungibleFlexDropToken::INonFungibleFlexDropToken; + diff --git a/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo b/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo index 412492f..9f184d9 100644 --- a/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo +++ b/flex_marketplace/src/marketplace/openedition/ERC721_open_edition.cairo @@ -1,12 +1,10 @@ #[starknet::contract] -mod ERC721 { +mod ERC721OpenEdition { use alexandria_storage::list::ListTrait; - use openzeppelin::token::erc721::erc721::ERC721Component; use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::security::reentrancyguard::ReentrancyGuardComponent; - use flex::marketplace::openedition::interfaces::IFlexDropContractMetadata::IFlexDropContractMetadata; - use flex::marketplace::openedition::erc721_metadata::ERC721_metadata::ERC721MetadataComponent; + use flex::marketplace::openedition::ERC721::ERC721Component; use flex::marketplace::openedition::interfaces::IFlexDrop::{ IFlexDropDispatcher, IFlexDropDispatcherTrait }; @@ -18,7 +16,6 @@ mod ERC721 { use starknet::{ContractAddress, get_caller_address, get_contract_address}; use integer::BoundedU64; - component!(path: ERC721MetadataComponent, storage: erc721_metadata, event: ERC721MetadataEvent); component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -33,15 +30,15 @@ mod ERC721 { impl ERC721CamelImpl = ERC721Component::ERC721CamelOnlyImpl; #[abi(embed_v0)] - impl ERC721Metadata = ERC721Component::ERC721MetadataImpl; + impl ERC721MetadataImpl = ERC721Component::ERC721MetadataImpl; #[abi(embed_v0)] - impl ERC721MetadataCamel = + impl ERC721MetadataCamelImpl = ERC721Component::ERC721MetadataCamelOnlyImpl; #[abi(embed_v0)] - impl ERC721FlexMetadataImpl = - ERC721MetadataComponent::FlexDropContractMetadataImpl; + impl FlexDropContractMetadataImpl = + ERC721Component::FlexDropContractMetadataImpl; #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; @@ -52,8 +49,6 @@ mod ERC721 { #[abi(embed_v0)] impl OwnableImpl = OwnableComponent::OwnableImpl; - impl ERC721MetadataInternalImpl = ERC721MetadataComponent::InternalImpl; - impl ERC721InternalImpl = ERC721Component::InternalImpl; impl OwnableInternalImpl = OwnableComponent::InternalImpl; @@ -75,8 +70,6 @@ mod ERC721 { enumerated_allowed_flex_drop: List, current_phase_id: u64, #[substorage(v0)] - erc721_metadata: ERC721MetadataComponent::Storage, - #[substorage(v0)] erc721: ERC721Component::Storage, #[substorage(v0)] src5: SRC5Component::Storage, @@ -89,15 +82,14 @@ mod ERC721 { #[constructor] fn constructor( ref self: ContractState, - owner: ContractAddress, - name: felt252, - symbol: felt252, - token_base_uri: felt252, + creator: ContractAddress, + name: ByteArray, + symbol: ByteArray, + token_base_uri: ByteArray, allowed_flex_drop: Array::, ) { - self.ownable.initializer(owner); - self.erc721_metadata.initializer(owner, token_base_uri); - self.erc721.initializer(name, symbol); + self.ownable.initializer(creator); + self.erc721.initializer(name, symbol, creator, token_base_uri); self.current_token_id.write(1); self.current_phase_id.write(1); @@ -125,8 +117,6 @@ mod ERC721 { enum Event { UpdateAllowedFlexDrop: UpdateAllowedFlexDrop, #[flat] - ERC721MetadataEvent: ERC721MetadataComponent::Event, - #[flat] ERC721Event: ERC721Component::Event, #[flat] SRC5Event: SRC5Component::Event, @@ -257,11 +247,11 @@ mod ERC721 { self.set_max_supply(max_supply); } - if config.base_uri.into() > 0_u256 { + if config.base_uri.len() > 0 { self.set_base_uri(config.base_uri); } - if config.contract_uri.into() > 0_u256 { + if config.contract_uri.len() > 0 { self.set_contract_uri(config.contract_uri); } @@ -323,7 +313,6 @@ mod ERC721 { impl InternalFlexDropToken of InternalFlexDropTokenTrait { fn safe_mint_flex_drop(ref self: ContractState, to: ContractAddress, quantity: u64) { let mut current_token_id = self.get_current_token_id(); - let base_uri = self.get_base_uri(); self .total_minted_per_wallet @@ -337,7 +326,6 @@ mod ERC721 { break; } self.erc721._safe_mint(to, current_token_id, ArrayTrait::::new().span()); - self.erc721._set_token_uri(current_token_id, base_uri); current_token_id += 1; index += 1; } diff --git a/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo b/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo index e3a7c01..c4b97a2 100644 --- a/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo +++ b/flex_marketplace/src/marketplace/openedition/FlexDrop.cairo @@ -2,7 +2,7 @@ mod FlexDrop { use core::box::BoxTrait; use flex::marketplace::utils::openedition::PhaseDrop; - use flex::marketplace::openedition::interfaces::IFlexDrop::IFlexDrop; + use flex::marketplace::openedition::IFlexDrop; use flex::marketplace::openedition::interfaces::INonFungibleFlexDropToken::{ INonFungibleFlexDropTokenDispatcher, INonFungibleFlexDropTokenDispatcherTrait, I_NON_FUNGIBLE_FLEX_DROP_TOKEN_ID @@ -405,6 +405,7 @@ mod FlexDrop { let nft_address = get_caller_address(); let is_supported_interface = ISRC5Dispatcher { contract_address: nft_address } .supports_interface(I_NON_FUNGIBLE_FLEX_DROP_TOKEN_ID); + assert(is_supported_interface, 'FlexDrop: Unsupport Interface'); } fn validate_new_phase_drop(self: @ContractState, phase_drop: @PhaseDrop) { diff --git a/flex_marketplace/src/marketplace/openedition/erc721/ERC721.cairo b/flex_marketplace/src/marketplace/openedition/erc721/ERC721.cairo new file mode 100644 index 0000000..4bca428 --- /dev/null +++ b/flex_marketplace/src/marketplace/openedition/erc721/ERC721.cairo @@ -0,0 +1,629 @@ +/// # ERC721 Component +/// +/// The ERC721 component provides implementations for the IERC721 interface, +/// the IERC721Metadata interface and IFlexDropContractMetadata interface. +#[starknet::component] +mod ERC721Component { + use core::byte_array::ByteArrayTrait; + use openzeppelin::account; + use openzeppelin::introspection::dual_src5::{DualCaseSRC5, DualCaseSRC5Trait}; + use openzeppelin::introspection::src5::SRC5Component::InternalTrait as SRC5InternalTrait; + use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin::token::erc721::dual721_receiver::{ + DualCaseERC721Receiver, DualCaseERC721ReceiverTrait + }; + use flex::marketplace::openedition::interfaces::IFlexDropContractMetadata; + use flex::marketplace::openedition::interfaces::IERC721; + use starknet::ContractAddress; + use starknet::get_caller_address; + use integer::{U64PartialOrd, BoundedU64}; + + + #[storage] + struct Storage { + ERC721_name: ByteArray, + ERC721_symbol: ByteArray, + ERC721_owners: LegacyMap, + ERC721_balances: LegacyMap, + ERC721_token_approvals: LegacyMap, + ERC721_operator_approvals: LegacyMap<(ContractAddress, ContractAddress), bool>, + ERC721_base_uri: ByteArray, + ERC721_max_supply: u64, + ERC721_contract_uri: ByteArray, + ERC721_creator: ContractAddress + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + Transfer: Transfer, + Approval: Approval, + ApprovalForAll: ApprovalForAll, + } + + /// Emitted when `token_id` token is transferred from `from` to `to`. + #[derive(Drop, starknet::Event)] + struct Transfer { + #[key] + from: ContractAddress, + #[key] + to: ContractAddress, + #[key] + token_id: u256 + } + + /// Emitted when `owner` enables `approved` to manage the `token_id` token. + #[derive(Drop, starknet::Event)] + struct Approval { + #[key] + owner: ContractAddress, + #[key] + approved: ContractAddress, + #[key] + token_id: u256 + } + + /// Emitted when `owner` enables or disables (`approved`) `operator` to manage + /// all of its assets. + #[derive(Drop, starknet::Event)] + struct ApprovalForAll { + #[key] + owner: ContractAddress, + #[key] + operator: ContractAddress, + approved: bool + } + + mod Errors { + const INVALID_TOKEN_ID: felt252 = 'ERC721: invalid token ID'; + const INVALID_ACCOUNT: felt252 = 'ERC721: invalid account'; + const UNAUTHORIZED: felt252 = 'ERC721: unauthorized caller'; + const APPROVAL_TO_OWNER: felt252 = 'ERC721: approval to owner'; + const SELF_APPROVAL: felt252 = 'ERC721: self approval'; + const INVALID_RECEIVER: felt252 = 'ERC721: invalid receiver'; + const ALREADY_MINTED: felt252 = 'ERC721: token already minted'; + const WRONG_SENDER: felt252 = 'ERC721: wrong sender'; + const SAFE_MINT_FAILED: felt252 = 'ERC721: safe mint failed'; + const SAFE_TRANSFER_FAILED: felt252 = 'ERC721: safe transfer failed'; + const NOT_CREATOR: felt252 = 'Caller is not the creator'; + const ZERO_ADDRESS_CALLER: felt252 = 'Caller is the zero address'; + const ZERO_ADDRESS_CREATOR: felt252 = 'New creator is the zero address'; + } + + // + // External + // + + #[embeddable_as(ERC721Impl)] + impl ERC721< + TContractState, + +HasComponent, + +SRC5Component::HasComponent, + +Drop + > of IERC721::IERC721> { + /// Returns the number of NFTs owned by `account`. + fn balance_of(self: @ComponentState, account: ContractAddress) -> u256 { + assert(!account.is_zero(), Errors::INVALID_ACCOUNT); + self.ERC721_balances.read(account) + } + + /// Returns the owner address of `token_id`. + /// + /// Requirements: + /// + /// - `token_id` exists. + fn owner_of(self: @ComponentState, token_id: u256) -> ContractAddress { + self._owner_of(token_id) + } + + /// Transfers ownership of `token_id` from `from` if `to` is either an account or `IERC721Receiver`. + /// + /// `data` is additional data, it has no specified format and it is sent in call to `to`. + /// + /// Requirements: + /// + /// - Caller is either approved or the `token_id` owner. + /// - `to` is not the zero address. + /// - `from` is not the zero address. + /// - `token_id` exists. + /// - `to` is either an account contract or supports the `IERC721Receiver` interface. + /// + /// Emits a `Transfer` event. + fn safe_transfer_from( + ref self: ComponentState, + from: ContractAddress, + to: ContractAddress, + token_id: u256, + data: Span + ) { + assert( + self._is_approved_or_owner(get_caller_address(), token_id), Errors::UNAUTHORIZED + ); + self._safe_transfer(from, to, token_id, data); + } + + /// Transfers ownership of `token_id` from `from` to `to`. + /// + /// Requirements: + /// + /// - Caller is either approved or the `token_id` owner. + /// - `to` is not the zero address. + /// - `from` is not the zero address. + /// - `token_id` exists. + /// + /// Emits a `Transfer` event. + fn transfer_from( + ref self: ComponentState, + from: ContractAddress, + to: ContractAddress, + token_id: u256 + ) { + assert( + self._is_approved_or_owner(get_caller_address(), token_id), Errors::UNAUTHORIZED + ); + self._transfer(from, to, token_id); + } + + /// Change or reaffirm the approved address for an NFT. + /// + /// Requirements: + /// + /// - The caller is either an approved operator or the `token_id` owner. + /// - `to` cannot be the token owner. + /// - `token_id` exists. + /// + /// Emits an `Approval` event. + fn approve(ref self: ComponentState, to: ContractAddress, token_id: u256) { + let owner = self._owner_of(token_id); + + let caller = get_caller_address(); + assert( + owner == caller || self.is_approved_for_all(owner, caller), Errors::UNAUTHORIZED + ); + self._approve(to, token_id); + } + + /// Enable or disable approval for `operator` to manage all of the + /// caller's assets. + /// + /// Requirements: + /// + /// - `operator` cannot be the caller. + /// + /// Emits an `Approval` event. + fn set_approval_for_all( + ref self: ComponentState, operator: ContractAddress, approved: bool + ) { + self._set_approval_for_all(get_caller_address(), operator, approved) + } + + /// Returns the address approved for `token_id`. + /// + /// Requirements: + /// + /// - `token_id` exists. + fn get_approved(self: @ComponentState, token_id: u256) -> ContractAddress { + assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); + self.ERC721_token_approvals.read(token_id) + } + + /// Query if `operator` is an authorized operator for `owner`. + fn is_approved_for_all( + self: @ComponentState, owner: ContractAddress, operator: ContractAddress + ) -> bool { + self.ERC721_operator_approvals.read((owner, operator)) + } + } + + #[embeddable_as(ERC721MetadataImpl)] + impl ERC721Metadata< + TContractState, + +HasComponent, + +SRC5Component::HasComponent, + +Drop + > of IERC721::IERC721Metadata> { + /// Returns the NFT name. + fn name(self: @ComponentState) -> ByteArray { + self.ERC721_name.read() + } + + /// Returns the NFT symbol. + fn symbol(self: @ComponentState) -> ByteArray { + self.ERC721_symbol.read() + } + + /// Returns the Uniform Resource Identifier (URI) for the `token_id` token. + /// If the URI is not set for the `token_id`, the return value will be `0`. + /// + /// Requirements: + /// + /// - `token_id` exists. + fn token_uri(self: @ComponentState, token_id: u256) -> ByteArray { + assert(self._exists(token_id), Errors::INVALID_TOKEN_ID); + let base_uri = self._base_uri(); + if base_uri.len() == 0 { + return ""; + } else { + return base_uri; + } + } + } + + /// Adds camelCase support for `IERC721`. + #[embeddable_as(ERC721CamelOnlyImpl)] + impl ERC721CamelOnly< + TContractState, + +HasComponent, + +SRC5Component::HasComponent, + +Drop + > of IERC721::IERC721CamelOnly> { + fn balanceOf(self: @ComponentState, account: ContractAddress) -> u256 { + self.balance_of(account) + } + + fn ownerOf(self: @ComponentState, tokenId: u256) -> ContractAddress { + self.owner_of(tokenId) + } + + fn safeTransferFrom( + ref self: ComponentState, + from: ContractAddress, + to: ContractAddress, + tokenId: u256, + data: Span + ) { + self.safe_transfer_from(from, to, tokenId, data) + } + + fn transferFrom( + ref self: ComponentState, + from: ContractAddress, + to: ContractAddress, + tokenId: u256 + ) { + self.transfer_from(from, to, tokenId) + } + + fn setApprovalForAll( + ref self: ComponentState, operator: ContractAddress, approved: bool + ) { + self.set_approval_for_all(operator, approved) + } + + fn getApproved(self: @ComponentState, tokenId: u256) -> ContractAddress { + self.get_approved(tokenId) + } + + fn isApprovedForAll( + self: @ComponentState, owner: ContractAddress, operator: ContractAddress + ) -> bool { + self.is_approved_for_all(owner, operator) + } + } + + /// Adds camelCase support for `IERC721Metadata`. + #[embeddable_as(ERC721MetadataCamelOnlyImpl)] + impl ERC721MetadataCamelOnly< + TContractState, + +HasComponent, + +SRC5Component::HasComponent, + +Drop + > of IERC721::IERC721MetadataCamelOnly> { + fn tokenURI(self: @ComponentState, tokenId: u256) -> ByteArray { + self.token_uri(tokenId) + } + } + + #[embeddable_as(FlexDropContractMetadataImpl)] + impl FlexDropContractMetadata< + TContractState, + +HasComponent, + +SRC5Component::HasComponent, + +Drop + > of IFlexDropContractMetadata::IFlexDropContractMetadata> { + fn set_base_uri(ref self: ComponentState, new_token_uri: ByteArray) { + self._assert_only_creator(); + self._set_base_uri(new_token_uri); + } + + fn set_contract_uri(ref self: ComponentState, new_contract_uri: ByteArray) { + self._assert_only_creator(); + self._set_contract_uri(new_contract_uri); + } + + fn set_max_supply(ref self: ComponentState, new_max_supply: u64) { + self._assert_only_creator(); + self._set_max_supply(new_max_supply); + } + + fn get_base_uri(self: @ComponentState) -> ByteArray { + self._base_uri() + } + + fn get_contract_uri(self: @ComponentState) -> ByteArray { + self._contract_uri() + } + + fn get_max_supply(self: @ComponentState) -> u64 { + self._get_max_supply() + } + } + + // + // Internal + // + + #[generate_trait] + impl InternalImpl< + TContractState, + +HasComponent, + impl SRC5: SRC5Component::HasComponent, + +Drop + > of InternalTrait { + /// Initializes the contract by setting the token name and symbol. + /// This should only be used inside the contract's constructor. + fn initializer( + ref self: ComponentState, + name: ByteArray, + symbol: ByteArray, + creator: ContractAddress, + token_base_uri: ByteArray + ) { + self.ERC721_creator.write(creator); + self.ERC721_name.write(name); + self.ERC721_symbol.write(symbol); + self.ERC721_base_uri.write(token_base_uri); + + let mut src5_component = get_dep_component_mut!(ref self, SRC5); + src5_component.register_interface(IERC721::IERC721_ID); + src5_component.register_interface(IERC721::IERC721_METADATA_ID); + } + + /// Returns the owner address of `token_id`. + /// + /// Requirements: + /// + /// - `token_id` exists. + fn _owner_of(self: @ComponentState, token_id: u256) -> ContractAddress { + let owner = self.ERC721_owners.read(token_id); + match owner.is_zero() { + bool::False(()) => owner, + bool::True(()) => panic_with_felt252(Errors::INVALID_TOKEN_ID) + } + } + + /// Returns whether `token_id` exists. + fn _exists(self: @ComponentState, token_id: u256) -> bool { + !self.ERC721_owners.read(token_id).is_zero() + } + + /// Returns whether `spender` is allowed to manage `token_id`. + /// + /// Requirements: + /// + /// - `token_id` exists. + fn _is_approved_or_owner( + self: @ComponentState, spender: ContractAddress, token_id: u256 + ) -> bool { + let owner = self._owner_of(token_id); + let is_approved_for_all = self.is_approved_for_all(owner, spender); + owner == spender || is_approved_for_all || spender == self.get_approved(token_id) + } + + /// Changes or reaffirms the approved address for an NFT. + /// + /// Internal function without access restriction. + /// + /// Requirements: + /// + /// - `token_id` exists. + /// - `to` is not the current token owner. + /// + /// Emits an `Approval` event. + fn _approve(ref self: ComponentState, to: ContractAddress, token_id: u256) { + let owner = self._owner_of(token_id); + assert(owner != to, Errors::APPROVAL_TO_OWNER); + + self.ERC721_token_approvals.write(token_id, to); + self.emit(Approval { owner, approved: to, token_id }); + } + + /// Enables or disables approval for `operator` to manage + /// all of the `owner` assets. + /// + /// Requirements: + /// + /// - `operator` cannot be the caller. + /// + /// Emits an `Approval` event. + fn _set_approval_for_all( + ref self: ComponentState, + owner: ContractAddress, + operator: ContractAddress, + approved: bool + ) { + assert(owner != operator, Errors::SELF_APPROVAL); + self.ERC721_operator_approvals.write((owner, operator), approved); + self.emit(ApprovalForAll { owner, operator, approved }); + } + + /// Mints `token_id` and transfers it to `to`. + /// Internal function without access restriction. + /// + /// Requirements: + /// + /// - `to` is not the zero address. + /// - `token_id` does not exist. + /// + /// Emits a `Transfer` event. + fn _mint(ref self: ComponentState, to: ContractAddress, token_id: u256) { + assert(!to.is_zero(), Errors::INVALID_RECEIVER); + assert(!self._exists(token_id), Errors::ALREADY_MINTED); + + self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1); + self.ERC721_owners.write(token_id, to); + + self.emit(Transfer { from: Zeroable::zero(), to, token_id }); + } + + /// Transfers `token_id` from `from` to `to`. + /// + /// Internal function without access restriction. + /// + /// Requirements: + /// + /// - `to` is not the zero address. + /// - `from` is the token owner. + /// - `token_id` exists. + /// + /// Emits a `Transfer` event. + fn _transfer( + ref self: ComponentState, + from: ContractAddress, + to: ContractAddress, + token_id: u256 + ) { + assert(!to.is_zero(), Errors::INVALID_RECEIVER); + let owner = self._owner_of(token_id); + assert(from == owner, Errors::WRONG_SENDER); + + // Implicit clear approvals, no need to emit an event + self.ERC721_token_approvals.write(token_id, Zeroable::zero()); + + self.ERC721_balances.write(from, self.ERC721_balances.read(from) - 1); + self.ERC721_balances.write(to, self.ERC721_balances.read(to) + 1); + self.ERC721_owners.write(token_id, to); + + self.emit(Transfer { from, to, token_id }); + } + + /// Destroys `token_id`. The approval is cleared when the token is burned. + /// + /// This internal function does not check if the caller is authorized + /// to operate on the token. + /// + /// Requirements: + /// + /// - `token_id` exists. + /// + /// Emits a `Transfer` event. + fn _burn(ref self: ComponentState, token_id: u256) { + let owner = self._owner_of(token_id); + + // Implicit clear approvals, no need to emit an event + self.ERC721_token_approvals.write(token_id, Zeroable::zero()); + + self.ERC721_balances.write(owner, self.ERC721_balances.read(owner) - 1); + self.ERC721_owners.write(token_id, Zeroable::zero()); + + self.emit(Transfer { from: owner, to: Zeroable::zero(), token_id }); + } + + /// Mints `token_id` if `to` is either an account or `IERC721Receiver`. + /// + /// `data` is additional data, it has no specified format and it is sent in call to `to`. + /// + /// Requirements: + /// + /// - `token_id` does not exist. + /// - `to` is either an account contract or supports the `IERC721Receiver` interface. + /// + /// Emits a `Transfer` event. + fn _safe_mint( + ref self: ComponentState, + to: ContractAddress, + token_id: u256, + data: Span + ) { + self._mint(to, token_id); + assert( + _check_on_erc721_received(Zeroable::zero(), to, token_id, data), + Errors::SAFE_MINT_FAILED + ); + } + + /// Transfers ownership of `token_id` from `from` if `to` is either an account or `IERC721Receiver`. + /// + /// `data` is additional data, it has no specified format and it is sent in call to `to`. + /// + /// Requirements: + /// + /// - `to` cannot be the zero address. + /// - `from` must be the token owner. + /// - `token_id` exists. + /// - `to` is either an account contract or supports the `IERC721Receiver` interface. + /// + /// Emits a `Transfer` event. + fn _safe_transfer( + ref self: ComponentState, + from: ContractAddress, + to: ContractAddress, + token_id: u256, + data: Span + ) { + self._transfer(from, to, token_id); + assert( + _check_on_erc721_received(from, to, token_id, data), Errors::SAFE_TRANSFER_FAILED + ); + } + + /// Sets the base URI. + fn _set_base_uri(ref self: ComponentState, base_uri: ByteArray) { + self.ERC721_base_uri.write(base_uri); + } + + /// Base URI for computing `token_uri`. + /// + /// If set, the resulting URI for each token will be the concatenation of the base URI and the token ID. + /// Returns an empty `ByteArray` if not set. + fn _base_uri(self: @ComponentState) -> ByteArray { + self.ERC721_base_uri.read() + } + + fn _set_contract_uri( + ref self: ComponentState, new_contract_uri: ByteArray + ) { + self.ERC721_contract_uri.write(new_contract_uri); + } + + fn _contract_uri(self: @ComponentState) -> ByteArray { + self.ERC721_contract_uri.read() + } + + fn _set_max_supply(ref self: ComponentState, new_max_supply: u64) { + assert( + U64PartialOrd::lt(new_max_supply, BoundedU64::max()), + 'Cannot Exceed MaxSupply Of U64' + ); + self.ERC721_max_supply.write(new_max_supply); + } + + fn _get_max_supply(self: @ComponentState) -> u64 { + self.ERC721_max_supply.read() + } + + fn _assert_only_creator(self: @ComponentState) { + let creator: ContractAddress = self.ERC721_creator.read(); + let caller: ContractAddress = get_caller_address(); + + assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER); + assert(caller == creator, Errors::NOT_CREATOR); + } + } + + /// Checks if `to` either is an account contract or has registered support + /// for the `IERC721Receiver` interface through SRC5. + fn _check_on_erc721_received( + from: ContractAddress, to: ContractAddress, token_id: u256, data: Span + ) -> bool { + if (DualCaseSRC5 { contract_address: to } + .supports_interface(IERC721::IERC721_RECEIVER_ID)) { + DualCaseERC721Receiver { contract_address: to } + .on_erc721_received( + get_caller_address(), from, token_id, data + ) == IERC721::IERC721_RECEIVER_ID + } else { + DualCaseSRC5 { contract_address: to }.supports_interface(account::interface::ISRC6_ID) + } + } +} diff --git a/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo b/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo deleted file mode 100644 index 90ee62c..0000000 --- a/flex_marketplace/src/marketplace/openedition/erc721_metadata/ERC721_metadata.cairo +++ /dev/null @@ -1,93 +0,0 @@ -#[starknet::component] -mod ERC721MetadataComponent { - use flex::marketplace::openedition::interfaces::IFlexDropContractMetadata::IFlexDropContractMetadata; - use starknet::{ContractAddress, get_caller_address}; - use integer::{U64PartialOrd, BoundedU64}; - - #[storage] - struct Storage { - max_supply: u64, - token_base_uri: felt252, - contract_uri: felt252, - owner: ContractAddress - } - - mod Errors { - const NOT_OWNER: felt252 = 'Caller is not the owner'; - const ZERO_ADDRESS_CALLER: felt252 = 'Caller is the zero address'; - const ZERO_ADDRESS_OWNER: felt252 = 'New owner is the zero address'; - } - - #[embeddable_as(FlexDropContractMetadataImpl)] - impl FlexDropContractMetadata< - TContractState, +HasComponent - > of IFlexDropContractMetadata> { - fn set_base_uri(ref self: ComponentState, new_token_uri: felt252) { - self.assert_only_owner(); - self._set_token_base_uri(new_token_uri); - } - - fn set_contract_uri(ref self: ComponentState, new_contract_uri: felt252) { - self.assert_only_owner(); - self._set_contract_uri(new_contract_uri); - } - - fn set_max_supply(ref self: ComponentState, new_max_supply: u64) { - self.assert_only_owner(); - self._set_max_supply(new_max_supply); - } - - fn get_base_uri(self: @ComponentState) -> felt252 { - self.token_base_uri.read() - } - - fn get_contract_uri(self: @ComponentState) -> felt252 { - self.contract_uri.read() - } - - fn get_max_supply(self: @ComponentState) -> u64 { - self.max_supply.read() - } - } - - #[generate_trait] - impl InternalImpl< - TContractState, +HasComponent - > of InternalTrait { - /// Sets the contract's initial owner. - /// - /// This function should be called at construction time. - 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_token_base_uri(ref self: ComponentState, new_token_uri: felt252) { - self.token_base_uri.write(new_token_uri); - } - - fn _set_contract_uri(ref self: ComponentState, new_contract_uri: felt252) { - self.contract_uri.write(new_contract_uri); - } - - fn _set_max_supply(ref self: ComponentState, new_max_supply: u64) { - assert( - U64PartialOrd::lt(new_max_supply, BoundedU64::max()), - 'Cannot Exceed MaxSupply Of U64' - ); - self.max_supply.write(new_max_supply); - } - - fn assert_only_owner(self: @ComponentState) { - let owner: ContractAddress = self.owner.read(); - let caller: ContractAddress = get_caller_address(); - - assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER); - assert(caller == owner, Errors::NOT_OWNER); - } - } -} diff --git a/flex_marketplace/src/marketplace/openedition/interfaces/IERC721.cairo b/flex_marketplace/src/marketplace/openedition/interfaces/IERC721.cairo new file mode 100644 index 0000000..fb61845 --- /dev/null +++ b/flex_marketplace/src/marketplace/openedition/interfaces/IERC721.cairo @@ -0,0 +1,157 @@ +use starknet::ContractAddress; + +const IERC721_ID: felt252 = 0x33eb2f84c309543403fd69f0d0f363781ef06ef6faeb0131ff16ea3175bd943; +const IERC721_METADATA_ID: felt252 = + 0xabbcd595a567dce909050a1038e055daccb3c42af06f0add544fa90ee91f25; +const IERC721_RECEIVER_ID: felt252 = + 0x3a0dff5f70d80458ad14ae37bb182a728e3c8cdda0402a5daa86620bdf910bc; + +#[starknet::interface] +trait IERC721 { + fn balance_of(self: @TState, account: ContractAddress) -> u256; + fn owner_of(self: @TState, token_id: u256) -> ContractAddress; + fn safe_transfer_from( + ref self: TState, + from: ContractAddress, + to: ContractAddress, + token_id: u256, + data: Span + ); + fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); + fn approve(ref self: TState, to: ContractAddress, token_id: u256); + fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); + fn get_approved(self: @TState, token_id: u256) -> ContractAddress; + fn is_approved_for_all( + self: @TState, owner: ContractAddress, operator: ContractAddress + ) -> bool; +} + +#[starknet::interface] +trait IERC721Metadata { + fn name(self: @TState) -> ByteArray; + fn symbol(self: @TState) -> ByteArray; + fn token_uri(self: @TState, token_id: u256) -> ByteArray; +} + +#[starknet::interface] +trait IERC721CamelOnly { + fn balanceOf(self: @TState, account: ContractAddress) -> u256; + fn ownerOf(self: @TState, tokenId: u256) -> ContractAddress; + fn safeTransferFrom( + ref self: TState, + from: ContractAddress, + to: ContractAddress, + tokenId: u256, + data: Span + ); + fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); + fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); + fn getApproved(self: @TState, tokenId: u256) -> ContractAddress; + fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; +} + +#[starknet::interface] +trait IERC721MetadataCamelOnly { + fn tokenURI(self: @TState, tokenId: u256) -> ByteArray; +} + +// +// ERC721 ABI +// + +#[starknet::interface] +trait ERC721ABI { + // IERC721 + fn balance_of(self: @TState, account: ContractAddress) -> u256; + fn owner_of(self: @TState, token_id: u256) -> ContractAddress; + fn safe_transfer_from( + ref self: TState, + from: ContractAddress, + to: ContractAddress, + token_id: u256, + data: Span + ); + fn transfer_from(ref self: TState, from: ContractAddress, to: ContractAddress, token_id: u256); + fn approve(ref self: TState, to: ContractAddress, token_id: u256); + fn set_approval_for_all(ref self: TState, operator: ContractAddress, approved: bool); + fn get_approved(self: @TState, token_id: u256) -> ContractAddress; + fn is_approved_for_all( + self: @TState, owner: ContractAddress, operator: ContractAddress + ) -> bool; + + // ISRC5 + fn supports_interface(self: @TState, interface_id: felt252) -> bool; + + // IERC721Metadata + fn name(self: @TState) -> ByteArray; + fn symbol(self: @TState) -> ByteArray; + fn token_uri(self: @TState, token_id: u256) -> ByteArray; + + // IERC721CamelOnly + fn balanceOf(self: @TState, account: ContractAddress) -> u256; + fn ownerOf(self: @TState, tokenId: u256) -> ContractAddress; + fn safeTransferFrom( + ref self: TState, + from: ContractAddress, + to: ContractAddress, + tokenId: u256, + data: Span + ); + fn transferFrom(ref self: TState, from: ContractAddress, to: ContractAddress, tokenId: u256); + fn setApprovalForAll(ref self: TState, operator: ContractAddress, approved: bool); + fn getApproved(self: @TState, tokenId: u256) -> ContractAddress; + fn isApprovedForAll(self: @TState, owner: ContractAddress, operator: ContractAddress) -> bool; + + // IERC721MetadataCamelOnly + fn tokenURI(self: @TState, tokenId: u256) -> ByteArray; +} + +// +// ERC721Receiver +// + +#[starknet::interface] +trait IERC721Receiver { + fn on_erc721_received( + self: @TState, + operator: ContractAddress, + from: ContractAddress, + token_id: u256, + data: Span + ) -> felt252; +} + +#[starknet::interface] +trait IERC721ReceiverCamel { + fn onERC721Received( + self: @TState, + operator: ContractAddress, + from: ContractAddress, + tokenId: u256, + data: Span + ) -> felt252; +} + +#[starknet::interface] +trait ERC721ReceiverMixin { + // IERC721Receiver + fn on_erc721_received( + self: @TState, + operator: ContractAddress, + from: ContractAddress, + token_id: u256, + data: Span + ) -> felt252; + + // IERC721ReceiverCamel + fn onERC721Received( + self: @TState, + operator: ContractAddress, + from: ContractAddress, + tokenId: u256, + data: Span + ) -> felt252; + + // ISRC5 + fn supports_interface(self: @TState, interface_id: felt252) -> bool; +} diff --git a/flex_marketplace/src/marketplace/openedition/interfaces/IFlexDropContractMetadata.cairo b/flex_marketplace/src/marketplace/openedition/interfaces/IFlexDropContractMetadata.cairo index 2bda46a..9f93383 100644 --- a/flex_marketplace/src/marketplace/openedition/interfaces/IFlexDropContractMetadata.cairo +++ b/flex_marketplace/src/marketplace/openedition/interfaces/IFlexDropContractMetadata.cairo @@ -1,9 +1,12 @@ +use starknet::ContractAddress; + #[starknet::interface] trait IFlexDropContractMetadata { - fn set_base_uri(ref self: TContractState, new_token_uri: felt252); - fn set_contract_uri(ref self: TContractState, new_contract_uri: felt252); + fn set_base_uri(ref self: TContractState, new_token_uri: ByteArray); + fn set_contract_uri(ref self: TContractState, new_contract_uri: ByteArray); fn set_max_supply(ref self: TContractState, new_max_supply: u64); - fn get_base_uri(self: @TContractState) -> felt252; - fn get_contract_uri(self: @TContractState) -> felt252; + fn get_base_uri(self: @TContractState) -> ByteArray; + fn get_contract_uri(self: @TContractState) -> ByteArray; fn get_max_supply(self: @TContractState) -> u64; } + diff --git a/flex_marketplace/src/marketplace/proxy.cairo b/flex_marketplace/src/marketplace/proxy.cairo index 7b1ce8f..17f336a 100644 --- a/flex_marketplace/src/marketplace/proxy.cairo +++ b/flex_marketplace/src/marketplace/proxy.cairo @@ -26,7 +26,7 @@ mod Proxy { ) { // TODO } - #[external(v0)] + #[abi(embed_v0)] impl ProxyImpl of super::IProxy { fn upgrade(ref self: ContractState, new_implementation: ClassHash) { // TODO } diff --git a/flex_marketplace/src/marketplace/royalty_fee_manager.cairo b/flex_marketplace/src/marketplace/royalty_fee_manager.cairo index 0c7538e..2980fa9 100644 --- a/flex_marketplace/src/marketplace/royalty_fee_manager.cairo +++ b/flex_marketplace/src/marketplace/royalty_fee_manager.cairo @@ -61,7 +61,7 @@ mod RoyaltyFeeManager { UpgradeableEvent: UpgradeableComponent::Event, } - #[external(v0)] + #[abi(embed_v0)] impl RoyaltyFeeManagerImpl of super::IRoyaltyFeeManager { fn initializer( ref self: ContractState, fee_registry: ContractAddress, owner: ContractAddress, diff --git a/flex_marketplace/src/marketplace/royalty_fee_registry.cairo b/flex_marketplace/src/marketplace/royalty_fee_registry.cairo index 3f8d719..d4962b4 100644 --- a/flex_marketplace/src/marketplace/royalty_fee_registry.cairo +++ b/flex_marketplace/src/marketplace/royalty_fee_registry.cairo @@ -71,7 +71,7 @@ mod RoyaltyFeeRegistry { timestamp: u64, } - #[external(v0)] + #[abi(embed_v0)] impl RoyaltyFeeRegistryImpl of super::IRoyaltyFeeRegistry { fn initializer(ref self: ContractState, fee_limit: u128, owner: ContractAddress,) { assert!(!self.initialized.read(), "RoyaltyFeeRegistry: already initialized"); diff --git a/flex_marketplace/src/marketplace/signature_checker2.cairo b/flex_marketplace/src/marketplace/signature_checker2.cairo index 315bd8b..a5869ae 100644 --- a/flex_marketplace/src/marketplace/signature_checker2.cairo +++ b/flex_marketplace/src/marketplace/signature_checker2.cairo @@ -28,7 +28,7 @@ mod SignatureChecker2 { #[storage] struct Storage {} - #[external(v0)] + #[abi(embed_v0)] impl SignatureChecker2Impl of super::ISignatureChecker2 { fn compute_maker_order_hash( self: @ContractState, hash_domain: felt252, order: MakerOrder diff --git a/flex_marketplace/src/marketplace/strategy_standard_sale_for_fixed_price.cairo b/flex_marketplace/src/marketplace/strategy_standard_sale_for_fixed_price.cairo index e63e13b..3fc35e0 100644 --- a/flex_marketplace/src/marketplace/strategy_standard_sale_for_fixed_price.cairo +++ b/flex_marketplace/src/marketplace/strategy_standard_sale_for_fixed_price.cairo @@ -52,7 +52,7 @@ mod StrategyStandardSaleForFixedPrice { UpgradeableEvent: UpgradeableComponent::Event, } - #[external(v0)] + #[abi(embed_v0)] impl StrategyStandardSaleForFixedPriceImpl of super::IStrategyStandardSaleForFixedPrice< ContractState > { diff --git a/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo b/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo index 385b922..7aaa688 100644 --- a/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo +++ b/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo @@ -35,7 +35,7 @@ mod ERC1155TransferManager { UpgradeableEvent: UpgradeableComponent::Event, } - #[external(v0)] + #[abi(embed_v0)] impl ERC1155TransferManagerImpl of ITransferManagerNFT { fn initializer( ref self: ContractState, marketplace: ContractAddress, owner: ContractAddress, diff --git a/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo b/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo index 11905ea..f423c72 100644 --- a/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo +++ b/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo @@ -32,7 +32,7 @@ mod TransferManagerNFT { OwnableEvent: OwnableComponent::Event } - #[external(v0)] + #[abi(embed_v0)] impl TransferManagerNFTImpl of ITransferManagerNFT { fn initializer( ref self: ContractState, marketplace: ContractAddress, owner: ContractAddress, diff --git a/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo b/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo index c8b9195..0b10678 100644 --- a/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo +++ b/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo @@ -78,7 +78,7 @@ mod TransferSelectorNFT { } - #[external(v0)] + #[abi(embed_v0)] impl TransferSelectorNFTImpl of super::ITransferSelectorNFT { fn initializer( ref self: ContractState, diff --git a/flex_marketplace/src/marketplace/utils/openedition.cairo b/flex_marketplace/src/marketplace/utils/openedition.cairo index 3b367d6..11f324c 100644 --- a/flex_marketplace/src/marketplace/utils/openedition.cairo +++ b/flex_marketplace/src/marketplace/utils/openedition.cairo @@ -14,8 +14,8 @@ struct PhaseDrop { #[derive(Drop, Serde)] struct MultiConfigureStruct { max_supply: u64, - base_uri: felt252, - contract_uri: felt252, + base_uri: ByteArray, + contract_uri: ByteArray, flex_drop: ContractAddress, phase_drop: PhaseDrop, new_phase: bool, diff --git a/flex_marketplace/src/mocks/account.cairo b/flex_marketplace/src/mocks/account.cairo index e00d15e..1a01a20 100644 --- a/flex_marketplace/src/mocks/account.cairo +++ b/flex_marketplace/src/mocks/account.cairo @@ -34,6 +34,7 @@ mod Account { impl SRC5InternalImpl = SRC5Component::InternalImpl; component!(path: AccountComponent, storage: account, event: AccountEvent); + #[abi(embed_v0)] impl SRC6Impl = AccountComponent::SRC6Impl; #[abi(embed_v0)] diff --git a/flex_marketplace/src/mocks/erc1155.cairo b/flex_marketplace/src/mocks/erc1155.cairo index 8b4a0fa..750d2f6 100644 --- a/flex_marketplace/src/mocks/erc1155.cairo +++ b/flex_marketplace/src/mocks/erc1155.cairo @@ -17,7 +17,7 @@ mod ERC1155 { #[storage] struct Storage {} - #[external(v0)] + #[abi(embed_v0)] impl ERC1155Impl of super::IERC1155 { fn safe_transfer_from( ref self: ContractState, diff --git a/flex_marketplace/src/mocks/erc20.cairo b/flex_marketplace/src/mocks/erc20.cairo index 3720a18..ee6141d 100644 --- a/flex_marketplace/src/mocks/erc20.cairo +++ b/flex_marketplace/src/mocks/erc20.cairo @@ -119,7 +119,7 @@ mod ERC20 { // External // - #[external(v0)] + #[abi(embed_v0)] impl ERC20Impl of super::IERC20 { /// Returns the name of the token. fn name(self: @ContractState) -> felt252 { @@ -206,7 +206,7 @@ mod ERC20 { self._decrease_allowance(spender, subtracted_value) } - #[external(v0)] + #[abi(embed_v0)] impl ERC20CamelOnlyImpl of super::IERC20CamelOnly { /// Camel case support. /// See [total_supply](total-supply). diff --git a/flex_marketplace/src/mocks/erc721.cairo b/flex_marketplace/src/mocks/erc721.cairo index 436a625..d27f4d0 100644 --- a/flex_marketplace/src/mocks/erc721.cairo +++ b/flex_marketplace/src/mocks/erc721.cairo @@ -19,10 +19,6 @@ mod ERC721 { component!(path: SRC5Component, storage: src5, event: SRC5Event); component!(path: ERC721Component, storage: erc721, event: ERC721Event); - const NAME: felt252 = 'FLEX TOKEN'; - const SYMBOL: felt252 = 'FLX'; - const TOKEN_URI: felt252 = ''; - #[storage] struct Storage { id: u256, @@ -51,7 +47,10 @@ mod ERC721 { #[constructor] fn constructor(ref self: ContractState) { - self.erc721.initializer(NAME, SYMBOL); + let name: ByteArray = "FLEX TOKEN"; + let symbol: ByteArray = "FLX"; + let base_uri: ByteArray = ""; + self.erc721.initializer(name, symbol, base_uri); } #[abi(embed_v0)] @@ -76,7 +75,6 @@ mod ERC721 { self.id.write(token_id); self.erc721._mint(recipient, token_id); - self.erc721._set_token_uri(token_id, TOKEN_URI); } } } diff --git a/flex_marketplace/src/mocks/strategy.cairo b/flex_marketplace/src/mocks/strategy.cairo index 139aaef..4b8344f 100644 --- a/flex_marketplace/src/mocks/strategy.cairo +++ b/flex_marketplace/src/mocks/strategy.cairo @@ -30,7 +30,7 @@ mod Strategy { #[storage] struct Storage {} - #[external(v0)] + #[abi(embed_v0)] impl MockExecutionStrategyImpl of super::IExecutionStrategy { fn protocolFee(self: @ContractState) -> u128 { 1000 @@ -50,7 +50,7 @@ mod Strategy { } } - #[external(v0)] + #[abi(embed_v0)] impl MockAuctionStrategyImpl of super::IAuctionStrategy { fn auctionRelayer(self: @ContractState) -> ContractAddress { starknet::contract_address_const::<'RELAYER'>()