From eb0f88dce0ebcf4e5ef49b05cdebf8df257c6b32 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Mon, 26 Aug 2024 15:37:44 +0100 Subject: [PATCH 1/8] functions selling any item at a fix price --- marketplace/Scarb.lock | 4 +- marketplace/Scarb.toml | 2 +- ...item_from_collection_for_fixed_price.cairo | 155 ++++++++++++++++++ marketplace/src/utils/order_types.cairo | 7 + 4 files changed, 165 insertions(+), 3 deletions(-) diff --git a/marketplace/Scarb.lock b/marketplace/Scarb.lock index 13a7d15..c60e18f 100644 --- a/marketplace/Scarb.lock +++ b/marketplace/Scarb.lock @@ -22,5 +22,5 @@ source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.10.0#d77082 [[package]] name = "snforge_std" -version = "0.14.0" -source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.14.0#e8cbecee4e31ed428c76d5173eaa90c8df796fe3" +version = "0.27.0" +source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de" diff --git a/marketplace/Scarb.toml b/marketplace/Scarb.toml index 4d7bf86..cf9b3f4 100644 --- a/marketplace/Scarb.toml +++ b/marketplace/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_01" [dependencies] starknet = "2.6.3" -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.14.0" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.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" } diff --git a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo index 8b13789..1622be8 100644 --- a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo +++ b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo @@ -1 +1,156 @@ +use starknet::ContractAddress; +use starknet::class_hash::ClassHash; +use marketplace::utils::order_types::{TakerOrder, MakerOrder, BuyerBidOrder}; +#[starknet::interface] +trait IStrategySaleAnyItemAtFixedPrice { + // fn initializer(ref self: TState, fee: u128, owner: ContractAddress); + fn update_protocol_fee(ref self: TState, fee: u128); + fn protocol_fee(self: @TState) -> u128; + fn set_item_sale(ref self: TState, token_id: u128); + fn set_price_for_item(ref self: TState, token_id: u128, price: u128); + fn can_execute_buyer_bid(self: @TState, buyer_bid: BuyerBidOrder) -> (bool, u128, u128); + fn upgrade(ref self: TState, impl_hash: ClassHash); +} + +#[feature("deprecated_legacy_map")] +#[starknet::contract] +mod StrategySaleAnyItemAtFixedPrice { + use starknet::{ContractAddress, contract_address_const, get_caller_address}; + use starknet::class_hash::ClassHash; + use starknet::get_block_timestamp; + + use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin::upgrades::{ + {UpgradeableComponent, interface::IUpgradeable}, + upgradeable::UpgradeableComponent::InternalTrait as UpgradeableInternalTrait + }; + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); + component!(path: UpgradeableComponent, storage: upgradable, event: UpgradeableEvent); + + #[abi(embed_v0)] + impl OwnableImpl = OwnableComponent::OwnableImpl; + + impl OwnableInternalImpl = OwnableComponent::InternalImpl; + + use marketplace::utils::order_types::{TakerOrder, MakerOrder, BuyerBidOrder}; + + #[derive(Debug, Drop, Copy, Serde, starknet::Store)] + pub struct Bids { + pub token_id: u128, + pub price: u128 + } + + #[storage] + struct Storage { + bid_count: u256, + protocol_fee: u128, + item_for_sale: LegacyMap::< + u128, ContractAddress + >, // token_id: u128, seller_address:ContractAddress + buyer_bids: LegacyMap< + ContractAddress, Bids + >, // LegacyMap LegacyMap + #[substorage(v0)] + ownable: OwnableComponent::Storage, + #[substorage(v0)] + upgradable: UpgradeableComponent::Storage, + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + OwnableEvent: OwnableComponent::Event, + #[flat] + UpgradeableEvent: UpgradeableComponent::Event, + ItemForSaleAdded: ItemForSaleAdded, + SetPriceForItemByBuyer: SetPriceForItemByBuyer + } + + #[derive(Drop, starknet::Event)] + pub struct ItemForSaleAdded { + #[key] + pub token_id: u128, + pub token_owner: ContractAddress, + } + + #[derive(Drop, starknet::Event)] + pub struct SetPriceForItemByBuyer { + #[key] + pub token_id: u128, + pub buyer_address: ContractAddress, + pub price: u128, + } + + + #[constructor] + fn constructor(ref self: ContractState, owner: ContractAddress, fee: u128) { + assert(!owner.is_zero(), 'Owner cannot be a zero addr'); + self.ownable.initializer(owner); + self.protocol_fee.write(fee); + } + + #[abi(embed_v0)] + impl StrategySaleAnyItemAtFixedPriceImpl of super::IStrategySaleAnyItemAtFixedPrice< + ContractState + > { + fn update_protocol_fee(ref self: ContractState, fee: u128) { + self.ownable.assert_only_owner(); + self.protocol_fee.write(fee); + } + fn protocol_fee(self: @ContractState) -> u128 { + self.protocol_fee.read() + } + fn set_item_sale(ref self: ContractState, token_id: u128) { + let item_for_sale_owner = self.item_for_sale.read(token_id); + let token_owner = get_caller_address(); + assert(item_for_sale_owner == token_owner, 'Not Token owner'); + self.item_for_sale.write(token_id, token_owner); + + // emit event + self.emit(ItemForSaleAdded { token_id: token_id, token_owner: token_owner }); + } + fn set_price_for_item(ref self: ContractState, token_id: u128, price: u128) { + let item_for_sale_owner = self.item_for_sale.read(token_id); + let buyer = get_caller_address(); + assert(item_for_sale_owner != buyer, 'Cannot Buy Your Own Token'); + let existing_buyer_bids = self.buyer_bids.read(buyer); + + let buyer_token_price = existing_buyer_bids.price; + assert(buyer_token_price != price, 'Bid Placed Already'); + + let new_buyer_bid = Bids { token_id: token_id, price: price }; + self.buyer_bids.write(buyer, new_buyer_bid); + // emit an event + self + .emit( + SetPriceForItemByBuyer { + token_id: token_id, buyer_address: buyer, price: price + } + ); + } + + fn can_execute_buyer_bid( + self: @ContractState, buyer_bid: BuyerBidOrder + ) -> (bool, u128, u128) { + let seller_item_listed_address = self.item_for_sale.read(buyer_bid.token_id); + let seller_address = get_caller_address(); + // check if seller has listed the token to be sold at any price + assert(seller_address == seller_item_listed_address, 'Not avaialable for sale'); + + // get the buyer token from the bid + let buyer_bids = self.buyer_bids.read(buyer_bid.buyer_adddress); + let buyer_token_price = buyer_bids.price; + if (buyer_token_price < 0) { + return (false, buyer_bid.token_id, buyer_bid.price); + } + return (true, buyer_bid.token_id, buyer_bid.price); + + } + fn upgrade(ref self: ContractState, impl_hash: ClassHash) { + self.ownable.assert_only_owner(); + self.upgradable._upgrade(impl_hash); + } + } +} diff --git a/marketplace/src/utils/order_types.cairo b/marketplace/src/utils/order_types.cairo index d66adf4..3bdde07 100644 --- a/marketplace/src/utils/order_types.cairo +++ b/marketplace/src/utils/order_types.cairo @@ -29,3 +29,10 @@ struct TakerOrder { min_percentage_to_ask: u128, // slippage protection (9000 = 90% of the final price must return to ask) params: felt252, } + +#[derive(Copy, Drop, Serde, Default)] +struct BuyerBidOrder { + token_id: u128, + buyer_adddress: ContractAddress, + price: u128 +} From 525f3b3095b3db4dc2573c889e59f982b263f109 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Mon, 2 Sep 2024 09:01:20 +0100 Subject: [PATCH 2/8] refactor function for buy back Item at a certain price --- .tool-versions | 2 + marketplace/.tool-versions | 1 + marketplace/Scarb.lock | 4 +- marketplace/Scarb.toml | 2 +- ...item_from_collection_for_fixed_price.cairo | 57 ++++++++++--------- 5 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 .tool-versions create mode 100644 marketplace/.tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..43b2f18 --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +starknet-foundry 0.27.0 +scarb 2.6.3 diff --git a/marketplace/.tool-versions b/marketplace/.tool-versions new file mode 100644 index 0000000..f239fe2 --- /dev/null +++ b/marketplace/.tool-versions @@ -0,0 +1 @@ +scarb 2.6.3 diff --git a/marketplace/Scarb.lock b/marketplace/Scarb.lock index c60e18f..dc27f49 100644 --- a/marketplace/Scarb.lock +++ b/marketplace/Scarb.lock @@ -22,5 +22,5 @@ source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.10.0#d77082 [[package]] name = "snforge_std" -version = "0.27.0" -source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.27.0#2d99b7c00678ef0363881ee0273550c44a9263de" +version = "0.26.0" +source = "git+https://github.com/foundry-rs/starknet-foundry.git?tag=v0.26.0#50eb589db65e113efe4f09241feb59b574228c7e" diff --git a/marketplace/Scarb.toml b/marketplace/Scarb.toml index cf9b3f4..31f5366 100644 --- a/marketplace/Scarb.toml +++ b/marketplace/Scarb.toml @@ -5,7 +5,7 @@ edition = "2023_01" [dependencies] starknet = "2.6.3" -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.27.0" } +snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.26.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" } diff --git a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo index 1622be8..72f1df9 100644 --- a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo +++ b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo @@ -7,8 +7,10 @@ trait IStrategySaleAnyItemAtFixedPrice { // fn initializer(ref self: TState, fee: u128, owner: ContractAddress); fn update_protocol_fee(ref self: TState, fee: u128); fn protocol_fee(self: @TState) -> u128; - fn set_item_sale(ref self: TState, token_id: u128); - fn set_price_for_item(ref self: TState, token_id: u128, price: u128); + // fn set_item_sale(ref self: TState, token_id: u128); + fn set_buy_back_price_for_item( + ref self: TState, token_id: u128, price: u128, collection_address: ContractAddress + ); fn can_execute_buyer_bid(self: @TState, buyer_bid: BuyerBidOrder) -> (bool, u128, u128); fn upgrade(ref self: TState, impl_hash: ClassHash); } @@ -19,7 +21,7 @@ mod StrategySaleAnyItemAtFixedPrice { use starknet::{ContractAddress, contract_address_const, get_caller_address}; use starknet::class_hash::ClassHash; use starknet::get_block_timestamp; - + use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::upgrades::{ {UpgradeableComponent, interface::IUpgradeable}, @@ -38,12 +40,12 @@ mod StrategySaleAnyItemAtFixedPrice { #[derive(Debug, Drop, Copy, Serde, starknet::Store)] pub struct Bids { pub token_id: u128, - pub price: u128 + pub price: u128, + pub collection_address: ContractAddress } #[storage] struct Storage { - bid_count: u256, protocol_fee: u128, item_for_sale: LegacyMap::< u128, ContractAddress @@ -65,7 +67,7 @@ mod StrategySaleAnyItemAtFixedPrice { #[flat] UpgradeableEvent: UpgradeableComponent::Event, ItemForSaleAdded: ItemForSaleAdded, - SetPriceForItemByBuyer: SetPriceForItemByBuyer + SetBuyBackPriceForItem: SetBuyBackPriceForItem } #[derive(Drop, starknet::Event)] @@ -76,11 +78,12 @@ mod StrategySaleAnyItemAtFixedPrice { } #[derive(Drop, starknet::Event)] - pub struct SetPriceForItemByBuyer { + pub struct SetBuyBackPriceForItem { #[key] pub token_id: u128, pub buyer_address: ContractAddress, pub price: u128, + pub collection_address: ContractAddress } @@ -102,31 +105,32 @@ mod StrategySaleAnyItemAtFixedPrice { fn protocol_fee(self: @ContractState) -> u128 { self.protocol_fee.read() } - fn set_item_sale(ref self: ContractState, token_id: u128) { - let item_for_sale_owner = self.item_for_sale.read(token_id); - let token_owner = get_caller_address(); - assert(item_for_sale_owner == token_owner, 'Not Token owner'); - self.item_for_sale.write(token_id, token_owner); - - // emit event - self.emit(ItemForSaleAdded { token_id: token_id, token_owner: token_owner }); - } - fn set_price_for_item(ref self: ContractState, token_id: u128, price: u128) { - let item_for_sale_owner = self.item_for_sale.read(token_id); - let buyer = get_caller_address(); - assert(item_for_sale_owner != buyer, 'Cannot Buy Your Own Token'); - let existing_buyer_bids = self.buyer_bids.read(buyer); + + fn set_buy_back_price_for_item( + ref self: ContractState, + token_id: u128, + price: u128, + collection_address: ContractAddress + ) { + let owner = get_caller_address(); + + let existing_buyer_bids = self.buyer_bids.read(owner); let buyer_token_price = existing_buyer_bids.price; - assert(buyer_token_price != price, 'Bid Placed Already'); + assert(buyer_token_price != price, 'Buy Back Price Set Already'); - let new_buyer_bid = Bids { token_id: token_id, price: price }; - self.buyer_bids.write(buyer, new_buyer_bid); + let new_buy_back_price = Bids { + token_id: token_id, price: price, collection_address: collection_address + }; + self.buyer_bids.write(owner, new_buy_back_price); // emit an event self .emit( - SetPriceForItemByBuyer { - token_id: token_id, buyer_address: buyer, price: price + SetBuyBackPriceForItem { + token_id: token_id, + buyer_address: owner, + price: price, + collection_address: collection_address } ); } @@ -146,7 +150,6 @@ mod StrategySaleAnyItemAtFixedPrice { return (false, buyer_bid.token_id, buyer_bid.price); } return (true, buyer_bid.token_id, buyer_bid.price); - } fn upgrade(ref self: ContractState, impl_hash: ClassHash) { self.ownable.assert_only_owner(); From aab03e455c2f31194debddc060a813c370270f78 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Tue, 3 Sep 2024 06:58:10 +0100 Subject: [PATCH 3/8] add read me for strategy for selling any item at a fixed price --- marketplace/Sell_any_item_at_fixed_price.md | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 marketplace/Sell_any_item_at_fixed_price.md diff --git a/marketplace/Sell_any_item_at_fixed_price.md b/marketplace/Sell_any_item_at_fixed_price.md new file mode 100644 index 0000000..081b219 --- /dev/null +++ b/marketplace/Sell_any_item_at_fixed_price.md @@ -0,0 +1,34 @@ +## Strategy for selling any item at a fix price + +The function implements a Cairo contract named 'StrategySaleAnyItemAtFixedPrice'. This contract manages the sale of items (identified by token_id) at a fixed price, with specific features such as setting prices, handling bids, and upgrading the contract. +Key functionalities: + + Initialization (constructor): + Initializes the contract with the owner's address and a protocol fee. + + Updating Protocol Fee (update_protocol_fee): + Allows the owner to update the protocol fee, which is the fee applied to transactions. + + Getting Protocol Fee (protocol_fee): + Retrieves the current protocol fee. + + Setting an Item for Sale (set_item_sale): + Allows the owner of a specific token_id to list it for sale. It checks if the caller is the token owner and emits an event once the item is listed. + + Setting Price for an Item (set_price_for_item): + Allows a buyer to set a price for a listed item. It verifies that the buyer is not the token owner, checks if the bid price is different from any existing bids by the buyer, and then records the bid, emitting an event for the action. + + Executing Buyer Bids (can_execute_buyer_bid): + Checks if a buyer's bid can be executed. It verifies that the token has been listed by the seller and compares the buyer's bid price against the existing bid to determine if the bid is executable. + + Contract Upgrading (upgrade): + Allows the contract owner to upgrade the contract implementation using a new ClassHash, ensuring only the owner can perform this action. + +Events: + + ItemForSaleAdded: Emitted when a new item is listed for sale. + SetPriceForItemByBuyer: Emitted when a buyer sets a price for a listed item. + +This contract integrates with StarkNet's components for ownership (OwnableComponent) and upgradability (UpgradeableComponent), ensuring that only authorized users can perform sensitive operations like updating the protocol fee and upgrading the contract. + +PR: https://github.com/Flex-NFT-Marketplace/Flex-Marketplace-Contract/pull/98 From b9f12ed2c21936026096b03f8e6aa683355ec61f Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Tue, 3 Sep 2024 10:43:44 +0100 Subject: [PATCH 4/8] map price to a collection --- ...item_from_collection_for_fixed_price.cairo | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo index 72f1df9..76902d6 100644 --- a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo +++ b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo @@ -9,7 +9,7 @@ trait IStrategySaleAnyItemAtFixedPrice { fn protocol_fee(self: @TState) -> u128; // fn set_item_sale(ref self: TState, token_id: u128); fn set_buy_back_price_for_item( - ref self: TState, token_id: u128, price: u128, collection_address: ContractAddress + ref self: TState, price: u128, collection_address: ContractAddress ); fn can_execute_buyer_bid(self: @TState, buyer_bid: BuyerBidOrder) -> (bool, u128, u128); fn upgrade(ref self: TState, impl_hash: ClassHash); @@ -38,8 +38,7 @@ mod StrategySaleAnyItemAtFixedPrice { use marketplace::utils::order_types::{TakerOrder, MakerOrder, BuyerBidOrder}; #[derive(Debug, Drop, Copy, Serde, starknet::Store)] - pub struct Bids { - pub token_id: u128, + pub struct BuyBack { pub price: u128, pub collection_address: ContractAddress } @@ -51,8 +50,8 @@ mod StrategySaleAnyItemAtFixedPrice { u128, ContractAddress >, // token_id: u128, seller_address:ContractAddress buyer_bids: LegacyMap< - ContractAddress, Bids - >, // LegacyMap LegacyMap + ContractAddress, BuyBack + >, // LegacyMap LegacyMap #[substorage(v0)] ownable: OwnableComponent::Storage, #[substorage(v0)] @@ -66,21 +65,13 @@ mod StrategySaleAnyItemAtFixedPrice { OwnableEvent: OwnableComponent::Event, #[flat] UpgradeableEvent: UpgradeableComponent::Event, - ItemForSaleAdded: ItemForSaleAdded, SetBuyBackPriceForItem: SetBuyBackPriceForItem } - #[derive(Drop, starknet::Event)] - pub struct ItemForSaleAdded { - #[key] - pub token_id: u128, - pub token_owner: ContractAddress, - } #[derive(Drop, starknet::Event)] pub struct SetBuyBackPriceForItem { #[key] - pub token_id: u128, pub buyer_address: ContractAddress, pub price: u128, pub collection_address: ContractAddress @@ -107,10 +98,7 @@ mod StrategySaleAnyItemAtFixedPrice { } fn set_buy_back_price_for_item( - ref self: ContractState, - token_id: u128, - price: u128, - collection_address: ContractAddress + ref self: ContractState, price: u128, collection_address: ContractAddress ) { let owner = get_caller_address(); @@ -119,18 +107,15 @@ mod StrategySaleAnyItemAtFixedPrice { let buyer_token_price = existing_buyer_bids.price; assert(buyer_token_price != price, 'Buy Back Price Set Already'); - let new_buy_back_price = Bids { - token_id: token_id, price: price, collection_address: collection_address + let new_buy_back_price = BuyBack { + price: price, collection_address: collection_address }; self.buyer_bids.write(owner, new_buy_back_price); // emit an event self .emit( SetBuyBackPriceForItem { - token_id: token_id, - buyer_address: owner, - price: price, - collection_address: collection_address + buyer_address: owner, price: price, collection_address: collection_address } ); } From 9e24c93759b1ee7aa1c58cf51800b81a6c566172 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Tue, 3 Sep 2024 17:47:59 +0100 Subject: [PATCH 5/8] update readMe file --- marketplace/Sell_any_item_at_fixed_price.md | 33 ++++++++++----------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/marketplace/Sell_any_item_at_fixed_price.md b/marketplace/Sell_any_item_at_fixed_price.md index 081b219..6dcc12b 100644 --- a/marketplace/Sell_any_item_at_fixed_price.md +++ b/marketplace/Sell_any_item_at_fixed_price.md @@ -1,34 +1,33 @@ -## Strategy for selling any item at a fix price +## Strategy for Selling Any Item at a Fixed Price -The function implements a Cairo contract named 'StrategySaleAnyItemAtFixedPrice'. This contract manages the sale of items (identified by token_id) at a fixed price, with specific features such as setting prices, handling bids, and upgrading the contract. -Key functionalities: +This contract, StrategySaleAnyItemAtFixedPrice, implements a strategy for selling items at a fixed price on StarkNet. The contract manages sales by allowing owners to list items (identified by token_id), set prices, handle buyer bids, and upgrade the contract. +Key Functionalities Initialization (constructor): - Initializes the contract with the owner's address and a protocol fee. + Initializes the contract with the owner's address and a protocol fee. The owner's address must not be zero, and the protocol fee is set during the initialization process. Updating Protocol Fee (update_protocol_fee): - Allows the owner to update the protocol fee, which is the fee applied to transactions. + Allows the contract owner to update the protocol fee, which is a fee applied to transactions executed within the marketplace. Only the contract owner has the authority to modify this fee. Getting Protocol Fee (protocol_fee): - Retrieves the current protocol fee. + Retrieves the current protocol fee stored in the contract. - Setting an Item for Sale (set_item_sale): - Allows the owner of a specific token_id to list it for sale. It checks if the caller is the token owner and emits an event once the item is listed. - - Setting Price for an Item (set_price_for_item): - Allows a buyer to set a price for a listed item. It verifies that the buyer is not the token owner, checks if the bid price is different from any existing bids by the buyer, and then records the bid, emitting an event for the action. + Setting Buy-Back Price for an Item (set_buy_back_price_for_item): + Allows a buyer to set a buy-back price for an item from a specific collection. The buyer must be the caller, and the new price must be different from any existing price set by the buyer. If the conditions are met, the price is updated, and an event is emitted to notify that the price has been set. Executing Buyer Bids (can_execute_buyer_bid): - Checks if a buyer's bid can be executed. It verifies that the token has been listed by the seller and compares the buyer's bid price against the existing bid to determine if the bid is executable. + Verifies whether a buyer's bid can be executed. The contract checks if the token was listed for sale by the seller and compares the bid price with the existing buy-back price to determine if the bid is valid and executable. Contract Upgrading (upgrade): - Allows the contract owner to upgrade the contract implementation using a new ClassHash, ensuring only the owner can perform this action. + Allows the contract owner to upgrade the contract's implementation using a new ClassHash. This operation can only be performed by the contract owner to ensure the contract's integrity. + +Events -Events: + SetBuyBackPriceForItem: + Emitted when a buyer sets a buy-back price for an item. This event logs the buyer's address, the price set, and the collection address. - ItemForSaleAdded: Emitted when a new item is listed for sale. - SetPriceForItemByBuyer: Emitted when a buyer sets a price for a listed item. +Integrations -This contract integrates with StarkNet's components for ownership (OwnableComponent) and upgradability (UpgradeableComponent), ensuring that only authorized users can perform sensitive operations like updating the protocol fee and upgrading the contract. +This contract integrates with StarkNet's OwnableComponent for ownership management and UpgradeableComponent for upgradability. These integrations ensure that sensitive operations, such as updating protocol fees and upgrading the contract, are restricted to authorized users only. PR: https://github.com/Flex-NFT-Marketplace/Flex-Marketplace-Contract/pull/98 From 6022a42e5988e06550f5be2b7d0237c6f5659566 Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Tue, 3 Sep 2024 17:56:01 +0100 Subject: [PATCH 6/8] change collectionId to collectionAddress --- .../src/strategy_any_item_from_collection_for_fixed_price.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo index 76902d6..868340b 100644 --- a/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo +++ b/marketplace/src/strategy_any_item_from_collection_for_fixed_price.cairo @@ -51,7 +51,7 @@ mod StrategySaleAnyItemAtFixedPrice { >, // token_id: u128, seller_address:ContractAddress buyer_bids: LegacyMap< ContractAddress, BuyBack - >, // LegacyMap LegacyMap + >, // LegacyMap LegacyMap #[substorage(v0)] ownable: OwnableComponent::Storage, #[substorage(v0)] From c2d69b47470f32e482850209f15c2c778ce72b3f Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Wed, 4 Sep 2024 08:35:04 +0100 Subject: [PATCH 7/8] change function description --- marketplace/Sell_any_item_at_fixed_price.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marketplace/Sell_any_item_at_fixed_price.md b/marketplace/Sell_any_item_at_fixed_price.md index 6dcc12b..50e04c0 100644 --- a/marketplace/Sell_any_item_at_fixed_price.md +++ b/marketplace/Sell_any_item_at_fixed_price.md @@ -13,7 +13,7 @@ Key Functionalities Retrieves the current protocol fee stored in the contract. Setting Buy-Back Price for an Item (set_buy_back_price_for_item): - Allows a buyer to set a buy-back price for an item from a specific collection. The buyer must be the caller, and the new price must be different from any existing price set by the buyer. If the conditions are met, the price is updated, and an event is emitted to notify that the price has been set. + Allows a buyer to set a buy-back price for any item from a specific collection. Executing Buyer Bids (can_execute_buyer_bid): Verifies whether a buyer's bid can be executed. The contract checks if the token was listed for sale by the seller and compares the bid price with the existing buy-back price to determine if the bid is valid and executable. From c186583a6ce8e3c7145c3c0b1b356702be0f7bbd Mon Sep 17 00:00:00 2001 From: mubarak23 Date: Wed, 4 Sep 2024 10:44:35 +0100 Subject: [PATCH 8/8] change sentence --- marketplace/Sell_any_item_at_fixed_price.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marketplace/Sell_any_item_at_fixed_price.md b/marketplace/Sell_any_item_at_fixed_price.md index 50e04c0..78be05f 100644 --- a/marketplace/Sell_any_item_at_fixed_price.md +++ b/marketplace/Sell_any_item_at_fixed_price.md @@ -12,7 +12,7 @@ Key Functionalities Getting Protocol Fee (protocol_fee): Retrieves the current protocol fee stored in the contract. - Setting Buy-Back Price for an Item (set_buy_back_price_for_item): + Setting Buy-Back Price for any item (set_buy_back_price_for_any_item): Allows a buyer to set a buy-back price for any item from a specific collection. Executing Buyer Bids (can_execute_buyer_bid):