增加一个用721芯片换取1155的接口
This commit is contained in:
parent
c8c67ff227
commit
f2302b3076
File diff suppressed because one or more lines are too long
@ -15,11 +15,20 @@ interface IMintableERC1155 is IERC1155 {
|
|||||||
bytes memory data
|
bytes memory data
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function mint(
|
||||||
|
address to,
|
||||||
|
uint256 id,
|
||||||
|
uint256 amount,
|
||||||
|
bytes memory data
|
||||||
|
) external;
|
||||||
|
|
||||||
function burn(
|
function burn(
|
||||||
address owner,
|
address owner,
|
||||||
uint256 tokenId,
|
uint256 tokenId,
|
||||||
uint256 amount
|
uint256 amount
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function exists(uint256 id) external view returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IBurnableERC721 is IERC721 {
|
interface IBurnableERC721 is IERC721 {
|
||||||
@ -41,15 +50,22 @@ contract BEChipFactory is Ownable, Initializable, HasSignature {
|
|||||||
uint256[] ids
|
uint256[] ids
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event Chip1155Activate(
|
||||||
|
address indexed to,
|
||||||
|
uint256 indexed nftOld,
|
||||||
|
uint256 nftNew
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
constructor() HasSignature("BEChipFactory", "1") {}
|
constructor() HasSignature("BEChipFactory", "1") {}
|
||||||
|
|
||||||
function init(address _erc1155)
|
function init(address _erc1155, address _erc721)
|
||||||
external
|
external
|
||||||
initializer
|
initializer
|
||||||
onlyOwner
|
onlyOwner
|
||||||
{
|
{
|
||||||
chip = IMintableERC1155(_erc1155);
|
chip = IMintableERC1155(_erc1155);
|
||||||
|
chipOld = IBurnableERC721(_erc721);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +99,7 @@ contract BEChipFactory is Ownable, Initializable, HasSignature {
|
|||||||
require(ids.length > 0, "BEChipFactory: ids cannot be empty");
|
require(ids.length > 0, "BEChipFactory: ids cannot be empty");
|
||||||
require(
|
require(
|
||||||
!usedSignatures[signature],
|
!usedSignatures[signature],
|
||||||
"BEChipFactory: signature used. please send another transaction with new signature"
|
"BEChipFactory:: mintChipSelf: signature used. please send another transaction with new signature"
|
||||||
);
|
);
|
||||||
address to = _msgSender();
|
address to = _msgSender();
|
||||||
bytes32 criteriaMessageHash = getMessageHash(
|
bytes32 criteriaMessageHash = getMessageHash(
|
||||||
@ -102,6 +118,37 @@ contract BEChipFactory is Ownable, Initializable, HasSignature {
|
|||||||
emit Chip1155Minted(address(chip), to, ids);
|
emit Chip1155Minted(address(chip), to, ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function activateOneChip(
|
||||||
|
uint256[] memory ids,
|
||||||
|
uint256 saltNonce,
|
||||||
|
bytes calldata signature
|
||||||
|
) external{
|
||||||
|
require(ids.length == 2, "BEChipFactory: ids length mismatch");
|
||||||
|
require(
|
||||||
|
!usedSignatures[signature],
|
||||||
|
"BEChipFactory:: activateOneChip: signature used. please send another transaction with new signature"
|
||||||
|
);
|
||||||
|
address to = _msgSender();
|
||||||
|
require(
|
||||||
|
chipOld.ownerOf(ids[1]) == to,
|
||||||
|
"BEChipFactory: only owner can activate this nft"
|
||||||
|
);
|
||||||
|
require(
|
||||||
|
!chip.exists(ids[0]),
|
||||||
|
"BEChipFactory: 1155 nftid duplicated"
|
||||||
|
);
|
||||||
|
|
||||||
|
bytes32 criteriaMessageHash = getMessageHash(
|
||||||
|
to,
|
||||||
|
saltNonce,
|
||||||
|
ids
|
||||||
|
);
|
||||||
|
checkSigner(executor, criteriaMessageHash, signature);
|
||||||
|
usedSignatures[signature] = true;
|
||||||
|
chip.mint(to, ids[0], 1, "");
|
||||||
|
chipOld.burn(to, ids[1]);
|
||||||
|
emit Chip1155Activate(to, ids[1], ids[0]);
|
||||||
|
}
|
||||||
|
|
||||||
function getMessageHash(
|
function getMessageHash(
|
||||||
address _to,
|
address _to,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const Chip = artifacts.require('chip1155/BEChip1155');
|
const Chip = artifacts.require('chip1155/BEChip1155');
|
||||||
|
const Chip721 = artifacts.require('BEChip');
|
||||||
const ChipFactory = artifacts.require('chip1155/BEChipFactory');
|
const ChipFactory = artifacts.require('chip1155/BEChipFactory');
|
||||||
const config = require("../config/config");
|
const config = require("../config/config");
|
||||||
|
|
||||||
@ -13,11 +14,13 @@ module.exports = async function (deployer, network, accounts) {
|
|||||||
if(factoryInstance) {
|
if(factoryInstance) {
|
||||||
console.log("Chip 1155 Factory successfully deployed.")
|
console.log("Chip 1155 Factory successfully deployed.")
|
||||||
}
|
}
|
||||||
await factoryInstance.init(chipInstance.address);
|
const chip721Instance = await Chip721.deployed();
|
||||||
|
await factoryInstance.init(chipInstance.address, chip721Instance.address);
|
||||||
await factoryInstance.updateExecutor(config.admins.admin);
|
await factoryInstance.updateExecutor(config.admins.admin);
|
||||||
console.log("Chip 1155 Factory successfully update setting.")
|
console.log("Chip 1155 Factory successfully update setting.")
|
||||||
await chipInstance.setMintFactory(factoryInstance.address);
|
await chipInstance.setMintFactory(factoryInstance.address);
|
||||||
console.log("Chip 1155 successfully update factory.")
|
console.log("Chip 1155 successfully update factory.")
|
||||||
await chipInstance.grantLockRole(config.admins.admin);
|
await chipInstance.grantLockRole(config.admins.admin);
|
||||||
console.log("Chip 1155 successfully grantLockRole.")
|
console.log("Chip 1155 successfully grantLockRole.")
|
||||||
|
await chip721Instance.setBurnProxy(factoryInstance.address);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user