修正部分erc20转账不revert导致没有正确判断转账是否成功的bug

This commit is contained in:
CounterFire2023 2024-06-18 13:48:34 +08:00
parent d4acaea8a0
commit ad8a60a8d0
2 changed files with 7 additions and 3 deletions

View File

@ -3,6 +3,7 @@ pragma solidity 0.8.19;
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {HasSignature} from "../core/HasSignature.sol";
/**
@ -13,6 +14,7 @@ interface IClaimAbleNFT {
}
contract NFTClaimStage2 is HasSignature, ReentrancyGuard {
using SafeERC20 for IERC20;
struct MintConfig {
uint256 parse1MaxSupply; // max supply for phase1
uint256 maxSupply; // max supply for phase2
@ -102,7 +104,7 @@ contract NFTClaimStage2 is HasSignature, ReentrancyGuard {
saltNonce
);
checkSigner(verifier, criteriaMessageHash, signature);
IERC20(mintConfig.currency).transferFrom(to, mintConfig.feeToAddress, tokenAmount);
IERC20(mintConfig.currency).safeTransferFrom(to, mintConfig.feeToAddress, tokenAmount);
for (uint256 i = 0; i < count; ++i) {
IClaimAbleNFT(nftAddress).safeMint(to, ids[i]);
}

View File

@ -5,6 +5,7 @@ import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
/**
* Contract for the activity of NFT claim stage 2.
*/
@ -14,6 +15,7 @@ interface IClaimAbleNFT {
contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
using EnumerableSet for EnumerableSet.UintSet;
using SafeERC20 for IERC20;
/// @notice Only UPDATE_WL_ROLE can add white listing
bytes32 public constant UPDATE_WL_ROLE = bytes32("UPDATE_WL_ROLE");
/// @notice Only MANAGE_ROLE can change mint config
@ -96,7 +98,7 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
/**
* @dev claim NFT
* Get whitelist signature from a third-party service, then call this method to claim NFT
* @param nftCount nft count to claim
*/
function claim(
uint256 nftCount
@ -111,7 +113,7 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
require(_whitelist1[to] + _whitelist2[to] >= _mintedCount + nftCount, "NFTClaimer: not in whitelist or exceed limit");
}
uint256 _tokenAmount = mintConfig.mintPrice * nftCount;
IERC20(mintConfig.currency).transferFrom(to, mintConfig.feeToAddress, _tokenAmount);
IERC20(mintConfig.currency).safeTransferFrom(to, mintConfig.feeToAddress, _tokenAmount);
uint256[] memory ids = new uint256[](nftCount);
for (uint256 i = 0; i < nftCount; ++i) {
uint256 _nftId = nftIdStart + totalCount + i;