修改badge的nftid的生成方式, 改由合约生成
This commit is contained in:
parent
5b64f2494e
commit
d35db0b407
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -16789,7 +16789,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"schemaVersion": "3.4.11",
|
"schemaVersion": "3.4.11",
|
||||||
"updatedAt": "2023-04-19T02:14:02.502Z",
|
"updatedAt": "2023-04-23T02:44:39.968Z",
|
||||||
"networkType": "ethereum",
|
"networkType": "ethereum",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"kind": "dev",
|
"kind": "dev",
|
||||||
|
@ -3235,7 +3235,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"schemaVersion": "3.4.11",
|
"schemaVersion": "3.4.11",
|
||||||
"updatedAt": "2023-04-19T02:14:02.528Z",
|
"updatedAt": "2023-04-23T02:44:39.989Z",
|
||||||
"networkType": "ethereum",
|
"networkType": "ethereum",
|
||||||
"devdoc": {
|
"devdoc": {
|
||||||
"kind": "dev",
|
"kind": "dev",
|
||||||
|
File diff suppressed because one or more lines are too long
@ -6,8 +6,6 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
|
|||||||
* MultiSigWallet with timelocker
|
* MultiSigWallet with timelocker
|
||||||
*/
|
*/
|
||||||
contract BEMultiSigWallet is AccessControlEnumerable {
|
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 PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
|
||||||
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
|
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
|
||||||
bytes32 public constant CONFIRM_ROLE = keccak256("CONFIRM_ROLE");
|
bytes32 public constant CONFIRM_ROLE = keccak256("CONFIRM_ROLE");
|
||||||
@ -64,14 +62,13 @@ contract BEMultiSigWallet is AccessControlEnumerable {
|
|||||||
address[] memory confirmers,
|
address[] memory confirmers,
|
||||||
address[] memory executors
|
address[] memory executors
|
||||||
) {
|
) {
|
||||||
_setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);
|
_setRoleAdmin(PROPOSER_ROLE, DEFAULT_ADMIN_ROLE);
|
||||||
_setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);
|
_setRoleAdmin(EXECUTOR_ROLE, DEFAULT_ADMIN_ROLE);
|
||||||
_setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);
|
_setRoleAdmin(CONFIRM_ROLE, DEFAULT_ADMIN_ROLE);
|
||||||
_setRoleAdmin(CONFIRM_ROLE, TIMELOCK_ADMIN_ROLE);
|
|
||||||
|
|
||||||
// deployer + self administration
|
// deployer + self administration
|
||||||
_setupRole(TIMELOCK_ADMIN_ROLE, _msgSender());
|
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
|
||||||
_setupRole(TIMELOCK_ADMIN_ROLE, address(this));
|
_setupRole(DEFAULT_ADMIN_ROLE, address(this));
|
||||||
|
|
||||||
// register proposers
|
// register proposers
|
||||||
for (uint256 i = 0; i < proposers.length; ++i) {
|
for (uint256 i = 0; i < proposers.length; ++i) {
|
||||||
|
@ -6,7 +6,10 @@ import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|||||||
interface IBEERC721 is IERC721 {
|
interface IBEERC721 is IERC721 {
|
||||||
function mint(address to, uint256 tokenId) external;
|
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;
|
function burn(address owner, uint256 tokenId) external;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
|
|||||||
import "../interfaces/IBEERC721.sol";
|
import "../interfaces/IBEERC721.sol";
|
||||||
|
|
||||||
contract NftDistributor is AccessControlEnumerable {
|
contract NftDistributor is AccessControlEnumerable {
|
||||||
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
|
|
||||||
bytes32 public constant MANAGE_ROLE = keccak256("MANAGE_ROLE");
|
bytes32 public constant MANAGE_ROLE = keccak256("MANAGE_ROLE");
|
||||||
|
|
||||||
// user address => nft ids
|
// user address => nft ids
|
||||||
@ -34,12 +33,10 @@ contract NftDistributor is AccessControlEnumerable {
|
|||||||
*/
|
*/
|
||||||
constructor(address _nftTarget, address[] memory _manageAddress) {
|
constructor(address _nftTarget, address[] memory _manageAddress) {
|
||||||
// Set up the ADMIN_ROLE and MANAGE_ROLE
|
// Set up the ADMIN_ROLE and MANAGE_ROLE
|
||||||
_setRoleAdmin(ADMIN_ROLE, ADMIN_ROLE);
|
_setRoleAdmin(MANAGE_ROLE, DEFAULT_ADMIN_ROLE);
|
||||||
_setRoleAdmin(MANAGE_ROLE, ADMIN_ROLE);
|
|
||||||
|
|
||||||
// Grant the ADMIN_ROLE to the deployer and to the contract itself
|
// Grant the ADMIN_ROLE to the deployer and to the contract itself
|
||||||
_setupRole(ADMIN_ROLE, _msgSender());
|
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
|
||||||
_setupRole(ADMIN_ROLE, address(this));
|
|
||||||
|
|
||||||
// Grant the MANAGE_ROLE to the specified address
|
// Grant the MANAGE_ROLE to the specified address
|
||||||
for (uint256 i = 0; i < _manageAddress.length; ++i) {
|
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.
|
* Then it emits the Minted event with details of the operation.
|
||||||
*
|
*
|
||||||
* @param _user - The address of the user receiving the NFTs
|
* @param _user - The address of the user receiving the NFTs
|
||||||
* @param _nftIds - An array of the IDs for the NFTs being minted
|
|
||||||
*/
|
*/
|
||||||
function mintToUser(
|
function mintToUser(address _user, uint256 count) external onlyManager {
|
||||||
address _user,
|
|
||||||
uint256[] calldata _nftIds
|
|
||||||
) external onlyManager {
|
|
||||||
// Check that there are enough mintable NFTs
|
// Check that there are enough mintable NFTs
|
||||||
require(
|
require(count <= getMintableCount(_user), "Mintable count is not enough");
|
||||||
_nftIds.length <= getMintableCount(_user),
|
|
||||||
"Mintable count is not enough"
|
|
||||||
);
|
|
||||||
// Get the array of the user's owned NFTs
|
// Get the array of the user's owned NFTs
|
||||||
uint256[] memory nfts = ownerToNFTs[_user];
|
uint256[] memory nfts = ownerToNFTs[_user];
|
||||||
// Initialize variables
|
// Initialize variables
|
||||||
uint256 index = 0;
|
uint256 index = 0;
|
||||||
uint256[] memory nftSource = new uint256[](_nftIds.length);
|
uint256[] memory nftSource = new uint256[](count);
|
||||||
|
|
||||||
// Loop through the user's owned NFTs
|
// Loop through the user's owned NFTs
|
||||||
for (uint256 i = 0; i < nfts.length; i++) {
|
for (uint256 i = 0; i < nfts.length; i++) {
|
||||||
uint256 nftSId = nfts[i];
|
uint256 nftSId = nfts[i];
|
||||||
|
|
||||||
// Check if the NFT is mintable
|
// Check if the NFT is mintable
|
||||||
if (!nftMinted[nftSId]) {
|
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
|
// Add the NFT's source ID to the list of sources
|
||||||
nftSource[index] = nftSId;
|
nftSource[index] = nftSId;
|
||||||
nftMinted[nftSId] = true;
|
nftMinted[nftSId] = true;
|
||||||
// Mint the NFT to the user's address
|
// Mint the NFT to the user's address
|
||||||
nft.mint(_user, nftId);
|
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uint256[] memory _nftIds = nft.batchMint(_user, count);
|
||||||
// Emit event with details of the minting operation
|
// Emit event with details of the minting operation
|
||||||
emit Minted(_user, address(nft), nftSource, _nftIds);
|
emit Minted(_user, address(nft), nftSource, _nftIds);
|
||||||
}
|
}
|
||||||
|
@ -10,46 +10,36 @@ contract BEBadge is AccessControl, ERC721Enumerable {
|
|||||||
bytes32 public constant BURN_ROLE = keccak256("BURN_ROLE");
|
bytes32 public constant BURN_ROLE = keccak256("BURN_ROLE");
|
||||||
bytes32 public constant LOCK_ROLE = keccak256("LOCK_ROLE");
|
bytes32 public constant LOCK_ROLE = keccak256("LOCK_ROLE");
|
||||||
uint256 public immutable supplyLimit;
|
uint256 public immutable supplyLimit;
|
||||||
|
uint256 tokenIndex;
|
||||||
|
|
||||||
event Lock(uint256 indexed tokenId);
|
event Lock(uint256 indexed tokenId);
|
||||||
event UnLock(uint256 indexed tokenId);
|
event UnLock(uint256 indexed tokenId);
|
||||||
event BatchMint(address indexed to, uint256[] tokenIds);
|
event BatchMint(address indexed to, uint256[] tokenIds);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
string memory name_,
|
string memory _name,
|
||||||
string memory symbol_,
|
string memory _symbol,
|
||||||
uint256 supplyLimt_
|
uint256 _supplyLimt
|
||||||
) ERC721(name_, symbol_) {
|
) 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(DEFAULT_ADMIN_ROLE, msg.sender);
|
||||||
_setupRole(MINTER_ROLE, msg.sender);
|
_setupRole(MINTER_ROLE, msg.sender);
|
||||||
_setupRole(BURN_ROLE, msg.sender);
|
_setupRole(BURN_ROLE, msg.sender);
|
||||||
_setupRole(LOCK_ROLE, msg.sender);
|
_setupRole(LOCK_ROLE, msg.sender);
|
||||||
supplyLimit = supplyLimt_;
|
supplyLimit = _supplyLimt;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _baseURI() internal view virtual override returns (string memory) {
|
function _baseURI() internal view virtual override returns (string memory) {
|
||||||
return _baseTokenURI;
|
return _baseTokenURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
function setBaseURI(
|
||||||
* @dev Creates a new token for `to`. Its token ID will be automatically
|
string memory baseURI_
|
||||||
* assigned (and available on the emitted {IERC721-Transfer} event), and the token
|
) external onlyRole(DEFAULT_ADMIN_ROLE) {
|
||||||
* URI autogenerated based on the base URI passed at construction.
|
_baseTokenURI = baseURI_;
|
||||||
*
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,19 +53,24 @@ contract BEBadge is AccessControl, ERC721Enumerable {
|
|||||||
|
|
||||||
function batchMint(
|
function batchMint(
|
||||||
address to,
|
address to,
|
||||||
uint256[] calldata tokenIds
|
uint256 count
|
||||||
) external onlyRole(MINTER_ROLE) {
|
) external onlyRole(MINTER_ROLE) returns (uint256[] memory) {
|
||||||
|
require(count <= 100, "tokenIds too many");
|
||||||
if (supplyLimit > 0) {
|
if (supplyLimit > 0) {
|
||||||
require(
|
require(
|
||||||
(totalSupply() + tokenIds.length) <= supplyLimit,
|
(totalSupply() + count) <= supplyLimit,
|
||||||
"Exceed the total supply"
|
"Exceed the total supply"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
require(tokenIds.length <= 100, "tokenIds too many");
|
uint256[] memory tokenIds = new uint256[](count);
|
||||||
for (uint256 i = 0; i < tokenIds.length; i++) {
|
for (uint256 i = 0; i < count; i++) {
|
||||||
_mint(to, tokenIds[i]);
|
tokenIndex += 1;
|
||||||
|
uint256 tokenId = tokenIndex;
|
||||||
|
_safeMint(to, tokenId);
|
||||||
|
tokenIds[i] = tokenId;
|
||||||
}
|
}
|
||||||
emit BatchMint(to, tokenIds);
|
emit BatchMint(to, tokenIds);
|
||||||
|
return tokenIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,36 +5,36 @@ const Distributor = artifacts.require("logic/NftDistributor");
|
|||||||
const config = require("../config/config");
|
const config = require("../config/config");
|
||||||
|
|
||||||
module.exports = async function (deployer, network, accounts) {
|
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();
|
const badgeInstance = await Badge.deployed();
|
||||||
// if (badgeInstance) {
|
if (badgeInstance) {
|
||||||
// console.log("BEBadge successfully deployed. ");
|
console.log("BEBadge successfully deployed. ");
|
||||||
// console.log("address: " + badgeInstance.address);
|
console.log("address: " + badgeInstance.address);
|
||||||
// }
|
}
|
||||||
// await badgeInstance.updateBaseURI(config.token.baseTokenURI);
|
await badgeInstance.updateBaseURI(config.token.baseTokenURI);
|
||||||
// await deployer.deploy(Coin, "BE test USDT", "USDT");
|
// await deployer.deploy(Coin, "BE test USDT", "USDT");
|
||||||
// const coinInstance = await Coin.deployed();
|
const coinInstance = await Coin.deployed();
|
||||||
// if (coinInstance) {
|
// if (coinInstance) {
|
||||||
// console.log("BEUSDT successfully deployed. ");
|
// console.log("BEUSDT successfully deployed. ");
|
||||||
// console.log("address: " + coinInstance.address);
|
// console.log("address: " + coinInstance.address);
|
||||||
// }
|
// }
|
||||||
// await deployer.deploy(
|
await deployer.deploy(
|
||||||
// Wallet,
|
Wallet,
|
||||||
// 60,
|
60,
|
||||||
// 1,
|
1,
|
||||||
// config.admins.proposers,
|
config.admins.proposers,
|
||||||
// config.admins.confirmers,
|
config.admins.confirmers,
|
||||||
// config.admins.executors
|
config.admins.executors
|
||||||
// );
|
);
|
||||||
const walletInstance = await Wallet.deployed();
|
const walletInstance = await Wallet.deployed();
|
||||||
// if (walletInstance) {
|
if (walletInstance) {
|
||||||
// console.log("BEMultiSigWallet successfully deployed.");
|
console.log("BEMultiSigWallet successfully deployed.");
|
||||||
// console.log("address: " + walletInstance.address);
|
console.log("address: " + walletInstance.address);
|
||||||
// }
|
}
|
||||||
// await badgeInstance.setMintRole(walletInstance.address);
|
await badgeInstance.setMintRole(walletInstance.address);
|
||||||
// console.log("success add wallet to badge's mint role");
|
console.log("success add wallet to badge's mint role");
|
||||||
// await coinInstance.setMintRole(walletInstance.address);
|
await coinInstance.setMintRole(walletInstance.address);
|
||||||
// console.log("success add wallet to usdt's mint role");
|
console.log("success add wallet to usdt's mint role");
|
||||||
|
|
||||||
await deployer.deploy(
|
await deployer.deploy(
|
||||||
Distributor,
|
Distributor,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user