增加芯片升级逻辑
This commit is contained in:
parent
86e5ec2531
commit
defedda2e9
@ -17,5 +17,7 @@ interface IBEERC1155 is IERC1155 {
|
|||||||
uint256[] memory values
|
uint256[] memory values
|
||||||
) external;
|
) external;
|
||||||
|
|
||||||
|
function balanceOf(address account, uint256 id) external view returns (uint256);
|
||||||
|
|
||||||
function canMint(uint256 id) external view returns (bool);
|
function canMint(uint256 id) external view returns (bool);
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,5 @@ 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 burn(address owner, uint256 tokenId) external;
|
function burn(address owner, uint256 tokenId) external;
|
||||||
}
|
function ownerOf(uint256 tokenId) external view returns (address owner);
|
||||||
|
}
|
||||||
|
27
contracts/interfaces/IEvolveFactory.sol
Normal file
27
contracts/interfaces/IEvolveFactory.sol
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity 0.8.10;
|
||||||
|
import "../interfaces/IBEERC721.sol";
|
||||||
|
import "../interfaces/IBEERC1155.sol";
|
||||||
|
|
||||||
|
interface IEvolveFactory {
|
||||||
|
function evolve721NFT(
|
||||||
|
address to,
|
||||||
|
uint256[3] calldata tokenIds,
|
||||||
|
uint256 startTime,
|
||||||
|
uint256 saltNonce,
|
||||||
|
bytes calldata signature,
|
||||||
|
IBEERC721 nft
|
||||||
|
) external;
|
||||||
|
|
||||||
|
function evolveChip(
|
||||||
|
address to,
|
||||||
|
uint256[] memory tokenIds,
|
||||||
|
uint256 startTime,
|
||||||
|
uint256 saltNonce,
|
||||||
|
bytes calldata signature
|
||||||
|
) external;
|
||||||
|
|
||||||
|
function useSignature(
|
||||||
|
bytes calldata signature
|
||||||
|
) external;
|
||||||
|
}
|
@ -13,110 +13,134 @@ import "../core/HasSignature.sol";
|
|||||||
// all onlyowner method would add timelock
|
// all onlyowner method would add timelock
|
||||||
|
|
||||||
contract EvolveFactory is Ownable, TimeChecker, Initializable, HasSignature {
|
contract EvolveFactory is Ownable, TimeChecker, Initializable, HasSignature {
|
||||||
using UInt for uint256;
|
using UInt for uint256;
|
||||||
IBEERC721 public hero;
|
IBEERC721 public hero;
|
||||||
IBEERC721 public equip;
|
IBEERC721 public equip;
|
||||||
IBEERC1155 public chip;
|
IBEERC1155 public chip;
|
||||||
uint256 private _duration;
|
|
||||||
|
|
||||||
address public executor;
|
address public executor;
|
||||||
|
|
||||||
event TokenEvolved(
|
event TokenEvolved(
|
||||||
address indexed owner,
|
address indexed owner,
|
||||||
uint256[3] tokenIds
|
uint256[] tokenIds
|
||||||
|
);
|
||||||
|
|
||||||
|
constructor()
|
||||||
|
HasSignature("EvolveFactory", "1"){
|
||||||
|
}
|
||||||
|
|
||||||
|
function init(address[3] calldata _erc721s) external initializer onlyOwner {
|
||||||
|
hero = IBEERC721(_erc721s[0]);
|
||||||
|
equip = IBEERC721(_erc721s[1]);
|
||||||
|
chip = IBEERC1155(_erc721s[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev update executor
|
||||||
|
*/
|
||||||
|
function updateExecutor(address account) external onlyOwner {
|
||||||
|
require(account != address(0), 'address can not be zero');
|
||||||
|
executor = account;
|
||||||
|
}
|
||||||
|
|
||||||
|
function evolve721NFT(
|
||||||
|
address to,
|
||||||
|
uint256[3] calldata tokenIds,
|
||||||
|
uint256 startTime,
|
||||||
|
uint256 saltNonce,
|
||||||
|
bytes calldata signature,
|
||||||
|
IBEERC721 nft
|
||||||
|
) external signatureValid(signature) timeValid(startTime){
|
||||||
|
require(
|
||||||
|
tokenIds[0] > 0 && tokenIds[1] > 0,
|
||||||
|
"EvolveFactory: token to evolve and burn can not be 0"
|
||||||
);
|
);
|
||||||
|
|
||||||
constructor()
|
require(
|
||||||
HasSignature("EvolveFactory", "1"){
|
tokenIds[0] != tokenIds[1],
|
||||||
|
"EvolveFactory: token to evolve and burn can not be same"
|
||||||
|
);
|
||||||
|
|
||||||
|
require(
|
||||||
|
nft.ownerOf(tokenIds[0]) == to && nft.ownerOf(tokenIds[1]) == to,
|
||||||
|
"EvolveFactory: current address is not owner of this nft now"
|
||||||
|
);
|
||||||
|
if (tokenIds[2] > 0) {
|
||||||
|
require(
|
||||||
|
chip.balanceOf(to, tokenIds[2]) > 0,
|
||||||
|
"EvolveFactory: not enough chip"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(address[3] calldata _erc721s) external initializer onlyOwner {
|
uint256[] memory signArray = new uint256[](3);
|
||||||
hero = IBEERC721(_erc721s[0]);
|
for (uint256 i = 0; i < tokenIds.length; ++ i) {
|
||||||
equip = IBEERC721(_erc721s[1]);
|
uint256 _id = tokenIds[i];
|
||||||
chip = IBEERC1155(_erc721s[2]);
|
signArray[i] = _id;
|
||||||
}
|
}
|
||||||
|
bytes32 criteriaMessageHash = getMessageHash(
|
||||||
/**
|
to,
|
||||||
* @dev update executor
|
startTime,
|
||||||
*/
|
saltNonce,
|
||||||
function updateExecutor(address account) external onlyOwner {
|
signArray
|
||||||
require(account != address(0), 'address can not be zero');
|
);
|
||||||
executor = account;
|
checkSigner(executor, criteriaMessageHash, signature);
|
||||||
|
nft.burn(to, tokenIds[1]);
|
||||||
|
if (tokenIds[2] > 0) {
|
||||||
|
uint256 amount = 1;
|
||||||
|
chip.burnBatch(to,
|
||||||
|
tokenIds[2].asSingletonArray(),
|
||||||
|
amount.asSingletonArray());
|
||||||
}
|
}
|
||||||
|
useSignature(signature);
|
||||||
|
emit TokenEvolved(
|
||||||
|
to,
|
||||||
|
signArray
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function evolve721NFT(
|
function evolveChip(
|
||||||
address to,
|
address to,
|
||||||
uint256[3] calldata tokenIds,
|
uint256[] memory tokenIds,
|
||||||
uint256 startTime,
|
uint256 startTime,
|
||||||
uint256 saltNonce,
|
uint256 saltNonce,
|
||||||
bytes calldata signature,
|
bytes calldata signature
|
||||||
IBEERC721 nft
|
) external signatureValid(signature) timeValid(startTime){
|
||||||
) internal signatureValid(signature) timeValid(startTime){
|
require(to != address(0), "EvolveFacrory: address is zero address");
|
||||||
require(
|
uint256 len = tokenIds.length;
|
||||||
tokenIds[0] > 0 && tokenIds[1] > 0,
|
uint256[] memory amounts = new uint256[](len -1);
|
||||||
"EvolveFactory: equip to evolve and burn can not be 0"
|
uint256[] memory idsForBurn = new uint256[](len - 1);
|
||||||
);
|
for (uint256 i = 0; i < len; ++ i) {
|
||||||
|
require(
|
||||||
require(
|
chip.balanceOf(to, tokenIds[i]) > 0,
|
||||||
tokenIds[0] != tokenIds[1],
|
"EvolveFacrory: Chip specified not exists"
|
||||||
"EvolveFactory: equip to evolve and burn can not be same"
|
);
|
||||||
);
|
if (i > 0) {
|
||||||
|
idsForBurn[i - 1] = tokenIds[i];
|
||||||
require(
|
amounts[i - 1] = 1;
|
||||||
nft.ownerOf(tokenIds[0]) == to,
|
}
|
||||||
"EvolveFactory: current address is not owner of this nft now"
|
|
||||||
);
|
|
||||||
|
|
||||||
require(
|
|
||||||
nft.ownerOf(tokenIds[1]) == to,
|
|
||||||
"EvolveFactory: current address is not owner of this nft now"
|
|
||||||
);
|
|
||||||
if (tokenIds[2] > 0) {
|
|
||||||
require(
|
|
||||||
nft.ownerOf(tokenIds[2]) == to,
|
|
||||||
"EvolveFactory: current address is not owner of this nft now"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint256[] memory signArray = new uint256[](3);
|
|
||||||
for (uint256 i = 0; i < tokenIds.length; ++ i) {
|
|
||||||
signArray[i] = tokenIds[i];
|
|
||||||
}
|
|
||||||
bytes32 criteriaMessageHash = getMessageHash(
|
|
||||||
to,
|
|
||||||
startTime,
|
|
||||||
saltNonce,
|
|
||||||
signArray
|
|
||||||
);
|
|
||||||
checkSigner(executor, criteriaMessageHash, signature);
|
|
||||||
nft.burn(to, tokenIds[1]);
|
|
||||||
if (tokenIds[2] > 0) {
|
|
||||||
uint256 amount = 1;
|
|
||||||
chip.burnBatch(to,
|
|
||||||
tokenIds[2].asSingletonArray(),
|
|
||||||
amount.asSingletonArray());
|
|
||||||
}
|
|
||||||
useSignature(signature);
|
|
||||||
emit TokenEvolved(
|
|
||||||
to,
|
|
||||||
tokenIds
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
bytes32 criteriaMessageHash = getMessageHash(to, startTime, saltNonce, tokenIds);
|
||||||
|
checkSigner(executor, criteriaMessageHash, signature);
|
||||||
|
chip.burnBatch(to, idsForBurn, amounts);
|
||||||
|
useSignature(signature);
|
||||||
|
emit TokenEvolved(
|
||||||
|
to,
|
||||||
|
tokenIds
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMessageHash(
|
||||||
|
address _to,
|
||||||
function getMessageHash(
|
uint256 _startTime,
|
||||||
address _to,
|
uint256 _saltNonce,
|
||||||
uint256 _startTime,
|
uint256[] memory _ids
|
||||||
uint256 _saltNonce,
|
) public pure returns (bytes32) {
|
||||||
uint256[] memory _ids
|
bytes memory encoded = abi.encodePacked(_to, _startTime, _saltNonce);
|
||||||
) public pure returns (bytes32) {
|
uint256 len = _ids.length;
|
||||||
bytes memory encoded = abi.encodePacked(_to, _startTime, _saltNonce);
|
for (uint256 i = 0; i < len; ++i) {
|
||||||
uint256 len = _ids.length;
|
encoded = bytes.concat(encoded, abi.encodePacked(_ids[i]));
|
||||||
for (uint256 i = 0; i < len; ++i) {
|
|
||||||
encoded = bytes.concat(encoded, abi.encodePacked(_ids[i]));
|
|
||||||
}
|
|
||||||
return keccak256(encoded);
|
|
||||||
}
|
}
|
||||||
|
return keccak256(encoded);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,47 +2,138 @@
|
|||||||
pragma solidity 0.8.10;
|
pragma solidity 0.8.10;
|
||||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
||||||
import "../interfaces/INFTFactory.sol";
|
import "../interfaces/IEvolveFactory.sol";
|
||||||
import "../interfaces/IBEERC721.sol";
|
import "../interfaces/IBEERC721.sol";
|
||||||
import "../interfaces/IBEERC1155.sol";
|
import "../interfaces/IBEERC1155.sol";
|
||||||
|
|
||||||
contract UserEvolveFactory is Ownable, Initializable {
|
contract UserEvolveFactory is Ownable, Initializable {
|
||||||
|
IEvolveFactory factory;
|
||||||
IBEERC721 public hero;
|
IBEERC721 public hero;
|
||||||
IBEERC721 public equip;
|
IBEERC721 public equip;
|
||||||
IBEERC1155 public chip;
|
IBEERC1155 public chip;
|
||||||
IBEERC1155 public shard;
|
|
||||||
|
|
||||||
event TokenEvolveFail (
|
event TokenEvolveFail (
|
||||||
address indexed to,
|
address indexed to,
|
||||||
uint256 mainToken,
|
|
||||||
bytes signature,
|
bytes signature,
|
||||||
string reason,
|
string reason,
|
||||||
bytes byteReason
|
bytes byteReason
|
||||||
);
|
);
|
||||||
|
|
||||||
function init() external initializer onlyOwner {
|
function init(address[3] calldata _nfts) external initializer onlyOwner {
|
||||||
|
hero = IBEERC721(_nfts[0]);
|
||||||
|
equip = IBEERC721(_nfts[1]);
|
||||||
|
chip = IBEERC1155(_nfts[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev evolve function to Blissful Elites Hero NFT
|
* @dev evolve function Hero NFT
|
||||||
* tokenIds: [hero_to_evolve, hero_for_burn, chip]
|
* tokenIds: [hero_to_evolve, hero_for_burn, chip]
|
||||||
*/
|
*/
|
||||||
function evolveHero(
|
function evolveHero(
|
||||||
uint256[3] calldata tokenIds,
|
uint256[3] calldata tokenIds,
|
||||||
|
uint256 startTime,
|
||||||
uint256 saltNonce,
|
uint256 saltNonce,
|
||||||
bytes calldata signature
|
bytes calldata signature
|
||||||
) external {
|
) external returns (bool success){
|
||||||
|
address to = _msgSender();
|
||||||
|
try factory.evolve721NFT(to, tokenIds, startTime, saltNonce, signature, hero) {
|
||||||
|
return true;
|
||||||
|
} catch Error(string memory reason) {
|
||||||
|
bytes memory by;
|
||||||
|
factory.useSignature(signature);
|
||||||
|
emit TokenEvolveFail(
|
||||||
|
to,
|
||||||
|
signature,
|
||||||
|
reason,
|
||||||
|
by
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
} catch (bytes memory lowLevelData) {
|
||||||
|
factory.useSignature(signature);
|
||||||
|
string memory reason;
|
||||||
|
emit TokenEvolveFail(
|
||||||
|
to,
|
||||||
|
signature,
|
||||||
|
reason,
|
||||||
|
lowLevelData
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @dev evolve function to Blissful Elites Equip NFT
|
* @dev evolve function for equip NFT
|
||||||
* tokenIds: [equip_to_evolve, equip_for_burn, chip]
|
* tokenIds: [equip_to_evolve, equip_for_burn, chip]
|
||||||
*/
|
*/
|
||||||
function evolveEquip(
|
function evolveEquip(
|
||||||
uint256[3] calldata tokenIds,
|
uint256[3] calldata tokenIds,
|
||||||
|
uint256 startTime,
|
||||||
uint256 saltNonce,
|
uint256 saltNonce,
|
||||||
bytes calldata signature
|
bytes calldata signature
|
||||||
) external{
|
) external returns (bool success){
|
||||||
|
address to = _msgSender();
|
||||||
|
try factory.evolve721NFT(to, tokenIds, startTime, saltNonce, signature, equip) {
|
||||||
|
return true;
|
||||||
|
} catch Error(string memory reason) {
|
||||||
|
bytes memory by;
|
||||||
|
factory.useSignature(signature);
|
||||||
|
emit TokenEvolveFail(
|
||||||
|
to,
|
||||||
|
signature,
|
||||||
|
reason,
|
||||||
|
by
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
} catch (bytes memory lowLevelData) {
|
||||||
|
factory.useSignature(signature);
|
||||||
|
string memory reason;
|
||||||
|
emit TokenEvolveFail(
|
||||||
|
to,
|
||||||
|
signature,
|
||||||
|
reason,
|
||||||
|
lowLevelData
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev evolve function for chip
|
||||||
|
*/
|
||||||
|
function evolveChip(
|
||||||
|
uint256[] memory ids,
|
||||||
|
uint256 startTime,
|
||||||
|
uint256 saltNonce,
|
||||||
|
bytes calldata signature
|
||||||
|
) external returns (bool success){
|
||||||
|
address to = _msgSender();
|
||||||
|
try factory.evolveChip(
|
||||||
|
to,
|
||||||
|
ids,
|
||||||
|
startTime,
|
||||||
|
saltNonce,
|
||||||
|
signature
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} catch Error(string memory reason) {
|
||||||
|
bytes memory by;
|
||||||
|
factory.useSignature(signature);
|
||||||
|
emit TokenEvolveFail(
|
||||||
|
to,
|
||||||
|
signature,
|
||||||
|
reason,
|
||||||
|
by
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
} catch (bytes memory lowLevelData) {
|
||||||
|
factory.useSignature(signature);
|
||||||
|
string memory reason;
|
||||||
|
emit TokenEvolveFail(
|
||||||
|
to,
|
||||||
|
signature,
|
||||||
|
reason,
|
||||||
|
lowLevelData
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,18 @@ contract UserMinterFactory is Ownable, Initializable {
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @dev mint hero or equip with shard
|
||||||
|
*/
|
||||||
|
function shardMixByUser(
|
||||||
|
uint256[] memory ids,
|
||||||
|
uint256[] memory amounts,
|
||||||
|
uint256 startTime,
|
||||||
|
uint256 saltNonce,
|
||||||
|
bytes calldata signature
|
||||||
|
) external returns (bool success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user