Skip to content

Commit

Permalink
Merge pull request #55 from OriumNetwork/ON-916
Browse files Browse the repository at this point in the history
fix: updating roleDeadline EndRental
  • Loading branch information
EduardoMelo00 authored Jun 26, 2024
2 parents 2f4f767 + ed6213e commit 7240d13
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 6 deletions.
179 changes: 179 additions & 0 deletions .openzeppelin/unknown-1284.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
}
}
}
4 changes: 2 additions & 2 deletions addresses/moonbeam/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"NftRentalMarketplace": {
"address": "0x201E1636BB21Dfd51F93815BCD008EAe2Fa29bD9",
"operator": "0x04c8c6c56dab836f8bd62cb6884371507e706806",
"implementation": "0xA4c07bCF0ACE9e85Ce59BDD8eC7590a1d946216d",
"implementation": "0x830cbc0e100e72e8682391a668ce6c9db703848f",
"proxyAdmin": "0x668e73cF24361cfE13801681d8885e6632A7Eaa6",
"libraries": {
"LibNftRentalMarketplace": "0x3c24b00dC7Cae303eF84560A9848f9775890D2d8"
"LibNftRentalMarketplace": "0x4BDb2d8f3833b38307dfC19231dC7cD65b59504a"
}
}
}
7 changes: 7 additions & 0 deletions contracts/NftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr
_offer.tokenId,
_offer.roles
);

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);
}
}

_rental.expirationDate = uint64(block.timestamp);
emit RentalEnded(_offer.lender, _offer.nonce);
Expand Down
48 changes: 44 additions & 4 deletions test/NftRentalMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -660,7 +701,6 @@ describe('NftRentalMarketplace', () => {
)
})
})

describe('When Rental Offer is accepted', async () => {
beforeEach(async () => {
await marketplace.connect(borrower).acceptRentalOffer(rentalOffer, duration)
Expand Down

0 comments on commit 7240d13

Please sign in to comment.