Skip to content

Commit

Permalink
ON-815: Direct Rentals
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Apr 23, 2024
1 parent 959e877 commit c6b6b98
Show file tree
Hide file tree
Showing 4 changed files with 359 additions and 4 deletions.
36 changes: 36 additions & 0 deletions contracts/NftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity 0.8.9;
import { IERC721 } from '@openzeppelin/contracts/token/ERC721/IERC721.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import { IERC7432VaultExtension } from './interfaces/IERC7432VaultExtension.sol';
import { IERC7432 } from './interfaces/IERC7432.sol';
import { ERC165Checker } from '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';
import { IOriumMarketplaceRoyalties } from './interfaces/IOriumMarketplaceRoyalties.sol';
import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
Expand Down Expand Up @@ -242,6 +243,41 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr
emit RentalEnded(_offer.lender, _offer.nonce);
}

/**
* @notice Withdraws the NFT from roles registry.
* @dev Can only be called by the token owner.
* @param _tokenAddresses The NFT tokenAddresses.
* @param _tokenIds The NFT tokenIds.
*/
function batchWithdraw(
address[] calldata _tokenAddresses,
uint256[] calldata _tokenIds
) external whenNotPaused {
LibNftRentalMarketplace.batchWithdraw(oriumMarketplaceRoyalties, _tokenAddresses, _tokenIds);
}

/**
* @notice batchGrantRole grant role in a single transaction.
* @param _params The array of role params.
*/
function batchGrantRole(IERC7432.Role[] calldata _params) external whenNotPaused {
LibNftRentalMarketplace.batchGrantRole(_params, oriumMarketplaceRoyalties);
}

/**
* @notice batchRevokeRole revokes role in a single transaction.
* @dev owner will be msg.sender and it must approve the marketplace to revoke the roles.
* @param _tokenAddresses The array of tokenAddresses
* @param _tokenIds The array of tokenIds
*/
function batchRevokeRole(
address[] memory _tokenAddresses,
uint256[] memory _tokenIds,
bytes32[] memory _roleIds
) external whenNotPaused {
LibNftRentalMarketplace.batchRevokeRole(_tokenAddresses, _tokenIds, _roleIds, oriumMarketplaceRoyalties);
}

/** ######### Internals ########### **/

/**
Expand Down
87 changes: 87 additions & 0 deletions contracts/libraries/LibNftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,91 @@ library LibNftRentalMarketplace {
IERC7432(_rolesRegsitry).revokeRole(_tokenAddress, _tokenId, _roleIds[i]);
}
}

/**
* @notice Withdraws tokens from registry
* @dev Can only be called by the token owner.
* @param _oriumMarketplaceRoyaltiesAddress The address of the OriumMarketplaceRoyalties contract.
* @param _tokenAddresses The NFT tokenAddresses.
* @param _tokenIds The NFT tokenIds.
*/
function batchWithdraw(
address _oriumMarketplaceRoyaltiesAddress,
address[] calldata _tokenAddresses,
uint256[] calldata _tokenIds
) external {
require(_tokenAddresses.length == _tokenIds.length, 'OriumNftMarketplace: arrays length mismatch');
for (uint256 i = 0; i < _tokenAddresses.length; i++) {
address _rolesRegistry = IOriumMarketplaceRoyalties(_oriumMarketplaceRoyaltiesAddress).nftRolesRegistryOf(
_tokenAddresses[i]
);
require(
msg.sender == IERC7432VaultExtension(_rolesRegistry).ownerOf(_tokenAddresses[i], _tokenIds[i]),
"OriumNftMarketplace: sender is not the token's owner"
);
IERC7432VaultExtension(_rolesRegistry).withdraw(_tokenAddresses[i], _tokenIds[i]);
}
}

/**
* @notice batchGrantRole grant role in a single transaction.
* @param _params The array of role params.
* @param _oriumMarketplaceRoyalties The Orium marketplace royalties contract address.
*/
function batchGrantRole(IERC7432.Role[] calldata _params, address _oriumMarketplaceRoyalties) external {
for (uint256 i = 0; i < _params.length; i++) {
address _rolesRegistry = IOriumMarketplaceRoyalties(_oriumMarketplaceRoyalties).nftRolesRegistryOf(
_params[i].tokenAddress
);
require(
msg.sender ==
IERC7432VaultExtension(_rolesRegistry).ownerOf(_params[i].tokenAddress, _params[i].tokenId) ||
msg.sender == IERC721(_params[i].tokenAddress).ownerOf(_params[i].tokenId),
'OriumNftMarketplace: sender is not the owner'
);

IERC7432(_rolesRegistry).grantRole(_params[i]);
}
}

/**
* @notice batchRevokeRole revokes role in a single transaction.
* @dev only the owner and recipient can call this function. Be careful as the marketplace have approvals from other users.
* @param _tokenAddresses The array of tokenAddresses
* @param _tokenIds The array of tokenIds
* @param _roleIds The array of roleIds
* @param _oriumMarketplaceRoyalties The Orium marketplace royalties contract address.
*/
function batchRevokeRole(
address[] memory _tokenAddresses,
uint256[] memory _tokenIds,
bytes32[] memory _roleIds,
address _oriumMarketplaceRoyalties
) external {
require(
_tokenIds.length == _tokenAddresses.length && _tokenIds.length == _roleIds.length,
'OriumNftMarketplace: arrays length mismatch'
);

for (uint256 i = 0; i < _tokenIds.length; i++) {
address _rolesRegistry = IOriumMarketplaceRoyalties(_oriumMarketplaceRoyalties).nftRolesRegistryOf(
_tokenAddresses[i]
);
require(
IERC7432(_rolesRegistry).isRoleRevocable(_tokenAddresses[i], _tokenIds[i], _roleIds[i]),
'OriumNftMarketplace: role is not revocable'
);
require(
IERC7432(_rolesRegistry).roleExpirationDate(_tokenAddresses[i], _tokenIds[i], _roleIds[i]) >
block.timestamp,
'OriumNftMarketplace: role is expired'
);
require(
msg.sender == IERC7432(_rolesRegistry).recipientOf(_tokenAddresses[i], _tokenIds[i], _roleIds[i]) ||
msg.sender == IERC7432VaultExtension(_rolesRegistry).ownerOf(_tokenAddresses[i], _tokenIds[i]),
"OriumNftMarketplace: sender is not the token's owner or recipient"
);
IERC7432(_rolesRegistry).revokeRole(_tokenAddresses[i], _tokenIds[i], _roleIds[i]);
}
}
}
Loading

0 comments on commit c6b6b98

Please sign in to comment.