Skip to content

Commit

Permalink
ON-823: Remove legacy functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed May 10, 2024
1 parent 6c9b61f commit 9cd007d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 172 deletions.
173 changes: 17 additions & 156 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 @@ -74,35 +74,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
bytes[] rolesData
);

/**
* @param nonce The nonce of the rental offer
* @param tokenAddress The address of the contract of the SFT to rent
* @param tokenId The tokenId of the SFT to rent
* @param tokenAmount The amount of SFT to rent
* @param commitmentId The commitmentId of the SFT to rent
* @param lender The address of the user lending the SFT
* @param borrower The address of the user renting the SFT
* @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 roles The array of roles to be assigned to the borrower
* @param rolesData The array of data for each role
*/
event RentalOfferCreated(
uint256 indexed nonce,
address indexed tokenAddress,
uint256 indexed tokenId,
uint256 tokenAmount,
uint256 commitmentId,
address lender,
address borrower,
address feeTokenAddress,
uint256 feeAmountPerSecond,
uint256 deadline,
bytes32[] roles,
bytes[] rolesData
);

/**
* @param lender The address of the lender
* @param nonce The nonce of the rental offer
Expand Down Expand Up @@ -149,61 +120,8 @@ 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
});
uint256 _commitmentId = _createRentalOffer(_parsedOffer);

emit RentalOfferCreated(
_offer.nonce,
_offer.tokenAddress,
_offer.tokenId,
_offer.tokenAmount,
_commitmentId,
_offer.lender,
_offer.borrower,
_offer.feeTokenAddress,
_offer.feeAmountPerSecond,
_offer.deadline,
_offer.roles,
_offer.rolesData
);
}

function createRentalOffer(RentalOffer calldata _offer) external whenNotPaused {
uint256 _commitmentId = _createRentalOffer(_offer);

emit RentalOfferCreated(
_offer.nonce,
_offer.tokenAddress,
_offer.tokenId,
_offer.tokenAmount,
_commitmentId,
_offer.lender,
_offer.borrower,
_offer.feeTokenAddress,
_offer.feeAmountPerSecond,
_offer.deadline,
_offer.minDuration,
_offer.roles,
_offer.rolesData
);
}

function _createRentalOffer(RentalOffer memory _offer) internal returns (uint256) {
function createRentalOffer(RentalOffer memory _offer) external whenNotPaused {
address _rolesRegistryAddress = IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(
_offer.tokenAddress
);
Expand All @@ -222,7 +140,21 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
isCreated[LibOriumSftMarketplace.hashRentalOffer(_offer)] = true;
commitmentIdToNonce[_rolesRegistryAddress][_offer.commitmentId] = _offer.nonce;

return _offer.commitmentId;
emit RentalOfferCreated(
_offer.nonce,
_offer.tokenAddress,
_offer.tokenId,
_offer.tokenAmount,
_offer.commitmentId,
_offer.lender,
_offer.borrower,
_offer.feeTokenAddress,
_offer.feeAmountPerSecond,
_offer.deadline,
_offer.minDuration,
_offer.roles,
_offer.rolesData
);
}

/**
Expand All @@ -233,29 +165,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
*/

function acceptRentalOffer(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 {
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);
uint64 _expirationDate = uint64(block.timestamp + _duration);
LibOriumSftMarketplace.validateAcceptRentalOffer(
Expand Down Expand Up @@ -293,31 +202,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 {
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 @@ -349,31 +234,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra
* @dev Borrower needs to approve marketplace to revoke the roles.
* @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 {
bytes32 _offerHash = LibOriumSftMarketplace.hashRentalOffer(_offer);

require(isCreated[_offerHash], 'OriumSftMarketplace: Offer not created');
Expand Down
16 changes: 0 additions & 16 deletions contracts/libraries/LibOriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,6 @@ struct RentalOffer {
bytes[] rolesData;
}

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

struct CommitAndGrantRoleParams {
uint256 commitmentId;
address tokenAddress;
Expand Down

0 comments on commit 9cd007d

Please sign in to comment.