文件 1 的 8:ArraySort.sol
pragma solidity ^0.8.7;
library ArraySort {
function sort(bytes32[] memory array) public pure returns (bytes32[] memory) {
_quickSort(array, 0, array.length);
return array;
}
function _quickSort(
bytes32[] memory array,
uint256 i,
uint256 j
) private pure {
if (j - i < 2) return;
uint256 p = i;
for (uint256 k = i + 1; k < j; ++k) {
if (array[i] > array[k]) {
_swap(array, ++p, k);
}
}
_swap(array, i, p);
_quickSort(array, i, p);
_quickSort(array, p + 1, j);
}
function _swap(
bytes32[] memory array,
uint256 i,
uint256 j
) private pure {
(array[i], array[j]) = (array[j], array[i]);
}
}
文件 2 的 8:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 3 的 8:ILL420BudStaking.sol
pragma solidity ^0.8.4;
interface ILL420BudStaking {
function setRevealedTHC(uint256[] calldata _ids, uint256[] calldata _thc) external;
function getBudInfo(uint256[] memory _ids) external view returns (uint256[] memory, uint256[] memory);
function getGKBuds(uint256 _id, address _user) external view returns (uint256[] memory);
function setRevealTimestamps(uint256 _timestamp, address _address) external;
}
文件 4 的 8:LL420BudReveal.sol
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./interfaces/ILL420BudStaking.sol";
import "./libraries/MerkleMultiProof.sol";
import "./libraries/ArraySort.sol";
contract LL420BudReveal is Ownable, Pausable, ReentrancyGuard {
uint16 public constant TOTAL_SUPPLY = 20000;
uint256 public revealPeriod = 7 days;
bytes32 public merkleRoot;
address public immutable stakingContractAddress;
mapping(uint256 => bool) public requested;
event RequestReveal(uint256 indexed _budId, address indexed _user, uint256 indexed _timestamp);
constructor(address _stakingAddress) {
require(_stakingAddress != address(0), "Zero address");
stakingContractAddress = _stakingAddress;
}
function reveal(uint256 _id, uint256[] memory _ids) external nonReentrant whenNotPaused {
require(_ids.length <= TOTAL_SUPPLY, "Incorrect bud ids");
uint256 _revealPeriod = revealPeriod;
ILL420BudStaking BUD_STAKING = ILL420BudStaking(stakingContractAddress);
uint256[] memory budIds = BUD_STAKING.getGKBuds(_id, _msgSender());
for (uint256 i = 0; i < _ids.length; i++) {
require(!requested[_ids[i]], "Bud is already requested to reveal");
bool belong = false;
for (uint256 j = 0; j < budIds.length; j++) {
if (_ids[i] == budIds[j]) {
belong = true;
break;
}
}
require(belong, "Bud not belong to the sender");
}
(uint256[] memory periods, ) = BUD_STAKING.getBudInfo(_ids);
for (uint256 i = 0; i < periods.length; i++) {
require(periods[i] >= _revealPeriod, "Staked more than limit");
requested[_ids[i]] = true;
emit RequestReveal(_ids[i], _msgSender(), block.timestamp);
}
BUD_STAKING.setRevealTimestamps(block.timestamp, _msgSender());
}
function setBudTHCs(
uint256[] calldata _ids,
uint256[] calldata _thcs,
bytes32[] calldata _proofs,
bool[] calldata _proofFlags
) external whenNotPaused nonReentrant {
require(_ids.length == _thcs.length && _ids.length > 0, "Unmatched thc count");
require(merkleRoot != 0, "Merklet root not set");
bytes32[] memory nodes = new bytes32[](_ids.length);
uint256 factor = 10**18;
for (uint256 i = 0; i < _ids.length; i++) {
nodes[i] = keccak256(abi.encodePacked(_ids[i] * factor, _thcs[i] * factor));
}
nodes = ArraySort.sort(nodes);
bool isValid = MerkleMultiProof.verifyMultiProof(merkleRoot, nodes, _proofs, _proofFlags);
require(isValid, "Invalid proof");
ILL420BudStaking(stakingContractAddress).setRevealedTHC(_ids, _thcs);
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
function setRevealPeriod(uint256 _seconds) external onlyOwner {
revealPeriod = _seconds;
}
function setMerkleRoot(bytes32 _merkleRoot) external onlyOwner {
merkleRoot = _merkleRoot;
}
}
文件 5 的 8:MerkleMultiProof.sol
pragma solidity ^0.8.7;
library MerkleMultiProof {
function calculateMultiMerkleRoot(
bytes32[] memory leafs,
bytes32[] memory proofs,
bool[] memory proofFlag
) public pure returns (bytes32 merkleRoot) {
uint256 leafsLen = leafs.length;
uint256 totalHashes = proofFlag.length;
bytes32[] memory hashes = new bytes32[](totalHashes);
uint256 leafPos = 0;
uint256 hashPos = 0;
uint256 proofPos = 0;
for (uint256 i = 0; i < totalHashes; i++) {
hashes[i] = hashPair(
proofFlag[i] ? (leafPos < leafsLen ? leafs[leafPos++] : hashes[hashPos++]) : proofs[proofPos++],
leafPos < leafsLen ? leafs[leafPos++] : hashes[hashPos++]
);
}
return hashes[totalHashes - 1];
}
function hashPair(bytes32 a, bytes32 b) private pure returns (bytes32) {
return a < b ? hash_node(a, b) : hash_node(b, a);
}
function hash_node(bytes32 left, bytes32 right) private pure returns (bytes32 hash) {
assembly {
mstore(0x00, left)
mstore(0x20, right)
hash := keccak256(0x00, 0x40)
}
return hash;
}
function verifyMultiProof(
bytes32 root,
bytes32[] memory leafs,
bytes32[] memory proofs,
bool[] memory proofFlag
) public pure returns (bool) {
return calculateMultiMerkleRoot(leafs, proofs, proofFlag) == root;
}
}
文件 6 的 8:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 7 的 8:Pausable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor() {
_paused = false;
}
function paused() public view virtual returns (bool) {
return _paused;
}
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
文件 8 的 8:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
{
"compilationTarget": {
"contracts/LL420BudReveal.sol": "LL420BudReveal"
},
"evmVersion": "london",
"libraries": {
"contracts/libraries/ArraySort.sol:ArraySort": "0xf63ab13dc8ce2009a6a0ed86f84b2df2c30257fd",
"contracts/libraries/MerkleMultiProof.sol:MerkleMultiProof": "0x8e613763d253713e221ada487542171fedbd29e5"
},
"metadata": {
"bytecodeHash": "none"
},
"optimizer": {
"enabled": true,
"runs": 800
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_stakingAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_budId","type":"uint256"},{"indexed":true,"internalType":"address","name":"_user","type":"address"},{"indexed":true,"internalType":"uint256","name":"_timestamp","type":"uint256"}],"name":"RequestReveal","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"TOTAL_SUPPLY","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"merkleRoot","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requested","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_id","type":"uint256"},{"internalType":"uint256[]","name":"_ids","type":"uint256[]"}],"name":"reveal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revealPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_ids","type":"uint256[]"},{"internalType":"uint256[]","name":"_thcs","type":"uint256[]"},{"internalType":"bytes32[]","name":"_proofs","type":"bytes32[]"},{"internalType":"bool[]","name":"_proofFlags","type":"bool[]"}],"name":"setBudTHCs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_merkleRoot","type":"bytes32"}],"name":"setMerkleRoot","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_seconds","type":"uint256"}],"name":"setRevealPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakingContractAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"}]