Skip to content

Commit

Permalink
feat: release version with Check Effect Interact to transferFee
Browse files Browse the repository at this point in the history
  • Loading branch information
EduardoMelo00 committed Aug 15, 2024
1 parent 6ed60f2 commit 8afd1d3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 69 deletions.
3 changes: 1 addition & 2 deletions contracts/NftRentalMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions contracts/OriumSftMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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);
}
Expand Down
66 changes: 1 addition & 65 deletions test/OriumSftMarketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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)
Expand Down

0 comments on commit 8afd1d3

Please sign in to comment.