From 5dc635df50acad122dcc2f3a9f7f11248bd1ed9f Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Tue, 25 Jun 2024 12:12:13 -0300 Subject: [PATCH 1/7] fix: updating roleDeadline EndRental --- contracts/NftRentalMarketplace.sol | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contracts/NftRentalMarketplace.sol b/contracts/NftRentalMarketplace.sol index cfd06bd..37b292f 100644 --- a/contracts/NftRentalMarketplace.sol +++ b/contracts/NftRentalMarketplace.sol @@ -234,6 +234,12 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr _offer.roles ); + for (uint256 i = 0; i < _offer.roles.length; i++) { + if( roleDeadline[_offer.roles[i]][_offer.tokenAddress][_offer.tokenId] > uint64(block.timestamp) ) { + roleDeadline[_offer.roles[i]][_offer.tokenAddress][_offer.tokenId] = uint64(block.timestamp); + } + } + _rental.expirationDate = uint64(block.timestamp); emit RentalEnded(_offer.lender, _offer.nonce); } From 9cad6f3178a74cead4e59cbe64534609a3acf2d6 Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Tue, 25 Jun 2024 13:15:07 -0300 Subject: [PATCH 2/7] fix: updating roleDeadline EndRental --- contracts/NftRentalMarketplace.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/NftRentalMarketplace.sol b/contracts/NftRentalMarketplace.sol index 37b292f..9654d89 100644 --- a/contracts/NftRentalMarketplace.sol +++ b/contracts/NftRentalMarketplace.sol @@ -233,13 +233,13 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr _offer.tokenId, _offer.roles ); - + for (uint256 i = 0; i < _offer.roles.length; i++) { - if( roleDeadline[_offer.roles[i]][_offer.tokenAddress][_offer.tokenId] > uint64(block.timestamp) ) { + if( _offer.deadline > uint64(block.timestamp) ) { roleDeadline[_offer.roles[i]][_offer.tokenAddress][_offer.tokenId] = uint64(block.timestamp); } } - + _rental.expirationDate = uint64(block.timestamp); emit RentalEnded(_offer.lender, _offer.nonce); } From fff0559ce283f222b9b5ba898cbeace203e11c64 Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Tue, 25 Jun 2024 17:33:30 -0300 Subject: [PATCH 3/7] fix: updating roleDeadline EndRental and adding test cases --- contracts/NftRentalMarketplace.sol | 7 +++-- test/NftRentalMarketplace.test.ts | 48 +++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/contracts/NftRentalMarketplace.sol b/contracts/NftRentalMarketplace.sol index 9654d89..cf94158 100644 --- a/contracts/NftRentalMarketplace.sol +++ b/contracts/NftRentalMarketplace.sol @@ -234,9 +234,10 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr _offer.roles ); - for (uint256 i = 0; i < _offer.roles.length; i++) { - if( _offer.deadline > uint64(block.timestamp) ) { - roleDeadline[_offer.roles[i]][_offer.tokenAddress][_offer.tokenId] = uint64(block.timestamp); + uint64 _offerDeadline = nonceDeadline[_offer.lender][_offer.nonce]; + if (_offerDeadline < uint64(block.timestamp)) { + for (uint256 i = 0; i < _offer.roles.length; i++) { + roleDeadline[_offer.roles[i]][_offer.tokenAddress][_offer.tokenId] = uint64(block.timestamp); } } diff --git a/test/NftRentalMarketplace.test.ts b/test/NftRentalMarketplace.test.ts index 2cd87ae..0677f83 100644 --- a/test/NftRentalMarketplace.test.ts +++ b/test/NftRentalMarketplace.test.ts @@ -404,16 +404,13 @@ describe('NftRentalMarketplace', () => { rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` rentalOffer.deadline = Number(await time.latest()) + ONE_HOUR + TEN_MINUTES const blockTimestamp = Number(await time.latest()) - console.log('blockTimestamp:', blockTimestamp.toString()) const newExpirationDate = blockTimestamp + duration - 1 - console.log('newExpirationDate', newExpirationDate.toString()) await marketplace.connect(lender).createRentalOffer(rentalOffer) const updatedRoleDeadline = await marketplace.roleDeadline( USER_ROLE, await mockERC721.getAddress(), tokenId, ) - console.log('Updated Role Deadline:', updatedRoleDeadline.toString()) await marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration) expect(newExpirationDate).to.be.greaterThan(updatedRoleDeadline) @@ -596,6 +593,50 @@ describe('NftRentalMarketplace', () => { .to.emit(marketplace, 'RentalOfferCancelled') .withArgs(rentalOffer.lender, rentalOffer.nonce) }) + + it('Should end a rental offer with an active role and LET create a new offer ', async () => { + await time.increase(ONE_DAY) + rentalOffer.borrower = borrower.address + rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` + rentalOffer.deadline = Number(await time.latest()) + ONE_DAY + rentalOffer.feeAmountPerSecond = toWei('0') + await marketplace.connect(lender).createRentalOffer(rentalOffer) + + const blockTimestamp = await time.latest() + const expirationDate = Number(blockTimestamp) + duration + + await expect(marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration - 1)) + .to.emit(marketplace, 'RentalStarted') + .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) + await rolesRegistry + .connect(borrower) + .setRoleApprovalForAll(await mockERC721.getAddress(), await marketplace.getAddress(), true) + + await expect(marketplace.connect(lender).cancelRentalOffer(rentalOffer)) + .to.emit(marketplace, 'RentalOfferCancelled') + .withArgs(rentalOffer.lender, rentalOffer.nonce) + + await expect(marketplace.connect(borrower).endRental(rentalOffer)) + .to.emit(marketplace, 'RentalEnded') + .withArgs(rentalOffer.lender, rentalOffer.nonce) + rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` + + await expect(marketplace.connect(lender).createRentalOffer(rentalOffer)) + .to.emit(marketplace, 'RentalOfferCreated') + .withArgs( + rentalOffer.nonce, + rentalOffer.tokenAddress, + rentalOffer.tokenId, + rentalOffer.lender, + rentalOffer.borrower, + rentalOffer.feeTokenAddress, + rentalOffer.feeAmountPerSecond, + rentalOffer.deadline, + rentalOffer.minDuration, + rentalOffer.roles, + rentalOffer.rolesData, + ) + }) it('Should cancel a rental offer with an active role And DO NOT let create another rental offer', async () => { await time.increase(ONE_DAY) rentalOffer.borrower = borrower.address @@ -660,7 +701,6 @@ describe('NftRentalMarketplace', () => { ) }) }) - describe('When Rental Offer is accepted', async () => { beforeEach(async () => { await marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration) From 50853225cca4a4cdc53db10ebb9725180ed3dd2b Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Wed, 26 Jun 2024 12:19:34 -0300 Subject: [PATCH 4/7] adding json files --- .openzeppelin/unknown-1284.json | 179 ++++++++++++++++++++++++++++++++ addresses/moonbeam/index.json | 2 +- 2 files changed, 180 insertions(+), 1 deletion(-) diff --git a/.openzeppelin/unknown-1284.json b/.openzeppelin/unknown-1284.json index 0d243c5..2311d06 100644 --- a/.openzeppelin/unknown-1284.json +++ b/.openzeppelin/unknown-1284.json @@ -932,6 +932,185 @@ }, "namespaces": {} } + }, + "1aace81812e308db6c63cbcd11c3dc1bceafe914d475b2a898f30fb4d3ec3dc7": { + "address": "0x830cBc0e100e72e8682391A668Ce6c9Db703848F", + "txHash": "0xff98898161e2c4ce112fca9999e11a288edc9dafbefe9210365e48920972d61b", + "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": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:23" + }, + { + "label": "isCreated", + "offset": 0, + "slot": "152", + "type": "t_mapping(t_bytes32,t_bool)", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:26" + }, + { + "label": "nonceDeadline", + "offset": 0, + "slot": "153", + "type": "t_mapping(t_address,t_mapping(t_uint256,t_uint64))", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:29" + }, + { + "label": "roleDeadline", + "offset": 0, + "slot": "154", + "type": "t_mapping(t_bytes32,t_mapping(t_address,t_mapping(t_uint256,t_uint64)))", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:32" + }, + { + "label": "rentals", + "offset": 0, + "slot": "155", + "type": "t_mapping(t_bytes32,t_struct(Rental)8746_storage)", + "contract": "NftRentalMarketplace", + "src": "contracts/NftRentalMarketplace.sol:35" + } + ], + "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_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_mapping(t_address,t_mapping(t_uint256,t_uint64)))": { + "label": "mapping(bytes32 => mapping(address => mapping(uint256 => uint64)))", + "numberOfBytes": "32" + }, + "t_mapping(t_bytes32,t_struct(Rental)8746_storage)": { + "label": "mapping(bytes32 => struct Rental)", + "numberOfBytes": "32" + }, + "t_mapping(t_uint256,t_uint64)": { + "label": "mapping(uint256 => uint64)", + "numberOfBytes": "32" + }, + "t_struct(Rental)8746_storage": { + "label": "struct 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/moonbeam/index.json b/addresses/moonbeam/index.json index fa81a50..d699648 100644 --- a/addresses/moonbeam/index.json +++ b/addresses/moonbeam/index.json @@ -38,7 +38,7 @@ "implementation": "0xA4c07bCF0ACE9e85Ce59BDD8eC7590a1d946216d", "proxyAdmin": "0x668e73cF24361cfE13801681d8885e6632A7Eaa6", "libraries": { - "LibNftRentalMarketplace": "0x3c24b00dC7Cae303eF84560A9848f9775890D2d8" + "LibNftRentalMarketplace": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a" } } } \ No newline at end of file From b6bc615c6ac64b3a111c08541cb216bb8081d244 Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Wed, 26 Jun 2024 12:25:45 -0300 Subject: [PATCH 5/7] fix: update implementation address --- addresses/moonbeam/index.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addresses/moonbeam/index.json b/addresses/moonbeam/index.json index d699648..4dae1a0 100644 --- a/addresses/moonbeam/index.json +++ b/addresses/moonbeam/index.json @@ -35,7 +35,7 @@ "NftRentalMarketplace": { "address": "0x201E1636BB21Dfd51F93815BCD008EAe2Fa29bD9", "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", - "implementation": "0xA4c07bCF0ACE9e85Ce59BDD8eC7590a1d946216d", + "implementation": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a", "proxyAdmin": "0x668e73cF24361cfE13801681d8885e6632A7Eaa6", "libraries": { "LibNftRentalMarketplace": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a" From 55029aa01b08e2f0a6b1da911d019edd62d26419 Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Wed, 26 Jun 2024 13:09:54 -0300 Subject: [PATCH 6/7] fix: update implementation address --- addresses/moonbeam/index.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addresses/moonbeam/index.json b/addresses/moonbeam/index.json index 4dae1a0..d699648 100644 --- a/addresses/moonbeam/index.json +++ b/addresses/moonbeam/index.json @@ -35,7 +35,7 @@ "NftRentalMarketplace": { "address": "0x201E1636BB21Dfd51F93815BCD008EAe2Fa29bD9", "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", - "implementation": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a", + "implementation": "0xA4c07bCF0ACE9e85Ce59BDD8eC7590a1d946216d", "proxyAdmin": "0x668e73cF24361cfE13801681d8885e6632A7Eaa6", "libraries": { "LibNftRentalMarketplace": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a" From ed6213eba058aeca7512bd62a35af002b325a8a3 Mon Sep 17 00:00:00 2001 From: EDUARDO MELO DE SIQUEIRA Date: Wed, 26 Jun 2024 14:11:48 -0300 Subject: [PATCH 7/7] fix: update implementation address verified --- addresses/moonbeam/index.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addresses/moonbeam/index.json b/addresses/moonbeam/index.json index d699648..8625b84 100644 --- a/addresses/moonbeam/index.json +++ b/addresses/moonbeam/index.json @@ -35,7 +35,7 @@ "NftRentalMarketplace": { "address": "0x201E1636BB21Dfd51F93815BCD008EAe2Fa29bD9", "operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806", - "implementation": "0xA4c07bCF0ACE9e85Ce59BDD8eC7590a1d946216d", + "implementation": "0x830cbc0e100e72e8682391a668ce6c9db703848f", "proxyAdmin": "0x668e73cF24361cfE13801681d8885e6632A7Eaa6", "libraries": { "LibNftRentalMarketplace": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a"