Skip to content

Commit

Permalink
Merge branch 'main' into marketplace-functions-body
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Dec 23, 2023
2 parents 707d050 + f388264 commit 44cacfd
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 36 deletions.
97 changes: 63 additions & 34 deletions flex_marketplace/src/marketplace/royalty_fee_manager.cairo
Original file line number Diff line number Diff line change
@@ -1,28 +1,41 @@
use starknet::ContractAddress;

use starknet::class_hash::ClassHash;
use flex::marketplace::royalty_fee_registry::{
IRoyaltyFeeRegistryDispatcher, IRoyaltyFeeRegistryDispatcherTrait
};
#[starknet::interface]
trait IRoyaltyFeeManager<TState> {
fn initializer(
ref self: TState,
fee_registry: ContractAddress,
owner: ContractAddress,
proxy_admin: ContractAddress
);
fn transfer_ownership(ref self: TState, new_owner: ContractAddress);
fn owner(ref self: TState) -> ContractAddress;
fn initializer(ref self: TState, fee_registry: ContractAddress, owner: ContractAddress,);
fn INTERFACE_ID_ERC2981(self: @TState) -> felt252;
fn get_royalty_fee_registry(self: @TState) -> ContractAddress;
fn get_royalty_fee_registry(self: @TState) -> IRoyaltyFeeRegistryDispatcher;
fn calculate_royalty_fee_and_get_recipient(
self: @TState, collection: ContractAddress, token_id: u256, amount: u128
) -> (ContractAddress, u128);
fn upgrade(ref self: TState, impl_hash: ClassHash);
}


#[starknet::interface]
trait IERC2981<TContractState> {
fn royaltyInfo(
ref self: TContractState, tokenId: u256, salePrice: u128
) -> (ContractAddress, u128);
}

#[starknet::contract]
mod RoyaltyFeeManager {
use starknet::{ContractAddress, contract_address_const};

use openzeppelin::upgrades::upgradeable::UpgradeableComponent::InternalTrait;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::introspection::interface::{ISRC5Dispatcher, ISRC5DispatcherTrait};
use starknet::get_caller_address;
use starknet::{ContractAddress, contract_address_const};
use super::ClassHash;
use super::IERC2981Dispatcher;
use super::IERC2981DispatcherTrait;
use super::{IRoyaltyFeeRegistryDispatcher, IRoyaltyFeeRegistryDispatcherTrait};
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: UpgradeableComponent, storage: upgradable, event: UpgradeableEvent);

#[abi(embed_v0)]
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
Expand All @@ -32,50 +45,66 @@ mod RoyaltyFeeManager {
#[storage]
struct Storage {
INTERFACE_ID_ERC2981: felt252,
royalty_fee_registry: ContractAddress,
royalty_fee_registry: IRoyaltyFeeRegistryDispatcher,
#[substorage(v0)]
ownable: OwnableComponent::Storage,
#[substorage(v0)]
ownable: OwnableComponent::Storage
upgradable: UpgradeableComponent::Storage,
}

#[event]
#[derive(Drop, starknet::Event)]
enum Event {
#[flat]
OwnableEvent: OwnableComponent::Event,
#[flat]
UpgradeableEvent: UpgradeableComponent::Event,
}

#[external(v0)]
impl RoyaltyFeeManagerImpl of super::IRoyaltyFeeManager<ContractState> {
fn initializer(
ref self: ContractState,
fee_registry: ContractAddress,
owner: ContractAddress,
proxy_admin: ContractAddress
) { // TODO
}

fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress) { // TODO
}

fn owner(ref self: ContractState) -> ContractAddress {
// TODO
contract_address_const::<0>()
ref self: ContractState, fee_registry: ContractAddress, owner: ContractAddress,
) {
self.INTERFACE_ID_ERC2981.write(0x2a55205a);
self
.royalty_fee_registry
.write(IRoyaltyFeeRegistryDispatcher { contract_address: fee_registry });
self.ownable.initializer(owner);
}

fn INTERFACE_ID_ERC2981(self: @ContractState) -> felt252 {
// TODO
0
return self.INTERFACE_ID_ERC2981.read();
}

fn get_royalty_fee_registry(self: @ContractState) -> ContractAddress {
// TODO
contract_address_const::<0>()
fn get_royalty_fee_registry(self: @ContractState) -> IRoyaltyFeeRegistryDispatcher {
return self.royalty_fee_registry.read();
}

fn calculate_royalty_fee_and_get_recipient(
self: @ContractState, collection: ContractAddress, token_id: u256, amount: u128
) -> (ContractAddress, u128) {
// TODO
(contract_address_const::<0>(), 0)
let feeRegistry = self.get_royalty_fee_registry();
let (receiver, royaltyAmount) = feeRegistry.get_royalty_fee_info(collection, amount);
if (!receiver.is_zero()) {
return (receiver, royaltyAmount);
}
let interfaceIDERC2981 = self.INTERFACE_ID_ERC2981();
let supportsERC2981: bool = ISRC5Dispatcher { contract_address: collection }
.supports_interface(interfaceIDERC2981);
if (supportsERC2981) {
let (receiverERC2981, royaltyAmountERC2981) = IERC2981Dispatcher {
contract_address: collection
}
.royaltyInfo(token_id, amount);
return (receiverERC2981, royaltyAmountERC2981);
}
return (receiver, royaltyAmount);
}

fn upgrade(ref self: ContractState, impl_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradable._upgrade(impl_hash);
}
}
}
8 changes: 6 additions & 2 deletions flex_marketplace/src/marketplace/royalty_fee_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ trait IRoyaltyFeeRegistry<TState> {
fn transfer_ownership(ref self: TState, new_owner: ContractAddress);
fn owner(ref self: TState) -> ContractAddress;
fn get_royalty_fee_limit(self: @TState) -> u128;
fn get_royalty_fee_info(self: @TState) -> (ContractAddress, u128);
fn get_royalty_fee_info(
self: @TState, collection: ContractAddress, amount: u128
) -> (ContractAddress, u128);
fn get_royalty_fee_info_collection(
self: @TState, collection: ContractAddress
) -> (ContractAddress, ContractAddress, u128);
Expand Down Expand Up @@ -107,7 +109,9 @@ mod RoyaltyFeeRegistry {
0
}

fn get_royalty_fee_info(self: @ContractState) -> (ContractAddress, u128) {
fn get_royalty_fee_info(
self: @ContractState, collection: ContractAddress, amount: u128
) -> (ContractAddress, u128) {
// TODO
(contract_address_const::<0>(), 0)
}
Expand Down

0 comments on commit 44cacfd

Please sign in to comment.