Skip to content

Commit

Permalink
ON-814: PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Apr 23, 2024
1 parent 685e026 commit 786d655
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
32 changes: 32 additions & 0 deletions contracts/NftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ 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 { ERC165Checker } from '@openzeppelin/contracts/utils/introspection/ERC165Checker.sol';
import { IOriumMarketplaceRoyalties } from './interfaces/IOriumMarketplaceRoyalties.sol';
import { OwnableUpgradeable } from '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol';
import { Initializable } from '@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol';
Expand All @@ -16,6 +18,8 @@ import { LibNftRentalMarketplace, RentalOffer, Rental } from './libraries/LibNft
* @author Orium Network Team - [email protected]
*/
contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgradeable {
using ERC165Checker for address;

/** ######### Global Variables ########### **/

/// @dev oriumMarketplaceRoyalties stores the collection royalties and fees
Expand Down Expand Up @@ -190,6 +194,34 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr
*/

function cancelRentalOffer(RentalOffer calldata _offer) external whenNotPaused {
_cancelRentalOffer(_offer);
}

/**
* @notice Cancels a rental offer and withdraws the NFT.
* @dev Can only be called by the lender, and only withdraws the NFT if the rental has expired.
* @param _offer The rental offer struct. It should be the same as the one used to create the offer.
*/

function cancelRentalOfferAndWithdraw(RentalOffer calldata _offer) external whenNotPaused {
_cancelRentalOffer(_offer);

address _rolesRegistry = IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).nftRolesRegistryOf(
_offer.tokenAddress
);
require(
_rolesRegistry.supportsERC165InterfaceUnchecked(type(IERC7432VaultExtension).interfaceId),
'NftRentalMarketplace: roles registry does not support IERC7432VaultExtension'
);
IERC7432VaultExtension(_rolesRegistry).withdraw(_offer.tokenAddress, _offer.tokenId);
}

/**
* @notice Cancels a rental offer.
* @dev Internal function to cancel a rental offer.
* @param _offer The rental offer struct. It should be the same as the one used to create the offer.
*/
function _cancelRentalOffer(RentalOffer calldata _offer) internal {
bytes32 _offerHash = LibNftRentalMarketplace.hashRentalOffer(_offer);
LibNftRentalMarketplace.validateCancelRentalOfferParams(
isCreated[_offerHash],
Expand Down
20 changes: 19 additions & 1 deletion test/NftRentalMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ describe('NftRentalMarketplace', () => {
})

describe('Cancel Rental Offer', async () => {
it('Should cancel a rental offer and releaseTokens from rolesRegistry', async () => {
it('Should cancel a rental offer', async () => {
await expect(marketplace.connect(lender).cancelRentalOffer(rentalOffer))
.to.emit(marketplace, 'RentalOfferCancelled')
.withArgs(rentalOffer.lender, rentalOffer.nonce)
Expand Down Expand Up @@ -568,6 +568,24 @@ describe('NftRentalMarketplace', () => {
)
})
})

describe('Cancel Rental Offer', async function () {
it('Should cancel a rental offer and withdraw from rolesRegistry, if rental is not active', async () => {
await expect(marketplace.connect(lender).cancelRentalOfferAndWithdraw(rentalOffer))
.to.emit(marketplace, 'RentalOfferCancelled')
.withArgs(rentalOffer.lender, rentalOffer.nonce)
.to.emit(rolesRegistry, 'Withdraw')
.withArgs(rentalOffer.lender, rentalOffer.tokenAddress, rentalOffer.tokenId)
})
it('Should NOT cancel a rental offer and withdraw from rolesRegistry, if rolesRegistry does not support IERC7432VaultExtension', async () => {
await marketplaceRoyalties
.connect(operator)
.setRolesRegistry(await mockERC721.getAddress(), AddressZero)
await expect(marketplace.connect(lender).cancelRentalOfferAndWithdraw(rentalOffer)).to.be.revertedWith(
'NftRentalMarketplace: roles registry does not support IERC7432VaultExtension',
)
})
})
})
})
})
Expand Down

0 comments on commit 786d655

Please sign in to comment.