编译器
0.8.15+commit.e14f2714
文件 1 的 5: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;
}
}
文件 2 的 5:EnumerableSet.sol
pragma solidity ^0.8.0;
library EnumerableSet {
struct Set {
bytes32[] _values;
mapping(bytes32 => uint256) _indexes;
}
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
function _remove(Set storage set, bytes32 value) private returns (bool) {
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
set._values[toDeleteIndex] = lastValue;
set._indexes[lastValue] = valueIndex;
}
set._values.pop();
delete set._indexes[value];
return true;
} else {
return false;
}
}
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
struct Bytes32Set {
Set _inner;
}
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
struct AddressSet {
Set _inner;
}
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
assembly {
result := store
}
return result;
}
struct UintSet {
Set _inner;
}
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
assembly {
result := store
}
return result;
}
}
文件 3 的 5:Ownable.sol
pragma solidity ^0.8.0;
import "Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
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);
}
}
文件 4 的 5:SafeMath.sol
pragma solidity ^0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
文件 5 的 5:WVRHController.sol
pragma solidity ^0.8.0;
import "Ownable.sol";
import "SafeMath.sol";
import "EnumerableSet.sol";
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function mint(address account, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
}
interface VotingEscrow {
function create_lock(uint256 _value, uint256 _unlock_time) external;
function increase_amount(uint256 _value) external;
function increase_unlock_time(uint256 _unlock_time) external;
}
interface GasEscrow {
function create_gas(uint256 _value) external;
function increase_amount(uint256 _value) external;
function clear_gas() external;
}
interface Guild {
function join_guild() external;
function user_checkpoint(address addr) external returns (bool);
}
interface Minter {
function mint() external;
}
interface WVRHStakePool{
function notifyRewardAmount(uint256 reward) external;
}
contract WVRHController is Ownable {
using SafeMath for uint256;
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private operators;
event ConvertToWVRH(address sender, uint256 amount);
event ClaimVrh(uint256 bonusAmount, uint256 );
address public vrhAddress;
address public wvrhAddress;
address public votingEscrowAddress;
address public mohAddress;
address public gasEscrowAddress;
address public minterAddress;
uint256 public MAXTIME = 4 * 365 * 86400;
address public fundAddress;
uint256 public fundRatio;
uint256 private MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
address public poolAddress;
address public guildAddress;
constructor(address _vrhAddress, address _wvrhAddress, address _votingEscrowAddress, address _mohAddress, address _gasEscrowAddress,
address _minterAddress, address _fundAddress, uint256 _fundRatio, address _poolAddress){
vrhAddress = _vrhAddress;
wvrhAddress = _wvrhAddress;
votingEscrowAddress = _votingEscrowAddress;
mohAddress = _mohAddress;
gasEscrowAddress = _gasEscrowAddress;
minterAddress = _minterAddress;
fundAddress = _fundAddress;
fundRatio = _fundRatio;
poolAddress = _poolAddress;
IERC20(vrhAddress).approve(votingEscrowAddress, MAX_INT);
IERC20(mohAddress).approve(gasEscrowAddress, MAX_INT);
}
function addOperator(address _operator) external onlyOwner {
operators.add(_operator);
}
function deletedOperator(address _operator) external onlyOwner {
operators.remove(_operator);
}
function isOperator(address _operator) public view returns (bool){
return operators.contains(_operator);
}
modifier onlyOperator() {
require(isOperator(_msgSender()), "not operator");
_;
}
function setFundAddress(address _fundAddress) external onlyOwner {
fundAddress = _fundAddress;
}
function setFundRatio(uint256 _fundRatio) external onlyOwner {
fundRatio = _fundRatio;
}
function convertToWVRH(uint256 _amount) external{
require(_amount > 0, "amount invalid");
require(IERC20(vrhAddress).transferFrom(msg.sender, address(this), _amount));
IERC20(wvrhAddress).mint(msg.sender, _amount);
emit ConvertToWVRH(msg.sender, _amount);
}
function createVrhLock() external onlyOperator{
uint256 balance = IERC20(vrhAddress).balanceOf(address(this));
require(balance > 0, "balance invalid");
VotingEscrow(votingEscrowAddress).create_lock(balance, block.timestamp + MAXTIME);
}
function increaseVrhAmount() external onlyOperator{
uint256 balance = IERC20(vrhAddress).balanceOf(address(this));
require(balance > 0, "balance invalid");
VotingEscrow(votingEscrowAddress).increase_amount(balance);
}
function increaseVrhUnlockTime() external onlyOperator{
VotingEscrow(votingEscrowAddress).increase_unlock_time(block.timestamp + MAXTIME);
}
function createGas() external onlyOperator{
uint256 balance = IERC20(mohAddress).balanceOf(address(this));
require(balance > 0, "balance invalid");
GasEscrow(gasEscrowAddress).create_gas(balance);
}
function increaseGasAmount() external onlyOperator{
uint256 balance = IERC20(mohAddress).balanceOf(address(this));
require(balance > 0, "balance invalid");
GasEscrow(gasEscrowAddress).increase_amount(balance);
}
function clearGas() external onlyOperator{
GasEscrow(gasEscrowAddress).clear_gas();
}
function joinGuild(address _guildAddress) external onlyOperator{
Guild(_guildAddress).join_guild();
guildAddress = _guildAddress;
}
function updatePower() external onlyOperator{
require( Guild(guildAddress).user_checkpoint(address(this)) );
}
function claimVrh() external onlyOperator{
uint256 balanceBefore = IERC20(vrhAddress).balanceOf(address(this));
Minter(minterAddress).mint();
uint256 balanceAfter = IERC20(vrhAddress).balanceOf(address(this));
uint256 bonus = balanceAfter.sub(balanceBefore);
require(bonus > 0, "bonus invalid");
uint256 fund = bonus.mul(fundRatio).div(1000);
IERC20(vrhAddress).transfer(fundAddress, fund);
uint256 poolAmount = bonus.sub(fund);
IERC20(vrhAddress).transfer(poolAddress, poolAmount);
WVRHStakePool(poolAddress).notifyRewardAmount(poolAmount);
}
function addExtraReward(uint256 _amount) external onlyOperator{
require(_amount > 0, "amount invalid");
require(IERC20(vrhAddress).transferFrom(fundAddress, poolAddress, _amount));
WVRHStakePool(poolAddress).notifyRewardAmount(_amount);
}
}
{
"compilationTarget": {
"WVRHController.sol": "WVRHController"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_vrhAddress","type":"address"},{"internalType":"address","name":"_wvrhAddress","type":"address"},{"internalType":"address","name":"_votingEscrowAddress","type":"address"},{"internalType":"address","name":"_mohAddress","type":"address"},{"internalType":"address","name":"_gasEscrowAddress","type":"address"},{"internalType":"address","name":"_minterAddress","type":"address"},{"internalType":"address","name":"_fundAddress","type":"address"},{"internalType":"uint256","name":"_fundRatio","type":"uint256"},{"internalType":"address","name":"_poolAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"bonusAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"ClaimVrh","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ConvertToWVRH","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"MAXTIME","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"addExtraReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"addOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimVrh","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"clearGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"convertToWVRH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"createGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"createVrhLock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"deletedOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"fundAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fundRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gasEscrowAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"guildAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"increaseGasAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"increaseVrhAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"increaseVrhUnlockTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_guildAddress","type":"address"}],"name":"joinGuild","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minterAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mohAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_fundAddress","type":"address"}],"name":"setFundAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fundRatio","type":"uint256"}],"name":"setFundRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updatePower","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"votingEscrowAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vrhAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wvrhAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]