编译器
0.5.17+commit.d19bba13
文件 1 的 17:Address.sol
pragma solidity ^0.5.5;
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function toPayable(address account) internal pure returns (address payable) {
return address(uint160(account));
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
文件 2 的 17:Context.sol
pragma solidity ^0.5.0;
contract Context {
constructor () internal { }
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this;
return msg.data;
}
}
文件 3 的 17:ERC20.sol
pragma solidity ^0.5.0;
import "../../GSN/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";
contract ERC20 is Context, IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal {
require(account != address(0), "ERC20: burn from the zero address");
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance"));
}
}
文件 4 的 17:ERC20Burnable.sol
pragma solidity ^0.5.0;
import "../../GSN/Context.sol";
import "./ERC20.sol";
contract ERC20Burnable is Context, ERC20 {
function burn(uint256 amount) public {
_burn(_msgSender(), amount);
}
function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount);
}
}
文件 5 的 17:ERC20Capped.sol
pragma solidity ^0.5.0;
import "./ERC20Mintable.sol";
contract ERC20Capped is ERC20Mintable {
uint256 private _cap;
constructor (uint256 cap) public {
require(cap > 0, "ERC20Capped: cap is 0");
_cap = cap;
}
function cap() public view returns (uint256) {
return _cap;
}
function _mint(address account, uint256 value) internal {
require(totalSupply().add(value) <= _cap, "ERC20Capped: cap exceeded");
super._mint(account, value);
}
}
文件 6 的 17:ERC20Detailed.sol
pragma solidity ^0.5.0;
import "./IERC20.sol";
contract ERC20Detailed is IERC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
function name() public view returns (string memory) {
return _name;
}
function symbol() public view returns (string memory) {
return _symbol;
}
function decimals() public view returns (uint8) {
return _decimals;
}
}
文件 7 的 17:ERC20Mintable.sol
pragma solidity ^0.5.0;
import "./ERC20.sol";
import "../../access/roles/MinterRole.sol";
contract ERC20Mintable is ERC20, MinterRole {
function mint(address account, uint256 amount) public onlyMinter returns (bool) {
_mint(account, amount);
return true;
}
}
文件 8 的 17:IERC20.sol
pragma solidity ^0.5.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, 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 sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 9 的 17:IUniswapOracle.sol
pragma solidity 0.5.17;
interface IUniswapOracle {
function update() external returns (bool success);
function consult(address token, uint256 amountIn)
external
view
returns (uint256 amountOut);
}
文件 10 的 17:MinterRole.sol
pragma solidity ^0.5.0;
import "../../GSN/Context.sol";
import "../Roles.sol";
contract MinterRole is Context {
using Roles for Roles.Role;
event MinterAdded(address indexed account);
event MinterRemoved(address indexed account);
Roles.Role private _minters;
constructor () internal {
_addMinter(_msgSender());
}
modifier onlyMinter() {
require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role");
_;
}
function isMinter(address account) public view returns (bool) {
return _minters.has(account);
}
function addMinter(address account) public onlyMinter {
_addMinter(account);
}
function renounceMinter() public {
_removeMinter(_msgSender());
}
function _addMinter(address account) internal {
_minters.add(account);
emit MinterAdded(account);
}
function _removeMinter(address account) internal {
_minters.remove(account);
emit MinterRemoved(account);
}
}
文件 11 的 17:PeakReward.sol
pragma solidity 0.5.17;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/access/roles/SignerRole.sol";
import "../staking/PeakStaking.sol";
import "../PeakToken.sol";
import "../IUniswapOracle.sol";
contract PeakReward is SignerRole {
using SafeMath for uint256;
using SafeERC20 for IERC20;
event Register(address user, address referrer);
event RankChange(address user, uint256 oldRank, uint256 newRank);
event PayCommission(
address referrer,
address recipient,
address token,
uint256 amount,
uint8 level
);
event ChangedCareerValue(address user, uint256 changeAmount, bool positive);
event ReceiveRankReward(address user, uint256 peakReward);
modifier regUser(address user) {
if (!isUser[user]) {
isUser[user] = true;
emit Register(user, address(0));
}
_;
}
uint256 public constant PEAK_MINT_CAP = 5 * 10**15;
uint256 internal constant COMMISSION_RATE = 20 * (10**16);
uint256 internal constant PEAK_PRECISION = 10**8;
uint256 internal constant USDC_PRECISION = 10**6;
uint8 internal constant COMMISSION_LEVELS = 8;
mapping(address => address) public referrerOf;
mapping(address => bool) public isUser;
mapping(address => uint256) public careerValue;
mapping(address => uint256) public rankOf;
mapping(uint256 => mapping(uint256 => uint256)) public rankReward;
mapping(address => mapping(uint256 => uint256)) public downlineRanks;
uint256[] public commissionPercentages;
uint256[] public commissionStakeRequirements;
uint256 public mintedPeakTokens;
address public marketPeakWallet;
PeakStaking public peakStaking;
PeakToken public peakToken;
address public stablecoin;
IUniswapOracle public oracle;
constructor(
address _marketPeakWallet,
address _peakStaking,
address _peakToken,
address _stablecoin,
address _oracle
) public {
commissionPercentages.push(10 * (10**16));
commissionPercentages.push(4 * (10**16));
commissionPercentages.push(2 * (10**16));
commissionPercentages.push(1 * (10**16));
commissionPercentages.push(1 * (10**16));
commissionPercentages.push(1 * (10**16));
commissionPercentages.push(5 * (10**15));
commissionPercentages.push(5 * (10**15));
commissionStakeRequirements.push(0);
commissionStakeRequirements.push(PEAK_PRECISION.mul(2000));
commissionStakeRequirements.push(PEAK_PRECISION.mul(4000));
commissionStakeRequirements.push(PEAK_PRECISION.mul(6000));
commissionStakeRequirements.push(PEAK_PRECISION.mul(7000));
commissionStakeRequirements.push(PEAK_PRECISION.mul(8000));
commissionStakeRequirements.push(PEAK_PRECISION.mul(9000));
commissionStakeRequirements.push(PEAK_PRECISION.mul(10000));
for (uint256 i = 0; i < 8; i = i.add(1)) {
uint256 rewardInUSDC = 0;
for (uint256 j = i.add(1); j <= 8; j = j.add(1)) {
if (j == 1) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(100));
} else if (j == 2) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(300));
} else if (j == 3) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(600));
} else if (j == 4) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(1200));
} else if (j == 5) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(2400));
} else if (j == 6) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(7500));
} else if (j == 7) {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(15000));
} else {
rewardInUSDC = rewardInUSDC.add(USDC_PRECISION.mul(50000));
}
rankReward[i][j] = rewardInUSDC;
}
}
marketPeakWallet = _marketPeakWallet;
peakStaking = PeakStaking(_peakStaking);
peakToken = PeakToken(_peakToken);
stablecoin = _stablecoin;
oracle = IUniswapOracle(_oracle);
}
function multiRefer(address[] calldata users, address[] calldata referrers) external onlySigner {
require(users.length == referrers.length, "PeakReward: arrays length are not equal");
for (uint256 i = 0; i < users.length; i++) {
refer(users[i], referrers[i]);
}
}
function refer(address user, address referrer) public onlySigner {
require(!isUser[user], "PeakReward: referred is already a user");
require(user != referrer, "PeakReward: can't refer self");
require(
user != address(0) && referrer != address(0),
"PeakReward: 0 address"
);
isUser[user] = true;
isUser[referrer] = true;
referrerOf[user] = referrer;
downlineRanks[referrer][0] = downlineRanks[referrer][0].add(1);
emit Register(user, referrer);
}
function canRefer(address user, address referrer)
public
view
returns (bool)
{
return
!isUser[user] &&
user != referrer &&
user != address(0) &&
referrer != address(0);
}
function payCommission(
address referrer,
address commissionToken,
uint256 rawCommission,
bool returnLeftovers
) public regUser(referrer) onlySigner returns (uint256 leftoverAmount) {
IERC20 token = IERC20(commissionToken);
token.safeTransferFrom(msg.sender, address(this), rawCommission);
address ptr = referrer;
uint256 commissionLeft = rawCommission;
uint8 i = 0;
while (ptr != address(0) && i < COMMISSION_LEVELS) {
if (_peakStakeOf(ptr) >= commissionStakeRequirements[i]) {
uint256 com = rawCommission.mul(commissionPercentages[i]).div(
COMMISSION_RATE
);
if (com > commissionLeft) {
com = commissionLeft;
}
token.safeTransfer(ptr, com);
commissionLeft = commissionLeft.sub(com);
if (commissionToken == address(peakToken)) {
incrementCareerValueInPeak(ptr, com);
} else if (commissionToken == stablecoin) {
incrementCareerValueInUsdc(ptr, com);
}
emit PayCommission(referrer, ptr, commissionToken, com, i);
}
ptr = referrerOf[ptr];
i += 1;
}
if (returnLeftovers) {
token.safeTransfer(msg.sender, commissionLeft);
return commissionLeft;
} else {
token.safeTransfer(marketPeakWallet, commissionLeft);
return 0;
}
}
function incrementCareerValueInUsdc(address user, uint256 incCV)
public
regUser(user)
onlySigner
{
careerValue[user] = careerValue[user].add(incCV);
emit ChangedCareerValue(user, incCV, true);
}
function incrementCareerValueInPeak(address user, uint256 incCVInPeak)
public
regUser(user)
onlySigner
{
uint256 peakPriceInUsdc = _getPeakPriceInUsdc();
uint256 incCVInUsdc = incCVInPeak.mul(peakPriceInUsdc).div(
PEAK_PRECISION
);
careerValue[user] = careerValue[user].add(incCVInUsdc);
emit ChangedCareerValue(user, incCVInUsdc, true);
}
function cvRankOf(address user) public view returns (uint256) {
uint256 cv = careerValue[user];
if (cv < USDC_PRECISION.mul(100)) {
return 0;
} else if (cv < USDC_PRECISION.mul(250)) {
return 1;
} else if (cv < USDC_PRECISION.mul(750)) {
return 2;
} else if (cv < USDC_PRECISION.mul(1500)) {
return 3;
} else if (cv < USDC_PRECISION.mul(3000)) {
return 4;
} else if (cv < USDC_PRECISION.mul(10000)) {
return 5;
} else if (cv < USDC_PRECISION.mul(50000)) {
return 6;
} else if (cv < USDC_PRECISION.mul(150000)) {
return 7;
} else {
return 8;
}
}
function rankUp(address user) external {
uint256 currentRank = rankOf[user];
uint256 cvRank = cvRankOf(user);
require(cvRank > currentRank, "PeakReward: career value is not enough!");
require(downlineRanks[user][currentRank] >= 2 || currentRank == 0, "PeakReward: downlines count and requirement not passed!");
uint256 targetRank = currentRank + 1;
rankOf[user] = targetRank;
emit RankChange(user, currentRank, targetRank);
address referrer = referrerOf[user];
if (referrer != address(0)) {
downlineRanks[referrer][targetRank] = downlineRanks[referrer][targetRank]
.add(1);
downlineRanks[referrer][currentRank] = downlineRanks[referrer][currentRank]
.sub(1);
}
uint256 rewardInPeak = rankReward[currentRank][targetRank]
.mul(PEAK_PRECISION)
.div(_getPeakPriceInUsdc());
if (mintedPeakTokens.add(rewardInPeak) <= PEAK_MINT_CAP) {
mintedPeakTokens = mintedPeakTokens.add(rewardInPeak);
peakToken.mint(user, rewardInPeak);
emit ReceiveRankReward(user, rewardInPeak);
}
}
function canRankUp(address user) external view returns (bool) {
uint256 currentRank = rankOf[user];
uint256 cvRank = cvRankOf(user);
return
(cvRank > currentRank) &&
(downlineRanks[user][currentRank] >= 2 || currentRank == 0);
}
function _peakStakeOf(address user) internal view returns (uint256) {
return peakStaking.userStakeAmount(user);
}
function _getPeakPriceInUsdc() internal returns (uint256) {
oracle.update();
uint256 priceInUSDC = oracle.consult(address(peakToken), PEAK_PRECISION);
if (priceInUSDC == 0) {
return USDC_PRECISION.mul(3).div(10);
}
return priceInUSDC;
}
}
文件 12 的 17:PeakStaking.sol
pragma solidity 0.5.17;
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "../reward/PeakReward.sol";
import "../PeakToken.sol";
contract PeakStaking {
using SafeMath for uint256;
using SafeERC20 for PeakToken;
event CreateStake(
uint256 idx,
address user,
address referrer,
uint256 stakeAmount,
uint256 stakeTimeInDays,
uint256 interestAmount
);
event ReceiveStakeReward(uint256 idx, address user, uint256 rewardAmount);
event WithdrawReward(uint256 idx, address user, uint256 rewardAmount);
event WithdrawStake(uint256 idx, address user);
uint256 internal constant PRECISION = 10**18;
uint256 internal constant PEAK_PRECISION = 10**8;
uint256 internal constant INTEREST_SLOPE = 2 * (10**8);
uint256 internal constant BIGGER_BONUS_DIVISOR = 10**15;
uint256 internal constant MAX_BIGGER_BONUS = 10**17;
uint256 internal constant DAILY_BASE_REWARD = 15 * (10**14);
uint256 internal constant DAILY_GROWING_REWARD = 10**12;
uint256 internal constant MAX_STAKE_PERIOD = 1000;
uint256 internal constant MIN_STAKE_PERIOD = 10;
uint256 internal constant DAY_IN_SECONDS = 86400;
uint256 internal constant COMMISSION_RATE = 20 * (10**16);
uint256 internal constant REFERRAL_STAKER_BONUS = 3 * (10**16);
uint256 internal constant YEAR_IN_DAYS = 365;
uint256 public constant PEAK_MINT_CAP = 7 * 10**16;
struct Stake {
address staker;
uint256 stakeAmount;
uint256 interestAmount;
uint256 withdrawnInterestAmount;
uint256 stakeTimestamp;
uint256 stakeTimeInDays;
bool active;
}
Stake[] public stakeList;
mapping(address => uint256) public userStakeAmount;
uint256 public mintedPeakTokens;
bool public initialized;
PeakToken public peakToken;
PeakReward public peakReward;
constructor(address _peakToken) public {
peakToken = PeakToken(_peakToken);
}
function init(address _peakReward) public {
require(!initialized, "PeakStaking: Already initialized");
initialized = true;
peakReward = PeakReward(_peakReward);
}
function stake(
uint256 stakeAmount,
uint256 stakeTimeInDays,
address referrer
) public returns (uint256 stakeIdx) {
require(
stakeTimeInDays >= MIN_STAKE_PERIOD,
"PeakStaking: stakeTimeInDays < MIN_STAKE_PERIOD"
);
require(
stakeTimeInDays <= MAX_STAKE_PERIOD,
"PeakStaking: stakeTimeInDays > MAX_STAKE_PERIOD"
);
uint256 interestAmount = getInterestAmount(
stakeAmount,
stakeTimeInDays
);
stakeIdx = stakeList.length;
stakeList.push(
Stake({
staker: msg.sender,
stakeAmount: stakeAmount,
interestAmount: interestAmount,
withdrawnInterestAmount: 0,
stakeTimestamp: now,
stakeTimeInDays: stakeTimeInDays,
active: true
})
);
mintedPeakTokens = mintedPeakTokens.add(interestAmount);
userStakeAmount[msg.sender] = userStakeAmount[msg.sender].add(
stakeAmount
);
peakToken.safeTransferFrom(msg.sender, address(this), stakeAmount);
peakToken.mint(address(this), interestAmount);
if (peakReward.canRefer(msg.sender, referrer)) {
peakReward.refer(msg.sender, referrer);
}
address actualReferrer = peakReward.referrerOf(msg.sender);
if (actualReferrer != address(0)) {
uint256 rawCommission = interestAmount.mul(COMMISSION_RATE).div(
PRECISION
);
peakToken.mint(address(this), rawCommission);
peakToken.safeApprove(address(peakReward), rawCommission);
uint256 leftoverAmount = peakReward.payCommission(
actualReferrer,
address(peakToken),
rawCommission,
true
);
peakToken.burn(leftoverAmount);
uint256 referralStakerBonus = interestAmount
.mul(REFERRAL_STAKER_BONUS)
.div(PRECISION);
peakToken.mint(msg.sender, referralStakerBonus);
mintedPeakTokens = mintedPeakTokens.add(
rawCommission.sub(leftoverAmount).add(referralStakerBonus)
);
emit ReceiveStakeReward(stakeIdx, msg.sender, referralStakerBonus);
}
require(mintedPeakTokens <= PEAK_MINT_CAP, "PeakStaking: reached cap");
emit CreateStake(
stakeIdx,
msg.sender,
actualReferrer,
stakeAmount,
stakeTimeInDays,
interestAmount
);
}
function withdraw(uint256 stakeIdx) public {
Stake storage stakeObj = stakeList[stakeIdx];
require(
stakeObj.staker == msg.sender,
"PeakStaking: Sender not staker"
);
require(stakeObj.active, "PeakStaking: Not active");
uint256 stakeTimeInSeconds = stakeObj.stakeTimeInDays.mul(
DAY_IN_SECONDS
);
uint256 withdrawAmount;
if (now >= stakeObj.stakeTimestamp.add(stakeTimeInSeconds)) {
withdrawAmount = stakeObj
.stakeAmount
.add(stakeObj.interestAmount)
.sub(stakeObj.withdrawnInterestAmount);
stakeObj.active = false;
stakeObj.withdrawnInterestAmount = stakeObj.interestAmount;
userStakeAmount[msg.sender] = userStakeAmount[msg.sender].sub(
stakeObj.stakeAmount
);
emit WithdrawReward(
stakeIdx,
msg.sender,
stakeObj.interestAmount.sub(stakeObj.withdrawnInterestAmount)
);
emit WithdrawStake(stakeIdx, msg.sender);
} else {
withdrawAmount = stakeObj
.interestAmount
.mul(uint256(now).sub(stakeObj.stakeTimestamp))
.div(stakeTimeInSeconds)
.sub(stakeObj.withdrawnInterestAmount);
stakeObj.withdrawnInterestAmount = stakeObj
.withdrawnInterestAmount
.add(withdrawAmount);
emit WithdrawReward(stakeIdx, msg.sender, withdrawAmount);
}
peakToken.safeTransfer(msg.sender, withdrawAmount);
}
function getInterestAmount(uint256 stakeAmount, uint256 stakeTimeInDays)
public
view
returns (uint256)
{
uint256 earlyFactor = _earlyFactor(mintedPeakTokens);
uint256 biggerBonus = stakeAmount.mul(PRECISION).div(
BIGGER_BONUS_DIVISOR
);
if (biggerBonus > MAX_BIGGER_BONUS) {
biggerBonus = MAX_BIGGER_BONUS;
}
biggerBonus = biggerBonus.mul(stakeTimeInDays).div(YEAR_IN_DAYS);
uint256 longerBonus = _longerBonus(stakeTimeInDays);
uint256 interestRate = biggerBonus.add(longerBonus).mul(earlyFactor).div(
PRECISION
);
uint256 interestAmount = stakeAmount.mul(interestRate).div(PRECISION);
return interestAmount;
}
function _longerBonus(uint256 stakeTimeInDays)
internal
pure
returns (uint256)
{
return
DAILY_BASE_REWARD.mul(stakeTimeInDays).add(
DAILY_GROWING_REWARD
.mul(stakeTimeInDays)
.mul(stakeTimeInDays.add(1))
.div(2)
);
}
function _earlyFactor(uint256 _mintedPeakTokens)
internal
pure
returns (uint256)
{
uint256 tmp = INTEREST_SLOPE.mul(_mintedPeakTokens).div(PEAK_PRECISION);
if (tmp > PRECISION) {
return 0;
}
return PRECISION.sub(tmp);
}
}
文件 13 的 17:PeakToken.sol
pragma solidity 0.5.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Capped.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
contract PeakToken is ERC20, ERC20Detailed, ERC20Capped, ERC20Burnable {
constructor(
string memory name,
string memory symbol,
uint8 decimals,
uint256 cap
) ERC20Detailed(name, symbol, decimals) ERC20Capped(cap) public {}
}
文件 14 的 17:Roles.sol
pragma solidity ^0.5.0;
library Roles {
struct Role {
mapping (address => bool) bearer;
}
function add(Role storage role, address account) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] = true;
}
function remove(Role storage role, address account) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] = false;
}
function has(Role storage role, address account) internal view returns (bool) {
require(account != address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}
文件 15 的 17:SafeERC20.sol
pragma solidity ^0.5.0;
import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function callOptionalReturn(IERC20 token, bytes memory data) private {
require(address(token).isContract(), "SafeERC20: call to non-contract");
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
文件 16 的 17:SafeMath.sol
pragma solidity ^0.5.0;
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
文件 17 的 17:SignerRole.sol
pragma solidity ^0.5.0;
import "../../GSN/Context.sol";
import "../Roles.sol";
contract SignerRole is Context {
using Roles for Roles.Role;
event SignerAdded(address indexed account);
event SignerRemoved(address indexed account);
Roles.Role private _signers;
constructor () internal {
_addSigner(_msgSender());
}
modifier onlySigner() {
require(isSigner(_msgSender()), "SignerRole: caller does not have the Signer role");
_;
}
function isSigner(address account) public view returns (bool) {
return _signers.has(account);
}
function addSigner(address account) public onlySigner {
_addSigner(account);
}
function renounceSigner() public {
_removeSigner(_msgSender());
}
function _addSigner(address account) internal {
_signers.add(account);
emit SignerAdded(account);
}
function _removeSigner(address account) internal {
_signers.remove(account);
emit SignerRemoved(account);
}
}
{
"compilationTarget": {
"contracts/peak/staking/PeakStaking.sol": "PeakStaking"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_peakToken","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idx","type":"uint256"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"referrer","type":"address"},{"indexed":false,"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"stakeTimeInDays","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"interestAmount","type":"uint256"}],"name":"CreateStake","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idx","type":"uint256"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"name":"ReceiveStakeReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idx","type":"uint256"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"name":"WithdrawReward","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idx","type":"uint256"},{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"WithdrawStake","type":"event"},{"constant":true,"inputs":[],"name":"PEAK_MINT_CAP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"uint256","name":"stakeTimeInDays","type":"uint256"}],"name":"getInterestAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_peakReward","type":"address"}],"name":"init","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"initialized","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"mintedPeakTokens","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"peakReward","outputs":[{"internalType":"contract PeakReward","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"peakToken","outputs":[{"internalType":"contract PeakToken","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"uint256","name":"stakeTimeInDays","type":"uint256"},{"internalType":"address","name":"referrer","type":"address"}],"name":"stake","outputs":[{"internalType":"uint256","name":"stakeIdx","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"stakeList","outputs":[{"internalType":"address","name":"staker","type":"address"},{"internalType":"uint256","name":"stakeAmount","type":"uint256"},{"internalType":"uint256","name":"interestAmount","type":"uint256"},{"internalType":"uint256","name":"withdrawnInterestAmount","type":"uint256"},{"internalType":"uint256","name":"stakeTimestamp","type":"uint256"},{"internalType":"uint256","name":"stakeTimeInDays","type":"uint256"},{"internalType":"bool","name":"active","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userStakeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"stakeIdx","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]