From 6c9b61fe461e90939ba39d58a8c317b079ad4f25 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Fri, 10 May 2024 10:48:29 -0300 Subject: [PATCH] prettier --- contracts/OriumSftMarketplace.sol | 60 +++++++++++++++++++------------ 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/contracts/OriumSftMarketplace.sol b/contracts/OriumSftMarketplace.sol index 623d0ba..d8daaf3 100644 --- a/contracts/OriumSftMarketplace.sol +++ b/contracts/OriumSftMarketplace.sol @@ -2,13 +2,13 @@ pragma solidity 0.8.9; -import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; -import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; -import { IERC1155 } from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; -import { IERC7589 } from "./interfaces/IERC7589.sol"; -import { LibOriumSftMarketplace, RentalOffer, RentalOfferLegacy, CommitAndGrantRoleParams } from "./libraries/LibOriumSftMarketplace.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'; +import { PausableUpgradeable } from '@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol'; +import { IERC1155 } from '@openzeppelin/contracts/token/ERC1155/IERC1155.sol'; +import { IERC7589 } from './interfaces/IERC7589.sol'; +import { LibOriumSftMarketplace, RentalOffer, RentalOfferLegacy, CommitAndGrantRoleParams } from './libraries/LibOriumSftMarketplace.sol'; +import { IOriumMarketplaceRoyalties } from './interfaces/IOriumMarketplaceRoyalties.sol'; /** * @title Orium Marketplace - Marketplace for renting SFTs @@ -166,7 +166,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra rolesData: _offer.rolesData }); uint256 _commitmentId = _createRentalOffer(_parsedOffer); - + emit RentalOfferCreated( _offer.nonce, _offer.tokenAddress, @@ -202,6 +202,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra _offer.rolesData ); } + function _createRentalOffer(RentalOffer memory _offer) internal returns (uint256) { address _rolesRegistryAddress = IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf( _offer.tokenAddress @@ -253,6 +254,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra }); _acceptRentalOffer(_parsedOffer, _duration); } + function _acceptRentalOffer(RentalOffer memory _offer, uint64 _duration) internal { bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer); uint64 _expirationDate = uint64(block.timestamp + _duration); @@ -295,6 +297,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra function cancelRentalOffer(RentalOffer calldata _offer) external whenNotPaused { _cancelRentalOffer(_offer); } + function cancelRentalOffer(RentalOfferLegacy calldata _offer) external whenNotPaused { RentalOffer memory _parsedOffer = RentalOffer({ nonce: _offer.nonce, @@ -313,13 +316,14 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra }); _cancelRentalOffer(_parsedOffer); } + function _cancelRentalOffer(RentalOffer memory _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(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" + 'OriumSftMarketplace: Nonce expired or not used yet' ); IERC7589 _rolesRegistry = IERC7589( @@ -328,7 +332,10 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra // if There are no active rentals, release tokens (else, tokens will be released via `batchReleaseTokens`) // this is ok for single-role tokens, but tokens with multiple roles might revert if another non-revocable role exists // if token amount is 0, it means that the tokens were already released, trying to release it again would revert the transaction - if (rentals[_offerHash].expirationDate < block.timestamp && _rolesRegistry.tokenAmountOf(_offer.commitmentId) > 0) { + if ( + rentals[_offerHash].expirationDate < block.timestamp && + _rolesRegistry.tokenAmountOf(_offer.commitmentId) > 0 + ) { _rolesRegistry.releaseTokens(_offer.commitmentId); } @@ -369,11 +376,11 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra function _endRental(RentalOffer memory _offer) internal { bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer); - require(isCreated[_offerHash], "OriumSftMarketplace: Offer not created"); - require(msg.sender == rentals[_offerHash].borrower, "OriumSftMarketplace: Only borrower can end a rental"); + require(isCreated[_offerHash], 'OriumSftMarketplace: Offer not created'); + require(msg.sender == rentals[_offerHash].borrower, 'OriumSftMarketplace: Only borrower can end a rental'); require( rentals[_offerHash].expirationDate > block.timestamp, - "OriumSftMarketplace: There are no active Rentals" + 'OriumSftMarketplace: There are no active Rentals' ); IERC7589 _rolesRegistry = IERC7589( @@ -460,7 +467,13 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra address[] memory _grantees, address[] memory _tokenAddresses ) external whenNotPaused { - LibOriumSftMarketplace.batchRevokeRole(_commitmentIds, _roles, _grantees, _tokenAddresses, oriumMarketplaceRoyalties); + LibOriumSftMarketplace.batchRevokeRole( + _commitmentIds, + _roles, + _grantees, + _tokenAddresses, + oriumMarketplaceRoyalties + ); } /** ######### Internals ########### **/ @@ -470,16 +483,19 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra */ function _validateCreateRentalOffer(RentalOffer memory _offer, address _rolesRegistryAddress) internal view { require( - IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).isTrustedFeeTokenAddressForToken(_offer.tokenAddress, _offer.feeTokenAddress), - "OriumSftMarketplace: tokenAddress is not trusted" + IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).isTrustedFeeTokenAddressForToken( + _offer.tokenAddress, + _offer.feeTokenAddress + ), + 'OriumSftMarketplace: tokenAddress is not trusted' ); require( _offer.deadline <= block.timestamp + IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).maxDuration() && _offer.deadline > block.timestamp, - "OriumSftMarketplace: Invalid deadline" + 'OriumSftMarketplace: Invalid deadline' ); LibOriumSftMarketplace.validateOffer(_offer); - require(nonceDeadline[_offer.lender][_offer.nonce] == 0, "OriumSftMarketplace: nonce already used"); + require(nonceDeadline[_offer.lender][_offer.nonce] == 0, 'OriumSftMarketplace: nonce already used'); if (_offer.commitmentId != 0) { uint256 _commitmentNonce = commitmentIdToNonce[_rolesRegistryAddress][_offer.commitmentId]; @@ -487,7 +503,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra if (_commitmentNonce != 0) { require( nonceDeadline[_offer.lender][_commitmentNonce] < block.timestamp, - "OriumSftMarketplace: commitmentId is in an active rental offer" + 'OriumSftMarketplace: commitmentId is in an active rental offer' ); } @@ -502,7 +518,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra } else { require( IERC1155(_offer.tokenAddress).balanceOf(msg.sender, _offer.tokenId) >= _offer.tokenAmount, - "OriumSftMarketplace: caller does not have enough balance for the token" + 'OriumSftMarketplace: caller does not have enough balance for the token' ); } }