diff --git a/contracts/NftRentalMarketplace.sol b/contracts/NftRentalMarketplace.sol index 378bcf8..62ebfa3 100644 --- a/contracts/NftRentalMarketplace.sol +++ b/contracts/NftRentalMarketplace.sol @@ -162,8 +162,6 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr _expirationDate ); - _transferFees(_offer.tokenAddress, _offer.feeTokenAddress, _offer.feeAmountPerSecond, _duration, _offer.lender); - LibNftRentalMarketplace.grantRoles( oriumMarketplaceRoyalties, _offer.tokenAddress, @@ -181,6 +179,7 @@ contract NftRentalMarketplace is Initializable, OwnableUpgradeable, PausableUpgr } rentals[_offerHash] = Rental({ borrower: msg.sender, expirationDate: _expirationDate }); + _transferFees(_offer.tokenAddress, _offer.feeTokenAddress, _offer.feeAmountPerSecond, _duration, _offer.lender); emit RentalStarted(_offer.lender, _offer.nonce, msg.sender, _expirationDate); } diff --git a/contracts/OriumSftMarketplace.sol b/contracts/OriumSftMarketplace.sol index ee5baca..0ddf6b7 100644 --- a/contracts/OriumSftMarketplace.sol +++ b/contracts/OriumSftMarketplace.sol @@ -183,8 +183,6 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra _expirationDate ); - _transferFees(_offer.tokenAddress, _offer.feeTokenAddress, _offer.feeAmountPerSecond, _duration, _offer.lender); - IERC7589 _rolesRegistry = IERC7589( IOriumMarketplaceRoyalties(oriumMarketplaceRoyalties).sftRolesRegistryOf(_offer.tokenAddress) ); @@ -200,6 +198,7 @@ contract OriumSftMarketplace is Initializable, OwnableUpgradeable, PausableUpgra } rentals[_offerHash] = Rental({ borrower: msg.sender, expirationDate: _expirationDate }); + _transferFees(_offer.tokenAddress, _offer.feeTokenAddress, _offer.feeAmountPerSecond, _duration, _offer.lender); emit RentalStarted(_offer.lender, _offer.nonce, msg.sender, _expirationDate); } diff --git a/test/OriumSftMarketplace.test.ts b/test/OriumSftMarketplace.test.ts index e45e4b2..ac6a9df 100644 --- a/test/OriumSftMarketplace.test.ts +++ b/test/OriumSftMarketplace.test.ts @@ -703,7 +703,7 @@ describe('OriumSftMarketplace', () => { .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) }) - it('Should revert when accepting a rental offer with insufficient native tokens', async function () { + it('Should revert when accept a rental offer with insufficient native tokens', async function () { await marketplaceRoyalties .connect(operator) .setTrustedFeeTokenForToken([rentalOffer.tokenAddress], [AddressZero], [true]) @@ -723,70 +723,6 @@ describe('OriumSftMarketplace', () => { ).to.be.revertedWith('OriumSftMarketplace: Insufficient native token amount') }) - it('should detect reentrancy attack during fee transfer', async () => { - const AttackContract = await ethers.getContractFactory('ReentrancyAttack') - attackContract = (await AttackContract.deploy(marketplace)) as ReentrancyAttack - await attackContract.waitForDeployment() - - await marketplaceRoyalties - .connect(operator) - .setTrustedFeeTokenForToken([rentalOffer.tokenAddress], [AddressZero], [true]) - rentalOffer.minDuration = duration - rentalOffer.feeTokenAddress = AddressZero - rentalOffer.feeAmountPerSecond = toWei('0.0000001') - const totalFeeAmount = rentalOffer.feeAmountPerSecond * BigInt(duration) - - rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - await marketplace.connect(lender).createRentalOffer({ ...rentalOffer, commitmentId: BigInt(0) }) - rentalOffer.commitmentId = BigInt(2) - - await attackContract.connect(lender).attack(rentalOffer, duration, { - value: totalFeeAmount, - }) - - await expect( - lender.sendTransaction({ - to: attackContract.getAddress(), - value: toWei('1'), - }), - ).to.be.revertedWith('OriumSftMarketplace: This offer has an ongoing rental') - }) - - it('should revert when accept offer is called from Attack contract after a offer be accepeted by borrower', async () => { - const AttackContract = await ethers.getContractFactory('ReentrancyAttack') - attackContract = (await AttackContract.deploy(marketplace)) as ReentrancyAttack - await attackContract.waitForDeployment() - - await marketplaceRoyalties - .connect(operator) - .setTrustedFeeTokenForToken([rentalOffer.tokenAddress], [AddressZero], [true]) - rentalOffer.minDuration = duration - rentalOffer.feeTokenAddress = AddressZero - rentalOffer.feeAmountPerSecond = toWei('0.0000001') - const totalFeeAmount = rentalOffer.feeAmountPerSecond * BigInt(duration) - - rentalOffer.nonce = `0x${randomBytes(32).toString('hex')}` - 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(rentalOffer, duration, { - value: totalFeeAmount.toString(), - }), - ) - .to.emit(marketplace, 'RentalStarted') - .withArgs(rentalOffer.lender, rentalOffer.nonce, borrower.address, expirationDate) - - await expect( - attackContract.connect(lender).attack(rentalOffer, duration, { - value: totalFeeAmount, - }), - ).to.be.revertedWith('OriumSftMarketplace: This offer has an ongoing rental') - }) - describe('Fees', async function () { const feeAmountPerSecond = toWei('1') const feeAmount = feeAmountPerSecond * BigInt(duration)