Skip to content

Commit

Permalink
ON-872: delist rental offer
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed May 20, 2024
1 parent 21645af commit 594b381
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion contracts/OriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 ########### **/
Expand Down

0 comments on commit 594b381

Please sign in to comment.