Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed May 10, 2024
1 parent 8c36c4a commit 6c9b61f
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions contracts/OriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -166,7 +166,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
rolesData: _offer.rolesData
});
uint256 _commitmentId = _createRentalOffer(_parsedOffer);

emit RentalOfferCreated(
_offer.nonce,
_offer.tokenAddress,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 ########### **/
Expand All @@ -470,24 +483,27 @@ 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];

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'
);
}

Expand All @@ -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'
);
}
}
Expand Down

0 comments on commit 6c9b61f

Please sign in to comment.