修改badge的nftid的生成方式, 改由合约生成

This commit is contained in:
zhl 2023-04-23 11:05:48 +08:00
parent 5b64f2494e
commit d35db0b407
10 changed files with 18647 additions and 15676 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -16789,7 +16789,7 @@
}
},
"schemaVersion": "3.4.11",
"updatedAt": "2023-04-19T02:14:02.502Z",
"updatedAt": "2023-04-23T02:44:39.968Z",
"networkType": "ethereum",
"devdoc": {
"kind": "dev",

View File

@ -3235,7 +3235,7 @@
}
},
"schemaVersion": "3.4.11",
"updatedAt": "2023-04-19T02:14:02.528Z",
"updatedAt": "2023-04-23T02:44:39.989Z",
"networkType": "ethereum",
"devdoc": {
"kind": "dev",

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,6 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
* MultiSigWallet with timelocker
*/
contract BEMultiSigWallet is AccessControlEnumerable {
bytes32 public constant TIMELOCK_ADMIN_ROLE =
keccak256("TIMELOCK_ADMIN_ROLE");
bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
bytes32 public constant CONFIRM_ROLE = keccak256("CONFIRM_ROLE");
@ -64,14 +62,13 @@ contract BEMultiSigWallet is AccessControlEnumerable {
address[] memory confirmers,
address[] memory executors
) {
_setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(CONFIRM_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(PROPOSER_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(EXECUTOR_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(CONFIRM_ROLE, DEFAULT_ADMIN_ROLE);
// deployer + self administration
_setupRole(TIMELOCK_ADMIN_ROLE, _msgSender());
_setupRole(TIMELOCK_ADMIN_ROLE, address(this));
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setupRole(DEFAULT_ADMIN_ROLE, address(this));
// register proposers
for (uint256 i = 0; i < proposers.length; ++i) {

View File

@ -6,7 +6,10 @@ import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface IBEERC721 is IERC721 {
function mint(address to, uint256 tokenId) external;
function batchMint(address to, uint256[] calldata tokenIds) external;
function batchMint(
address to,
uint256 count
) external returns (uint256[] memory);
function burn(address owner, uint256 tokenId) external;

View File

@ -5,7 +5,6 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "../interfaces/IBEERC721.sol";
contract NftDistributor is AccessControlEnumerable {
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant MANAGE_ROLE = keccak256("MANAGE_ROLE");
// user address => nft ids
@ -34,12 +33,10 @@ contract NftDistributor is AccessControlEnumerable {
*/
constructor(address _nftTarget, address[] memory _manageAddress) {
// Set up the ADMIN_ROLE and MANAGE_ROLE
_setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
_setRoleAdmin(MANAGE_ROLE, ADMIN_ROLE);
_setRoleAdmin(MANAGE_ROLE, DEFAULT_ADMIN_ROLE);
// Grant the ADMIN_ROLE to the deployer and to the contract itself
_setupRole(ADMIN_ROLE, _msgSender());
_setupRole(ADMIN_ROLE, address(this));
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
// Grant the MANAGE_ROLE to the specified address
for (uint256 i = 0; i < _manageAddress.length; ++i) {
@ -72,39 +69,29 @@ contract NftDistributor is AccessControlEnumerable {
* Then it emits the Minted event with details of the operation.
*
* @param _user - The address of the user receiving the NFTs
* @param _nftIds - An array of the IDs for the NFTs being minted
*/
function mintToUser(
address _user,
uint256[] calldata _nftIds
) external onlyManager {
function mintToUser(address _user, uint256 count) external onlyManager {
// Check that there are enough mintable NFTs
require(
_nftIds.length <= getMintableCount(_user),
"Mintable count is not enough"
);
require(count <= getMintableCount(_user), "Mintable count is not enough");
// Get the array of the user's owned NFTs
uint256[] memory nfts = ownerToNFTs[_user];
// Initialize variables
uint256 index = 0;
uint256[] memory nftSource = new uint256[](_nftIds.length);
uint256[] memory nftSource = new uint256[](count);
// Loop through the user's owned NFTs
for (uint256 i = 0; i < nfts.length; i++) {
uint256 nftSId = nfts[i];
// Check if the NFT is mintable
if (!nftMinted[nftSId]) {
// If the NFT is mintable, add it to the list to be minted
uint256 nftId = _nftIds[index];
// Add the NFT's source ID to the list of sources
nftSource[index] = nftSId;
nftMinted[nftSId] = true;
// Mint the NFT to the user's address
nft.mint(_user, nftId);
index++;
}
}
uint256[] memory _nftIds = nft.batchMint(_user, count);
// Emit event with details of the minting operation
emit Minted(_user, address(nft), nftSource, _nftIds);
}

View File

@ -10,46 +10,36 @@ contract BEBadge is AccessControl, ERC721Enumerable {
bytes32 public constant BURN_ROLE = keccak256("BURN_ROLE");
bytes32 public constant LOCK_ROLE = keccak256("LOCK_ROLE");
uint256 public immutable supplyLimit;
uint256 tokenIndex;
event Lock(uint256 indexed tokenId);
event UnLock(uint256 indexed tokenId);
event BatchMint(address indexed to, uint256[] tokenIds);
constructor(
string memory name_,
string memory symbol_,
uint256 supplyLimt_
) ERC721(name_, symbol_) {
string memory _name,
string memory _symbol,
uint256 _supplyLimt
) ERC721(_name, _symbol) {
_setRoleAdmin(MINTER_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(BURN_ROLE, DEFAULT_ADMIN_ROLE);
_setRoleAdmin(LOCK_ROLE, DEFAULT_ADMIN_ROLE);
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(MINTER_ROLE, msg.sender);
_setupRole(BURN_ROLE, msg.sender);
_setupRole(LOCK_ROLE, msg.sender);
supplyLimit = supplyLimt_;
supplyLimit = _supplyLimt;
}
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
/**
* @dev Creates a new token for `to`. Its token ID will be automatically
* assigned (and available on the emitted {IERC721-Transfer} event), and the token
* URI autogenerated based on the base URI passed at construction.
*
* See {ERC721-_mint}.
*
* Requirements:
*
* - the caller must have the `MINTER_ROLE`.
*/
function mint(
address to,
uint256 tokenId
) external virtual onlyRole(MINTER_ROLE) {
if (supplyLimit > 0) {
require(totalSupply() < supplyLimit, "Exceed the total supply");
}
_mint(to, tokenId);
function setBaseURI(
string memory baseURI_
) external onlyRole(DEFAULT_ADMIN_ROLE) {
_baseTokenURI = baseURI_;
}
/**
@ -63,19 +53,24 @@ contract BEBadge is AccessControl, ERC721Enumerable {
function batchMint(
address to,
uint256[] calldata tokenIds
) external onlyRole(MINTER_ROLE) {
uint256 count
) external onlyRole(MINTER_ROLE) returns (uint256[] memory) {
require(count <= 100, "tokenIds too many");
if (supplyLimit > 0) {
require(
(totalSupply() + tokenIds.length) <= supplyLimit,
(totalSupply() + count) <= supplyLimit,
"Exceed the total supply"
);
}
require(tokenIds.length <= 100, "tokenIds too many");
for (uint256 i = 0; i < tokenIds.length; i++) {
_mint(to, tokenIds[i]);
uint256[] memory tokenIds = new uint256[](count);
for (uint256 i = 0; i < count; i++) {
tokenIndex += 1;
uint256 tokenId = tokenIndex;
_safeMint(to, tokenId);
tokenIds[i] = tokenId;
}
emit BatchMint(to, tokenIds);
return tokenIds;
}
/**

View File

@ -5,36 +5,36 @@ const Distributor = artifacts.require("logic/NftDistributor");
const config = require("../config/config");
module.exports = async function (deployer, network, accounts) {
// await deployer.deploy(Badge, "BE Badge", "Badge", "0");
await deployer.deploy(Badge, "BE Badge", "Badge", "0");
const badgeInstance = await Badge.deployed();
// if (badgeInstance) {
// console.log("BEBadge successfully deployed. ");
// console.log("address: " + badgeInstance.address);
// }
// await badgeInstance.updateBaseURI(config.token.baseTokenURI);
if (badgeInstance) {
console.log("BEBadge successfully deployed. ");
console.log("address: " + badgeInstance.address);
}
await badgeInstance.updateBaseURI(config.token.baseTokenURI);
// await deployer.deploy(Coin, "BE test USDT", "USDT");
// const coinInstance = await Coin.deployed();
const coinInstance = await Coin.deployed();
// if (coinInstance) {
// console.log("BEUSDT successfully deployed. ");
// console.log("address: " + coinInstance.address);
// }
// await deployer.deploy(
// Wallet,
// 60,
// 1,
// config.admins.proposers,
// config.admins.confirmers,
// config.admins.executors
// );
await deployer.deploy(
Wallet,
60,
1,
config.admins.proposers,
config.admins.confirmers,
config.admins.executors
);
const walletInstance = await Wallet.deployed();
// if (walletInstance) {
// console.log("BEMultiSigWallet successfully deployed.");
// console.log("address: " + walletInstance.address);
// }
// await badgeInstance.setMintRole(walletInstance.address);
// console.log("success add wallet to badge's mint role");
// await coinInstance.setMintRole(walletInstance.address);
// console.log("success add wallet to usdt's mint role");
if (walletInstance) {
console.log("BEMultiSigWallet successfully deployed.");
console.log("address: " + walletInstance.address);
}
await badgeInstance.setMintRole(walletInstance.address);
console.log("success add wallet to badge's mint role");
await coinInstance.setMintRole(walletInstance.address);
console.log("success add wallet to usdt's mint role");
await deployer.deploy(
Distributor,