diff --git a/contracts/OriumSftMarketplace.sol b/contracts/OriumSftMarketplace.sol index a7de715..5fdabdc 100644 --- a/contracts/OriumSftMarketplace.sol +++ b/contracts/OriumSftMarketplace.sol @@ -198,7 +198,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra emit RentalStarted(_offer.lender, _offer.nonce, msg.sender, _expirationDate); } - /** + /** * @notice Cancels a rental offer. * @param _offer The rental offer struct. It should be the same as the one used to create the offer. */ @@ -228,6 +228,26 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra emit RentalOfferCancelled(_offer.lender, _offer.nonce); } + /** + * @notice Cancels a rental offer. + * @param _offer The rental offer struct. It should be the same as the one used to create the offer. + */ + function delistRentalOffer(RentalOffer calldata _offer) external whenNotPaused { + _delistRentalOffer(_offer); + } + + /** + * @notice Cancels a rental offer. + * @param _offer The rental offer struct. It should be the same as the one used to create the offer. + */ + function delistRentalOfferAndWithdraw(RentalOffer calldata _offer) external whenNotPaused { + _delistRentalOffer(_offer); + IERC7589 _rolesRegistry = IERC7589( + IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(_offer.tokenAddress) + ); + _rolesRegistry.releaseTokens(_offer.commitmentId); + } + /** * @notice Ends the rental prematurely. * @dev Can only be called by the borrower. @@ -426,6 +446,22 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra ); } + /** + * @dev Cancels a rental offer. + * @param _offer The rental offer struct. + */ + function _delistRentalOffer(RentalOffer calldata _offer) internal { + bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer); + require(isCreated[_offerHash], 'OriumSftMarketplace: Offer not created'); + require(msg.sender == _offer.lender, 'OriumSftMarketplace: Only lender can cancel a rental offer'); + require( + nonceDeadline[_offer.lender][_offer.nonce] > block.timestamp, + 'OriumSftMarketplace: Nonce expired or not used yet' + ); + nonceDeadline[msg.sender][_offer.nonce] = uint64(block.timestamp); + emit RentalOfferCancelled(_offer.lender, _offer.nonce); + } + /** ============================ Core Functions ================================== **/ /** ######### Setters ########### **/