2021-04-12 16:31:26 +08:00
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
Copyright 2020 DODO ZOO.
|
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
pragma solidity 0.6.9;
|
|
|
|
|
|
|
|
|
|
interface IRandomGenerator {
|
2021-04-13 11:12:13 +08:00
|
|
|
function random(uint256 seed) external view returns (uint256);
|
2021-04-12 16:31:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IDODOMidPrice {
|
|
|
|
|
function getMidPrice() external view returns (uint256 midPrice);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 22:13:26 +08:00
|
|
|
contract RandomGenerator is IRandomGenerator{
|
2021-04-13 11:12:13 +08:00
|
|
|
address[] public pools;
|
2021-04-12 16:31:26 +08:00
|
|
|
|
|
|
|
|
constructor(address[] memory _pools) public {
|
2021-04-15 13:40:48 +08:00
|
|
|
for (uint256 i = 0; i < _pools.length; i++) {
|
2021-04-12 16:31:26 +08:00
|
|
|
pools.push(_pools[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-20 22:13:26 +08:00
|
|
|
function random(uint256 seed) external override view returns (uint256) {
|
2021-04-12 16:31:26 +08:00
|
|
|
uint256 priceSum;
|
|
|
|
|
for (uint256 i = 0; i < pools.length; i++) {
|
|
|
|
|
priceSum += IDODOMidPrice(pools[i]).getMidPrice();
|
|
|
|
|
}
|
2021-04-13 11:12:13 +08:00
|
|
|
return uint256(keccak256(abi.encodePacked(blockhash(block.number-1), priceSum, seed)));
|
2021-04-12 16:31:26 +08:00
|
|
|
}
|
|
|
|
|
}
|