update contract for mint2
This commit is contained in:
parent
8e951948d7
commit
ece167d8dd
File diff suppressed because one or more lines are too long
@ -30,8 +30,8 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
|
||||
}
|
||||
// parse: 0: not open or end, 1: phase1, 2: phase2
|
||||
uint256 public mintParse = 0;
|
||||
address public immutable nftAddress;
|
||||
uint256 public immutable nftIdStart;
|
||||
address public nftAddress;
|
||||
uint256 public nftIdStart;
|
||||
|
||||
MintConfig public mintConfig;
|
||||
uint256 public totalCount;
|
||||
@ -44,6 +44,8 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
|
||||
|
||||
event ParseUpdated(uint256 _parse);
|
||||
event MintConfigUpdated(MintConfig config);
|
||||
event NFTAddressUpdated(address _nft);
|
||||
event NFTIdStartUpdated(uint256 _nftIdStart);
|
||||
|
||||
constructor(address _nftAddress, uint256 _nftIdStart, MintConfig memory _mintConfig) {
|
||||
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
|
||||
@ -95,6 +97,17 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
|
||||
}
|
||||
}
|
||||
|
||||
function updateNftAddress(address _nft) external onlyRole(MANAGE_ROLE) {
|
||||
require(_nft != address(0), "NFTClaimer: invalid nft address");
|
||||
nftAddress = _nft;
|
||||
emit NFTAddressUpdated(_nft);
|
||||
}
|
||||
|
||||
function updateNftIdStart(uint256 _nftIdStart) external onlyRole(MANAGE_ROLE) {
|
||||
nftIdStart = _nftIdStart;
|
||||
emit NFTIdStartUpdated(_nftIdStart);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dev claim NFT
|
||||
@ -113,7 +126,6 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
|
||||
require(_whitelist1[to] + _whitelist2[to] >= _mintedCount + nftCount, "NFTClaimer: not in whitelist or exceed limit");
|
||||
}
|
||||
uint256 _tokenAmount = mintConfig.mintPrice * nftCount;
|
||||
totalCount += nftCount;
|
||||
IERC20(mintConfig.currency).safeTransferFrom(to, mintConfig.feeToAddress, _tokenAmount);
|
||||
uint256[] memory ids = new uint256[](nftCount);
|
||||
for (uint256 i = 0; i < nftCount; ++i) {
|
||||
@ -122,6 +134,7 @@ contract NFTClaimStage2WL is ReentrancyGuard, AccessControl {
|
||||
_mintedRecords[to].add(_nftId);
|
||||
IClaimAbleNFT(nftAddress).safeMint(to, _nftId);
|
||||
}
|
||||
totalCount += nftCount;
|
||||
emit NFTClaimed(nftAddress, to, ids);
|
||||
}
|
||||
|
||||
|
43
contracts/tools/AirdropToken.sol
Normal file
43
contracts/tools/AirdropToken.sol
Normal file
@ -0,0 +1,43 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
||||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
|
||||
contract AirdropToken {
|
||||
using SafeERC20 for IERC20;
|
||||
mapping(address user => uint256 amount) public failTransferList;
|
||||
|
||||
function getSum(uint256[] calldata _arr) public pure returns (uint256 sum) {
|
||||
for (uint256 i = 0; i < _arr.length; i++) sum = sum + _arr[i];
|
||||
}
|
||||
|
||||
function multiTransferETH(address payable[] calldata _addresses, uint256[] calldata _amounts) public payable {
|
||||
require(_addresses.length == _amounts.length, "Lengths of Addresses and Amounts NOT EQUAL");
|
||||
uint256 _amountSum = getSum(_amounts);
|
||||
require(msg.value == _amountSum, "Transfer amount error");
|
||||
for (uint256 i = 0; i < _addresses.length; i++) {
|
||||
(bool success, ) = _addresses[i].call{value: _amounts[i]}("");
|
||||
if (!success) {
|
||||
failTransferList[_addresses[i]] = _amounts[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function multiTransferERC20(address _token, address[] calldata _addresses, uint256[] calldata _amounts) external {
|
||||
require(_addresses.length == _amounts.length, "Lengths of Addresses and Amounts NOT EQUAL");
|
||||
IERC20 token = IERC20(_token);
|
||||
for (uint256 i; i < _addresses.length; i++) {
|
||||
token.safeTransferFrom(msg.sender, _addresses[i], _amounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function multiTransferERC721(address _token, address[] calldata _addresses, uint256[] calldata _tokenIds) external {
|
||||
require(_addresses.length == _tokenIds.length, "Lengths of Addresses and TokenIds NOT EQUAL");
|
||||
IERC721 token = IERC721(_token);
|
||||
for (uint256 i; i < _addresses.length; i++) {
|
||||
token.transferFrom(msg.sender, _addresses[i], _tokenIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
27
deploy/5_deploy_airdrop.ts
Normal file
27
deploy/5_deploy_airdrop.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
||||
import { DeployFunction } from "hardhat-deploy/types";
|
||||
import { updateArray } from "../scripts/utils"
|
||||
|
||||
|
||||
const deployNFTClaim: DeployFunction =
|
||||
async function (hre: HardhatRuntimeEnvironment) {
|
||||
const provider = hre.ethers.provider;
|
||||
const from = await (await provider.getSigner()).getAddress();
|
||||
const ret = await hre.deployments.deploy("AirdropToken", {
|
||||
from,
|
||||
args: [],
|
||||
log: true,
|
||||
});
|
||||
console.log("==AirdropToken addr=", ret.address);
|
||||
updateArray({
|
||||
name: "AirdropToken",
|
||||
type: "logic",
|
||||
json: "assets/contracts/AirdropToken.json",
|
||||
address: ret.address,
|
||||
network: hre.network.name,
|
||||
});
|
||||
};
|
||||
|
||||
deployNFTClaim.tags = ["AirdropToken"];
|
||||
|
||||
export default deployNFTClaim;
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -29,10 +29,16 @@
|
||||
"json": "assets/contracts/CFNFTGame.json",
|
||||
"address": "0x75C0c6eD851036DB28c750Bd9bfa3A72B5107801"
|
||||
},
|
||||
{
|
||||
"name": "AirdropToken",
|
||||
"type": "logic",
|
||||
"json": "assets/contracts/AirdropToken.json",
|
||||
"address": "0x4Ef766854EE104053cF2D243620b7A643fCC2B54"
|
||||
},
|
||||
{
|
||||
"name": "NFTClaimStage2WL",
|
||||
"type": "logic",
|
||||
"json": "assets/contracts/NFTClaimStage2WL.json",
|
||||
"address": "0xc43Efb17C24e4e027d3F2613DB858181abE2994e"
|
||||
"address": "0xc11A64Cc2Ec7aEFbd5E25a37f1d9216f3f8CF11a"
|
||||
}
|
||||
]
|
@ -13,6 +13,7 @@
|
||||
"deploy:nft": "hardhat deploy --tags CFNFTGame --network imtbl_test --reset",
|
||||
"deploy:nftlock": "hardhat deploy --tags NFTLock --network imtbl_test --reset",
|
||||
"deploy:testtoken": "hardhat deploy --tags TestToken --network imtbl_test --reset",
|
||||
"deploy:airdrop": "hardhat deploy --tags AirdropToken --network imtbl_test --reset",
|
||||
"solhint": "solhint --config ./.solhint.json"
|
||||
},
|
||||
"author": "",
|
||||
|
Loading…
x
Reference in New Issue
Block a user