diff --git a/.gitignore b/.gitignore index 479f519..564d1aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ flex_marketplace/target/ +.snfoundry_cache + flex_marketplace/.snfoundry_cache/ + diff --git a/flex_marketplace/.tool-versions b/flex_marketplace/.tool-versions new file mode 100644 index 0000000..3b81bc9 --- /dev/null +++ b/flex_marketplace/.tool-versions @@ -0,0 +1,2 @@ +starknet-foundry 0.13.0 +scarb 2.4.0 diff --git a/flex_marketplace/Scarb.toml b/flex_marketplace/Scarb.toml index 842caad..a4a6a90 100644 --- a/flex_marketplace/Scarb.toml +++ b/flex_marketplace/Scarb.toml @@ -8,5 +8,17 @@ starknet = "2.4.0" snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.13.0" } openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.8.0" } +[[target.starknet-contract]] +sierra = true +casm = true +allowed-libfuncs-list.name = "experimental" + +[cairo] +sierra-replace-ids = true + +[tool.fmt] +sort-module-level-items = true + [scripts] -test = "snforge test" \ No newline at end of file +test = "snforge test" + diff --git a/flex_marketplace/src/lib.cairo b/flex_marketplace/src/lib.cairo index e9812d0..8cb55bb 100644 --- a/flex_marketplace/src/lib.cairo +++ b/flex_marketplace/src/lib.cairo @@ -34,4 +34,4 @@ mod marketplace { mod transfer_manager_ERC721; mod transfer_manager_ERC1155; mod transfer_selector_NFT; -} +} \ No newline at end of file diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index 75f3dd2..10fc126 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -5,23 +5,30 @@ trait ICurrencyManager { fn initializer(ref self: TState, owner: ContractAddress, proxy_admin: ContractAddress); fn add_currency(ref self: TState, currency: ContractAddress); fn remove_currency(ref self: TState, currency: ContractAddress); - fn transfer_ownership(ref self: TState, new_owner: ContractAddress); - fn owner(self: @TState) -> ContractAddress; fn is_currency_whitelisted(self: @TState, currency: ContractAddress) -> bool; fn whitelisted_currency_count(self: @TState) -> usize; fn whitelisted_currency(self: @TState, index: usize) -> ContractAddress; } +#[starknet::interface] +trait ICurrencyManage { + fn owner(self: @TState) -> ContractAddress; + fn transfer_ownership(ref self: TState, new_owner: ContractAddress); +} + #[starknet::contract] mod CurrencyManager { - use starknet::{ContractAddress, contract_address_const}; + use openzeppelin::access::ownable::interface::IOwnable; + use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait as OwnableInternalTrait; + use openzeppelin::access::ownable::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const, get_block_timestamp}; - use openzeppelin::access::ownable::OwnableComponent; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] impl OwnableImpl = OwnableComponent::OwnableImpl; + // impl OwnableInternalImpl = OwnableComponent::InternalImpl; impl OwnableInternalImpl = OwnableComponent::InternalImpl; #[storage] @@ -29,6 +36,7 @@ mod CurrencyManager { whitelisted_currency_count: usize, whitelisted_currencies: LegacyMap::, whitelisted_currency_index: LegacyMap::, + initialized: bool, #[substorage(v0)] ownable: OwnableComponent::Storage } @@ -38,6 +46,7 @@ mod CurrencyManager { enum Event { CurrencyRemoved: CurrencyRemoved, CurrencyWhitelisted: CurrencyWhitelisted, + #[flat] OwnableEvent: OwnableComponent::Event, } @@ -57,36 +66,56 @@ mod CurrencyManager { impl CurrencyManagerImpl of super::ICurrencyManager { fn initializer( ref self: ContractState, owner: ContractAddress, proxy_admin: ContractAddress - ) { // TODO - } - - fn add_currency(ref self: ContractState, currency: ContractAddress) { // TODO - } - - fn remove_currency(ref self: ContractState, currency: ContractAddress) { // TODO + ) { + assert!(!self.initialized.read(), "CurrencyManager: already initialized"); + self.initialized.write(true); + self.ownable.initializer(owner); } - fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { // TODO + fn add_currency(ref self: ContractState, currency: ContractAddress) { + self.ownable.assert_only_owner(); + let index = self.whitelisted_currency_index.read(currency); + assert!(index.is_zero(), "CurrencyManager: currency {} already whitelisted", currency); + let new_count = self.whitelisted_currency_count.read() + 1; + self.whitelisted_currency_index.write(currency, new_count); + self.whitelisted_currencies.write(new_count, currency); + self.whitelisted_currency_count.write(new_count); + let timestamp = get_block_timestamp(); + self.emit(CurrencyWhitelisted { currency, timestamp }); } - fn owner(self: @ContractState) -> ContractAddress { - // TODO - contract_address_const::<0>() + fn remove_currency(ref self: ContractState, currency: ContractAddress) { + self.ownable.assert_only_owner(); + let index = self.whitelisted_currency_index.read(currency); + assert!(!index.is_zero(), "CurrencyManager: currency {} not whitelisted", currency); + let count = self.whitelisted_currency_count.read(); + + let currency_at_last_index = self.whitelisted_currencies.read(count); + self.whitelisted_currencies.write(index, currency_at_last_index); + self.whitelisted_currencies.write(count, contract_address_const::<0>()); + self.whitelisted_currency_index.write(currency, 0); + if (count != 1) { + self.whitelisted_currency_index.write(currency_at_last_index, index); + } + self.whitelisted_currency_count.write(count - 1); + let timestamp = get_block_timestamp(); + self.emit(CurrencyRemoved { currency, timestamp }); } fn is_currency_whitelisted(self: @ContractState, currency: ContractAddress) -> bool { - // TODO + let index = self.whitelisted_currency_index.read(currency); + if (index == 0) { + return false; + } true } fn whitelisted_currency_count(self: @ContractState) -> usize { - // TODO - 0 + self.whitelisted_currency_count.read() } fn whitelisted_currency(self: @ContractState, index: usize) -> ContractAddress { - // TODO - contract_address_const::<0>() + self.whitelisted_currencies.read(index) } } } diff --git a/flex_marketplace/src/marketplace/execution_manager.cairo b/flex_marketplace/src/marketplace/execution_manager.cairo index 28b965f..360e791 100644 --- a/flex_marketplace/src/marketplace/execution_manager.cairo +++ b/flex_marketplace/src/marketplace/execution_manager.cairo @@ -14,9 +14,8 @@ trait IExecutionManager { #[starknet::contract] mod ExecutionManager { - use starknet::{ContractAddress, contract_address_const}; - use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] diff --git a/flex_marketplace/src/marketplace/market_place.cairo b/flex_marketplace/src/marketplace/market_place.cairo index 9fdd529..5a167b2 100644 --- a/flex_marketplace/src/marketplace/market_place.cairo +++ b/flex_marketplace/src/marketplace/market_place.cairo @@ -1,6 +1,5 @@ -use starknet::ContractAddress; - use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder}; +use starknet::ContractAddress; trait IMarketPlace { fn cancel_all_orders_for_sender(ref self: TState, min_nonce: u128); @@ -50,11 +49,10 @@ trait IMarketPlace { #[starknet::contract] mod MarketPlace { - use starknet::{ContractAddress, contract_address_const}; - use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder}; use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] diff --git a/flex_marketplace/src/marketplace/royalty_fee_manager.cairo b/flex_marketplace/src/marketplace/royalty_fee_manager.cairo index a385317..3b7f76f 100644 --- a/flex_marketplace/src/marketplace/royalty_fee_manager.cairo +++ b/flex_marketplace/src/marketplace/royalty_fee_manager.cairo @@ -24,6 +24,7 @@ trait IERC2981 { #[starknet::contract] mod RoyaltyFeeManager { + use openzeppelin::upgrades::upgradeable::UpgradeableComponent::InternalTrait; use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::upgrades::UpgradeableComponent; diff --git a/flex_marketplace/src/marketplace/royalty_fee_registry.cairo b/flex_marketplace/src/marketplace/royalty_fee_registry.cairo index b382099..d9b0db8 100644 --- a/flex_marketplace/src/marketplace/royalty_fee_registry.cairo +++ b/flex_marketplace/src/marketplace/royalty_fee_registry.cairo @@ -26,9 +26,8 @@ trait IRoyaltyFeeRegistry { #[starknet::contract] mod RoyaltyFeeRegistry { - use starknet::{ContractAddress, contract_address_const}; - use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] diff --git a/flex_marketplace/src/marketplace/signature_checker2.cairo b/flex_marketplace/src/marketplace/signature_checker2.cairo index 90f4871..9ba7b59 100644 --- a/flex_marketplace/src/marketplace/signature_checker2.cairo +++ b/flex_marketplace/src/marketplace/signature_checker2.cairo @@ -1,6 +1,5 @@ -use starknet::ContractAddress; - use flex::marketplace::utils::order_types::MakerOrder; +use starknet::ContractAddress; trait ISignatureChecker2 { fn initializer(ref self: TState, proxy_admin: ContractAddress); @@ -12,9 +11,8 @@ trait ISignatureChecker2 { #[starknet::contract] mod SignatureChecker2 { - use starknet::ContractAddress; - use flex::marketplace::utils::order_types::MakerOrder; + use starknet::ContractAddress; #[storage] struct Storage {} 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 6bda63c..694f018 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 @@ -1,6 +1,5 @@ -use starknet::ContractAddress; - use flex::marketplace::utils::order_types::{TakerOrder, MakerOrder}; +use starknet::ContractAddress; #[starknet::interface] trait IStrategyStandardSaleForFixedPrice { @@ -21,9 +20,10 @@ trait IStrategyStandardSaleForFixedPrice { #[starknet::contract] mod StrategyStandardSaleForFixedPrice { - use starknet::{ContractAddress, contract_address_const}; + use flex::marketplace::utils::order_types::{TakerOrder, MakerOrder}; use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] @@ -31,8 +31,6 @@ mod StrategyStandardSaleForFixedPrice { impl OwnableInternalImpl = OwnableComponent::InternalImpl; - use flex::marketplace::utils::order_types::{TakerOrder, MakerOrder}; - #[storage] struct Storage { protocol_fee: u128, diff --git a/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo b/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo index 273eb0b..df7b6aa 100644 --- a/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo +++ b/flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo @@ -24,11 +24,10 @@ trait IERC1155 { #[starknet::contract] mod ERC1155 { - use starknet::{ContractAddress, contract_address_const}; - use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder}; use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] diff --git a/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo b/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo index 5070774..eff3b5d 100644 --- a/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo +++ b/flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo @@ -24,11 +24,10 @@ trait IERC721 { #[starknet::contract] mod ERC721 { - use starknet::{ContractAddress, contract_address_const}; - use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder}; use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] diff --git a/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo b/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo index 0a79e6f..d34e958 100644 --- a/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo +++ b/flex_marketplace/src/marketplace/transfer_selector_NFT.cairo @@ -31,11 +31,10 @@ trait ITransferSelectorNFT { #[starknet::contract] mod TransferSelectorNFT { - use starknet::{ContractAddress, contract_address_const}; - use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder}; use openzeppelin::access::ownable::OwnableComponent; + use starknet::{ContractAddress, contract_address_const}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)]