initialize project
This commit is contained in:
commit
0beec632cd
|
@ -0,0 +1,3 @@
|
|||
[*.sol]
|
||||
indent_style = space
|
||||
indent_size = 4
|
|
@ -0,0 +1,3 @@
|
|||
.gitkeep
|
||||
node_modules
|
||||
build
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"manifestVersion": "2.2",
|
||||
"contracts": {},
|
||||
"dependencies": {},
|
||||
"name": "poa-mania",
|
||||
"version": "1.0.0",
|
||||
"compiler": {
|
||||
"compilerSettings": {
|
||||
"optimizer": {
|
||||
"enabled": false,
|
||||
"runs": "200"
|
||||
}
|
||||
},
|
||||
"typechain": {
|
||||
"enabled": false
|
||||
},
|
||||
"manager": "openzeppelin",
|
||||
"solcVersion": "0.5.16",
|
||||
"artifactsDir": "build/contracts",
|
||||
"contractsDir": "contracts"
|
||||
},
|
||||
"telemetryOptIn": false
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
pragma solidity ^0.5.16;
|
||||
|
||||
interface IPOSDAORandom {
|
||||
function collectRoundLength() external view returns(uint256);
|
||||
function currentSeed() external view returns(uint256);
|
||||
function isCommitPhase() external view returns(bool);
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
pragma solidity ^0.5.16;
|
||||
|
||||
import "@openzeppelin/upgrades/contracts/Initializable.sol";
|
||||
import "@openzeppelin/contracts/ownership/Ownable.sol";
|
||||
import "@openzeppelin/contracts/math/SafeMath.sol";
|
||||
import "./Random.sol";
|
||||
|
||||
contract PoaMania is Initializable, Ownable, Random {
|
||||
using SafeMath for uint256;
|
||||
|
||||
struct Round {
|
||||
uint256 startedAt;
|
||||
address winner;
|
||||
uint256 reward;
|
||||
}
|
||||
Round[] public rounds;
|
||||
|
||||
uint256 public roundDuration;
|
||||
uint256 public fee;
|
||||
address public feeReceiver;
|
||||
uint256 public nextRoundShare;
|
||||
uint256 public executorShare;
|
||||
|
||||
function initialize(
|
||||
address _owner,
|
||||
address _randomContract,
|
||||
uint256 _roundDuration,
|
||||
uint256 _fee,
|
||||
address _feeReceiver,
|
||||
uint256 _nextRoundShare,
|
||||
uint256 _executorShare
|
||||
) public initializer {
|
||||
_transferOwnership(_owner);
|
||||
_setRoundDuration(_roundDuration);
|
||||
_setFee(_fee);
|
||||
_setFeeReceiver(_feeReceiver);
|
||||
_setNextRoundShare(_nextRoundShare);
|
||||
_setExecutorShare(_executorShare);
|
||||
_validateSumOfShares();
|
||||
Random._init(_randomContract);
|
||||
}
|
||||
|
||||
function setRoundDuration(uint256 _roundDuration) external onlyOwner {
|
||||
_setRoundDuration(_roundDuration);
|
||||
}
|
||||
|
||||
function setFee(uint256 _fee) external onlyOwner {
|
||||
_setFee(_fee);
|
||||
_validateSumOfShares();
|
||||
}
|
||||
|
||||
function setFeeReceiver(address _feeReceiver) external onlyOwner {
|
||||
_setFeeReceiver(_feeReceiver);
|
||||
}
|
||||
|
||||
function setNextRoundShare(uint256 _nextRoundShare) external onlyOwner {
|
||||
_setNextRoundShare(_nextRoundShare);
|
||||
_validateSumOfShares();
|
||||
}
|
||||
|
||||
function setExecutorShare(uint256 _executorShare) external onlyOwner {
|
||||
_setExecutorShare(_executorShare);
|
||||
_validateSumOfShares();
|
||||
}
|
||||
|
||||
function _setRoundDuration(uint256 _roundDuration) internal {
|
||||
require(_roundDuration > 0, "should be greater than 0");
|
||||
roundDuration = _roundDuration;
|
||||
}
|
||||
|
||||
function _setFee(uint256 _fee) internal {
|
||||
fee = _fee;
|
||||
}
|
||||
|
||||
function _setFeeReceiver(address _feeReceiver) internal {
|
||||
require(_feeReceiver != address(0), "empty address");
|
||||
feeReceiver = _feeReceiver;
|
||||
}
|
||||
|
||||
function _setNextRoundShare(uint256 _nextRoundShare) internal {
|
||||
nextRoundShare = _nextRoundShare;
|
||||
}
|
||||
|
||||
function _setExecutorShare(uint256 _executorShare) internal {
|
||||
executorShare = _executorShare;
|
||||
}
|
||||
|
||||
function _validateSumOfShares() internal view {
|
||||
uint256 sum = fee.add(nextRoundShare).add(executorShare);
|
||||
require(sum < 1 ether, "should be less than 1 ether");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
pragma solidity ^0.5.16;
|
||||
|
||||
import "./IPOSDAORandom.sol";
|
||||
|
||||
contract Random {
|
||||
IPOSDAORandom public posdaoRandomContract;
|
||||
|
||||
uint256 private _seed;
|
||||
uint256 private _seedLastBlock;
|
||||
uint256 private _updateInterval;
|
||||
|
||||
function _init(address _randomContract) internal {
|
||||
require(_randomContract != address(0), "Random/contract-zero");
|
||||
posdaoRandomContract = IPOSDAORandom(_randomContract);
|
||||
_seed = posdaoRandomContract.currentSeed();
|
||||
_seedLastBlock = block.number;
|
||||
_updateInterval = posdaoRandomContract.collectRoundLength();
|
||||
require(_updateInterval != 0, "Random/interval-zero");
|
||||
}
|
||||
|
||||
function _useSeed() internal returns (uint256) {
|
||||
require(_wasSeedUpdated(), "Random/seed-not-updated");
|
||||
require(posdaoRandomContract.isCommitPhase(), "Random/not-commit-phase");
|
||||
return _seed;
|
||||
}
|
||||
|
||||
function _wasSeedUpdated() private returns (bool) {
|
||||
if (block.number - _seedLastBlock <= _updateInterval) {
|
||||
return false;
|
||||
}
|
||||
|
||||
_updateInterval = posdaoRandomContract.collectRoundLength();
|
||||
|
||||
uint256 remoteSeed = posdaoRandomContract.currentSeed();
|
||||
if (remoteSeed != _seed) {
|
||||
_seed = remoteSeed;
|
||||
_seedLastBlock = block.number;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
module.exports = {
|
||||
networks: {
|
||||
development: {
|
||||
protocol: 'http',
|
||||
host: 'localhost',
|
||||
port: 8545,
|
||||
gas: 5000000,
|
||||
gasPrice: 5e9,
|
||||
networkId: '*',
|
||||
},
|
||||
},
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "poa-mania",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/poanetwork/poa-mania.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/poanetwork/poa-mania/issues"
|
||||
},
|
||||
"homepage": "https://github.com/poanetwork/poa-mania#readme",
|
||||
"dependencies": {
|
||||
"@openzeppelin/cli": "^2.7.1",
|
||||
"@openzeppelin/contracts": "^2.5.0"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue