Skip to content

Commit

Permalink
ON-787: fix diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Apr 9, 2024
1 parent 2043bdc commit c6f6c54
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 610 deletions.
107 changes: 5 additions & 102 deletions contracts/OriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/I
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 { LibOriumSftMarketplace, RentalOffer, CommitAndGrantRoleParams } from "./libraries/LibOriumSftMarketplace.sol";
import { IOriumMarketplaceRoyalties } from "./interfaces/IOriumMarketplaceRoyalties.sol";

/**
Expand Down Expand Up @@ -54,7 +54,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
* @param feeTokenAddress The address of the ERC20 token for rental fees
* @param feeAmountPerSecond The amount of fee per second
* @param deadline The deadline until when the rental offer is valid
* @param minDuration The minimum duration of the rental
* @param roles The array of roles to be assigned to the borrower
* @param rolesData The array of data for each role
*/
Expand All @@ -69,7 +68,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
address feeTokenAddress,
uint256 feeAmountPerSecond,
uint256 deadline,
uint64 minDuration,
bytes32[] roles,
bytes[] rolesData
);
Expand Down Expand Up @@ -120,29 +118,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
* @dev To optimize for gas, only the offer hash is stored on-chain
* @param _offer The rental offer struct.
*/
function createRentalOffer(RentalOfferLegacy calldata _offer) external whenNotPaused {
RentalOffer memory _parsedOffer = RentalOffer({
nonce: _offer.nonce,
tokenAddress: _offer.tokenAddress,
tokenId: _offer.tokenId,
tokenAmount: _offer.tokenAmount,
commitmentId: _offer.commitmentId,
lender: _offer.lender,
borrower: _offer.borrower,
feeTokenAddress: _offer.feeTokenAddress,
feeAmountPerSecond: _offer.feeAmountPerSecond,
deadline: _offer.deadline,
minDuration: 0,
roles: _offer.roles,
rolesData: _offer.rolesData
});
_createRentalOffer(_parsedOffer);
}

function createRentalOffer(RentalOffer calldata _offer) external whenNotPaused {
_createRentalOffer(_offer);
}
function _createRentalOffer(RentalOffer memory _offer) internal {
function createRentalOffer(RentalOffer memory _offer) external whenNotPaused {
address _rolesRegistryAddress = IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(
_offer.tokenAddress
);
Expand Down Expand Up @@ -172,7 +148,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
_offer.feeTokenAddress,
_offer.feeAmountPerSecond,
_offer.deadline,
_offer.minDuration,
_offer.roles,
_offer.rolesData
);
Expand All @@ -184,40 +159,13 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
* @param _offer The rental offer struct. It should be the same as the one used to create the offer.
* @param _duration The duration of the rental.
*/

function acceptReentalOffer(RentalOffer calldata _offer, uint64 _duration) external whenNotPaused {
_acceptRentalOffer(_offer, _duration);
}

function acceptRentalOffer(RentalOfferLegacy calldata _offer, uint64 _duration) external whenNotPaused {
RentalOffer memory _parsedOffer = RentalOffer({
nonce: _offer.nonce,
tokenAddress: _offer.tokenAddress,
tokenId: _offer.tokenId,
tokenAmount: _offer.tokenAmount,
commitmentId: _offer.commitmentId,
lender: _offer.lender,
borrower: _offer.borrower,
feeTokenAddress: _offer.feeTokenAddress,
feeAmountPerSecond: _offer.feeAmountPerSecond,
deadline: _offer.deadline,
minDuration: 0,
roles: _offer.roles,
rolesData: _offer.rolesData
});
_acceptRentalOffer(_parsedOffer, _duration);
}
function _acceptRentalOffer(RentalOffer memory _offer, uint64 _duration) internal {
function acceptRentalOffer(RentalOffer memory _offer, uint64 _duration) external whenNotPaused {
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);
require(isCreated[_offerHash], "OriumSftMarketplace: Offer not created");
require(
rentals[_offerHash].expirationDate <= block.timestamp,
"OriumSftMarketplace: This offer has an ongoing rental"
);
require(
_duration >= _offer.minDuration,
"OriumSftMarketplace: Duration is less than the offer minimum duration"
);

uint64 _expirationDate = uint64(block.timestamp + _duration);
require(
Expand Down Expand Up @@ -255,29 +203,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
* @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 cancelRentalOffer(RentalOffer calldata _offer) external whenNotPaused {
_cancelRentalOffer(_offer);
}
function cancelRentalOffer(RentalOfferLegacy calldata _offer) external whenNotPaused {
RentalOffer memory _parsedOffer = RentalOffer({
nonce: _offer.nonce,
tokenAddress: _offer.tokenAddress,
tokenId: _offer.tokenId,
tokenAmount: _offer.tokenAmount,
commitmentId: _offer.commitmentId,
lender: _offer.lender,
borrower: _offer.borrower,
feeTokenAddress: _offer.feeTokenAddress,
feeAmountPerSecond: _offer.feeAmountPerSecond,
deadline: _offer.deadline,
minDuration: 0,
roles: _offer.roles,
rolesData: _offer.rolesData
});
_cancelRentalOffer(_parsedOffer);
}
function _cancelRentalOffer(RentalOffer memory _offer) internal {
function cancelRentalOffer(RentalOffer memory _offer) external whenNotPaused {
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");
Expand Down Expand Up @@ -307,30 +233,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
* @param _offer The rental offer struct. It should be the same as the one used to create the offer.
*/

function endRental(RentalOffer calldata _offer) external whenNotPaused {
_endRental(_offer);
}

function endRental(RentalOfferLegacy calldata _offer) external whenNotPaused {
RentalOffer memory _parsedOffer = RentalOffer({
nonce: _offer.nonce,
tokenAddress: _offer.tokenAddress,
tokenId: _offer.tokenId,
tokenAmount: _offer.tokenAmount,
commitmentId: _offer.commitmentId,
lender: _offer.lender,
borrower: _offer.borrower,
feeTokenAddress: _offer.feeTokenAddress,
feeAmountPerSecond: _offer.feeAmountPerSecond,
deadline: _offer.deadline,
minDuration: 0,
roles: _offer.roles,
rolesData: _offer.rolesData
});
_endRental(_parsedOffer);
}

function _endRental(RentalOffer memory _offer) internal {
function endRental(RentalOffer memory _offer) external whenNotPaused {
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);

require(isCreated[_offerHash], "OriumSftMarketplace: Offer not created");
Expand Down
22 changes: 1 addition & 21 deletions contracts/libraries/LibOriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,6 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @dev Rental offer info.
struct RentalOffer {
address lender;
address borrower;
address tokenAddress;
uint256 tokenId;
uint256 tokenAmount;
address feeTokenAddress;
uint256 feeAmountPerSecond;
uint256 nonce;
uint256 commitmentId;
uint64 deadline;
uint64 minDuration;
bytes32[] roles;
bytes[] rolesData;
}

/// @dev Rental offer info.
struct RentalOfferLegacy {
address lender;
address borrower;
address tokenAddress;
Expand Down Expand Up @@ -65,8 +48,7 @@ library LibOriumSftMarketplace {
function hashRentalOffer(RentalOffer memory _offer) external pure returns (bytes32) {
return
keccak256(
_offer.minDuration == 0
? abi.encode(
abi.encode(
_offer.lender,
_offer.borrower,
_offer.tokenAddress,
Expand All @@ -80,7 +62,6 @@ library LibOriumSftMarketplace {
_offer.roles,
_offer.rolesData
)
: abi.encode(_offer)
);
}

Expand Down Expand Up @@ -146,7 +127,6 @@ library LibOriumSftMarketplace {
_offer.borrower != address(0) || _offer.feeAmountPerSecond > 0,
"OriumSftMarketplace: feeAmountPerSecond should be greater than 0"
);
require(_offer.minDuration <= _offer.deadline - block.timestamp, "OriumSftMarketplace: minDuration is invalid");
}

/**
Expand Down
Loading

0 comments on commit c6f6c54

Please sign in to comment.