Use trySafeTransferFrom instead of transferFrom

This commit is contained in:
Arnaud 2025-06-13 12:06:02 +02:00
parent 08e91c2443
commit 0c12a370b9
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
2 changed files with 5 additions and 3 deletions

View File

@ -2,6 +2,7 @@
pragma solidity 0.8.28;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./Configuration.sol";
@ -45,6 +46,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
using EnumerableSet for EnumerableSet.AddressSet;
using Requests for Request;
using AskHelpers for Ask;
using SafeERC20 for IERC20;
IERC20 private immutable _token;
MarketplaceConfig private _config;
@ -687,7 +689,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
function _transferFrom(address sender, uint256 amount) internal {
address receiver = address(this);
if (!_token.transferFrom(sender, receiver, amount))
if (!_token.trySafeTransferFrom(sender, receiver, amount))
revert Marketplace_TransferFailed();
}

View File

@ -215,7 +215,7 @@ describe("Marketplace", function () {
let insufficient = maxPrice(request) - 1
await token.approve(marketplace.address, insufficient)
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"ERC20InsufficientAllowance"
"Marketplace_TransferFailed"
)
})
@ -456,7 +456,7 @@ describe("Marketplace", function () {
await marketplace.reserveSlot(slot.request, slot.index)
await expect(
marketplace.fillSlot(slot.request, slot.index, proof)
).to.be.revertedWith("ERC20InsufficientAllowance")
).to.be.revertedWith("Marketplace_TransferFailed")
})
it("collects only requested collateral and not more", async function () {