Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ON-815: Direct Rentals #45

Merged
merged 8 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -240,6 +241,41 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr
emit RentalEnded(_offer.lender, _offer.nonce);
}

/**
* @notice Withdraws NFTs 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 Grants multiple roles.
* @param _params The array of role params.
*/
function batchGrantRole(IERC7432.Role[] calldata _params) external whenNotPaused {
LibNftRentalMarketplace.batchGrantRole(_params, oriumMarketplaceRoyalties);
}

/**
* @notice Revokes multiple roles.
* @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
89 changes: 88 additions & 1 deletion contracts/libraries/LibNftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ library LibNftRentalMarketplace {
/**
* @notice Validates the cancel rental offer params.
* @dev This function is used to validate the cancel rental offer params.
* @param _isCreated Whether the offer is created
* @param _isCreated Whether the offer is created
* @param _lender The lender address
* @param _nonceDeadline The nonce deadline
*/
Expand Down 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 Grants multiple roles.
* @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 == IERC721(_params[i].tokenAddress).ownerOf(_params[i].tokenId) ||
msg.sender ==
IERC7432VaultExtension(_rolesRegistry).ownerOf(_params[i].tokenAddress, _params[i].tokenId),
'OriumNftMarketplace: sender is not the owner'
);

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

/**
* @notice Revokes multiple roles.
* @dev only the owner and recipient can call this function. Be careful as the marketplace receives role 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 == IERC7432VaultExtension(_rolesRegistry).ownerOf(_tokenAddresses[i], _tokenIds[i]) ||
msg.sender == IERC7432(_rolesRegistry).recipientOf(_tokenAddresses[i], _tokenIds[i], _roleIds[i]),
"OriumNftMarketplace: sender is not the token's owner or recipient"
);
IERC7432(_rolesRegistry).revokeRole(_tokenAddresses[i], _tokenIds[i], _roleIds[i]);
}
}
}
Loading
Loading