Skip to content

Commit

Permalink
Feat: royalties (#56)
Browse files Browse the repository at this point in the history
* wip: royalties

* wip: fallback on creator

* feat: use soliditiy 0.8

* wip: make old test pass

* feat: test royalties;

* feat: enhance error messages

* feat: add missing test cases

* feat: compute royalties

* refactor: unused var

* feat: add more tests

* feat: send fees on publication fees

* feat: add deployers

* feat: deploy with priv

* fix: tests
  • Loading branch information
nachomazzara committed Jan 6, 2022
1 parent efb1507 commit 32d17b0
Show file tree
Hide file tree
Showing 29 changed files with 5,038 additions and 267 deletions.
4 changes: 3 additions & 1 deletion contracts/commons/ContextMixin.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma solidity ^0.7.6;
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;


contract ContextMixin {
Expand Down
4 changes: 3 additions & 1 deletion contracts/commons/EIP712Base.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma solidity ^0.7.6;
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;


contract EIP712Base {
Expand Down
4 changes: 3 additions & 1 deletion contracts/commons/NativeMetaTransaction.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma solidity ^0.7.6;
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;


import { EIP712Base } from "./EIP712Base.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/commons/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0;

import "./ContextMixin.sol";

Expand All @@ -24,7 +24,7 @@ abstract contract Ownable is ContextMixin {
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
Expand Down
4 changes: 2 additions & 2 deletions contracts/commons/Pausable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity >=0.6.0;

import "./ContextMixin.sol";

Expand Down Expand Up @@ -29,7 +29,7 @@ abstract contract Pausable is ContextMixin {
/**
* @dev Initializes the contract in unpaused state.
*/
constructor () internal {
constructor () {
_paused = false;
}

Expand Down
11 changes: 11 additions & 0 deletions contracts/interfaces/IERC721CollectionV2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;
pragma experimental ABIEncoderV2;


interface IERC721CollectionV2 {
function creator() external view returns (address);
function decodeTokenId(uint256 _tokenId) external view returns (uint256, uint256);
function items(uint256 _itemId) external view returns (string memory, uint256, uint256, uint256, address, string memory, string memory);
}
10 changes: 10 additions & 0 deletions contracts/interfaces/IERC721Verifiable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC721/IERC721.sol";


interface IERC721Verifiable is IERC721 {
function verifyFingerprint(uint256, bytes memory) external view returns (bool);
}
7 changes: 7 additions & 0 deletions contracts/interfaces/IRoyaltiesManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;

interface IRoyaltiesManager {
function getRoyaltiesReceiver(address _contractAddress, uint256 _tokenId) external view returns (address);
}
65 changes: 65 additions & 0 deletions contracts/managers/RoyaltiesManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;


import '../interfaces/IERC721CollectionV2.sol';


contract RoyaltiesManager{

constructor() {}

/**
* @notice Get the royalties receiver for an specific token
* @dev It tries to get the item beneficiary. If it is the ZERO address, will try to get the creator
* @param _contractAddress - contract address
* @param _tokenId - token id
* @return royaltiesReceiver - address of the royalties receiver
*/
function getRoyaltiesReceiver(address _contractAddress, uint256 _tokenId) external view returns(address royaltiesReceiver) {
bool success;
bytes memory res;

(success, res) = _contractAddress.staticcall(
abi.encodeWithSelector(
IERC721CollectionV2(_contractAddress).decodeTokenId.selector,
_tokenId
)
);

if (!success) {
return royaltiesReceiver;
}

(uint256 itemId,) = abi.decode(res, (uint256, uint256));

(success, res) = _contractAddress.staticcall(
abi.encodeWithSelector(
IERC721CollectionV2(_contractAddress).items.selector,
itemId
)
);

if (success) {
// Get item beneficiary
(,,,,royaltiesReceiver,,) = abi.decode(res, (string, uint256, uint256, uint256, address, string, string));
}

if (royaltiesReceiver == address(0)) {
// If still the zero address, use the creator
(success, res) = _contractAddress.staticcall(
abi.encodeWithSelector(
IERC721CollectionV2(_contractAddress).creator.selector
));

if (!success) {
return royaltiesReceiver;
}

royaltiesReceiver = abi.decode(res, (address));
}

return royaltiesReceiver;
}
}
10 changes: 5 additions & 5 deletions contracts/marketplace/Marketplace.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pragma solidity ^0.7.6;
// SPDX-License-Identifier: MIT

import "@openzeppelin/contracts/math/SafeMath.sol";
pragma solidity ^0.8.10;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";

import "./MarketplaceStorage.sol";
Expand All @@ -24,9 +26,7 @@ contract Marketplace is Ownable, Pausable, MarketplaceStorage, NativeMetaTransac
address _acceptedToken,
uint256 _ownerCutPerMillion,
address _owner
)
public
{
) {
// EIP712 init
_initializeEIP712('Decentraland Marketplace', '1');

Expand Down
4 changes: 3 additions & 1 deletion contracts/marketplace/MarketplaceStorage.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
pragma solidity ^0.7.6;
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.10;


/**
Expand Down
Loading

0 comments on commit 32d17b0

Please sign in to comment.