From 9cd007d2bcd970f597ee5350869a0016be0f100d Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Thu, 25 Apr 2024 15:39:04 -0300 Subject: [PATCH 1/3] ON-823: Remove legacy functions --- contracts/OriumSftMarketplace.sol | 173 ++---------------- .../libraries/LibOriumSftMarketplace.sol | 16 -- 2 files changed, 17 insertions(+), 172 deletions(-) diff --git a/contracts/OriumSftMarketplace.sol b/contracts/OriumSftMarketplace.sol index d8daaf3..a7de715 100644 --- a/contracts/OriumSftMarketplace.sol +++ b/contracts/OriumSftMarketplace.sol @@ -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'; /** @@ -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 @@ -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 ); @@ -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 + ); } /** @@ -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( @@ -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'); @@ -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'); diff --git a/contracts/libraries/LibOriumSftMarketplace.sol b/contracts/libraries/LibOriumSftMarketplace.sol index 3dfd7a7..9acc682 100644 --- a/contracts/libraries/LibOriumSftMarketplace.sol +++ b/contracts/libraries/LibOriumSftMarketplace.sol @@ -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; From 6793a694b29d481428a6a3a30fb020d96e69bb00 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 14 May 2024 11:37:44 -0300 Subject: [PATCH 2/3] ON-823: Update Tests --- test/OriumSftMarketplace.test.ts | 625 ++++++++----------------------- 1 file changed, 147 insertions(+), 478 deletions(-) diff --git a/test/OriumSftMarketplace.test.ts b/test/OriumSftMarketplace.test.ts index 081b87c..2e30866 100644 --- a/test/OriumSftMarketplace.test.ts +++ b/test/OriumSftMarketplace.test.ts @@ -121,17 +121,8 @@ describe('OriumSftMarketplace', () => { describe('Create Rental Offer', async () => { describe("When commitmentId doesn't exist", async () => { it('Should create a rental offer', async () => { - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) - .to.emit( - marketplace, - 'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])', - ) + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)) + .to.emit(marketplace, 'RentalOfferCreated') .withArgs( rentalOffer.nonce, rentalOffer.tokenAddress, @@ -163,17 +154,8 @@ describe('OriumSftMarketplace', () => { .connect(operator) .setRolesRegistry(await mockERC1155.getAddress(), await rolesRegistry.getAddress()) await mockERC1155.setApprovalForAll(await rolesRegistry.getAddress(), true) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) - .to.emit( - marketplace, - 'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])', - ) + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)) + .to.emit(marketplace, 'RentalOfferCreated') .withArgs( rentalOffer.nonce, rentalOffer.tokenAddress, @@ -203,17 +185,8 @@ describe('OriumSftMarketplace', () => { it('Should create a rental offer with feeAmountPerSecond equal to 0 if offer is private', async function () { rentalOffer.feeAmountPerSecond = BigInt(0) rentalOffer.borrower = lender.address - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) - .to.emit( - marketplace, - 'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])', - ) + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)) + .to.emit(marketplace, 'RentalOfferCreated') .withArgs( rentalOffer.nonce, rentalOffer.tokenAddress, @@ -241,195 +214,114 @@ describe('OriumSftMarketplace', () => { .withArgs(lender.address, 1, await mockERC1155.getAddress(), tokenId, tokenAmount) }) it('Should NOT create a rental offer if caller is not the lender', async () => { - await expect( - marketplace - .connect(notOperator) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Sender and Lender mismatch') + await expect(marketplace.connect(notOperator).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Sender and Lender mismatch', + ) }) it("Should NOT create a rental offer if lender is not the caller's address", async () => { rentalOffer.lender = creator.address - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Sender and Lender mismatch') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Sender and Lender mismatch', + ) }) it("Should NOT create a rental offer if roles and rolesData don't have the same length", async () => { rentalOffer.roles = [`0x${randomBytes(32).toString('hex')}`] rentalOffer.rolesData = [`0x${randomBytes(32).toString('hex')}`, `0x${randomBytes(32).toString('hex')}`] - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: roles and rolesData should have the same length') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: roles and rolesData should have the same length', + ) }) it('Should NOT create a rental offer if deadline is greater than maxDeadline', async () => { rentalOffer.deadline = maxDeadline + 1 - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Invalid deadline') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Invalid deadline', + ) }) it("Should NOT create a rental offer if deadline is less than block's timestamp", async () => { rentalOffer.deadline = Number((await ethers.provider.getBlock('latest'))?.timestamp) - 1 - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Invalid deadline') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Invalid deadline', + ) }) it('Should NOT create the same rental offer twice', async () => { - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: nonce already used') + await marketplace.connect(lender).createRentalOffer(rentalOffer) + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: nonce already used', + ) }) it('Should NOT create a rental offer if roles or rolesData are empty', async () => { rentalOffer.roles = [] - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: roles should not be empty') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: roles should not be empty', + ) }) it('Should NOT create a rental offer if nonce is 0', async () => { rentalOffer.nonce = '0' - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Nonce cannot be 0') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Nonce cannot be 0', + ) }) it('Should NOT create a rental offer if tokenAmount is 0', async () => { rentalOffer.tokenAmount = BigInt(0) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: tokenAmount should be greater than 0') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: tokenAmount should be greater than 0', + ) }) it('Should NOT create a rental offer with the same commitmentId is in an active rental offer', async () => { - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer) + await marketplace.connect(lender).createRentalOffer(rentalOffer) rentalOffer.commitmentId = BigInt(1) rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: commitmentId is in an active rental offer') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: commitmentId is in an active rental offer', + ) }) it("Should NOT create a rental offer if SFT address isn't trusted", async () => { rentalOffer.tokenAddress = AddressZero - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: tokenAddress is not trusted') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: tokenAddress is not trusted', + ) }) it("Should NOT create a rental offer if fee token address isn't trusted", async () => { rentalOffer.feeTokenAddress = AddressZero - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: tokenAddress is not trusted') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: tokenAddress is not trusted', + ) }) it('Should NOT create a rental offer if contract is paused', async () => { await marketplace.connect(operator).pause() - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('Pausable: paused') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'Pausable: paused', + ) }) it('Should NOT create a rental offer if offer is public and feeAmountPerSecond is 0', async function () { rentalOffer.feeAmountPerSecond = BigInt(0) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: feeAmountPerSecond should be greater than 0') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: feeAmountPerSecond should be greater than 0', + ) }) it("Should NOT create a rental offer if lender doesn't have enough balance", async () => { const balance = await mockERC1155.balanceOf(lender.address, tokenId) await mockERC1155 .connect(lender) .safeTransferFrom(lender.address, creator.address, tokenId, balance, '0x') - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: caller does not have enough balance for the token') + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: caller does not have enough balance for the token', + ) }) }) describe('When commitmentId exists and rental offer deadline expired', async () => { beforeEach(async () => { - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer) + await marketplace.connect(lender).createRentalOffer(rentalOffer) await time.increase(ONE_DAY) rentalOffer.commitmentId = BigInt(1) rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` rentalOffer.deadline = (await time.latest()) + ONE_DAY }) it("Should create a rental offer if commitmentId already exists and it's not associated with an active rental offer", async () => { - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) - .to.emit( - marketplace, - 'RentalOfferCreated(uint256,address,uint256,uint256,uint256,address,address,address,uint256,uint256,uint64,bytes32[],bytes[])', - ) + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)) + .to.emit(marketplace, 'RentalOfferCreated') .withArgs( rentalOffer.nonce, rentalOffer.tokenAddress, @@ -455,13 +347,7 @@ describe('OriumSftMarketplace', () => { .connect(creator) .commitTokens(creator.address, rentalOffer.tokenAddress, rentalOffer.tokenId, rentalOffer.tokenAmount) rentalOffer.commitmentId = BigInt(2) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith( + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( 'OriumSftMarketplace: expected grantor does not match the grantor of the commitmentId', ) }) @@ -483,13 +369,7 @@ describe('OriumSftMarketplace', () => { .commitTokens(lender.address, await anotherMockERC1155.getAddress(), tokenId, tokenAmount) rentalOffer.tokenAddress = await anotherMockERC1155.getAddress() - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith( + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( "OriumSftMarketplace: tokenAddress provided does not match commitment's tokenAddress", ) }) @@ -501,24 +381,14 @@ describe('OriumSftMarketplace', () => { .connect(lender) .commitTokens(lender.address, rentalOffer.tokenAddress, newTokenId, rentalOffer.tokenAmount) rentalOffer.commitmentId = BigInt(2) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith("OriumSftMarketplace: tokenId provided does not match commitment's tokenId") + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( + "OriumSftMarketplace: tokenId provided does not match commitment's tokenId", + ) }) it('Should NOT create a rental offer if commitmentId token amount and offer token amount are different', async () => { rentalOffer.commitmentId = BigInt(2) rentalOffer.tokenAmount = BigInt(3) - await expect( - marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith( + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)).to.be.revertedWith( "OriumSftMarketplace: tokenAmount provided does not match commitment's tokenAmount", ) }) @@ -530,11 +400,7 @@ describe('OriumSftMarketplace', () => { let totalFeeAmount: bigint beforeEach(async () => { totalFeeAmount = rentalOffer.feeAmountPerSecond * BigInt(duration) - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer) + await marketplace.connect(lender).createRentalOffer(rentalOffer) rentalOffer.commitmentId = BigInt(1) await mockERC20.mint(borrower.address, totalFeeAmount.toString()) await mockERC20.connect(borrower).approve(await marketplace.getAddress(), totalFeeAmount.toString()) @@ -543,35 +409,19 @@ describe('OriumSftMarketplace', () => { it('Should accept a public rental offer', async () => { const blockTimestamp = (await ethers.provider.getBlock('latest'))?.timestamp const expirationDate = Number(blockTimestamp) + duration + 1 - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) }) it('Should accept a private rental offer', async () => { rentalOffer.borrower = borrower.address rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, commitmentId: BigInt(0) }) + await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) rentalOffer.commitmentId = BigInt(2) const blockTimestamp = (await ethers.provider.getBlock('latest'))?.timestamp const expirationDate = Number(blockTimestamp) + duration + 1 - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) }) @@ -581,26 +431,14 @@ describe('OriumSftMarketplace', () => { .setRolesRegistry(await mockERC1155.getAddress(), await rolesRegistry.getAddress()) const blockTimestamp = (await ethers.provider.getBlock('latest'))?.timestamp const expirationDate = Number(blockTimestamp) + duration + 1 - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) }) it('Should accept a rental offer more than once', async () => { const rentalExpirationDate1 = Number((await ethers.provider.getBlock('latest'))?.timestamp) + duration + 1 - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, rentalExpirationDate1) @@ -608,99 +446,56 @@ describe('OriumSftMarketplace', () => { await mockERC20.mint(borrower.address, totalFeeAmount.toString()) await mockERC20.connect(borrower).approve(await marketplace.getAddress(), totalFeeAmount.toString()) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, rentalExpirationDate1 + duration + 3) }) it('Should accept a rental offer by anyone if borrower is the zero address', async () => { rentalOffer.borrower = ethers.ZeroAddress rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, commitmentId: BigInt(0) }) + await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) rentalOffer.commitmentId = BigInt(2) const blockTimestamp = Number((await ethers.provider.getBlock('latest'))?.timestamp) await mockERC20.mint(notOperator.address, totalFeeAmount.toString()) await mockERC20.connect(notOperator).approve(await marketplace.getAddress(), totalFeeAmount.toString()) - await expect( - marketplace - .connect(notOperator) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(notOperator).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, notOperator.address, blockTimestamp + duration + 3) }) it('Should accept a rental offer if duration is greater or equal minDuration', async () => { rentalOffer.minDuration = duration / 2 rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, commitmentId: BigInt(0) }) + await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) rentalOffer.commitmentId = BigInt(2) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.emit(marketplace, 'RentalStarted') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.emit( + marketplace, + 'RentalStarted', + ) }) it('Should NOT accept a rental offer if duration is less than minDuration', async () => { rentalOffer.minDuration = duration rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, commitmentId: BigInt(0) }) + await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) rentalOffer.commitmentId = BigInt(2) await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration / 2), + marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration / 2), ).to.be.revertedWith('OriumSftMarketplace: Duration is less than the offer minimum duration') }) it('Should NOT accept a rental offer if contract is paused', async () => { await marketplace.connect(operator).pause() - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('Pausable: paused') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'Pausable: paused', + ) }) it('Should NOT accept a rental offer if caller is not the borrower', async () => { rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` rentalOffer.borrower = borrower.address - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, commitmentId: BigInt(0) }) + await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) rentalOffer.commitmentId = BigInt(2) await mockERC20.mint(notOperator.address, totalFeeAmount.toString()) await expect( - marketplace - .connect(notOperator) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), + marketplace.connect(notOperator).acceptRentalOffer(rentalOffer, duration), ).to.be.revertedWith('OriumSftMarketplace: Sender is not allowed to rent this SFT') }) it('Should NOT accept a rental offer if offer is expired', async () => { @@ -709,33 +504,21 @@ describe('OriumSftMarketplace', () => { const timeToMove = rentalOffer.deadline - Number(blockTimestamp) + 1 await ethers.provider.send('evm_increaseTime', [timeToMove]) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('OriumSftMarketplace: expiration date is greater than offer deadline') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'OriumSftMarketplace: expiration date is greater than offer deadline', + ) }) it('Should NOT accept a rental offer if offer is not created', async () => { rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('OriumSftMarketplace: Offer not created') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'OriumSftMarketplace: Offer not created', + ) }) it('Should NOT accept a rental offer if expiration date is higher than offer deadline', async () => { const maxDuration = rentalOffer.deadline - Number((await ethers.provider.getBlock('latest'))?.timestamp) + 1 await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, maxDuration), + marketplace.connect(borrower).acceptRentalOffer(rentalOffer, maxDuration), ).to.be.revertedWith('OriumSftMarketplace: expiration date is greater than offer deadline') }) describe('Fees', async function () { @@ -745,11 +528,7 @@ describe('OriumSftMarketplace', () => { beforeEach(async () => { rentalOffer.feeAmountPerSecond = feeAmountPerSecond rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await marketplace - .connect(lender) - [ - 'createRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, commitmentId: BigInt(0) }) + await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) rentalOffer.commitmentId = BigInt(2) await mockERC20.mint(borrower.address, feeAmount * BigInt(2)) await mockERC20.connect(borrower).approve(await marketplace.getAddress(), feeAmount * BigInt(2)) @@ -758,13 +537,7 @@ describe('OriumSftMarketplace', () => { it('Should accept a rental offer with fee', async () => { const blockTimestamp = (await ethers.provider.getBlock('latest'))?.timestamp const expirationDate = Number(blockTimestamp) + duration + 1 - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)) .to.emit(marketplace, 'RentalStarted') .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) .to.emit(mockERC20, 'Transfer') @@ -773,82 +546,50 @@ describe('OriumSftMarketplace', () => { await marketplaceRoyalties .connect(operator) .setMarketplaceFeeForCollection(await mockERC1155.getAddress(), 0, true) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.emit(marketplace, 'RentalStarted') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.emit( + marketplace, + 'RentalStarted', + ) }) it('Should accept a rental offer if royalty fee is 0', async () => { await marketplaceRoyalties .connect(creator) .setRoyaltyInfo(creator.address, await mockERC1155.getAddress(), '0', creatorTreasury.address) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.emit(marketplace, 'RentalStarted') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.emit( + marketplace, + 'RentalStarted', + ) }) it('Should NOT accept a rental offer if marketplace fee transfer fails', async () => { await mockERC20.transferReverts(true, 0) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('OriumSftMarketplace: Transfer failed') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'OriumSftMarketplace: Transfer failed', + ) }) it('Should NOT accept a rental offer if royalty fee transfer fails', async () => { await mockERC20.transferReverts(true, 1) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('OriumSftMarketplace: Transfer failed') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'OriumSftMarketplace: Transfer failed', + ) }) it('Should NOT accept a rental offer if lender fee transfer fails', async () => { await mockERC20.transferReverts(true, 2) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('OriumSftMarketplace: Transfer failed') + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'OriumSftMarketplace: Transfer failed', + ) }) it('Should NOT accept a rental offer twice', async () => { - await marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration) - await expect( - marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration), - ).to.be.revertedWith('OriumSftMarketplace: This offer has an ongoing rental') + await marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration) + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)).to.be.revertedWith( + 'OriumSftMarketplace: This offer has an ongoing rental', + ) }) }) }) describe('Cancel Rental Offer', async () => { it('Should cancel a rental offer and releaseTokens from rolesRegistry', async () => { - await expect( - marketplace - .connect(lender) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) + await expect(marketplace.connect(lender).cancelRentalOffer(rentalOffer)) .to.emit(marketplace, 'RentalOfferCancelled') .withArgs(rentalOffer.lender, rentalOffer.nonce) .to.emit(rolesRegistry, 'TokensReleased') @@ -856,34 +597,20 @@ describe('OriumSftMarketplace', () => { }) it('Should cancel a rental offer if tokens was released before directly from registry', async () => { await rolesRegistry.connect(lender).releaseTokens(rentalOffer.commitmentId) - await expect( - marketplace - .connect(lender) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) + await expect(marketplace.connect(lender).cancelRentalOffer(rentalOffer)) .to.emit(marketplace, 'RentalOfferCancelled') .withArgs(rentalOffer.lender, rentalOffer.nonce) }) it('Should NOT cancel a rental offer if contract is paused', async () => { await marketplace.connect(operator).pause() - await expect( - marketplace - .connect(borrower) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('Pausable: paused') + await expect(marketplace.connect(borrower).cancelRentalOffer(rentalOffer)).to.be.revertedWith( + 'Pausable: paused', + ) }) it('Should NOT cancel a rental offer if nonce not used yet by caller', async () => { - await expect( - marketplace - .connect(notOperator) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Only lender can cancel a rental offer') + await expect(marketplace.connect(notOperator).cancelRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Only lender can cancel a rental offer', + ) }) it("Should NOT cancel a rental offer after deadline's expiration", async () => { // move forward in time to expire the offer @@ -891,21 +618,15 @@ describe('OriumSftMarketplace', () => { const timeToMove = rentalOffer.deadline - Number(blockTimestamp) + 1 await ethers.provider.send('evm_increaseTime', [timeToMove]) - await expect( - marketplace - .connect(lender) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Nonce expired or not used yet') + await expect(marketplace.connect(lender).cancelRentalOffer(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Nonce expired or not used yet', + ) }) it("Should NOT cancel a rental offer if it's not created", async () => { await expect( marketplace .connect(lender) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, nonce: `0x${randomBytes(32).toString('hex')}` }), + .cancelRentalOffer({ ...rentalOffer, nonce: `0x${randomBytes(32).toString('hex')}` }), ).to.be.revertedWith('OriumSftMarketplace: Offer not created') }) }) @@ -950,62 +671,36 @@ describe('OriumSftMarketplace', () => { describe('When Rental Offer is accepted', async () => { beforeEach(async () => { - await marketplace - .connect(borrower) - [ - 'acceptRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]),uint64)' - ](rentalOffer, duration) + await marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration) await rolesRegistry .connect(borrower) .setRoleApprovalForAll(await mockERC1155.getAddress(), await marketplace.getAddress(), true) }) describe('End Rental', async () => { it('Should end a rental by the borrower', async () => { - await expect( - marketplace - .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) + await expect(marketplace.connect(borrower).endRental(rentalOffer)) .to.emit(marketplace, 'RentalEnded') .withArgs(rentalOffer.lender, rentalOffer.nonce) }) it('Should NOT end a rental if contract is paused', async () => { await marketplace.connect(operator).pause() - await expect( - marketplace - .connect(lender) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('Pausable: paused') + await expect(marketplace.connect(lender).endRental(rentalOffer)).to.be.revertedWith('Pausable: paused') }) it('Should NOT end a rental by the lender', async () => { - await expect( - marketplace - .connect(lender) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Only borrower can end a rental') + await expect(marketplace.connect(lender).endRental(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Only borrower can end a rental', + ) }) it('Should NOT end a rental if caller is not the borrower', async () => { - await expect( - marketplace - .connect(notOperator) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: Only borrower can end a rental') + await expect(marketplace.connect(notOperator).endRental(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: Only borrower can end a rental', + ) }) it('Should NOT end a rental if rental is not started', async () => { await expect( marketplace .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ]({ ...rentalOffer, nonce: `0x${randomBytes(32).toString('hex')}` }), + .endRental({ ...rentalOffer, nonce: `0x${randomBytes(32).toString('hex')}` }), ).to.be.revertedWith('OriumSftMarketplace: Offer not created') }) it('Should NOT end a rental if rental is expired', async () => { @@ -1014,13 +709,9 @@ describe('OriumSftMarketplace', () => { const timeToMove = rentalOffer.deadline - Number(blockTimestamp) + 1 await ethers.provider.send('evm_increaseTime', [timeToMove]) - await expect( - marketplace - .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: There are no active Rentals') + await expect(marketplace.connect(borrower).endRental(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: There are no active Rentals', + ) }) it('Should NOT end a rental if the role was revoked by borrower directly in registry', async () => { await rolesRegistry @@ -1029,39 +720,21 @@ describe('OriumSftMarketplace', () => { await rolesRegistry .connect(borrower) .revokeRole(rentalOffer.commitmentId, rentalOffer.roles[0], borrower.address) - await expect( - marketplace - .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('SftRolesRegistry: grantee mismatch') + await expect(marketplace.connect(borrower).endRental(rentalOffer)).to.be.revertedWith( + 'SftRolesRegistry: grantee mismatch', + ) }) it('Should NOT end rental twice', async () => { - await marketplace - .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer) - await expect( - marketplace - .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ).to.be.revertedWith('OriumSftMarketplace: There are no active Rentals') + await marketplace.connect(borrower).endRental(rentalOffer) + await expect(marketplace.connect(borrower).endRental(rentalOffer)).to.be.revertedWith( + 'OriumSftMarketplace: There are no active Rentals', + ) }) }) describe('Cancel Rental Offer', async function () { it('Should cancel a rental offer if it has an active rental but NOT releaseTokens from rolesRegistry', async () => { - await expect( - marketplace - .connect(lender) - [ - 'cancelRentalOffer((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer), - ) + await expect(marketplace.connect(lender).cancelRentalOffer(rentalOffer)) .to.emit(marketplace, 'RentalOfferCancelled') .withArgs(rentalOffer.lender, rentalOffer.nonce) .to.not.emit(rolesRegistry, 'TokensReleased') @@ -1070,11 +743,7 @@ describe('OriumSftMarketplace', () => { describe('Batch Release Tokens', async () => { it('Should release tokens after rental is ended and rental offer expired', async () => { - await marketplace - .connect(borrower) - [ - 'endRental((address,address,address,uint256,uint256,address,uint256,uint256,uint256,uint64,uint64,bytes32[],bytes[]))' - ](rentalOffer) + await marketplace.connect(borrower).endRental(rentalOffer) await time.increase(ONE_DAY) await expect( marketplace From e3bdddc6bb1beacf554d81b369327b470cea3b5f Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 14 May 2024 11:56:18 -0300 Subject: [PATCH 3/3] ON-823: Upgrade network files --- .openzeppelin/polygon.json | 183 ++++++++++++++++++++ addresses/polygon/index.json | 6 +- scripts/orium-sft-marketplace/08-upgrade.ts | 16 ++ 3 files changed, 202 insertions(+), 3 deletions(-) create mode 100644 scripts/orium-sft-marketplace/08-upgrade.ts diff --git a/.openzeppelin/polygon.json b/.openzeppelin/polygon.json index 8a84a54..d993b62 100644 --- a/.openzeppelin/polygon.json +++ b/.openzeppelin/polygon.json @@ -3481,6 +3481,189 @@ }, "namespaces": {} } + }, + "b7a3f62e7af4b299c0318e34b8bfba7bfff6fb56a03eeeed33fead0da6915083": { + "address": "0x28c0DFe3e6B53ff3A25B9655A0B9D62120Ae34Fc", + "txHash": "0xf3ee6f93985ef1719249ca7ea3916d5e5cfe5219183ec5788e1cd00f9df2644f", + "layout": { + "solcVersion": "0.8.9", + "storage": [ + { + "label": "_initialized", + "offset": 0, + "slot": "0", + "type": "t_uint8", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63", + "retypedFrom": "bool" + }, + { + "label": "_initializing", + "offset": 1, + "slot": "0", + "type": "t_bool", + "contract": "Initializable", + "src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68" + }, + { + "label": "__gap", + "offset": 0, + "slot": "1", + "type": "t_array(t_uint256)50_storage", + "contract": "ContextUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:40" + }, + { + "label": "_owner", + "offset": 0, + "slot": "51", + "type": "t_address", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22" + }, + { + "label": "__gap", + "offset": 0, + "slot": "52", + "type": "t_array(t_uint256)49_storage", + "contract": "OwnableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94" + }, + { + "label": "_paused", + "offset": 0, + "slot": "101", + "type": "t_bool", + "contract": "PausableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol:29" + }, + { + "label": "__gap", + "offset": 0, + "slot": "102", + "type": "t_array(t_uint256)49_storage", + "contract": "PausableUpgradeable", + "src": "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol:116" + }, + { + "label": "oriumMarketplaceRoyalties", + "offset": 0, + "slot": "151", + "type": "t_address", + "contract": "OriumSftMarketplace", + "src": "contracts/OriumSftMarketplace.sol:22" + }, + { + "label": "isCreated", + "offset": 0, + "slot": "152", + "type": "t_mapping(t_bytes32,t_bool)", + "contract": "OriumSftMarketplace", + "src": "contracts/OriumSftMarketplace.sol:25" + }, + { + "label": "nonceDeadline", + "offset": 0, + "slot": "153", + "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint64))", + "contract": "OriumSftMarketplace", + "src": "contracts/OriumSftMarketplace.sol:28" + }, + { + "label": "commitmentIdToNonce", + "offset": 0, + "slot": "154", + "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint256))", + "contract": "OriumSftMarketplace", + "src": "contracts/OriumSftMarketplace.sol:31" + }, + { + "label": "rentals", + "offset": 0, + "slot": "155", + "type": "t_mapping(t_bytes32,t_struct(Rental)1844_storage)", + "contract": "OriumSftMarketplace", + "src": "contracts/OriumSftMarketplace.sol:34" + } + ], + "types": { + "t_address": { + "label": "address", + "numberOfBytes": "20" + }, + "t_array(t_uint256)49_storage": { + "label": "uint256[49]", + "numberOfBytes": "1568" + }, + "t_array(t_uint256)50_storage": { + "label": "uint256[50]", + "numberOfBytes": "1600" + }, + "t_bool": { + "label": "bool", + "numberOfBytes": "1" + }, + "t_bytes32": { + "label": "bytes32", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_mapping(t_uint256,t_uint256))": { + "label": "mapping(address => mapping(uint256 => uint256))", + "numberOfBytes": "32" + }, + "t_mapping(t_address,t_mapping(t_uint256,t_uint64))": { + "label": "mapping(address => mapping(uint256 => uint64))", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_bool)": { + "label": "mapping(bytes32 => bool)", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_struct(Rental)1844_storage)": { + "label": "mapping(bytes32 => struct OriumSftMarketplace.Rental)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_uint256)": { + "label": "mapping(uint256 => uint256)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_uint64)": { + "label": "mapping(uint256 => uint64)", + "numberOfBytes": "32" + }, + "t_struct(Rental)1844_storage": { + "label": "struct OriumSftMarketplace.Rental", + "members": [ + { + "label": "borrower", + "type": "t_address", + "offset": 0, + "slot": "0" + }, + { + "label": "expirationDate", + "type": "t_uint64", + "offset": 20, + "slot": "0" + } + ], + "numberOfBytes": "32" + }, + "t_uint256": { + "label": "uint256", + "numberOfBytes": "32" + }, + "t_uint64": { + "label": "uint64", + "numberOfBytes": "8" + }, + "t_uint8": { + "label": "uint8", + "numberOfBytes": "1" + } + }, + "namespaces": {} + } } } } diff --git a/addresses/polygon/index.json b/addresses/polygon/index.json index b588485..64dd92a 100644 --- a/addresses/polygon/index.json +++ b/addresses/polygon/index.json @@ -31,9 +31,9 @@ "operator": "0x359E1208DE02Af11461A37D72165Ef2dcD2Adfc8", "implementation": "0xd04d97d855A24b4E70D5723Bb90C194EC8946938", "proxyAdmin": "0x48c769f6a8de57d824f0e7330d7A27dee53a43cD", - "libraries": [ - "0x39CdF22FA80A9E7B95Db29efb2936A9561c70601" - ] + "libraries": { + "LibOriumSftMarketplace": "0x69C4c9D8B8D815c57Cb252f228159b2794094a17" + } }, "ERC7432WrapperForERC4907": { "address": "" diff --git a/scripts/orium-sft-marketplace/08-upgrade.ts b/scripts/orium-sft-marketplace/08-upgrade.ts new file mode 100644 index 0000000..219f1ab --- /dev/null +++ b/scripts/orium-sft-marketplace/08-upgrade.ts @@ -0,0 +1,16 @@ +import { upgradeProxy } from '../../utils/upgrade-proxy' + +async function main() { + const CONTRACT_NAME = 'OriumSftMarketplace' + const LIBRARY_NAME = 'LibOriumSftMarketplace' + await upgradeProxy(CONTRACT_NAME, [LIBRARY_NAME]) +} + +main() + .then(() => { + console.log('Done!') + }) + .catch(error => { + console.error(error) + process.exitCode = 1 + })