编译器
0.8.10+commit.fc410830
文件 1 的 9: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 的 9:IHelixToken.sol
pragma solidity >= 0.8.0;
interface IHelixToken {
function mint(address to, uint256 amount) external returns(bool);
function transfer(address recipient, uint256 amount) external returns(bool);
function balanceOf(address account) external view returns (uint256);
}
文件 3 的 9:IOracleFactory.sol
pragma solidity >=0.8.0;
interface IOracleFactory {
function create(address token0, address token1) external;
function update(address token0, address token1) external;
function consult(address tokenIn, uint256 amountIn, address tokenOut) external view returns (uint256 amountOut);
function getOracle(address token0, address token1) external view returns (address oracle);
}
文件 4 的 9:IReferralRegister.sol
pragma solidity >=0.8.0;
import "./IHelixToken.sol";
interface IReferralRegister {
function toMintPerBlock() external view returns (uint256);
function helixToken() external view returns (IHelixToken);
function stakeRewardPercent() external view returns (uint256);
function swapRewardPercent() external view returns (uint256);
function lastMintBlock() external view returns (uint256);
function referrers(address _referred) external view returns (address);
function rewards(address _referrer) external view returns (uint256);
function initialize(
IHelixToken _helixToken,
address _feeHandler,
uint256 _stakeRewardPercent,
uint256 _swapRewardPercent,
uint256 _toMintPerBlock,
uint256 _lastMintBlock
) external;
function rewardStake(address _referred, uint256 _stakeAmount) external;
function rewardSwap(address _referred, uint256 _swapAmount) external;
function withdraw() external;
function setToMintPerBlock(uint256 _toMintPerBlock) external;
function setStakeRewardPercent(uint256 _stakeRewardPercent) external;
function setSwapRewardPercent(uint256 _swapRewardPercent) external;
function addReferrer(address _referrer) external;
function removeReferrer() external;
function update() external;
function addRecorder(address _recorder) external returns (bool);
function removeRecorder(address _recorder) external returns (bool);
function setLastRewardBlock(uint256 _lastMintBlock) external;
function pause() external;
function unpause() external;
function setFeeHandler(address _feeHandler) external;
function setCollectorPercent(uint256 _collectorPercent) external;
function getRecorder(uint256 _index) external view returns (address);
function getRecorderLength() external view returns (uint256);
function isRecorder(address _address) external view returns (bool);
}
文件 5 的 9:ISwapRewards.sol
pragma solidity >=0.8.0;
interface ISwapRewards {
function swap(address user, address tokenIn, uint256 amountIn) external;
}
文件 6 的 9: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 的 9: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 的 9:Percent.sol
pragma solidity >= 0.8.0;
library Percent {
uint256 public constant MAX_PERCENT = 100;
modifier onlyValidPercent(uint256 _percent, uint256 _decimals) {
require(_isValidPercent(_percent, _decimals), "Percent: invalid percent");
_;
}
function isValidPercent(uint256 _percent)
internal
pure
returns (bool)
{
return _isValidPercent(_percent, 0);
}
function isValidPercent(uint256 _percent, uint256 _decimals)
internal
pure
returns (bool)
{
return _isValidPercent(_percent, _decimals);
}
function _isValidPercent(uint256 _percent, uint256 _decimals)
private
pure
returns (bool)
{
return _percent <= MAX_PERCENT * 10 ** _decimals;
}
function getPercentage(uint256 _amount, uint256 _percent)
internal
pure
returns (uint256 percentage)
{
percentage = _getPercentage(_amount, _percent, 0);
}
function getPercentage(uint256 _amount, uint256 _percent, uint256 _decimals)
internal
pure
returns (uint256 percentage)
{
percentage =_getPercentage(_amount, _percent, _decimals);
}
function _getPercentage(uint256 _amount, uint256 _percent, uint256 _decimals)
private
pure
onlyValidPercent(_percent, _decimals)
returns (uint256 percentage)
{
percentage = _amount * _percent / (MAX_PERCENT * 10 ** _decimals);
}
function splitByPercent(uint256 _amount, uint256 _percent)
internal
pure
returns (uint256 percentage, uint256 remainder)
{
(percentage, remainder) = _splitByPercent(_amount, _percent, 0);
}
function splitByPercent(uint256 _amount, uint256 _percent, uint256 _decimals)
internal
pure
returns (uint256 percentage, uint256 remainder)
{
(percentage, remainder) = _splitByPercent(_amount, _percent, _decimals);
}
function _splitByPercent(uint256 _amount, uint256 _percent, uint256 _decimals)
private
pure
onlyValidPercent(_percent, _decimals)
returns (uint256 percentage, uint256 remainder)
{
percentage = _getPercentage(_amount, _percent, _decimals);
remainder = _amount - percentage;
}
}
文件 9 的 9:SwapRewards.sol
pragma solidity >= 0.8.0;
import "../interfaces/ISwapRewards.sol";
import "../interfaces/IOracleFactory.sol";
import "../interfaces/IHelixToken.sol";
import "../interfaces/IReferralRegister.sol";
import "../libraries/Percent.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
contract SwapRewards is ISwapRewards, Ownable, Pausable {
IHelixToken public helixToken;
IOracleFactory public oracleFactory;
IReferralRegister public refReg;
address public router;
event Swap(
address user,
address indexed tokenIn,
uint256 amountIn,
uint256 helixOut
);
event SetHelixToken(address indexed setter, address indexed helixToken);
event SetOracleFactory(address indexed setter, address indexed oracleFactory);
event SetRefReg(address indexed setter, address indexed refReg);
event SetRouter(address indexed setter, address indexed router);
modifier onlyValidAddress(address _address) {
require(_address != address(0), "SwapFee: zero address");
_;
}
constructor(
address _helixToken,
address _oracleFactory,
address _refReg,
address _router
) {
helixToken = IHelixToken(_helixToken);
oracleFactory = IOracleFactory(_oracleFactory);
refReg = IReferralRegister(_refReg);
router = _router;
}
function swap(address _user, address _tokenIn, uint256 _amountIn)
external
whenNotPaused
{
require(msg.sender == router, "SwapFee: not router");
uint256 helixOut = oracleFactory.consult(_tokenIn, _amountIn, address(helixToken));
if (helixOut > 0) {
refReg.rewardSwap(_user, helixOut);
}
emit Swap(_user, _tokenIn, _amountIn, helixOut);
}
function setHelixToken(address _helixToken)
external
onlyOwner
onlyValidAddress(_helixToken)
{
helixToken = IHelixToken(_helixToken);
emit SetHelixToken(msg.sender, _helixToken);
}
function setOracleFactory(address _oracleFactory)
external
onlyOwner
onlyValidAddress(_oracleFactory)
{
oracleFactory = IOracleFactory(_oracleFactory);
emit SetOracleFactory(msg.sender, _oracleFactory);
}
function setRefReg(address _refReg)
external
onlyOwner
onlyValidAddress(_refReg)
{
refReg = IReferralRegister(_refReg);
emit SetRefReg(msg.sender, _refReg);
}
function setRouter(address _router) external onlyOwner onlyValidAddress(_router) {
router = _router;
emit SetRouter(msg.sender, _router);
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
}
{
"compilationTarget": {
"contracts/swaps/SwapRewards.sol": "SwapRewards"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_helixToken","type":"address"},{"internalType":"address","name":"_oracleFactory","type":"address"},{"internalType":"address","name":"_refReg","type":"address"},{"internalType":"address","name":"_router","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":"address","name":"setter","type":"address"},{"indexed":true,"internalType":"address","name":"helixToken","type":"address"}],"name":"SetHelixToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"setter","type":"address"},{"indexed":true,"internalType":"address","name":"oracleFactory","type":"address"}],"name":"SetOracleFactory","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"setter","type":"address"},{"indexed":true,"internalType":"address","name":"refReg","type":"address"}],"name":"SetRefReg","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"setter","type":"address"},{"indexed":true,"internalType":"address","name":"router","type":"address"}],"name":"SetRouter","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"helixOut","type":"uint256"}],"name":"Swap","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"helixToken","outputs":[{"internalType":"contract IHelixToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleFactory","outputs":[{"internalType":"contract IOracleFactory","name":"","type":"address"}],"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":"refReg","outputs":[{"internalType":"contract IReferralRegister","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_helixToken","type":"address"}],"name":"setHelixToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oracleFactory","type":"address"}],"name":"setOracleFactory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_refReg","type":"address"}],"name":"setRefReg","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_router","type":"address"}],"name":"setRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address","name":"_tokenIn","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"}],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"}]