Skip to content

Commit

Permalink
Merge pull request #63 from briansinw3b/main
Browse files Browse the repository at this point in the history
update transfer erc1155 manager
  • Loading branch information
0xandee authored Mar 14, 2024
2 parents bc7af0c + 488d8ff commit 3415161
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 63 deletions.
4 changes: 4 additions & 0 deletions flex_marketplace/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ mod marketplace {
mod openedition;
}

mod interfaces {
mod nft_transfer_manager;
}

mod openedition;
mod contract_deployer;
mod currency_manager;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use starknet::ContractAddress;

#[starknet::interface]
trait ITransferManagerNFT<TState> {
fn initializer(
ref self: TState,
marketplace: ContractAddress,
owner: ContractAddress,
);
fn transfer_non_fungible_token(
ref self: TState,
collection: ContractAddress,
from: ContractAddress,
to: ContractAddress,
token_id: u256,
amount: u128,
data: Span<felt252>,
);
fn update_marketplace(ref self: TState, new_address: ContractAddress);
fn get_marketplace(self: @TState) -> ContractAddress;
}
5 changes: 3 additions & 2 deletions flex_marketplace/src/marketplace/marketplace.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ mod MarketPlace {
transfer_selector_NFT::{
ITransferSelectorNFTDispatcher, ITransferSelectorNFTDispatcherTrait
},
transfer_manager_ERC721::{ITransferManagerNFTDispatcher, ITransferManagerNFTDispatcherTrait}
interfaces::nft_transfer_manager::{ITransferManagerNFTDispatcher, ITransferManagerNFTDispatcherTrait}
};
use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};

use array::{Array, ArrayTrait};
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
use openzeppelin::access::ownable::OwnableComponent;
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
Expand Down Expand Up @@ -697,7 +698,7 @@ mod MarketPlace {
.check_transfer_manager_for_token(collection);
assert!(!manager.is_zero(), "MarketPlace: invalid tranfer manager {}", manager);
ITransferManagerNFTDispatcher { contract_address: manager }
.transfer_non_fungible_token(collection, from, to, token_id, amount);
.transfer_non_fungible_token(collection, from, to, token_id, amount, ArrayTrait::<felt252>::new().span());
}

fn calculate_protocol_fee(
Expand Down
34 changes: 5 additions & 29 deletions flex_marketplace/src/marketplace/transfer_manager_ERC1155.cairo
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
use starknet::ContractAddress;
use starknet::class_hash::ClassHash;
#[starknet::interface]
trait IERC1155TransferManager<TState> {
fn initializer(ref self: TState, marketplace: ContractAddress, owner: ContractAddress,);
fn transfer_non_fungible_token(
ref self: TState,
collection: ContractAddress,
from: ContractAddress,
to: ContractAddress,
token_id: u256,
amount: u128,
data: Span<felt252>,
);
fn update_marketplace(ref self: TState, address: ContractAddress);
fn get_marketplace(self: @TState) -> ContractAddress;
fn upgrade(ref self: TState, impl_hash: ClassHash);
}

#[starknet::contract]
mod ERC1155TransferManager {
use starknet::{ContractAddress, contract_address_const, get_caller_address};
use starknet::{ContractAddress, ClassHash, contract_address_const, get_caller_address};

use super::ClassHash;
use flex::marketplace::interfaces::nft_transfer_manager::ITransferManagerNFT;
use flex::{DebugContractAddress, DisplayContractAddress};
use flex::mocks::erc1155::{IERC1155Dispatcher, IERC1155DispatcherTrait};

Expand Down Expand Up @@ -55,7 +36,7 @@ mod ERC1155TransferManager {
}

#[external(v0)]
impl ERC1155TransferManagerImpl of super::IERC1155TransferManager<ContractState> {
impl ERC1155TransferManagerImpl of ITransferManagerNFT<ContractState> {
fn initializer(
ref self: ContractState, marketplace: ContractAddress, owner: ContractAddress,
) {
Expand Down Expand Up @@ -83,18 +64,13 @@ mod ERC1155TransferManager {
.safe_transfer_from(from, to, token_id, amount, data);
}

fn update_marketplace(ref self: ContractState, address: ContractAddress) {
fn update_marketplace(ref self: ContractState, new_address: ContractAddress) {
self.ownable.assert_only_owner();
self.marketplace.write(address);
self.marketplace.write(new_address);
}

fn get_marketplace(self: @ContractState) -> ContractAddress {
self.marketplace.read()
}

fn upgrade(ref self: ContractState, impl_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradable._upgrade(impl_hash);
}
}
}
30 changes: 5 additions & 25 deletions flex_marketplace/src/marketplace/transfer_manager_ERC721.cairo
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
use starknet::ContractAddress;

#[starknet::interface]
trait ITransferManagerNFT<TState> {
fn initializer(
ref self: TState,
marketplace: ContractAddress,
owner: ContractAddress,
proxy_admin: ContractAddress
);
fn transfer_non_fungible_token(
ref self: TState,
collection: ContractAddress,
from: ContractAddress,
to: ContractAddress,
token_id: u256,
amount: u128
);
fn update_marketplace(ref self: TState, new_address: ContractAddress);
fn get_marketplace(self: @TState) -> ContractAddress;
}

#[starknet::contract]
mod TransferManagerNFT {
use starknet::{ContractAddress, get_caller_address};

use flex::marketplace::interfaces::nft_transfer_manager::ITransferManagerNFT;
use flex::{DebugContractAddress, DisplayContractAddress};
use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};

Expand Down Expand Up @@ -53,12 +33,11 @@ mod TransferManagerNFT {
}

#[external(v0)]
impl TransferManagerNFTImpl of super::ITransferManagerNFT<ContractState> {
impl TransferManagerNFTImpl of ITransferManagerNFT<ContractState> {
fn initializer(
ref self: ContractState,
marketplace: ContractAddress,
owner: ContractAddress,
proxy_admin: ContractAddress
) {
// TODO: verify the role of Proxy here.
self.marketplace.write(marketplace);
Expand All @@ -71,7 +50,8 @@ mod TransferManagerNFT {
from: ContractAddress,
to: ContractAddress,
token_id: u256,
amount: u128
amount: u128,
data: Span<felt252>,
) {
let caller = get_caller_address();
assert!(
Expand All @@ -80,7 +60,7 @@ mod TransferManagerNFT {
caller
);
IERC721CamelOnlyDispatcher { contract_address: collection }
.transferFrom(from, to, token_id);
.safeTransferFrom(from, to, token_id, data);
}

fn update_marketplace(ref self: ContractState, new_address: ContractAddress) {
Expand Down
11 changes: 4 additions & 7 deletions flex_marketplace/src/marketplace/transfer_selector_NFT.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use starknet::ContractAddress;


#[starknet::interface]
trait ITransferSelectorNFT<TState> {
fn initializer(
Expand Down Expand Up @@ -33,10 +32,8 @@ mod TransferSelectorNFT {

use flex::{DebugContractAddress, DisplayContractAddress};
use flex::marketplace::utils::order_types::{MakerOrder, TakerOrder};
use flex::marketplace::transfer_manager_ERC721::{
ITransferManagerNFTDispatcher, ITransferManagerNFTDispatcherTrait
};

use flex::mocks::erc1155::IERC1155_ID;
use openzeppelin::token::erc721::interface::IERC721_ID;
use openzeppelin::introspection::interface::{ISRC5CamelDispatcher, ISRC5CamelDispatcherTrait};
use openzeppelin::access::ownable::OwnableComponent;
component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
Expand Down Expand Up @@ -91,8 +88,8 @@ mod TransferSelectorNFT {
) {
assert!(!self.initialized.read(), "TransferSelectorNFT: already initialized");
self.initialized.write(true);
self.INTERFACE_ID_ERC721.write(0x80ac58cd);
self.INTERFACE_ID_ERC1155.write(0xd9b67a26);
self.INTERFACE_ID_ERC721.write(IERC721_ID);
self.INTERFACE_ID_ERC1155.write(IERC1155_ID);
self.TRANSFER_MANAGER_ERC721.write(transfer_manager_ERC721);
self.TRANSFER_MANAGER_ERC1155.write(transfer_manager_ERC1155);
self.ownable.initializer(owner);
Expand Down
2 changes: 2 additions & 0 deletions flex_marketplace/src/mocks/erc1155.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const IERC1155_ID: felt252 = 0x6114a8f75559e1b39fcba08ce02961a1aa082d9256a158dd3e64964e4b1b52;

#[starknet::interface]
trait IERC1155<TContractState> {
fn safe_transfer_from(
Expand Down

0 comments on commit 3415161

Please sign in to comment.