编译器
0.8.24+commit.e11b9ed9
文件 1 的 12:AccessControl.sol
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
文件 2 的 12:Address.sol
pragma solidity ^0.8.20;
library Address {
error AddressInsufficientBalance(address account);
error AddressEmptyCode(address target);
error FailedInnerCall();
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
function _revert(bytes memory returndata) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
文件 3 的 12:Context.sol
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
文件 4 的 12:ERC165.sol
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 5 的 12:IAccessControl.sol
pragma solidity ^0.8.20;
interface IAccessControl {
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
error AccessControlBadConfirmation();
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address callerConfirmation) external;
}
文件 6 的 12:IERC165.sol
pragma solidity ^0.8.20;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 7 的 12:IERC20.sol
pragma solidity ^0.8.20;
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 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
文件 8 的 12:IERC20Permit.sol
pragma solidity ^0.8.20;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
文件 9 的 12:Math.sol
pragma solidity ^0.8.20;
library Math {
error MathOverflowedMulDiv();
enum Rounding {
Floor,
Ceil,
Trunc,
Expand
}
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
return a / b;
}
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0 = x * y;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (0 - denominator);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
文件 10 的 12:ReentrancyGuard.sol
pragma solidity ^0.8.20;
abstract contract ReentrancyGuard {
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
_status = ENTERED;
}
function _nonReentrantAfter() private {
_status = NOT_ENTERED;
}
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
文件 11 的 12:SafeERC20.sol
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
error SafeERC20FailedOperation(address token);
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
文件 12 的 12:Storage.sol
pragma solidity 0.8.24;
import '@openzeppelin/contracts/access/AccessControl.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
import '@openzeppelin/contracts/utils/math/Math.sol';
contract Storage is AccessControl, ReentrancyGuard {
using SafeERC20 for IERC20;
enum Option { Short, Long }
enum State { None, Opened, Closed }
struct Round {
bool defined;
State state;
uint256 sPrice;
uint256 lPrice;
uint256 sold;
uint256 supply;
}
struct Referral {
bool defined;
bool enabled;
uint256 firstRefRate;
uint256 secondRefRate;
}
bytes32 public constant OPERATOR_ROLE = keccak256('OPERATOR_ROLE');
address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
address internal constant TOKEN = 0x0000000000000000000000000000000000000001;
uint256 internal constant MAX = 1000000000000000000000000;
uint256 internal constant MIN = 1000000000000000000;
address private _treasury;
State private _state;
Round[] private _rounds;
uint256 private _currentRound;
uint256 private _max;
uint256 private _min;
uint256 private _authLimit;
mapping(address => bool) private _auth;
uint256 private _firstRefRate = 50;
uint256 private _secondRefRate = 50;
uint256 private _totalSold;
mapping(address => uint256) private _funds;
mapping(address => mapping(uint256 => uint256)) private _balances;
mapping(address => Referral) private _refs;
mapping(address => address) private _refsUsers;
mapping(address => mapping(address => uint256)) _refsBalances;
event StateUpdated(State state);
event RoundOpened(uint256 indexed round);
event RoundClosed(uint256 indexed round);
event RoundAdded(uint256 sPrice, uint256 lPrice, uint256 supply);
event RoundPriceUpdated(uint256 indexed round, uint256 sPrice, uint256 lPrice);
event RoundSupplyUpdated(uint256 indexed round, uint256 supply);
event Erc20Recovered(address token, uint256 amount);
event CoinRecovered(uint256 amount);
event AuthLimitUpdated(uint256 limit);
event AuthUserUpdated(address indexed user, bool value);
event MaxUpdated(uint256 amount);
event MinUpdated(uint256 amount);
event TreasuryUpdated(address indexed treasury);
event RefRateSetup(uint256 firstRefRate, uint256 secondRefRate);
event ReferralSetup(address indexed ref, uint256 firstRefRate, uint256 secondRefRate);
event ReferralEnabled(address indexed ref);
event ReferralDisabled(address indexed ref);
event ClaimedFunds(address indexed ref, address indexed token, uint256 amount);
error ErrParamsInvalid();
error ErrStarted();
error ErrClosed();
error ErrNullAddress();
error ErrRoundUndefined(uint256 index_);
error ErrRoundStarted(uint256 index_);
error ErrRoundClosed(uint256 index_);
error ErrRoundSupply(uint256 index_);
error ErrMin(uint256 amount_, uint256 min_);
error ErrMax(uint256 amount_, uint256 max_);
error ErrAuthLimit(uint256 limit_, uint256 min_, uint256 max_);
error ErrFirstRefFunds(uint256 reward_);
error ErrSecondRefFunds(uint256 reward_);
error ErrRefUndefined(address ref_);
error ErrRefEnabled(address ref_);
error ErrRefDisabled(address ref_);
error ErrTokenUndefined();
error ErrTransfer();
constructor(address treasury_) {
if (treasury_ == address(0)) {
revert ErrNullAddress();
}
_treasury = treasury_;
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_grantRole(OPERATOR_ROLE, _msgSender());
}
function open()
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (_state != State.None) {
revert ErrStarted();
}
_state = State.Opened;
emit StateUpdated(_state);
}
function close()
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (!isActive()) {
revert ErrClosed();
}
_state = State.Closed;
emit StateUpdated(_state);
}
function setRound(uint256 sPrice_, uint256 lPrice_, uint256 supply_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (isInactive()) {
revert ErrClosed();
}
_rounds.push(
Round({ defined: true, state: State.None, sPrice: sPrice_, lPrice: lPrice_, sold: 0, supply: supply_})
);
emit RoundAdded(sPrice_, lPrice_, supply_);
}
function setRefRate(uint256 firstRefRate_, uint256 secondRefRate_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (isInactive()) {
revert ErrClosed();
}
if (firstRefRate_ > 1000) {
revert ErrFirstRefFunds(firstRefRate_);
}
if (secondRefRate_ > 1000) {
revert ErrSecondRefFunds(secondRefRate_);
}
_firstRefRate = firstRefRate_;
_secondRefRate = secondRefRate_;
emit RefRateSetup(_firstRefRate, _secondRefRate);
}
function setupReferrals(address[] calldata refs_, uint256[] calldata firstRefRate_, uint256[] calldata secodRefFunds_)
external onlyRole(OPERATOR_ROLE)
{
if (isInactive()) {
revert ErrClosed();
}
if (refs_.length != firstRefRate_.length || refs_.length != secodRefFunds_.length) {
revert ErrParamsInvalid();
}
for (uint256 index = 0; index < refs_.length; index++) {
_refs[refs_[index]] = Referral({
defined: true,
enabled: true,
firstRefRate: firstRefRate_[index],
secondRefRate: secodRefFunds_[index]
});
emit ReferralSetup(refs_[index], firstRefRate_[index], secodRefFunds_[index]);
}
}
function updateRoundPrice(uint256 index_, uint256 sPrice_, uint256 lPrice_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (isInactive()) {
revert ErrClosed();
}
if (!_rounds[index_].defined) {
revert ErrRoundUndefined(index_);
}
if (_rounds[index_].state != State.None) {
revert ErrRoundStarted(index_);
}
_rounds[index_].sPrice = sPrice_;
_rounds[index_].lPrice = lPrice_;
emit RoundPriceUpdated(index_, sPrice_, lPrice_);
}
function updateRoundSupply(uint256 index_, uint256 supply_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (isInactive()) {
revert ErrClosed();
}
if (!_rounds[index_].defined) {
revert ErrRoundUndefined(index_);
}
if (_rounds[index_].state == State.Closed) {
revert ErrRoundClosed(index_);
}
if (_rounds[index_].sold > supply_) {
revert ErrRoundSupply(index_);
}
_rounds[index_].supply = supply_;
emit RoundSupplyUpdated(index_, supply_);
}
function openRound(uint256 index_)
external onlyRole(OPERATOR_ROLE)
{
if (!isActive()) {
revert ErrClosed();
}
if (!_rounds[index_].defined) {
revert ErrRoundUndefined(index_);
}
if (_rounds[index_].state != State.None) {
revert ErrRoundStarted(index_);
}
if (_rounds[_currentRound].state == State.Opened) {
_rounds[_currentRound].state = State.Closed;
}
_rounds[index_].state = State.Opened;
_currentRound = index_;
emit RoundOpened(index_);
}
function closeRound(uint256 index_)
external onlyRole(OPERATOR_ROLE)
{
if (!_rounds[index_].defined) {
revert ErrRoundUndefined(index_);
}
if (_rounds[index_].state != State.Opened) {
revert ErrRoundClosed(index_);
}
_rounds[index_].state = State.Closed;
emit RoundClosed(index_);
}
function setAuth(address user_, bool value_)
external onlyRole(OPERATOR_ROLE)
{
_auth[user_] = value_;
emit AuthUserUpdated(user_, value_);
}
function setAuthBatch(address[] calldata users_, bool[] calldata values_)
external onlyRole(OPERATOR_ROLE)
{
if (users_.length != values_.length) {
revert ErrParamsInvalid();
}
for (uint256 index = 0; index < users_.length; index++) {
_auth[users_[index]] = values_[index];
emit AuthUserUpdated(users_[index], values_[index]);
}
}
function setMax(uint256 amount_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (amount_ > MAX) {
revert ErrMax(amount_, MAX);
}
if (amount_ < _min) {
revert ErrMin(amount_, _min);
}
_max = amount_;
emit MaxUpdated(_max);
}
function setMin(uint256 amount_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (amount_ < MIN) {
revert ErrMin(amount_, MIN);
}
if (amount_ > _max) {
revert ErrMax(amount_, _max);
}
_min = amount_;
emit MinUpdated(_min);
}
function setAuthLimit(uint256 amount_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (_min > amount_ || amount_ > _max) {
revert ErrAuthLimit(amount_, _min, _max);
}
_authLimit = amount_;
emit AuthLimitUpdated(amount_);
}
function setTreasury(address treasury_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (treasury_ == address(0)) {
revert ErrNullAddress();
}
_treasury = treasury_;
emit TreasuryUpdated(_treasury);
}
function setState(address user_, address token_, uint256 amount_, uint256 sold_, address ref_, uint256 fReward_, uint256 sReward_)
external onlyRole(OPERATOR_ROLE)
{
_funds[user_] = _funds[user_] + amount_;
_totalSold = _totalSold + sold_;
_rounds[_currentRound].sold = _rounds[_currentRound].sold + sold_;
_balances[user_][_currentRound] = _balances[user_][_currentRound] + sold_;
if (ref_ != address(0)) {
if (!_refs[ref_].defined) {
_refs[ref_].defined = true;
_refs[ref_].enabled = true;
emit ReferralSetup(ref_, _firstRefRate, _secondRefRate);
}
_refsBalances[ref_][token_] += fReward_;
_refsBalances[ref_][TOKEN] += sReward_;
_refsUsers[user_] = ref_;
}
}
function enableReferral(address ref_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (!_refs[ref_].defined) {
revert ErrRefUndefined(ref_);
}
if (_refs[ref_].enabled) {
revert ErrRefEnabled(ref_);
}
_refs[ref_].enabled = true;
emit ReferralEnabled(ref_);
}
function disableReferral(address ref_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
if (!_refs[ref_].defined) {
revert ErrRefUndefined(ref_);
}
if (!_refs[ref_].enabled) {
revert ErrRefDisabled(ref_);
}
_refs[ref_].enabled = false;
emit ReferralDisabled(ref_);
}
function claimRef(address[] calldata tokens_)
external nonReentrant()
{
address ref_ = _msgSender();
if (tokens_.length == 0) {
revert ErrTokenUndefined();
}
if (!_refs[ref_].defined) {
revert ErrRefUndefined(ref_);
}
if (!_refs[ref_].enabled) {
revert ErrRefDisabled(ref_);
}
for (uint256 i = 0; i < tokens_.length; i++) {
address token = tokens_[i];
uint256 balance = _refsBalances[ref_][token];
if (balance == 0) { continue; }
_refsBalances[ref_][token] = 0;
if (token == ETH) {
(bool success, ) = ref_.call{value: balance}('');
if (!success) revert ErrTransfer();
} else {
IERC20(token).safeTransfer(ref_, balance);
}
emit ClaimedFunds(ref_, token, balance);
}
}
function recoverCoin()
external onlyRole(DEFAULT_ADMIN_ROLE)
{
uint256 balance = address(this).balance;
_msgSender().call{value: balance}('');
emit CoinRecovered(balance);
}
function recoverErc20(address token_, uint256 amount_)
external onlyRole(DEFAULT_ADMIN_ROLE)
{
IERC20(token_).safeTransfer(_msgSender(), amount_);
emit Erc20Recovered(token_, amount_);
}
function getTreasury() external view returns (address) {
return _treasury;
}
function getMax() external view returns (uint256) {
return _max;
}
function getMin() external view returns (uint256) {
return _min;
}
function getRoundsCount() external view returns (uint256) {
return _rounds.length;
}
function getCurrentRound() external view returns (uint256) {
return _currentRound;
}
function getRound(uint256 index_) external view returns (Round memory) {
return _rounds[index_];
}
function getTotalSold() external view returns (uint256) {
return _totalSold;
}
function balanceOf(uint256 round_, address user_) external view returns (uint256) {
return _balances[user_][round_];
}
function refBalanceOf(address token_, address user_) external view returns (uint256) {
return _refsBalances[user_][token_];
}
function limitOf(address user_) external view returns (uint256) {
uint256 amount = _funds[user_];
uint256 limit = _authLimit;
if (isAuth(user_)) {
limit = _max;
}
return amount < limit ? limit - amount : 0;
}
function maxLimitOf(address user_) external view returns (uint256) {
uint256 amount = _funds[user_];
return amount < _max ? _max - amount : 0;
}
function getAuthLimit() external view returns (uint256) {
return _authLimit;
}
function getRefRates() external view returns (uint256, uint256) {
return (_firstRefRate, _secondRefRate);
}
function getRef(address user_, address ref_) external view returns (address) {
Referral memory ref = _refs[_refsUsers[user_]];
if (ref.defined && ref.enabled) {
return _refsUsers[user_];
}
ref = _refs[ref_];
if (!ref.defined || ref.enabled) {
return ref_;
}
return address(0);
}
function getRefRates(address ref_) external view returns (uint256, uint256) {
Referral memory ref = _refs[ref_];
if (ref.defined) {
return (Math.max(ref.firstRefRate, _firstRefRate), Math.max(ref.secondRefRate, _secondRefRate));
}
return (_firstRefRate, _secondRefRate);
}
function isActive() public view returns (bool) {
return _state == State.Opened;
}
function isInactive() public view returns (bool) {
return _state == State.Closed;
}
function getPrice(Option option_) public view returns (uint256) {
if (_rounds[_currentRound].state == State.Opened) {
return option_ == Option.Short ? _rounds[_currentRound].sPrice : _rounds[_currentRound].lPrice;
}
return 0;
}
function isAuth(address user_) public view returns (bool) {
return _auth[user_];
}
receive() external payable { }
}
{
"compilationTarget": {
"contracts/Storage.sol": "Storage"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"viaIR": true
}
[{"inputs":[{"internalType":"address","name":"treasury_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[{"internalType":"uint256","name":"limit_","type":"uint256"},{"internalType":"uint256","name":"min_","type":"uint256"},{"internalType":"uint256","name":"max_","type":"uint256"}],"name":"ErrAuthLimit","type":"error"},{"inputs":[],"name":"ErrClosed","type":"error"},{"inputs":[{"internalType":"uint256","name":"reward_","type":"uint256"}],"name":"ErrFirstRefFunds","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint256","name":"max_","type":"uint256"}],"name":"ErrMax","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint256","name":"min_","type":"uint256"}],"name":"ErrMin","type":"error"},{"inputs":[],"name":"ErrNullAddress","type":"error"},{"inputs":[],"name":"ErrParamsInvalid","type":"error"},{"inputs":[{"internalType":"address","name":"ref_","type":"address"}],"name":"ErrRefDisabled","type":"error"},{"inputs":[{"internalType":"address","name":"ref_","type":"address"}],"name":"ErrRefEnabled","type":"error"},{"inputs":[{"internalType":"address","name":"ref_","type":"address"}],"name":"ErrRefUndefined","type":"error"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"ErrRoundClosed","type":"error"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"ErrRoundStarted","type":"error"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"ErrRoundSupply","type":"error"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"ErrRoundUndefined","type":"error"},{"inputs":[{"internalType":"uint256","name":"reward_","type":"uint256"}],"name":"ErrSecondRefFunds","type":"error"},{"inputs":[],"name":"ErrStarted","type":"error"},{"inputs":[],"name":"ErrTokenUndefined","type":"error"},{"inputs":[],"name":"ErrTransfer","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"limit","type":"uint256"}],"name":"AuthLimitUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"bool","name":"value","type":"bool"}],"name":"AuthUserUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"ref","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ClaimedFunds","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"CoinRecovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Erc20Recovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"MaxUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"MinUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"firstRefRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"secondRefRate","type":"uint256"}],"name":"RefRateSetup","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"ref","type":"address"}],"name":"ReferralDisabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"ref","type":"address"}],"name":"ReferralEnabled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"ref","type":"address"},{"indexed":false,"internalType":"uint256","name":"firstRefRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"secondRefRate","type":"uint256"}],"name":"ReferralSetup","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"sPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"supply","type":"uint256"}],"name":"RoundAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"}],"name":"RoundClosed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"}],"name":"RoundOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"sPrice","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lPrice","type":"uint256"}],"name":"RoundPriceUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"round","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"supply","type":"uint256"}],"name":"RoundSupplyUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum Storage.State","name":"state","type":"uint8"}],"name":"StateUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"treasury","type":"address"}],"name":"TreasuryUpdated","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"round_","type":"uint256"},{"internalType":"address","name":"user_","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens_","type":"address[]"}],"name":"claimRef","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"close","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"closeRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ref_","type":"address"}],"name":"disableReferral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ref_","type":"address"}],"name":"enableReferral","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAuthLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMax","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum Storage.Option","name":"option_","type":"uint8"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"},{"internalType":"address","name":"ref_","type":"address"}],"name":"getRef","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRefRates","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"ref_","type":"address"}],"name":"getRefRates","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"getRound","outputs":[{"components":[{"internalType":"bool","name":"defined","type":"bool"},{"internalType":"enum Storage.State","name":"state","type":"uint8"},{"internalType":"uint256","name":"sPrice","type":"uint256"},{"internalType":"uint256","name":"lPrice","type":"uint256"},{"internalType":"uint256","name":"sold","type":"uint256"},{"internalType":"uint256","name":"supply","type":"uint256"}],"internalType":"struct Storage.Round","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRoundsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotalSold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTreasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isActive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"}],"name":"isAuth","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isInactive","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"}],"name":"limitOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"}],"name":"maxLimitOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"open","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"}],"name":"openRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recoverCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"recoverErc20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token_","type":"address"},{"internalType":"address","name":"user_","type":"address"}],"name":"refBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"},{"internalType":"bool","name":"value_","type":"bool"}],"name":"setAuth","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"users_","type":"address[]"},{"internalType":"bool[]","name":"values_","type":"bool[]"}],"name":"setAuthBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"setAuthLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"setMax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount_","type":"uint256"}],"name":"setMin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"firstRefRate_","type":"uint256"},{"internalType":"uint256","name":"secondRefRate_","type":"uint256"}],"name":"setRefRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"sPrice_","type":"uint256"},{"internalType":"uint256","name":"lPrice_","type":"uint256"},{"internalType":"uint256","name":"supply_","type":"uint256"}],"name":"setRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user_","type":"address"},{"internalType":"address","name":"token_","type":"address"},{"internalType":"uint256","name":"amount_","type":"uint256"},{"internalType":"uint256","name":"sold_","type":"uint256"},{"internalType":"address","name":"ref_","type":"address"},{"internalType":"uint256","name":"fReward_","type":"uint256"},{"internalType":"uint256","name":"sReward_","type":"uint256"}],"name":"setState","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"treasury_","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"refs_","type":"address[]"},{"internalType":"uint256[]","name":"firstRefRate_","type":"uint256[]"},{"internalType":"uint256[]","name":"secodRefFunds_","type":"uint256[]"}],"name":"setupReferrals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"},{"internalType":"uint256","name":"sPrice_","type":"uint256"},{"internalType":"uint256","name":"lPrice_","type":"uint256"}],"name":"updateRoundPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"index_","type":"uint256"},{"internalType":"uint256","name":"supply_","type":"uint256"}],"name":"updateRoundSupply","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]