From 1087b4c78ab257879177251213f8e28753995aa3 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Thu, 21 Dec 2023 01:18:20 +0530 Subject: [PATCH 1/8] currency manager updated and first test added for the currency manager --- .gitignore | 1 + flex_marketplace/.tool-versions | 2 + flex_marketplace/Scarb.lock | 2 +- flex_marketplace/Scarb.toml | 16 +++- flex_marketplace/src/lib.cairo | 62 +++++++-------- .../src/marketplace/currency_manager.cairo | 76 +++++++++++++------ .../src/marketplace/market_place.cairo | 4 +- .../tests/test_currency_manager.cairo | 37 +++++++++ 8 files changed, 140 insertions(+), 60 deletions(-) create mode 100644 flex_marketplace/.tool-versions create mode 100644 flex_marketplace/tests/test_currency_manager.cairo diff --git a/.gitignore b/.gitignore index 4ef41bd..3f2e899 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ flex_marketplace/target/ +.snfoundry_cache \ No newline at end of file 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.lock b/flex_marketplace/Scarb.lock index 40ddf27..6ae0a09 100644 --- a/flex_marketplace/Scarb.lock +++ b/flex_marketplace/Scarb.lock @@ -17,4 +17,4 @@ source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.8.0#c23e8e9 [[package]] name = "snforge_std" version = "0.1.0" -source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.11.0#5465c41541c44a7804d16318fab45a2f0ccec9e7" +source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.13.0#99c2f9d33159988efd339bd969c78d82b0b4b6f7" diff --git a/flex_marketplace/Scarb.toml b/flex_marketplace/Scarb.toml index f01602a..4ee90e1 100644 --- a/flex_marketplace/Scarb.toml +++ b/flex_marketplace/Scarb.toml @@ -5,5 +5,17 @@ version = "0.1.0" # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html [dependencies] -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.11.0" } -openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag = "v0.8.0" } \ No newline at end of file +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 \ No newline at end of file diff --git a/flex_marketplace/src/lib.cairo b/flex_marketplace/src/lib.cairo index 9e62e4c..d94ba62 100644 --- a/flex_marketplace/src/lib.cairo +++ b/flex_marketplace/src/lib.cairo @@ -1,37 +1,37 @@ mod marketplace { - mod launchpad { - mod ERC721_launchpad_migrated; - mod ERC721_Launchpad; - mod minter; - } + // mod launchpad { + // mod ERC721_launchpad_migrated; + // mod ERC721_Launchpad; + // mod minter; + // } - mod swap { - mod exponential_curve; - mod pair_factory; - mod pair; - } + // mod swap { + // mod exponential_curve; + // mod pair_factory; + // mod pair; + // } - mod utils { - mod merkle; - mod order_types; - mod reentrancy_guard; - } + // mod utils { + // mod merkle; + // mod order_types; + // mod reentrancy_guard; + // } - mod contract_deployer; + // mod contract_deployer; mod currency_manager; - mod ERC721_flex; - mod execution_manager; - mod market_place; - mod proxy; - mod royalty_fee_manager; - mod royalty_fee_registry; - mod signature_checker; - mod signature_checker2; - mod strategy_any_item_from_collection_for_fixed_price; - mod strategy_highest_bidder_auction_sale; - mod strategy_private_sale; - mod strategy_standard_sale_for_fixed_price; - mod transfer_manager_ERC721; - mod transfer_manager_ERC1155; - mod transfer_selector_NFT; + // mod ERC721_flex; + // mod execution_manager; + // mod market_place; + // mod proxy; + // mod royalty_fee_manager; + // mod royalty_fee_registry; + // mod signature_checker; + // mod signature_checker2; + // mod strategy_any_item_from_collection_for_fixed_price; + // mod strategy_highest_bidder_auction_sale; + // mod strategy_private_sale; + // mod strategy_standard_sale_for_fixed_price; + // mod transfer_manager_ERC721; + // mod transfer_manager_ERC1155; + // mod transfer_selector_NFT; } diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index 75f3dd2..006a1a5 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -5,30 +5,33 @@ 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 transfer_contract_ownership(ref self: TState, new_owner: ContractAddress); + fn contract_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; + fn whitelisted_currency_count(self: @TState) -> u256; + fn whitelisted_currency(self: @TState, index: u256) -> ContractAddress; } #[starknet::contract] mod CurrencyManager { - use starknet::{ContractAddress, contract_address_const}; + use openzeppelin::access::ownable::ownable::OwnableComponent; + use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait as OwnableInternalTrait; + use openzeppelin::access::ownable::interface::IOwnable; + 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] struct Storage { - whitelisted_currency_count: usize, - whitelisted_currencies: LegacyMap::, - whitelisted_currency_index: LegacyMap::, + whitelisted_currency_count: u256, + whitelisted_currencies: LegacyMap::, + whitelisted_currency_index: LegacyMap::, #[substorage(v0)] ownable: OwnableComponent::Storage } @@ -57,36 +60,61 @@ mod CurrencyManager { impl CurrencyManagerImpl of super::ICurrencyManager { fn initializer( ref self: ContractState, owner: ContractAddress, proxy_admin: ContractAddress - ) { // TODO + ) { + // how to use the proxy_admin here? + self.ownable.initializer(owner); } - fn add_currency(ref self: ContractState, currency: 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 == 0, 'currency already whitelisted'); + 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 remove_currency(ref self: ContractState, currency: ContractAddress) { // TODO - } + fn remove_currency(ref self: ContractState, currency: ContractAddress) { + self.ownable.assert_only_owner(); + let index = self.whitelisted_currency_index.read(currency); + assert(index != 0, 'currency not whitelisted'); + 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); + 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 transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { // TODO } - fn owner(self: @ContractState) -> ContractAddress { - // TODO - contract_address_const::<0>() + fn transfer_contract_ownership(ref self: ContractState, new_owner: ContractAddress) { + self.ownable.assert_only_owner(); + self.ownable.transfer_ownership(new_owner); + } + fn contract_owner(self: @ContractState) -> ContractAddress { + self.ownable.owner() } 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 + fn whitelisted_currency_count(self: @ContractState) -> u256 { + self.whitelisted_currency_count.read() } - fn whitelisted_currency(self: @ContractState, index: usize) -> ContractAddress { - // TODO - contract_address_const::<0>() + fn whitelisted_currency(self: @ContractState, index: u256) -> ContractAddress { + self.whitelisted_currencies.read(index) } } } diff --git a/flex_marketplace/src/marketplace/market_place.cairo b/flex_marketplace/src/marketplace/market_place.cairo index ad46612..9fdd529 100644 --- a/flex_marketplace/src/marketplace/market_place.cairo +++ b/flex_marketplace/src/marketplace/market_place.cairo @@ -333,12 +333,12 @@ mod MarketPlace { fn calculate_protocol_fee( self: @ContractState, execution_strategy: felt252, amount: u128 ) -> u128 { // TODO - 0 + 0 } fn validate_order( self: @ContractState, order: MakerOrder, order_signature: Span - ) {// TODO + ) { // TODO } } } diff --git a/flex_marketplace/tests/test_currency_manager.cairo b/flex_marketplace/tests/test_currency_manager.cairo new file mode 100644 index 0000000..fad8ba6 --- /dev/null +++ b/flex_marketplace/tests/test_currency_manager.cairo @@ -0,0 +1,37 @@ +use snforge_std::{ + declare, ContractClassTrait, start_prank, stop_prank, RevertedTransaction, start_spoof, + CheatTarget, stop_spoof, cheatcodes +}; +use starknet::{ContractAddress, contract_address_const,}; +use flex::marketplace::currency_manager::{ICurrencyManagerDispatcher, ICurrencyManagerDispatcherTrait}; + +fn RECIPIENT() -> ContractAddress { + return contract_address_const::<'RECIPIENT'>(); +} + +fn SPENDER() -> ContractAddress { + return contract_address_const::<'RECIPIENT'>(); +} + +fn OWNER() -> ContractAddress { + return contract_address_const::<'OWNER'>(); +} + +fn deploy_contract() -> Result { + let contract = declare('CurrencyManager'); + let constructor_calldata = array![]; + contract.deploy(@constructor_calldata) +} + +#[test] +fn test_ownership() { + let contract_address = + match deploy_contract( + ) { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher {contract_address}; + currency_manager.initializer(OWNER(), OWNER()); + assert(currency_manager.contract_owner()==OWNER(), 'owner mismatch'); +} \ No newline at end of file From 68c00f71a3443092a67af29b9c5d27ce8fe5a6eb Mon Sep 17 00:00:00 2001 From: mohiiit Date: Thu, 21 Dec 2023 18:20:23 +0530 Subject: [PATCH 2/8] all test added for the currency_manager --- flex_marketplace/src/lib.cairo | 64 +++--- .../src/marketplace/currency_manager.cairo | 14 +- .../src/marketplace/execution_manager.cairo | 3 +- .../src/marketplace/market_place.cairo | 6 +- .../src/marketplace/royalty_fee_manager.cairo | 3 +- .../marketplace/royalty_fee_registry.cairo | 3 +- .../src/marketplace/signature_checker2.cairo | 6 +- ...rategy_standard_sale_for_fixed_price.cairo | 8 +- .../transfer_manager_ERC1155.cairo | 3 +- .../marketplace/transfer_manager_ERC721.cairo | 3 +- .../marketplace/transfer_selector_NFT.cairo | 3 +- .../tests/test_currency_manager.cairo | 198 ++++++++++++++++-- 12 files changed, 236 insertions(+), 78 deletions(-) diff --git a/flex_marketplace/src/lib.cairo b/flex_marketplace/src/lib.cairo index d94ba62..9c3ee78 100644 --- a/flex_marketplace/src/lib.cairo +++ b/flex_marketplace/src/lib.cairo @@ -1,37 +1,37 @@ mod marketplace { - // mod launchpad { - // mod ERC721_launchpad_migrated; - // mod ERC721_Launchpad; - // mod minter; - // } + mod ERC721_flex; - // mod swap { - // mod exponential_curve; - // mod pair_factory; - // mod pair; - // } + mod contract_deployer; + mod currency_manager; + mod execution_manager; + mod market_place; + mod proxy; + mod royalty_fee_manager; + mod royalty_fee_registry; + mod signature_checker; + mod signature_checker2; + mod strategy_any_item_from_collection_for_fixed_price; + mod strategy_highest_bidder_auction_sale; + mod strategy_private_sale; + mod strategy_standard_sale_for_fixed_price; + mod transfer_manager_ERC1155; + mod transfer_manager_ERC721; + mod transfer_selector_NFT; + mod launchpad { + mod ERC721_Launchpad; + mod ERC721_launchpad_migrated; + mod minter; + } - // mod utils { - // mod merkle; - // mod order_types; - // mod reentrancy_guard; - // } + mod swap { + mod exponential_curve; + mod pair; + mod pair_factory; + } - // mod contract_deployer; - mod currency_manager; - // mod ERC721_flex; - // mod execution_manager; - // mod market_place; - // mod proxy; - // mod royalty_fee_manager; - // mod royalty_fee_registry; - // mod signature_checker; - // mod signature_checker2; - // mod strategy_any_item_from_collection_for_fixed_price; - // mod strategy_highest_bidder_auction_sale; - // mod strategy_private_sale; - // mod strategy_standard_sale_for_fixed_price; - // mod transfer_manager_ERC721; - // mod transfer_manager_ERC1155; - // mod transfer_selector_NFT; + mod utils { + mod merkle; + mod order_types; + mod reentrancy_guard; + } } diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index 006a1a5..b254acf 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -14,9 +14,9 @@ trait ICurrencyManager { #[starknet::contract] mod CurrencyManager { - use openzeppelin::access::ownable::ownable::OwnableComponent; - use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait as OwnableInternalTrait; 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}; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); @@ -81,16 +81,18 @@ mod CurrencyManager { self.ownable.assert_only_owner(); let index = self.whitelisted_currency_index.read(currency); assert(index != 0, 'currency not whitelisted'); - let count = self.whitelisted_currency_count.read() ; + 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); - self.whitelisted_currency_index.write(currency_at_last_index, index); - self.whitelisted_currency_count.write(count-1); + 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 transfer_contract_ownership(ref self: ContractState, new_owner: ContractAddress) { 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 ee53ab9..4d408a4 100644 --- a/flex_marketplace/src/marketplace/royalty_fee_manager.cairo +++ b/flex_marketplace/src/marketplace/royalty_fee_manager.cairo @@ -19,9 +19,8 @@ trait IRoyaltyFeeManager { #[starknet::contract] mod RoyaltyFeeManager { - 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/royalty_fee_registry.cairo b/flex_marketplace/src/marketplace/royalty_fee_registry.cairo index 038ead0..f38279e 100644 --- a/flex_marketplace/src/marketplace/royalty_fee_registry.cairo +++ b/flex_marketplace/src/marketplace/royalty_fee_registry.cairo @@ -24,9 +24,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)] diff --git a/flex_marketplace/tests/test_currency_manager.cairo b/flex_marketplace/tests/test_currency_manager.cairo index fad8ba6..e5cd7b9 100644 --- a/flex_marketplace/tests/test_currency_manager.cairo +++ b/flex_marketplace/tests/test_currency_manager.cairo @@ -1,22 +1,28 @@ +use flex::marketplace::currency_manager::{ + ICurrencyManagerDispatcher, ICurrencyManagerDispatcherTrait +}; use snforge_std::{ declare, ContractClassTrait, start_prank, stop_prank, RevertedTransaction, start_spoof, CheatTarget, stop_spoof, cheatcodes }; use starknet::{ContractAddress, contract_address_const,}; -use flex::marketplace::currency_manager::{ICurrencyManagerDispatcher, ICurrencyManagerDispatcherTrait}; -fn RECIPIENT() -> ContractAddress { - return contract_address_const::<'RECIPIENT'>(); +fn CURRENCY0() -> ContractAddress { + return contract_address_const::<'CURRENCY0'>(); } -fn SPENDER() -> ContractAddress { - return contract_address_const::<'RECIPIENT'>(); +fn CURRENCY1() -> ContractAddress { + return contract_address_const::<'CURRENCY1'>(); } fn OWNER() -> ContractAddress { return contract_address_const::<'OWNER'>(); } +fn SECOND_OWNER() -> ContractAddress { + return contract_address_const::<'SECOND_OWNER'>(); +} + fn deploy_contract() -> Result { let contract = declare('CurrencyManager'); let constructor_calldata = array![]; @@ -25,13 +31,175 @@ fn deploy_contract() -> Result { #[test] fn test_ownership() { - let contract_address = - match deploy_contract( - ) { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher {contract_address}; - currency_manager.initializer(OWNER(), OWNER()); - assert(currency_manager.contract_owner()==OWNER(), 'owner mismatch'); -} \ No newline at end of file + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + assert(currency_manager.contract_owner() == OWNER(), 'owner mismatch'); +} + +#[test] +fn test_add_currency() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + currency_manager.add_currency(CURRENCY0()); + assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); + assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); + assert(currency_manager.whitelisted_currency(1) == CURRENCY0(), 'should be currency0'); +// assert(currency_manager.contract_owner()==OWNER(), 'owner mismatch'); +} + +#[test] +fn test_remove_currency() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + currency_manager.add_currency(CURRENCY0()); + currency_manager.add_currency(CURRENCY1()); + currency_manager.remove_currency(CURRENCY0()); + assert( + currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' + ); + assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); + assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); + assert(currency_manager.whitelisted_currency(1) == CURRENCY1(), 'should be currency1') +} + +#[test] +#[should_panic(expected: ('Caller is not the owner',))] +fn test_add_currency_not_owner() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + currency_manager.add_currency(CURRENCY0()); +} + +#[test] +#[should_panic(expected: ('Caller is not the owner',))] +fn test_remove_currency_not_owner() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + currency_manager.add_currency(CURRENCY0()); + stop_prank(CheatTarget::All); + currency_manager.remove_currency(CURRENCY0()); +} + +#[test] +fn test_transfer_contract_ownership() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + currency_manager.transfer_contract_ownership(SECOND_OWNER()); + assert(currency_manager.contract_owner() == SECOND_OWNER(), 'second owner should be owner'); +} + +#[test] +#[should_panic(expected: ('Caller is not the owner',))] +fn test_transfer_contract_ownership_not_owner() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + currency_manager.transfer_contract_ownership(SECOND_OWNER()); +} + +#[test] +fn test_whitelisted_currency_count() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + currency_manager.add_currency(CURRENCY0()); + assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); + currency_manager.add_currency(CURRENCY1()); + assert(currency_manager.whitelisted_currency_count() == 2, 'should be two'); +} + + +#[test] +fn test_whitelisted_currency() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + currency_manager.add_currency(CURRENCY0()); + currency_manager.add_currency(CURRENCY1()); + assert(currency_manager.whitelisted_currency(1) == CURRENCY0(), 'should be currency0'); + assert(currency_manager.whitelisted_currency(2) == CURRENCY1(), 'should be currency1'); + currency_manager.remove_currency(CURRENCY0()); + assert(currency_manager.whitelisted_currency(1) == CURRENCY1(), 'should be currency0'); +} + + +#[test] +fn test_is_currency_whitelisted() { + let contract_address = match deploy_contract() { + Result::Ok(address) => address, + Result::Err(msg) => panic(msg.panic_data), + }; + let currency_manager = ICurrencyManagerDispatcher { contract_address }; + currency_manager.initializer(OWNER(), OWNER()); + start_prank(CheatTarget::All, OWNER()); + + assert( + currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' + ); + assert( + currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not whitelisted' + ); + + currency_manager.add_currency(CURRENCY0()); + assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); + assert( + currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not be whitelisted' + ); + + currency_manager.add_currency(CURRENCY1()); + assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); + assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); + + currency_manager.remove_currency(CURRENCY0()); + assert( + currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' + ); + assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); + + currency_manager.remove_currency(CURRENCY1()); + assert( + currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' + ); + assert( + currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not whitelisted' + ); +} From c6ee00e96d36e1e6c1508ef11623552d21a32fc5 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 09:41:57 +0530 Subject: [PATCH 3/8] test removed, u256 to usize, owner and transfer_ownership removed --- .../src/marketplace/currency_manager.cairo | 24 +- .../tests/test_currency_manager.cairo | 205 ------------------ 2 files changed, 7 insertions(+), 222 deletions(-) delete mode 100644 flex_marketplace/tests/test_currency_manager.cairo diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index b254acf..065f06f 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -5,11 +5,9 @@ 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_contract_ownership(ref self: TState, new_owner: ContractAddress); - fn contract_owner(self: @TState) -> ContractAddress; fn is_currency_whitelisted(self: @TState, currency: ContractAddress) -> bool; - fn whitelisted_currency_count(self: @TState) -> u256; - fn whitelisted_currency(self: @TState, index: u256) -> ContractAddress; + fn whitelisted_currency_count(self: @TState) -> usize; + fn whitelisted_currency(self: @TState, index: usize) -> ContractAddress; } #[starknet::contract] @@ -29,9 +27,9 @@ mod CurrencyManager { #[storage] struct Storage { - whitelisted_currency_count: u256, - whitelisted_currencies: LegacyMap::, - whitelisted_currency_index: LegacyMap::, + whitelisted_currency_count: usize, + whitelisted_currencies: LegacyMap::, + whitelisted_currency_index: LegacyMap::, #[substorage(v0)] ownable: OwnableComponent::Storage } @@ -95,14 +93,6 @@ mod CurrencyManager { self.emit(CurrencyRemoved { currency, timestamp }); } - fn transfer_contract_ownership(ref self: ContractState, new_owner: ContractAddress) { - self.ownable.assert_only_owner(); - self.ownable.transfer_ownership(new_owner); - } - fn contract_owner(self: @ContractState) -> ContractAddress { - self.ownable.owner() - } - fn is_currency_whitelisted(self: @ContractState, currency: ContractAddress) -> bool { let index = self.whitelisted_currency_index.read(currency); if (index == 0) { @@ -111,11 +101,11 @@ mod CurrencyManager { true } - fn whitelisted_currency_count(self: @ContractState) -> u256 { + fn whitelisted_currency_count(self: @ContractState) -> usize { self.whitelisted_currency_count.read() } - fn whitelisted_currency(self: @ContractState, index: u256) -> ContractAddress { + fn whitelisted_currency(self: @ContractState, index: usize) -> ContractAddress { self.whitelisted_currencies.read(index) } } diff --git a/flex_marketplace/tests/test_currency_manager.cairo b/flex_marketplace/tests/test_currency_manager.cairo deleted file mode 100644 index e5cd7b9..0000000 --- a/flex_marketplace/tests/test_currency_manager.cairo +++ /dev/null @@ -1,205 +0,0 @@ -use flex::marketplace::currency_manager::{ - ICurrencyManagerDispatcher, ICurrencyManagerDispatcherTrait -}; -use snforge_std::{ - declare, ContractClassTrait, start_prank, stop_prank, RevertedTransaction, start_spoof, - CheatTarget, stop_spoof, cheatcodes -}; -use starknet::{ContractAddress, contract_address_const,}; - -fn CURRENCY0() -> ContractAddress { - return contract_address_const::<'CURRENCY0'>(); -} - -fn CURRENCY1() -> ContractAddress { - return contract_address_const::<'CURRENCY1'>(); -} - -fn OWNER() -> ContractAddress { - return contract_address_const::<'OWNER'>(); -} - -fn SECOND_OWNER() -> ContractAddress { - return contract_address_const::<'SECOND_OWNER'>(); -} - -fn deploy_contract() -> Result { - let contract = declare('CurrencyManager'); - let constructor_calldata = array![]; - contract.deploy(@constructor_calldata) -} - -#[test] -fn test_ownership() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - assert(currency_manager.contract_owner() == OWNER(), 'owner mismatch'); -} - -#[test] -fn test_add_currency() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); - assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); - assert(currency_manager.whitelisted_currency(1) == CURRENCY0(), 'should be currency0'); -// assert(currency_manager.contract_owner()==OWNER(), 'owner mismatch'); -} - -#[test] -fn test_remove_currency() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - currency_manager.add_currency(CURRENCY1()); - currency_manager.remove_currency(CURRENCY0()); - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); - assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); - assert(currency_manager.whitelisted_currency(1) == CURRENCY1(), 'should be currency1') -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_add_currency_not_owner() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - currency_manager.add_currency(CURRENCY0()); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_remove_currency_not_owner() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - stop_prank(CheatTarget::All); - currency_manager.remove_currency(CURRENCY0()); -} - -#[test] -fn test_transfer_contract_ownership() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.transfer_contract_ownership(SECOND_OWNER()); - assert(currency_manager.contract_owner() == SECOND_OWNER(), 'second owner should be owner'); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_transfer_contract_ownership_not_owner() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - currency_manager.transfer_contract_ownership(SECOND_OWNER()); -} - -#[test] -fn test_whitelisted_currency_count() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - assert(currency_manager.whitelisted_currency_count() == 1, 'should be one'); - currency_manager.add_currency(CURRENCY1()); - assert(currency_manager.whitelisted_currency_count() == 2, 'should be two'); -} - - -#[test] -fn test_whitelisted_currency() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - currency_manager.add_currency(CURRENCY0()); - currency_manager.add_currency(CURRENCY1()); - assert(currency_manager.whitelisted_currency(1) == CURRENCY0(), 'should be currency0'); - assert(currency_manager.whitelisted_currency(2) == CURRENCY1(), 'should be currency1'); - currency_manager.remove_currency(CURRENCY0()); - assert(currency_manager.whitelisted_currency(1) == CURRENCY1(), 'should be currency0'); -} - - -#[test] -fn test_is_currency_whitelisted() { - let contract_address = match deploy_contract() { - Result::Ok(address) => address, - Result::Err(msg) => panic(msg.panic_data), - }; - let currency_manager = ICurrencyManagerDispatcher { contract_address }; - currency_manager.initializer(OWNER(), OWNER()); - start_prank(CheatTarget::All, OWNER()); - - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert( - currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not whitelisted' - ); - - currency_manager.add_currency(CURRENCY0()); - assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); - assert( - currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not be whitelisted' - ); - - currency_manager.add_currency(CURRENCY1()); - assert(currency_manager.is_currency_whitelisted(CURRENCY0()) == true, 'should be whitelisted'); - assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); - - currency_manager.remove_currency(CURRENCY0()); - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert(currency_manager.is_currency_whitelisted(CURRENCY1()) == true, 'should be whitelisted'); - - currency_manager.remove_currency(CURRENCY1()); - assert( - currency_manager.is_currency_whitelisted(CURRENCY0()) == false, 'should not be whitelisted' - ); - assert( - currency_manager.is_currency_whitelisted(CURRENCY1()) == false, 'should not whitelisted' - ); -} From 5cddb1bddefa3eda3c0dcddf4a00669b4c5aad7f Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 09:52:25 +0530 Subject: [PATCH 4/8] error message improved --- flex_marketplace/src/marketplace/currency_manager.cairo | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index 065f06f..4d449d2 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -66,7 +66,7 @@ mod CurrencyManager { fn add_currency(ref self: ContractState, currency: ContractAddress) { self.ownable.assert_only_owner(); let index = self.whitelisted_currency_index.read(currency); - assert(index == 0, 'currency already whitelisted'); + 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); @@ -78,7 +78,7 @@ mod CurrencyManager { fn remove_currency(ref self: ContractState, currency: ContractAddress) { self.ownable.assert_only_owner(); let index = self.whitelisted_currency_index.read(currency); - assert(index != 0, 'currency not whitelisted'); + 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); From 5d6f6fb12689ce708edb5f20240f834958d3087b Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 15:55:13 +0530 Subject: [PATCH 5/8] initialized added in storage --- flex_marketplace/src/marketplace/currency_manager.cairo | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index 4d449d2..3ec6609 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -30,6 +30,7 @@ mod CurrencyManager { whitelisted_currency_count: usize, whitelisted_currencies: LegacyMap::, whitelisted_currency_index: LegacyMap::, + initialized: bool, #[substorage(v0)] ownable: OwnableComponent::Storage } @@ -59,7 +60,8 @@ mod CurrencyManager { fn initializer( ref self: ContractState, owner: ContractAddress, proxy_admin: ContractAddress ) { - // how to use the proxy_admin here? + assert!(!self.initialized.read(), "CurrencyManager: already initialized"); + self.initialized.write(true); self.ownable.initializer(owner); } @@ -78,7 +80,7 @@ mod CurrencyManager { 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); + 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); From 10aefb213cdeef0418aab14008a3a08cc5c7e432 Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 16:06:42 +0530 Subject: [PATCH 6/8] flat added to component event, component interface added --- flex_marketplace/src/marketplace/currency_manager.cairo | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index 3ec6609..d87edc6 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -10,6 +10,12 @@ trait ICurrencyManager { fn whitelisted_currency(self: @TState, index: usize) -> ContractAddress; } +#[starknet::interface] +trait ICurrencyManager { + fn owner(self: @TState) -> ContractAddress; + fn transfer_ownership(ref self: TState, new_owner: ContractAddress); +} + #[starknet::contract] mod CurrencyManager { use openzeppelin::access::ownable::interface::IOwnable; @@ -40,6 +46,7 @@ mod CurrencyManager { enum Event { CurrencyRemoved: CurrencyRemoved, CurrencyWhitelisted: CurrencyWhitelisted, + #[flat] OwnableEvent: OwnableComponent::Event, } From 646d9525f665fb7dbd03e3a1a0663d0d16cd180c Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 16:13:29 +0530 Subject: [PATCH 7/8] renamed correctly --- flex_marketplace/src/marketplace/currency_manager.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flex_marketplace/src/marketplace/currency_manager.cairo b/flex_marketplace/src/marketplace/currency_manager.cairo index d87edc6..10fc126 100644 --- a/flex_marketplace/src/marketplace/currency_manager.cairo +++ b/flex_marketplace/src/marketplace/currency_manager.cairo @@ -11,7 +11,7 @@ trait ICurrencyManager { } #[starknet::interface] -trait ICurrencyManager { +trait ICurrencyManage { fn owner(self: @TState) -> ContractAddress; fn transfer_ownership(ref self: TState, new_owner: ContractAddress); } From d8b1ad9f39488794dec9a0cc7459bb6b70d2b9ff Mon Sep 17 00:00:00 2001 From: mohiiit Date: Fri, 22 Dec 2023 16:14:18 +0530 Subject: [PATCH 8/8] renamed correctly --- flex_marketplace/src/lib.cairo | 40 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/flex_marketplace/src/lib.cairo b/flex_marketplace/src/lib.cairo index 9c3ee78..6eaf1bb 100644 --- a/flex_marketplace/src/lib.cairo +++ b/flex_marketplace/src/lib.cairo @@ -1,8 +1,25 @@ mod marketplace { - mod ERC721_flex; + mod launchpad { + mod ERC721_launchpad_migrated; + mod ERC721_Launchpad; + mod minter; + } + + mod swap { + mod exponential_curve; + mod pair_factory; + mod pair; + } + + mod utils { + mod merkle; + mod order_types; + mod reentrancy_guard; + } mod contract_deployer; mod currency_manager; + mod ERC721_flex; mod execution_manager; mod market_place; mod proxy; @@ -14,24 +31,7 @@ mod marketplace { mod strategy_highest_bidder_auction_sale; mod strategy_private_sale; mod strategy_standard_sale_for_fixed_price; - mod transfer_manager_ERC1155; mod transfer_manager_ERC721; + mod transfer_manager_ERC1155; mod transfer_selector_NFT; - mod launchpad { - mod ERC721_Launchpad; - mod ERC721_launchpad_migrated; - mod minter; - } - - mod swap { - mod exponential_curve; - mod pair; - mod pair_factory; - } - - mod utils { - mod merkle; - mod order_types; - mod reentrancy_guard; - } -} +} \ No newline at end of file