编译器
0.8.19+commit.7dd6d404
文件 1 的 7: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 的 7:IDistributor.sol
pragma solidity 0.8.19;
interface IDistributor {
function distribute() external;
function nextRewardAt(uint256 _rate) external view returns (uint256);
function nextVECReward() external view returns (uint256);
}
文件 3 的 7:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
文件 4 的 7:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 5 的 7:IsVEC.sol
pragma solidity 0.8.19;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IsVEC is IERC20 {
function rebase(uint256 amount_, uint epoch_) external returns (uint256);
function circulatingSupply() external view returns (uint256);
function gonsForBalance(uint amount) external view returns (uint);
function balanceForGons(uint gons) external view returns (uint);
function index() external view returns (uint);
}
文件 6 的 7: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());
}
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);
}
}
文件 7 的 7:VECStaking.sol
pragma solidity 0.8.19;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "../interface/IsVEC.sol";
import "../interface/IDistributor.sol";
contract VECStaking is Ownable {
event DistributorSet(address distributor);
event Stake(address indexed from, address indexed to, uint256 amount);
event Unstake(address indexed from, address indexed to, uint256 amount);
event EpochTriggerd(uint256 newEpoch);
struct Epoch {
uint256 length;
uint256 number;
uint256 end;
uint256 distribute;
}
IERC20 public immutable VEC;
IsVEC public immutable sVEC;
Epoch public epoch;
IDistributor public distributor;
constructor(
address _VEC,
address _sVEC,
uint256 _epochLength,
uint256 _secondsTillFirstEpoch
) {
VEC = IERC20(_VEC);
sVEC = IsVEC(_sVEC);
epoch = Epoch({
length: _epochLength,
number: 0,
end: block.timestamp + _secondsTillFirstEpoch,
distribute: 0
});
}
function stake(address _to, uint256 _amount) external {
rebase();
VEC.transferFrom(msg.sender, address(this), _amount);
sVEC.transfer(_to, _amount);
emit Stake(msg.sender, _to, _amount);
}
function unstake(address _to, uint256 _amount, bool _rebase) external {
if (_rebase) rebase();
sVEC.transferFrom(msg.sender, address(this), _amount);
require(
_amount <= VEC.balanceOf(address(this)),
"Insufficient VEC balance in contract"
);
VEC.transfer(_to, _amount);
emit Unstake(msg.sender, _to, _amount);
}
function rebase() public {
if (epoch.end <= block.timestamp) {
sVEC.rebase(epoch.distribute, epoch.number);
epoch.end = epoch.end + epoch.length;
epoch.number++;
if (address(distributor) != address(0)) {
distributor.distribute();
}
uint256 balance = VEC.balanceOf(address(this));
uint256 staked = sVEC.circulatingSupply();
if (balance <= staked) {
epoch.distribute = 0;
} else {
epoch.distribute = balance - staked;
}
emit EpochTriggerd(epoch.number);
}
}
function index() public view returns (uint256 index_) {
return sVEC.index();
}
function secondsToNextEpoch() external view returns (uint256 seconds_) {
return epoch.end > block.timestamp ? epoch.end - block.timestamp : 0;
}
function setDistributor(address _distributor) external onlyOwner {
distributor = IDistributor(_distributor);
emit DistributorSet(_distributor);
}
}
{
"compilationTarget": {
"contracts/staking/VECStaking.sol": "VECStaking"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_VEC","type":"address"},{"internalType":"address","name":"_sVEC","type":"address"},{"internalType":"uint256","name":"_epochLength","type":"uint256"},{"internalType":"uint256","name":"_secondsTillFirstEpoch","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"distributor","type":"address"}],"name":"DistributorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newEpoch","type":"uint256"}],"name":"EpochTriggerd","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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Stake","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Unstake","type":"event"},{"inputs":[],"name":"VEC","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"distributor","outputs":[{"internalType":"contract IDistributor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"epoch","outputs":[{"internalType":"uint256","name":"length","type":"uint256"},{"internalType":"uint256","name":"number","type":"uint256"},{"internalType":"uint256","name":"end","type":"uint256"},{"internalType":"uint256","name":"distribute","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"index","outputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebase","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sVEC","outputs":[{"internalType":"contract IsVEC","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"secondsToNextEpoch","outputs":[{"internalType":"uint256","name":"seconds_","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_distributor","type":"address"}],"name":"setDistributor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"bool","name":"_rebase","type":"bool"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"}]