Skip to content

Commit

Permalink
fix: struct logic lib to check grantOf and ownerOf
Browse files Browse the repository at this point in the history
  • Loading branch information
EDUARDO MELO DE SIQUEIRA authored and EDUARDO MELO DE SIQUEIRA committed Jul 12, 2024
1 parent eb5cd2e commit b2ef8a9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 267 deletions.
70 changes: 6 additions & 64 deletions contracts/OriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
_offer.lender,
_offer.tokenId,
_offer.tokenAmount
);
);
}

nonceDeadline[msg.sender][_offer.nonce] = _offer.deadline;
Expand Down Expand Up @@ -224,7 +224,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(_offer.tokenAddress)
);

if(_offer.tokenAddress == aavegotchiWearableAddress) {
if (_offer.tokenAddress == aavegotchiWearableAddress) {
_rolesRegistryLegacy.releaseTokens(_offer.commitmentId);
} else {
_rolesRegistry.unlockTokens(_offer.commitmentId);
Expand Down Expand Up @@ -283,7 +283,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
address _rolesRegistryAddress = IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(
_params[i].tokenAddress
);

uint256 _validCommitmentId = _params[i].commitmentId;
if (_params[i].commitmentId == 0) {
_validCommitmentId = _commitOrLockTokens(
Expand All @@ -306,9 +306,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
);
}

_grantRole(
_params[i].tokenAddress,
_rolesRegistryAddress,
IERC7589(_rolesRegistryAddress).grantRole(
_validCommitmentId,
_params[i].role,
_params[i].grantee,
Expand Down Expand Up @@ -342,7 +340,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
);
}


/** ######### Internals ########### **/

/**
Expand All @@ -361,61 +358,9 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
uint256 _tokenAmount
) internal returns (uint256) {
if (_tokenAddress == aavegotchiWearableAddress) {
return IERC7589Legacy(_rolesRegistryAddress).commitTokens(
_lender,
_tokenAddress,
_tokenId,
_tokenAmount
);
} else {
return IERC7589(_rolesRegistryAddress).lockTokens(
_lender,
_tokenAddress,
_tokenId,
_tokenAmount
);
}
}

/**
* @dev Validates if is wearable address to use current or legacy grantRole.
* @param _tokenAddress The address of the contract of the SFT to rent.
* @param _rolesRegistryAddress The rental offer struct.
* @param _commitmentId The commitmentId of the SFT to rent.
* @param _role role to be assigned to the borrower.
* @param _grantee recipient.
* @param _expirationDate expiration date of role.
* @param _revocable role is recovable.
* @param _data data struct to send others informations.
*/
function _grantRole(
address _tokenAddress,
address _rolesRegistryAddress,
uint256 _commitmentId,
bytes32 _role,
address _grantee,
uint64 _expirationDate,
bool _revocable,
bytes memory _data
) internal {
if (_tokenAddress == aavegotchiWearableAddress) {
IERC7589Legacy(_rolesRegistryAddress).grantRole(
_commitmentId,
_role,
_grantee,
_expirationDate,
_revocable,
_data
);
return IERC7589Legacy(_rolesRegistryAddress).commitTokens(_lender, _tokenAddress, _tokenId, _tokenAmount);
} else {
IERC7589(_rolesRegistryAddress).grantRole(
_commitmentId,
_role,
_grantee,
_expirationDate,
_revocable,
_data
);
return IERC7589(_rolesRegistryAddress).lockTokens(_lender, _tokenAddress, _tokenId, _tokenAmount);
}
}

Expand Down Expand Up @@ -523,8 +468,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
emit RentalOfferCancelled(_offer.lender, _offer.nonce);
}



/** ============================ Core Functions ================================== **/

/** ######### Setters ########### **/
Expand Down Expand Up @@ -553,6 +496,5 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
function setOriumMarketplaceRoyalties(address _oriumMarketplaceRoyalties) external onlyOwner {
oriumMarketplaceRoyalties = _oriumMarketplaceRoyalties;
}

/** ######### Getters ########### **/
}
64 changes: 46 additions & 18 deletions contracts/libraries/LibOriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,39 @@ library LibOriumSftMarketplace {
address _rolesRegistryAddress
) external view {
IERC7589 _rolesRegistry = IERC7589(_rolesRegistryAddress);
require(
_rolesRegistry.tokenAmountOf(_commitmentId) == _tokenAmount,
"OriumSftMarketplace: tokenAmount provided does not match commitment's tokenAmount"
);
require(
_rolesRegistry.ownerOf(_commitmentId) == _expectedGrantor,
'OriumSftMarketplace: expected grantor does not match the grantor of the commitmentId'
);
require(
_rolesRegistry.tokenAddressOf(_commitmentId) == _tokenAddress,
"OriumSftMarketplace: tokenAddress provided does not match commitment's tokenAddress"
);
require(
_rolesRegistry.tokenIdOf(_commitmentId) == _tokenId,
"OriumSftMarketplace: tokenId provided does not match commitment's tokenId"
);
IERC7589Legacy _rolesRegistryLegacy = IERC7589Legacy(_rolesRegistryAddress);

if (_tokenAddress == aavegotchiWearableAddress) {
require(
_rolesRegistryLegacy.grantorOf(_commitmentId) == _expectedGrantor,
'OriumSftMarketplace: expected grantor does not match the grantor of the commitmentId'
);
require(
_rolesRegistryLegacy.tokenAmountOf(_commitmentId) == _tokenAmount,
"OriumSftMarketplace: tokenAmount provided does not match commitment's tokenAmount"
);
require(
_rolesRegistryLegacy.tokenIdOf(_commitmentId) == _tokenId,
"OriumSftMarketplace: tokenId provided does not match commitment's tokenId"
);
} else {
require(
_rolesRegistry.tokenAmountOf(_commitmentId) == _tokenAmount,
"OriumSftMarketplace: tokenAmount provided does not match commitment's tokenAmount"
);
require(
_rolesRegistry.ownerOf(_commitmentId) == _expectedGrantor,
'OriumSftMarketplace: expected grantor does not match the grantor of the commitmentId'
);
require(
_rolesRegistry.tokenAddressOf(_commitmentId) == _tokenAddress,
"OriumSftMarketplace: tokenAddress provided does not match commitment's tokenAddress"
);
require(
_rolesRegistry.tokenIdOf(_commitmentId) == _tokenId,
"OriumSftMarketplace: tokenId provided does not match commitment's tokenId"
);
}
}

/**
Expand Down Expand Up @@ -249,17 +266,28 @@ library LibOriumSftMarketplace {
IERC7589Legacy(_rolesRegistryAddress).grantorOf(_commitmentIds[i]) == msg.sender,
"OriumSftMarketplace: sender is not the commitment's grantor or grantee Legacy"
);
require(
IERC7589Legacy(_rolesRegistryAddress).roleExpirationDate(
_commitmentIds[i],
_roles[i],
_grantees[i]
) > block.timestamp,
'OriumSftMarketplace: role is expired'
);
require(
IERC7589Legacy(_rolesRegistryAddress).isRoleRevocable(_commitmentIds[i], _roles[i], _grantees[i]),
'OriumSftMarketplace: role is not revocable Legacy'
);
IERC7589Legacy(_rolesRegistryAddress).revokeRole(_commitmentIds[i], _roles[i], _grantees[i]);
} else {
require(
msg.sender == _grantees[i] ||
IERC7589(_rolesRegistryAddress).ownerOf(_commitmentIds[i]) == msg.sender,
"OriumSftMarketplace: sender is not the commitment's grantor or grantee"
);
require(
IERC7589(_rolesRegistryAddress).roleExpirationDate(_commitmentIds[i], _roles[i]) > block.timestamp,
'OriumSftMarketplace: role is expired'
);
require(
IERC7589(_rolesRegistryAddress).isRoleRevocable(_commitmentIds[i], _roles[i]),
'OriumSftMarketplace: role is not revocable'
Expand All @@ -268,8 +296,8 @@ library LibOriumSftMarketplace {
IERC7589(_rolesRegistryAddress).tokenAddressOf(_commitmentIds[i]) == _tokenAddresses[i],
"OriumSftMarketplace: tokenAddress provided does not match commitment's tokenAddress"
);
IERC7589(_rolesRegistryAddress).revokeRole(_commitmentIds[i], _roles[i], _grantees[i]);
}
IERC7589(_rolesRegistryAddress).revokeRole(_commitmentIds[i], _roles[i], _grantees[i]);
}
}

Expand Down
Loading

0 comments on commit b2ef8a9

Please sign in to comment.