Skip to content

Commit

Permalink
ON-813: PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Apr 22, 2024
1 parent d85c4da commit b5ae053
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions contracts/libraries/LibNftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ library LibNftRentalMarketplace {
* @param _feeTokenAddress The fee token address.
* @param _marketplaceTreasuryAddress The marketplace treasury address.
* @param _lenderAddress The lender address.
* @param _royaltiesAddress The Orium marketplace royalties contract address.
* @param _oriumRoyaltiesAddress The Orium marketplace royalties contract address.
* @param _tokenAddress The token address.
* @param _feeAmountPerSecond The fee amount per second.
* @param _duration The duration of the rental.
Expand All @@ -115,40 +115,50 @@ library LibNftRentalMarketplace {
address _feeTokenAddress,
address _marketplaceTreasuryAddress,
address _lenderAddress,
address _royaltiesAddress,
address _oriumRoyaltiesAddress,
address _tokenAddress,
uint256 _feeAmountPerSecond,
uint64 _duration
) external {
uint256 _totalAmount = _feeAmountPerSecond * _duration;
if (_totalAmount == 0) return;

IOriumMarketplaceRoyalties _royalties = IOriumMarketplaceRoyalties(_royaltiesAddress);
IOriumMarketplaceRoyalties _royalties = IOriumMarketplaceRoyalties(_oriumRoyaltiesAddress);
uint256 _marketplaceFeePercentageInWei = _royalties.marketplaceFeeOf(_tokenAddress);
IOriumMarketplaceRoyalties.RoyaltyInfo memory _royaltyInfo = _royalties.royaltyInfoOf(_tokenAddress);

uint256 _marketplaceAmount = getAmountFromPercentage(_totalAmount, _marketplaceFeePercentageInWei);
uint256 _royaltyAmount = getAmountFromPercentage(_totalAmount, _royaltyInfo.royaltyPercentageInWei);
uint256 _lenderAmount = _totalAmount - _royaltyAmount - _marketplaceAmount;

_transferAmount(_feeTokenAddress, msg.sender, _marketplaceTreasuryAddress, _marketplaceAmount);
_transferAmount(_feeTokenAddress, msg.sender, _royaltyInfo.treasury, _royaltyAmount);
_transferAmount(_feeTokenAddress, msg.sender, _lenderAddress, _lenderAmount);
_transferAmount(_feeTokenAddress, _marketplaceTreasuryAddress, _marketplaceAmount);
_transferAmount(_feeTokenAddress, _royaltyInfo.treasury, _royaltyAmount);
_transferAmount(_feeTokenAddress, _lenderAddress, _lenderAmount);
}

/**
* @notice Transfers an amount to a receipient.
* @dev This function is used to make an ERC20 transfer.
* @param _tokenAddress The token address.
* @param _from The sender address.
* @param _to The recipient address.
* @param _amount The amount to transfer.
*/
function _transferAmount(address _tokenAddress, address _from, address _to, uint256 _amount) internal {
function _transferAmount(address _tokenAddress, address _to, uint256 _amount) internal {
if (_amount == 0) return;
require(IERC20(_tokenAddress).transferFrom(_from, _to, _amount), 'NftRentalMarketplace: Transfer failed');
require(IERC20(_tokenAddress).transferFrom(msg.sender, _to, _amount), 'NftRentalMarketplace: Transfer failed');
}

/**
* @notice Validates the accept rental offer.
* @dev This function is used to validate the accept rental offer params.
* @param _borrower The borrower address
* @param _minDuration The minimum duration of the rental
* @param _isCreated The boolean value to check if the offer is created
* @param _previousRentalExpirationDate The expiration date of the previous rental
* @param _duration The duration of the rental
* @param _nonceDeadline The deadline of the nonce
* @param _expirationDate The expiration date of the rental
*/
function validateAcceptRentalOfferParams(
address _borrower,
uint64 _minDuration,
Expand All @@ -175,7 +185,7 @@ library LibNftRentalMarketplace {
}

/**
* @notice grants roles for the same NFT.
* @notice Grants multiple roles to the same NFT.
* @dev This function is used to batch grant roles for the same NFT.
* @param _oriumMarketplaceRoyalties The Orium marketplace royalties contract address.
* @param _tokenAddress The token address.
Expand Down

0 comments on commit b5ae053

Please sign in to comment.