Skip to content

Commit

Permalink
ON-479: PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Sep 29, 2023
1 parent bfb075f commit 47f00ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
17 changes: 8 additions & 9 deletions contracts/OriumMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
/// @dev tokenAddress => royaltyInfo
mapping(address => RoyaltyInfo) public royaltyInfo;

/// @dev hashedOffer => deadline
mapping(bytes32 => uint64) public offerDeadline;
/// @dev hashedOffer => bool
mapping(bytes32 => bool) public isPresigned;

/// @dev nonce => deadline
mapping(uint256 => uint64) public nonceDeadline;
Expand Down Expand Up @@ -179,12 +179,11 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
function createRentalOffer(
RentalOffer calldata _offer
) external onlyTokenOwner(_offer.tokenAddress, _offer.tokenId) {
bytes32 _offerHash = hashRentalOffer(_offer);

_validateCreateRentalOffer(_offer, _offerHash);
_validateCreateRentalOffer(_offer);

bytes32 _offerHash = hashRentalOffer(_offer);
nonceDeadline[_offer.nonce] = _offer.deadline;
offerDeadline[_offerHash] = _offer.deadline;
isPresigned[_offerHash] = true;

emit RentalOfferCreated(
_offer.nonce,
Expand All @@ -200,7 +199,7 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
);
}

function _validateCreateRentalOffer(RentalOffer calldata _offer, bytes32 _offerHash) internal view {
function _validateCreateRentalOffer(RentalOffer calldata _offer) internal view {
require(msg.sender == _offer.lender, "OriumMarketplace: Sender and Lender mismatch");
require(_offer.roles.length > 0, "OriumMarketplace: roles should not be empty");
require(
Expand Down Expand Up @@ -255,13 +254,13 @@ contract OriumMarketplace is Initializable, OwnableUpgradeable, PausableUpgradea
*/
function _validateAcceptRentalOffer(RentalOffer calldata _offer, uint64 _expirationDate) internal view {
bytes32 _offerHash = hashRentalOffer(_offer);
require(offerDeadline[_offerHash] > block.timestamp, "OriumMarketplace: offer not created or expired");
require(isPresigned[_offerHash], "OriumMarketplace: Offer not created");
require(
address(0) == _offer.borrower || msg.sender == _offer.borrower,
"OriumMarketplace: Sender is not allowed to rent this NFT"
);
require(
offerDeadline[_offerHash] > _expirationDate,
nonceDeadline[_offer.nonce] > _expirationDate,
"OriumMarketplace: expiration date is greater than offer deadline"
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/OriumMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ describe('OriumMarketplace', () => {
await ethers.provider.send('evm_increaseTime', [timeToMove])

await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith(
'OriumMarketplace: offer not created or expired',
'OriumMarketplace: expiration date is greater than offer deadline',
)
})
it('Should NOT accept a rental offer if offer is not created', async () => {
rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}`
await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith(
'OriumMarketplace: offer not created or expired',
'OriumMarketplace: Offer not created',
)
})
it('Should NOT accept a rental offer if expiration date is higher than offer deadline', async () => {
Expand Down

0 comments on commit 47f00ab

Please sign in to comment.