- Contract name:
- StarsLeague
- Optimization enabled
- true
- Compiler version
- v0.8.9+commit.e5eed63a
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2023-11-09T12:43:07.797693Z
contracts/StarsLeague.sol
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.9;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
struct Pool {
uint256 initialShares;
uint256 endTimeBid;
uint256 value;
uint256 sharesSupply;
uint256 subjectFee;
uint256 referrerFee;
address owner;
address referrer;
mapping(address => uint256) sharesBalance;
}
struct PoolInitialTop {
address account;
uint256 amount;
}
contract StarsLeague is
Initializable,
OwnableUpgradeable,
AccessControlUpgradeable
{
using ECDSA for bytes32;
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
uint256 public constant PERCENT_BASE = 100;
uint256 public constant PRICE_STEP_PERCENT = 10;
// pricing params
uint256 public constant PRICE_A = 3 ether;
uint256 public constant PRICE_B = 4;
uint256 public constant PRICE_C = 4680000; // tax param
uint256 public constant INIT_BID_PRICE = 1 ether;
address public protocolFeeDestination;
uint256 public protocolFeePercent;
uint256 public subjectFeePercent;
uint256 public referrerFeePercent;
uint256 public poolFeePercent;
uint256 public maxInitialShares;
uint256 private totalFees;
mapping(address => Pool) pools;
mapping(address => PoolInitialTop[]) poolInitialTops;
// ReentrancyGuard
// Add new variable - 0.3.0
uint256 private constant GUARD_NOT_ENTERED = 1;
uint256 private constant GUARD_ENTERED = 2;
uint256 private _guardStatus;
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
require(_guardStatus != GUARD_ENTERED);
_guardStatus = GUARD_ENTERED;
_;
_guardStatus = GUARD_NOT_ENTERED;
}
event Trade(
address trader,
address subject,
bool isBuy,
uint256 shareAmount,
uint256 ethAmount,
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee,
uint256 balance,
uint256 totalSupply,
bool isAirdrop,
bool isBid
);
function initialize() public initializer {
__Ownable_init();
__AccessControl_init_unchained();
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
// init value
protocolFeeDestination = owner();
protocolFeePercent = ((1 ether) * 3) / 100;
subjectFeePercent = ((1 ether) * 5) / 100;
referrerFeePercent = ((1 ether) * 1) / 100;
poolFeePercent = ((1 ether) * 1) / 100;
_updateTotalFees();
maxInitialShares = 30;
}
///////////////////////////
////// SYSTEM ACTION //////
///////////////////////////
function initializeSharesSub(
address sharesSubject,
uint256 _initialShares,
uint256 _blockTime
) external payable onlyRole(OPERATOR_ROLE) {
require(_initialShares <= maxInitialShares, "Initial shares exceeded");
require(pools[sharesSubject].sharesSupply == 0, "Share pool exist");
Pool storage newPool = pools[sharesSubject];
newPool.initialShares = _initialShares;
newPool.endTimeBid = block.timestamp + _blockTime;
newPool.sharesSupply = 1;
newPool.sharesBalance[sharesSubject] = 1;
emit Trade(
sharesSubject,
sharesSubject,
true,
1,
0,
0,
0,
0,
0,
1,
1,
false,
false
);
}
function initializeSharesBySystem(
address sharesSubject,
address referrer,
uint256 _initialShares,
uint256 _blockTime
) external onlyRole(OPERATOR_ROLE) {
require(_initialShares <= maxInitialShares, "Initial shares exceeded");
require(sharesSubject != address(0), "Invalid Share Subject");
require(
referrer != address(0) && sharesSubject != referrer,
"Invalid Referer"
);
require(pools[sharesSubject].sharesSupply == 0, "Share pool exist");
//BUY FIRST SHARE FOR SHARE SUBJECT
Pool storage newPool = pools[sharesSubject];
newPool.owner = sharesSubject;
newPool.referrer = referrer;
newPool.initialShares = _initialShares;
newPool.endTimeBid = block.timestamp + _blockTime;
newPool.sharesSupply = 1;
newPool.sharesBalance[sharesSubject] = 1;
emit Trade(
sharesSubject,
sharesSubject,
true,
1,
0,
0,
0,
0,
0,
1,
1,
false,
false
);
//BUY SHARE FOR REF
newPool.sharesBalance[referrer] = 1;
newPool.sharesSupply += 1;
newPool.value = 0;
emit Trade(
referrer,
sharesSubject,
true,
1,
0,
0,
0,
0,
0,
1,
2,
true,
false
);
}
/////////////////////////
////// USER ACTION //////
/////////////////////////
function initializeShares(
address referrer,
uint256 _initialShares,
uint256 _blockTime,
uint256 nonce,
bytes memory signature
) external payable {
address sharesSubject = msg.sender;
require(_initialShares <= maxInitialShares, "Initial shares exceeded");
require(
referrer != address(0) && sharesSubject != referrer,
"Invalid Referer"
);
require(pools[sharesSubject].sharesSupply == 0, "Share pool exist");
bytes32 hash = keccak256(
abi.encodePacked(
address(this),
sharesSubject,
referrer,
_initialShares,
_blockTime,
msg.value,
nonce
)
);
address recoverAddress = hash.toEthSignedMessageHash().recover(
signature
);
require(
hasRole(OPERATOR_ROLE, recoverAddress),
"Caller doesn't have permission of operator"
);
//BUY FIRST SHARE FOR SHARE SUBJECT
Pool storage newPool = pools[sharesSubject];
newPool.owner = sharesSubject;
newPool.referrer = referrer;
newPool.initialShares = _initialShares;
newPool.endTimeBid = block.timestamp + _blockTime;
newPool.sharesSupply = 1;
newPool.sharesBalance[sharesSubject] = 1;
emit Trade(
sharesSubject,
sharesSubject,
true,
1,
0,
0,
0,
0,
0,
1,
1,
false,
false
);
//BUY SHARE FOR REF
uint256 price = getPrice(1, 1);
require(msg.value == price, "Invalid price");
newPool.sharesBalance[referrer] = 1;
newPool.sharesSupply += 1;
newPool.value = price;
emit Trade(
referrer,
sharesSubject,
true,
1,
price,
0,
0,
0,
0,
1,
2,
true,
false
);
}
function buyShares(address sharesSubject) external payable nonReentrant {
require(
pools[sharesSubject].sharesSupply > 0,
"Shared subject not initialize"
);
//check if initialBuys finish
if (_isBidding(sharesSubject)) {
_bidShares(sharesSubject);
} else {
_buyShares(sharesSubject);
}
}
function sellShares(
address sharesSubject,
uint256 amount
) external nonReentrant {
Pool storage pool = pools[sharesSubject];
require(
amount > 0 && pool.sharesSupply > amount,
"Cannot sell the last share"
);
require(
!_isBidding(sharesSubject),
"Cannot sell share in initial buy time"
);
require(
pool.sharesBalance[msg.sender] >= amount,
"Insufficient shares"
);
require(
pool.owner != msg.sender || pool.sharesBalance[msg.sender] > amount,
"Owner cannot sell all shares"
);
uint256 price = getSellPrice(sharesSubject, amount);
(
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee
) = getFee(price);
require(price >= 0, "Insufficient fund to sell");
pool.sharesBalance[msg.sender] -= amount;
pool.sharesSupply -= amount;
pool.value = pool.value + poolFee - price;
(bool success1, ) = msg.sender.call{
value: price - protocolFee - subjectFee - poolFee - referrerFee
}("");
(bool success2, ) = protocolFeeDestination.call{value: protocolFee}("");
require(success1 && success2, "Unable to send funds");
_transferForOwner(sharesSubject, subjectFee);
_transferForReferrer(sharesSubject, referrerFee);
uint balance = pool.sharesBalance[msg.sender];
uint supply = pool.sharesSupply;
emit Trade(
msg.sender,
sharesSubject,
false,
amount,
price,
protocolFee,
subjectFee,
referrerFee,
poolFee,
balance,
supply,
false,
false
);
}
function activateOwner(
address sharesSubject,
address referrer,
uint256 nonce,
bytes memory signature
) external nonReentrant {
Pool storage pool = pools[sharesSubject];
require(
pools[sharesSubject].sharesSupply > 0,
"Share pool does not exist"
);
require(
pools[sharesSubject].owner == address(0),
"Share pool activated owner"
);
bytes32 hash = keccak256(
abi.encodePacked(
address(this),
sharesSubject,
referrer,
msg.sender,
nonce
)
);
address recoverAddress = hash.toEthSignedMessageHash().recover(
signature
);
require(
hasRole(OPERATOR_ROLE, recoverAddress),
"Caller doesn't have permission of operator"
);
pool.owner = msg.sender;
pool.referrer = referrer;
_transferForOwner(sharesSubject, 0);
_transferForReferrer(sharesSubject, 0);
uint supply = pool.sharesSupply;
uint balance = pool.sharesBalance[sharesSubject];
// Transfer 1 share from shareSuject to new owner
pool.sharesBalance[sharesSubject] -= 1;
pool.sharesBalance[pool.owner] += 1;
emit Trade(
sharesSubject,
sharesSubject,
false,
1,
0,
0,
0,
0,
0,
balance - 1,
supply,
false,
false
);
uint ownerBalance = pool.sharesBalance[pool.owner];
emit Trade(
pool.owner,
sharesSubject,
true,
1,
0,
0,
0,
0,
0,
ownerBalance,
supply,
false,
false
);
}
////////////////////
////// SETTER //////
////////////////////
function setProtocolFeeDestination(
address _feeDestination
) public onlyOwner {
protocolFeeDestination = _feeDestination;
}
function setProtocolFeePercent(uint256 _feePercent) public onlyOwner {
protocolFeePercent = _feePercent;
_updateTotalFees();
}
function setSubjectFeePercent(uint256 _feePercent) public onlyOwner {
subjectFeePercent = _feePercent;
_updateTotalFees();
}
function setReferrerFeePercent(uint256 _feePercent) public onlyOwner {
referrerFeePercent = _feePercent;
_updateTotalFees();
}
function setPoolFeePercent(uint256 _feePercent) public onlyOwner {
poolFeePercent = _feePercent;
_updateTotalFees();
}
function setMaxInitialShares(uint256 _maxInitialShares) public onlyOwner {
maxInitialShares = _maxInitialShares;
}
////////////////////
////// GETTER //////
////////////////////
function getPrice(
uint256 supply,
uint256 amount
) public pure returns (uint256) {
uint256 sum1 = supply == 0
? 0
: ((supply - 1) * (supply) * (2 * (supply - 1) + 1)) / 6;
uint256 sum2 = supply == 0 && amount == 1
? 0
: ((supply + amount - 1) *
(supply + amount) *
(2 * (supply + amount - 1) + 1)) / 6;
uint256 summation = sum2 - sum1;
return (summation * PRICE_A) / PRICE_B;
}
function _getSupply(
uint256 supply,
uint256 liquid
) internal pure returns (uint256 _supply) {
_supply = supply;
uint256 _normLiquid1 = getPrice(0, _supply);
uint256 _normLiquid2 = _normLiquid1;
if (_normLiquid1 > liquid) {
while (_supply > 1 && _normLiquid2 > liquid) {
_supply--;
_normLiquid2 = getPrice(0, _supply);
}
if (_supply < supply) _supply++;
} else {
while (_normLiquid2 < liquid) {
_supply++;
_normLiquid2 = getPrice(_supply - supply, supply);
}
}
}
function getBuyPrice(
address sharesSubject,
uint256 amount
) public view returns (uint256 price) {
uint256 _supply = _getSupply(
pools[sharesSubject].sharesSupply,
pools[sharesSubject].value
);
price = getPrice(_supply, amount);
}
function getSellPrice(
address sharesSubject,
uint256 amount
) public view returns (uint256 price) {
uint256 supply = pools[sharesSubject].sharesSupply;
uint256 liquid = pools[sharesSubject].value;
uint256 _supply = _getSupply(supply, liquid);
uint256 minSellPrice = getPrice(1, 1);
uint256 minLiquid = minSellPrice * (supply - 1);
if (liquid <= minLiquid) {
price = minSellPrice;
} else {
if (_supply <= amount) _supply = amount + 1;
price = getPrice(_supply - amount, amount);
if (price > liquid) price = liquid;
if (liquid + minSellPrice - price < minLiquid)
price = liquid + minSellPrice - minLiquid;
}
// min price
if (price < minSellPrice) price = 0;
}
function getBuyPriceAfterFee(
address sharesSubject,
uint256 amount
) public view returns (uint256) {
uint256 price = getBuyPrice(sharesSubject, amount);
(
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee
) = getFee(price);
return price + protocolFee + subjectFee + referrerFee + poolFee;
}
function getSellPriceAfterFee(
address sharesSubject,
uint256 amount
) public view returns (uint256) {
uint256 price = getSellPrice(sharesSubject, amount);
(
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee
) = getFee(price);
return price - protocolFee - subjectFee - referrerFee - poolFee;
}
function balanceOf(
address sharesSubject,
address account
) external view returns (uint256) {
return pools[sharesSubject].sharesBalance[account];
}
function supplyOf(address sharesSubject) external view returns (uint256) {
return pools[sharesSubject].sharesSupply;
}
function ownerOf(address sharesSubject) external view returns (address) {
return pools[sharesSubject].owner;
}
function getPoolSubjectFee(
address sharesSubject
) external view returns (uint256) {
return pools[sharesSubject].subjectFee;
}
function getPoolReferrerFee(
address sharesSubject
) external view returns (uint256) {
return pools[sharesSubject].referrerFee;
}
function getPoolInitialTops(
address sharesSubject
) external view returns (PoolInitialTop[] memory) {
return poolInitialTops[sharesSubject];
}
function getPoolValue(
address sharesSubject
) external view returns (uint256) {
return pools[sharesSubject].value;
}
function getPoolReferrer(
address sharesSubject
) external view returns (address) {
return pools[sharesSubject].referrer;
}
function getPoolInitialBuy(
address sharesSubject
) external view returns (bool) {
return _isBidding(sharesSubject);
}
function getPoolInitialBuyPriceAfterFee(
address sharesSubject
) public view returns (uint256) {
if (
poolInitialTops[sharesSubject].length <
pools[sharesSubject].initialShares
) {
return INIT_BID_PRICE;
} else {
return
(poolInitialTops[sharesSubject][0].amount *
(100 + PRICE_STEP_PERCENT)) / 100;
}
}
function getBiddingTime(
address sharesSubject
) external view returns (uint256) {
return pools[sharesSubject].endTimeBid;
}
function getFee(
uint256 price
)
public
view
returns (
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee
)
{
uint maxTax = 1000;
uint taxByPrice = PRICE_C / _sqrt((price * PRICE_B * 10000) / PRICE_A);
if (taxByPrice > maxTax) taxByPrice = maxTax;
protocolFee =
((price * protocolFeePercent * taxByPrice) / maxTax) /
1 ether;
subjectFee =
((price * subjectFeePercent * taxByPrice) / maxTax) /
1 ether;
referrerFee =
((price * referrerFeePercent * taxByPrice) / maxTax) /
1 ether;
poolFee = ((price * poolFeePercent * taxByPrice) / maxTax) / 1 ether;
}
function version() external pure returns (string memory) {
return "0.3.0";
}
//////////////////////
////// INTERNAL //////
//////////////////////
function _isBidding(address sharesSubject) internal view returns (bool) {
return block.timestamp <= pools[sharesSubject].endTimeBid;
}
function _updateTotalFees() internal {
totalFees =
protocolFeePercent +
subjectFeePercent +
referrerFeePercent +
poolFeePercent;
require(totalFees <= (1 ether) / 10, "Total Fee must less than 10%");
}
function _checkIfValidToTop(
address sharesSubject,
uint256 amount
) internal view returns (bool valid, uint256 index) {
valid = amount >= getPoolInitialBuyPriceAfterFee(sharesSubject);
if (poolInitialTops[sharesSubject].length != 0 && valid) {
uint256 i;
if (
poolInitialTops[sharesSubject].length <
pools[sharesSubject].initialShares
) {
i = poolInitialTops[sharesSubject].length;
while (
i > 0 &&
amount < poolInitialTops[sharesSubject][i - 1].amount
) {
i--;
}
} else {
i = poolInitialTops[sharesSubject].length - 1;
while (
i > 0 && amount < poolInitialTops[sharesSubject][i].amount
) {
i--;
}
}
index = i;
}
}
function _injectToTops(
address sharesSubject,
address account,
uint256 amount
) internal returns (address shiftAccount, uint256 refundAmount) {
(bool isValidToTops, uint256 index) = _checkIfValidToTop(
sharesSubject,
amount
);
require((isValidToTops), "Invalid amount");
if (
poolInitialTops[sharesSubject].length <
pools[sharesSubject].initialShares
) {
//expand the array
PoolInitialTop memory newPoolInitialTop;
newPoolInitialTop.account = address(0);
poolInitialTops[sharesSubject].push(newPoolInitialTop);
// shift from index to right
for (
uint i = poolInitialTops[sharesSubject].length - 1;
i > index;
i--
) {
poolInitialTops[sharesSubject][i].account = poolInitialTops[
sharesSubject
][i - 1].account;
poolInitialTops[sharesSubject][i].amount = poolInitialTops[
sharesSubject
][i - 1].amount;
}
} else {
shiftAccount = poolInitialTops[sharesSubject][0].account;
refundAmount = poolInitialTops[sharesSubject][0].amount;
// shift from index to left
for (uint i = 0; i < index; i++) {
poolInitialTops[sharesSubject][i].account = poolInitialTops[
sharesSubject
][i + 1].account;
poolInitialTops[sharesSubject][i].amount = poolInitialTops[
sharesSubject
][i + 1].amount;
}
}
poolInitialTops[sharesSubject][index].account = account;
poolInitialTops[sharesSubject][index].amount = amount;
}
// Buy in bidding time
function _bidShares(address sharesSubject) internal {
(address shiftAccount, uint256 refundAmount) = _injectToTops(
sharesSubject,
msg.sender,
msg.value
);
Pool storage pool = pools[sharesSubject];
pool.sharesBalance[msg.sender] += 1;
// //shift first element of top list and refund to account if top list exceed
if (shiftAccount != address(0)) {
(bool status, ) = shiftAccount.call{value: refundAmount}("");
// payable(shiftAccount).transfer(refundAmount);
pool.sharesBalance[shiftAccount] -= 1;
} else {
pool.sharesSupply++;
}
uint256 diffPrice = ((msg.value - refundAmount) * 1 ether) /
(totalFees + 1 ether);
(
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee
) = getFee(diffPrice);
pool.value =
pool.value +
msg.value -
refundAmount -
protocolFee -
subjectFee -
referrerFee;
(bool success, ) = protocolFeeDestination.call{value: protocolFee}("");
require(success, "Unable to send funds");
_transferForOwner(sharesSubject, subjectFee);
_transferForReferrer(sharesSubject, referrerFee);
uint balance = pool.sharesBalance[shiftAccount];
uint supply = pool.sharesSupply;
if (shiftAccount != address(0)) {
emit Trade(
shiftAccount,
sharesSubject,
false,
1,
refundAmount,
0,
0,
0,
0,
balance,
supply,
false,
true
);
}
balance = pool.sharesBalance[msg.sender];
emit Trade(
msg.sender,
sharesSubject,
true,
1,
(msg.value * (1 ether)) / (1 ether + totalFees),
protocolFee,
subjectFee,
referrerFee,
poolFee,
balance,
supply,
false,
true
);
}
// buy
function _buyShares(address sharesSubject) internal {
Pool storage pool = pools[sharesSubject];
uint256 price = getBuyPrice(sharesSubject, 1);
(
uint256 protocolFee,
uint256 subjectFee,
uint256 referrerFee,
uint256 poolFee
) = getFee(price);
require(
msg.value >=
price + protocolFee + subjectFee + referrerFee + poolFee,
"Insufficient payment"
);
pool.sharesBalance[msg.sender] += 1;
pool.sharesSupply += 1;
pool.value =
pool.value +
msg.value -
protocolFee -
subjectFee -
referrerFee;
(bool success, ) = protocolFeeDestination.call{value: protocolFee}("");
require(success, "Unable to send funds");
_transferForOwner(sharesSubject, subjectFee);
_transferForReferrer(sharesSubject, referrerFee);
uint balance = pool.sharesBalance[msg.sender];
uint supply = pool.sharesSupply;
emit Trade(
msg.sender,
sharesSubject,
true,
1,
price,
protocolFee,
subjectFee,
referrerFee,
poolFee,
balance,
supply,
false,
false
);
}
function _transferForOwner(address sharesSubject, uint256 amount) internal {
address owner = pools[sharesSubject].owner;
if (owner != address(0)) {
uint subjectFee = pools[sharesSubject].subjectFee + amount;
require(subjectFee > 0, "Subject fee more than 0");
pools[sharesSubject].subjectFee = 0;
(bool success, ) = owner.call{value: subjectFee}("");
require(success, "Unable to send funds");
} else {
pools[sharesSubject].subjectFee += amount;
}
}
function _transferForReferrer(
address sharesSubject,
uint256 amount
) internal {
address referrer = pools[sharesSubject].referrer;
if (referrer != address(0)) {
uint referrerFee = pools[sharesSubject].referrerFee + amount;
require(referrerFee > 0, "Referrer fee more than 0");
pools[sharesSubject].referrerFee = 0;
(bool success, ) = referrer.call{value: referrerFee}("");
require(success, "Unable to send funds");
} else {
pools[sharesSubject].referrerFee += amount;
}
}
function _sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}
@openzeppelin/contracts/proxy/beacon/IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.0;
import "../../interfaces/draft-IERC1822.sol";
import "../ERC1967/ERC1967Upgrade.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/
abstract contract UUPSUpgradeable is IERC1822Proxiable, ERC1967Upgrade {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
address private immutable __self = address(this);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
require(address(this) != __self, "Function must be called through delegatecall");
require(_getImplementation() == __self, "Function must be called through active proxy");
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
require(address(this) == __self, "UUPSUpgradeable: must not be called through delegatecall");
_;
}
/**
* @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual override notDelegated returns (bytes32) {
return _IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeTo(address newImplementation) public virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, new bytes(0), false);
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data, true);
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeTo} and {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal override onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
}
@openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
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");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts/interfaces/draft-IERC1822.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(account),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}
@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
import "../../utils/AddressUpgradeable.sol";
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}
@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
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");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
import "../beacon/IBeacon.sol";
import "../../interfaces/IERC1967.sol";
import "../../interfaces/draft-IERC1822.sol";
import "../../utils/Address.sol";
import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967Upgrade is IERC1967 {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/MathUpgradeable.sol";
import "./math/SignedMathUpgradeable.sol";
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = MathUpgradeable.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMathUpgradeable.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, MathUpgradeable.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}
@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library MathUpgradeable {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
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);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 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;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 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;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
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;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
@openzeppelin/contracts-upgradeable/utils/math/SignedMathUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMathUpgradeable {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
@openzeppelin/contracts/interfaces/IERC1967.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*
* _Available since v4.8.3._
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}
@openzeppelin/contracts/utils/StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
@openzeppelin/contracts/utils/cryptography/ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
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);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 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;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 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;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
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;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
@openzeppelin/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
Contract ABI
[{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"INIT_BID_PRICE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"OPERATOR_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PERCENT_BASE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PRICE_A","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PRICE_B","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PRICE_C","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"PRICE_STEP_PERCENT","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"activateOwner","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"address","name":"referrer","internalType":"address"},{"type":"uint256","name":"nonce","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"balanceOf","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"buyShares","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBiddingTime","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"price","internalType":"uint256"}],"name":"getBuyPrice","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getBuyPriceAfterFee","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"protocolFee","internalType":"uint256"},{"type":"uint256","name":"subjectFee","internalType":"uint256"},{"type":"uint256","name":"referrerFee","internalType":"uint256"},{"type":"uint256","name":"poolFee","internalType":"uint256"}],"name":"getFee","inputs":[{"type":"uint256","name":"price","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"getPoolInitialBuy","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPoolInitialBuyPriceAfterFee","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"tuple[]","name":"","internalType":"struct PoolInitialTop[]","components":[{"type":"address"},{"type":"uint256"}]}],"name":"getPoolInitialTops","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"getPoolReferrer","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPoolReferrerFee","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPoolSubjectFee","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPoolValue","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getPrice","inputs":[{"type":"uint256","name":"supply","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"price","internalType":"uint256"}],"name":"getSellPrice","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getSellPriceAfterFee","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initialize","inputs":[]},{"type":"function","stateMutability":"payable","outputs":[],"name":"initializeShares","inputs":[{"type":"address","name":"referrer","internalType":"address"},{"type":"uint256","name":"_initialShares","internalType":"uint256"},{"type":"uint256","name":"_blockTime","internalType":"uint256"},{"type":"uint256","name":"nonce","internalType":"uint256"},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"initializeSharesBySystem","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"address","name":"referrer","internalType":"address"},{"type":"uint256","name":"_initialShares","internalType":"uint256"},{"type":"uint256","name":"_blockTime","internalType":"uint256"}]},{"type":"function","stateMutability":"payable","outputs":[],"name":"initializeSharesSub","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"uint256","name":"_initialShares","internalType":"uint256"},{"type":"uint256","name":"_blockTime","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"maxInitialShares","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"ownerOf","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"poolFeePercent","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"protocolFeeDestination","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"protocolFeePercent","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"referrerFeePercent","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"sellShares","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setMaxInitialShares","inputs":[{"type":"uint256","name":"_maxInitialShares","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setPoolFeePercent","inputs":[{"type":"uint256","name":"_feePercent","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setProtocolFeeDestination","inputs":[{"type":"address","name":"_feeDestination","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setProtocolFeePercent","inputs":[{"type":"uint256","name":"_feePercent","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setReferrerFeePercent","inputs":[{"type":"uint256","name":"_feePercent","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSubjectFeePercent","inputs":[{"type":"uint256","name":"_feePercent","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"subjectFeePercent","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"supplyOf","inputs":[{"type":"address","name":"sharesSubject","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"pure","outputs":[{"type":"string","name":"","internalType":"string"}],"name":"version","inputs":[]},{"type":"event","name":"Initialized","inputs":[{"type":"uint8","name":"version","indexed":false}],"anonymous":false},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","indexed":true},{"type":"address","name":"newOwner","indexed":true}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","indexed":true},{"type":"bytes32","name":"previousAdminRole","indexed":true},{"type":"bytes32","name":"newAdminRole","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","indexed":true},{"type":"address","name":"account","indexed":true},{"type":"address","name":"sender","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","indexed":true},{"type":"address","name":"account","indexed":true},{"type":"address","name":"sender","indexed":true}],"anonymous":false},{"type":"event","name":"Trade","inputs":[{"type":"address","name":"trader","indexed":false},{"type":"address","name":"subject","indexed":false},{"type":"bool","name":"isBuy","indexed":false},{"type":"uint256","name":"shareAmount","indexed":false},{"type":"uint256","name":"ethAmount","indexed":false},{"type":"uint256","name":"protocolFee","indexed":false},{"type":"uint256","name":"subjectFee","indexed":false},{"type":"uint256","name":"referrerFee","indexed":false},{"type":"uint256","name":"poolFee","indexed":false},{"type":"uint256","name":"balance","indexed":false},{"type":"uint256","name":"totalSupply","indexed":false},{"type":"bool","name":"isAirdrop","indexed":false},{"type":"bool","name":"isBid","indexed":false}],"anonymous":false}]
Deployed ByteCode
0x6080604052600436106103355760003560e01c8063645c5730116101ab578063a217fddf116100f7578063d692f1c111610095578063f2fde38b1161006f578063f2fde38b146109ef578063f5b541a614610a0f578063f7888aec14610a31578063fcee45f414610a7b57600080fd5b8063d692f1c114610980578063d6e6eb9f146109a0578063d7d92460146109b657600080fd5b8063b51d0534116100d1578063b51d0534146108ee578063c17dfdfa1461090e578063d2cc46bc14610924578063d547741f1461096057600080fd5b8063a217fddf1461088c578063a4983421146108a1578063a935fe83146108c157600080fd5b80638129fc1c1161016457806395f6fc8a1161013e57806395f6fc8a146108195780639ae717811461082c578063a10786b01461084c578063a1381bed1461086c57600080fd5b80638129fc1c146107c65780638da5cb5b146107db57806391d14854146107f957600080fd5b8063645c573014610716578063715018a61461074f57806373cda3e41461076457806375e9f7ff1461077b5780637c83aebe1461079b578063805d835d146107b157600080fd5b80632f2ff15d116102855780634d8a2bc51161022357806354fd4d50116101fd57806354fd4d50146106695780635a8a764e1461069d5780635cf4ee91146106bd57806362400e4c146106dd57600080fd5b80634d8a2bc514610606578063518c86311461063f57806353d794471461065457600080fd5b80634134a72b1161025f5780634134a72b146105a05780634635256e146105b35780634c85b425146105d35780634ce7957c146105e657600080fd5b80632f2ff15d1461054a57806335d6280c1461056a57806336568abe1461058057600080fd5b806315e58c96116102f257806324d30bd1116102cc57806324d30bd1146104d457806324dc441d146104f457806328003e961461050a5780632c79aa931461052a57600080fd5b806315e58c961461044b5780632267a89c14610484578063248a9ca3146104a457600080fd5b806301ffc9a71461033a578063063b84181461036f578063087c5fb2146103915780630f026f6d146103bb57806313eeea08146103db57806314afd79e146103f7575b600080fd5b34801561034657600080fd5b5061035a610355366004613860565b610abb565b60405190151581526020015b60405180910390f35b34801561037b57600080fd5b5061038f61038a36600461388a565b610af2565b005b34801561039d57600080fd5b506103ad670de0b6b3a764000081565b604051908152602001610366565b3480156103c757600080fd5b506103ad6103d63660046138ba565b610aff565b3480156103e757600080fd5b506103ad6729a2241af62c000081565b34801561040357600080fd5b506104336104123660046138e4565b6001600160a01b03908116600090815260d060205260409020600601541690565b6040516001600160a01b039091168152602001610366565b34801561045757600080fd5b506103ad6104663660046138e4565b6001600160a01b0316600090815260d0602052604090206005015490565b34801561049057600080fd5b506103ad61049f3660046138ba565b610b5e565b3480156104b057600080fd5b506103ad6104bf36600461388a565b60009081526097602052604090206001015490565b3480156104e057600080fd5b5061035a6104ef3660046138e4565b610bb1565b34801561050057600080fd5b506103ad60cb5481565b34801561051657600080fd5b5061038f6105253660046139a2565b610bd5565b34801561053657600080fd5b5061038f61054536600461388a565b610f00565b34801561055657600080fd5b5061038f610565366004613a0a565b610f18565b34801561057657600080fd5b506103ad60ce5481565b34801561058c57600080fd5b5061038f61059b366004613a0a565b610f42565b61038f6105ae366004613a2d565b610fc0565b3480156105bf57600080fd5b506103ad6105ce3660046138ba565b6112f2565b61038f6105e13660046138e4565b611334565b3480156105f257600080fd5b5060c954610433906001600160a01b031681565b34801561061257600080fd5b506103ad6106213660046138e4565b6001600160a01b0316600090815260d0602052604090206002015490565b34801561064b57600080fd5b506103ad600a81565b34801561066057600080fd5b506103ad600481565b34801561067557600080fd5b5060408051808201825260058152640302e332e360dc1b602082015290516103669190613ac8565b3480156106a957600080fd5b5061038f6106b836600461388a565b6113f2565b3480156106c957600080fd5b506103ad6106d8366004613afb565b611407565b3480156106e957600080fd5b506103ad6106f83660046138e4565b6001600160a01b0316600090815260d0602052604090206003015490565b34801561072257600080fd5b506103ad6107313660046138e4565b6001600160a01b0316600090815260d0602052604090206001015490565b34801561075b57600080fd5b5061038f611527565b34801561077057600080fd5b506103ad6247694081565b34801561078757600080fd5b5061038f610796366004613b1d565b61153b565b3480156107a757600080fd5b506103ad60cd5481565b3480156107bd57600080fd5b506103ad606481565b3480156107d257600080fd5b5061038f6117a2565b3480156107e757600080fd5b506033546001600160a01b0316610433565b34801561080557600080fd5b5061035a610814366004613a0a565b61191a565b61038f610827366004613b5f565b611945565b34801561083857600080fd5b506103ad6108473660046138ba565b611a4b565b34801561085857600080fd5b5061038f6108673660046138e4565b611b34565b34801561087857600080fd5b506103ad6108873660046138e4565b611b5e565b34801561089857600080fd5b506103ad600081565b3480156108ad57600080fd5b5061038f6108bc36600461388a565b611bf8565b3480156108cd57600080fd5b506108e16108dc3660046138e4565b611c0d565b6040516103669190613b92565b3480156108fa57600080fd5b5061038f6109093660046138ba565b611c98565b34801561091a57600080fd5b506103ad60cc5481565b34801561093057600080fd5b5061043361093f3660046138e4565b6001600160a01b03908116600090815260d060205260409020600701541690565b34801561096c57600080fd5b5061038f61097b366004613a0a565b612080565b34801561098c57600080fd5b5061038f61099b36600461388a565b6120a5565b3480156109ac57600080fd5b506103ad60ca5481565b3480156109c257600080fd5b506103ad6109d13660046138e4565b6001600160a01b0316600090815260d0602052604090206004015490565b3480156109fb57600080fd5b5061038f610a0a3660046138e4565b6120ba565b348015610a1b57600080fd5b506103ad600080516020613f1f83398151915281565b348015610a3d57600080fd5b506103ad610a4c366004613bea565b6001600160a01b03918216600090815260d0602090815260408083209390941682526008909201909152205490565b348015610a8757600080fd5b50610a9b610a9636600461388a565b612130565b604080519485526020850193909352918301526060820152608001610366565b60006001600160e01b03198216637965db0b60e01b1480610aec57506301ffc9a760e01b6001600160e01b03198316145b92915050565b610afa612272565b60ce55565b600080610b0c84846112f2565b9050600080600080610b1d85612130565b93509350935093508082848688610b349190613c2a565b610b3e9190613c2a565b610b489190613c2a565b610b529190613c2a565b98975050505050505050565b600080610b6b8484611a4b565b9050600080600080610b7c85612130565b93509350935093508082848688610b939190613c42565b610b9d9190613c42565b610ba79190613c42565b610b529190613c42565b6001600160a01b038116600090815260d06020526040812060010154421115610aec565b600260d2541415610be557600080fd5b600260d2556001600160a01b038416600090815260d0602052604090206003810154610c585760405162461bcd60e51b815260206004820152601960248201527f536861726520706f6f6c20646f6573206e6f742065786973740000000000000060448201526064015b60405180910390fd5b6001600160a01b03858116600090815260d060205260409020600601541615610cc35760405162461bcd60e51b815260206004820152601a60248201527f536861726520706f6f6c20616374697661746564206f776e65720000000000006044820152606401610c4f565b6040516bffffffffffffffffffffffff1930606090811b8216602084015287811b8216603484015286811b8216604884015233901b16605c820152607081018490526000906090016040516020818303038152906040528051906020012090506000610d6684610d60847f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b906122cc565b9050610d80600080516020613f1f8339815191528261191a565b610d9c5760405162461bcd60e51b8152600401610c4f90613c59565b600683018054336001600160a01b0319918216179091556007840180549091166001600160a01b038816179055610dd48760006122f0565b610ddf876000612455565b60038301546001600160a01b0388166000908152600885016020526040812080549160019190610e0f8385613c42565b909155505060068501546001600160a01b031660009081526008860160205260408120805460019290610e43908490613c2a565b90915550600080516020613eff83398151915290508980600060018180808080610e6d868c613c42565b8c600080604051610e8a9d9c9b9a99989796959493929190613ca3565b60405180910390a160068501546001600160a01b031660008181526008870160205260408082205490519092600080516020613eff83398151915292610ee7928e9160019182919081908190819081908c908f9083908190613ca3565b60405180910390a15050600160d2555050505050505050565b610f08612272565b60cd819055610f1561254a565b50565b600082815260976020526040902060010154610f33816125d0565b610f3d83836125da565b505050565b6001600160a01b0381163314610fb25760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610c4f565b610fbc8282612660565b5050565b60ce543390851115610fe45760405162461bcd60e51b8152600401610c4f90613d10565b6001600160a01b0386161580159061100e5750856001600160a01b0316816001600160a01b031614155b61104c5760405162461bcd60e51b815260206004820152600f60248201526e24b73b30b634b2102932b332b932b960891b6044820152606401610c4f565b6001600160a01b038116600090815260d06020526040902060030154156110855760405162461bcd60e51b8152600401610c4f90613d47565b6040516bffffffffffffffffffffffff1930606090811b8216602084015283811b8216603484015288901b166048820152605c8101869052607c810185905234609c82015260bc810184905260009060dc01604051602081830303815290604052805190602001209050600061112c84610d60847f19457468657265756d205369676e6564204d6573736167653a0a3332000000006000908152601c91909152603c902090565b9050611146600080516020613f1f8339815191528261191a565b6111625760405162461bcd60e51b8152600401610c4f90613c59565b6001600160a01b03838116600081815260d0602052604090206006810180546001600160a01b03199081169093179055600781018054909216928b169290921790558781556111b18742613c2a565b600180830191909155600382018190556001600160a01b038516600090815260088301602052604080822083905551600080516020613eff83398151915292611210928892839291829181908190819081908690819083908190613ca3565b60405180910390a16000611225600180611407565b90508034146112665760405162461bcd60e51b815260206004820152600d60248201526c496e76616c696420707269636560981b6044820152606401610c4f565b6001600160a01b038a16600090815260088301602052604081206001908190556003840180549192909161129b908490613c2a565b90915550506002808301829055604051600080516020613eff833981519152916112de918d91899160019182918891600091829182918291879182908490613ca3565b60405180910390a150505050505050505050565b6001600160a01b038216600090815260d06020526040812060038101546002909101548291611320916126c7565b905061132c8184611407565b949350505050565b600260d254141561134457600080fd5b600260d2556001600160a01b038116600090815260d060205260409020600301546113b15760405162461bcd60e51b815260206004820152601d60248201527f536861726564207375626a656374206e6f7420696e697469616c697a650000006044820152606401610c4f565b6001600160a01b038116600090815260d0602052604090206001015442116113e1576113dc81612766565b6113ea565b6113ea81612a91565b50600160d255565b6113fa612272565b60cb819055610f1561254a565b600080831561146257600661141d600186613c42565b611428906002613d71565b611433906001613c2a565b8561143f600182613c42565b6114499190613d71565b6114539190613d71565b61145d9190613d90565b611465565b60005b90506000841580156114775750836001145b6114ec57600660016114898688613c2a565b6114939190613c42565b61149e906002613d71565b6114a9906001613c2a565b6114b38688613c2a565b60016114bf888a613c2a565b6114c99190613c42565b6114d39190613d71565b6114dd9190613d71565b6114e79190613d90565b6114ef565b60005b905060006114fd8383613c42565b905060046115136729a2241af62c000083613d71565b61151d9190613d90565b9695505050505050565b61152f612272565b6115396000612c94565b565b600080516020613f1f833981519152611553816125d0565b60ce548311156115755760405162461bcd60e51b8152600401610c4f90613d10565b6001600160a01b0385166115c35760405162461bcd60e51b8152602060048201526015602482015274125b9d985b1a590814da185c994814dd589a9958dd605a1b6044820152606401610c4f565b6001600160a01b038416158015906115ed5750836001600160a01b0316856001600160a01b031614155b61162b5760405162461bcd60e51b815260206004820152600f60248201526e24b73b30b634b2102932b332b932b960891b6044820152606401610c4f565b6001600160a01b038516600090815260d06020526040902060030154156116645760405162461bcd60e51b8152600401610c4f90613d47565b6001600160a01b03858116600081815260d0602052604090206006810180546001600160a01b031990811690931790556007810180549092169287169290921790558381556116b38342613c2a565b600180830191909155600382018190556001600160a01b038716600090815260088301602052604080822083905551600080516020613eff83398151915292611712928a92839291829181908190819081908690819083908190613ca3565b60405180910390a16001600160a01b038516600090815260088201602052604081206001908190556003830180549192909161174f908490613c2a565b909155505060006002808301829055604051600080516020613eff833981519152926117929289928b926001928392829182918291829187919082908490613ca3565b60405180910390a1505050505050565b600054610100900460ff16158080156117c25750600054600160ff909116105b806117dc5750303b1580156117dc575060005460ff166001145b61183f5760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610c4f565b6000805460ff191660011790558015611862576000805461ff0019166101001790555b61186a612ce6565b611872612d15565b61187d600033612d3c565b60335460c980546001600160a01b0319166001600160a01b03909216919091179055666a94d74f43000060ca5566b1a2bc2ec5000060cb55662386f26fc1000060cc81905560cd556118cd61254a565b601e60ce558015610f15576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a150565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b600080516020613f1f83398151915261195d816125d0565b60ce5483111561197f5760405162461bcd60e51b8152600401610c4f90613d10565b6001600160a01b038416600090815260d06020526040902060030154156119b85760405162461bcd60e51b8152600401610c4f90613d47565b6001600160a01b038416600090815260d0602052604090208381556119dd8342613c2a565b600180830191909155600382018190556001600160a01b038616600090815260088301602052604080822083905551600080516020613eff83398151915292611a3c928992839291829181908190819081908690819083908190613ca3565b60405180910390a15050505050565b6001600160a01b038216600090815260d060205260408120600381015460029091015482611a7983836126c7565b90506000611a88600180611407565b90506000611a97600186613c42565b611aa19083613d71565b9050808411611ab257819550611b1c565b868311611ac757611ac4876001613c2a565b92505b611ada611ad48885613c42565b88611407565b955083861115611ae8578395505b8086611af48487613c2a565b611afe9190613c42565b1015611b1c5780611b0f8386613c2a565b611b199190613c42565b95505b81861015611b2957600095505b505050505092915050565b611b3c612272565b60c980546001600160a01b0319166001600160a01b0392909216919091179055565b6001600160a01b038116600090815260d0602090815260408083205460d19092528220541015611b975750670de0b6b3a7640000919050565b6064611ba4600a82613c2a565b6001600160a01b038416600090815260d1602052604081208054909190611bcd57611bcd613db2565b906000526020600020906002020160010154611be99190613d71565b610aec9190613d90565b919050565b611c00612272565b60ca819055610f1561254a565b6001600160a01b038116600090815260d160209081526040808320805482518185028101850190935280835260609492939192909184015b82821015611c8d576000848152602090819020604080518082019091526002850290910180546001600160a01b03168252600190810154828401529083529092019101611c45565b505050509050919050565b600260d2541415611ca857600080fd5b600260d2556001600160a01b038216600090815260d0602052604090208115801590611cd75750818160030154115b611d235760405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f742073656c6c20746865206c6173742073686172650000000000006044820152606401610c4f565b6001600160a01b038316600090815260d060205260409020600101544211611d9b5760405162461bcd60e51b815260206004820152602560248201527f43616e6e6f742073656c6c20736861726520696e20696e697469616c206275796044820152642074696d6560d81b6064820152608401610c4f565b336000908152600882016020526040902054821115611df25760405162461bcd60e51b8152602060048201526013602482015272496e73756666696369656e742073686172657360681b6044820152606401610c4f565b60068101546001600160a01b031633141580611e1e575033600090815260088201602052604090205482105b611e6a5760405162461bcd60e51b815260206004820152601c60248201527f4f776e65722063616e6e6f742073656c6c20616c6c20736861726573000000006044820152606401610c4f565b6000611e768484611a4b565b9050600080600080611e8785612130565b9296509094509250905033600090815260088701602052604081208054899290611eb2908490613c42565b9250508190555086866003016000828254611ecd9190613c42565b909155505060028601548590611ee4908390613c2a565b611eee9190613c42565b6002870155600033838386611f03898b613c42565b611f0d9190613c42565b611f179190613c42565b611f219190613c42565b604051600081818185875af1925050503d8060008114611f5d576040519150601f19603f3d011682016040523d82523d6000602084013e611f62565b606091505b505060c9546040519192506000916001600160a01b039091169087908381818185875af1925050503d8060008114611fb6576040519150601f19603f3d011682016040523d82523d6000602084013e611fbb565b606091505b50509050818015611fc95750805b611fe55760405162461bcd60e51b8152600401610c4f90613dc8565b611fef8a866122f0565b611ff98a85612455565b6000886008016000336001600160a01b03166001600160a01b03168152602001908152602001600020549050600089600301549050600080516020613eff833981519152338d60008e8d8d8d8d8d8b8b6000806040516120659d9c9b9a99989796959493929190613ca3565b60405180910390a15050600160d25550505050505050505050565b60008281526097602052604090206001015461209b816125d0565b610f3d8383612660565b6120ad612272565b60cc819055610f1561254a565b6120c2612272565b6001600160a01b0381166121275760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610c4f565b610f1581612c94565b60008080806103e88161216b6729a2241af62c000061215060048a613d71565b61215c90612710613d71565b6121669190613d90565b612d46565b6121789062476940613d90565b9050818111156121855750805b670de0b6b3a7640000828260ca548a61219e9190613d71565b6121a89190613d71565b6121b29190613d90565b6121bc9190613d90565b9550670de0b6b3a7640000828260cb548a6121d79190613d71565b6121e19190613d71565b6121eb9190613d90565b6121f59190613d90565b9450670de0b6b3a7640000828260cc548a6122109190613d71565b61221a9190613d71565b6122249190613d90565b61222e9190613d90565b9350670de0b6b3a7640000828260cd548a6122499190613d71565b6122539190613d71565b61225d9190613d90565b6122679190613d90565b925050509193509193565b6033546001600160a01b031633146115395760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610c4f565b60008060006122db8585612db5565b915091506122e881612dfb565b509392505050565b6001600160a01b03808316600090815260d06020526040902060060154168015612420576001600160a01b038316600090815260d0602052604081206004015461233b908490613c2a565b90506000811161238d5760405162461bcd60e51b815260206004820152601760248201527f5375626a65637420666565206d6f7265207468616e20300000000000000000006044820152606401610c4f565b6001600160a01b03808516600090815260d0602052604080822060040182905551909184169083905b60006040518083038185875af1925050503d80600081146123f3576040519150601f19603f3d011682016040523d82523d6000602084013e6123f8565b606091505b50509050806124195760405162461bcd60e51b8152600401610c4f90613dc8565b5050505050565b6001600160a01b038316600090815260d060205260408120600401805484929061244b908490613c2a565b9091555050505050565b6001600160a01b03808316600090815260d0602052604090206007015416801561251f576001600160a01b038316600090815260d060205260408120600501546124a0908490613c2a565b9050600081116124f25760405162461bcd60e51b815260206004820152601860248201527f526566657272657220666565206d6f7265207468616e203000000000000000006044820152606401610c4f565b6001600160a01b03808516600090815260d0602052604080822060050182905551909184169083906123b6565b6001600160a01b038316600090815260d060205260408120600501805484929061244b908490613c2a565b60cd5460cc5460cb5460ca546125609190613c2a565b61256a9190613c2a565b6125749190613c2a565b60cf81905567016345785d8a000010156115395760405162461bcd60e51b815260206004820152601c60248201527f546f74616c20466565206d757374206c657373207468616e20313025000000006044820152606401610c4f565b610f158133612f49565b6125e4828261191a565b610fbc5760008281526097602090815260408083206001600160a01b03851684529091529020805460ff1916600117905561261c3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b61266a828261191a565b15610fbc5760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b8160006126d48183611407565b9050808381111561272e575b6001831180156126ef57508381115b1561271357826126fe81613df6565b93505061270c600084611407565b90506126e0565b84831015612729578261272581613e0d565b9350505b61275e565b8381101561275e578261274081613e0d565b935061275790506127518685613c42565b86611407565b905061272e565b505092915050565b600080612774833334612fa2565b6001600160a01b038516600090815260d06020908152604080832033845260088101909252822080549496509294509260019291906127b4908490613c2a565b90915550506001600160a01b03831615612858576000836001600160a01b03168360405160006040518083038185875af1925050503d8060008114612815576040519150601f19603f3d011682016040523d82523d6000602084013e61281a565b606091505b50506001600160a01b03851660009081526008840160205260408120805492935060019290919061284c908490613c42565b90915550612870915050565b60038101805490600061286a83613e0d565b91905055505b600060cf54670de0b6b3a76400006128889190613c2a565b6128928434613c42565b6128a490670de0b6b3a7640000613d71565b6128ae9190613d90565b90506000806000806128bf85612130565b935093509350935081838589348a600201546128db9190613c2a565b6128e59190613c42565b6128ef9190613c42565b6128f99190613c42565b6129039190613c42565b600287015560c9546040516000916001600160a01b03169086908381818185875af1925050503d8060008114612955576040519150601f19603f3d011682016040523d82523d6000602084013e61295a565b606091505b505090508061297b5760405162461bcd60e51b8152600401610c4f90613dc8565b6129858a856122f0565b61298f8a84612455565b6001600160a01b038916600081815260088901602052604090205460038901549091156129fa57600080516020613eff8339815191528b8d600060018e6000806000808b8b600060016040516129f19d9c9b9a99989796959493929190613ca3565b60405180910390a15b33600081815260088b01602052604090205460cf54909350600080516020613eff83398151915291908e906001908190612a3c90670de0b6b3a7640000613c2a565b612a4e34670de0b6b3a7640000613d71565b612a589190613d90565b8c8c8c8c8b8b60006001604051612a7b9d9c9b9a99989796959493929190613ca3565b60405180910390a1505050505050505050505050565b6001600160a01b038116600090815260d06020526040812090612ab58360016112f2565b9050600080600080612ac685612130565b93509350935093508082848688612add9190613c2a565b612ae79190613c2a565b612af19190613c2a565b612afb9190613c2a565b341015612b415760405162461bcd60e51b8152602060048201526014602482015273125b9cdd59999a58da595b9d081c185e5b595b9d60621b6044820152606401610c4f565b3360009081526008870160205260408120805460019290612b63908490613c2a565b925050819055506001866003016000828254612b7f9190613c2a565b92505081905550818385348960020154612b999190613c2a565b612ba39190613c42565b612bad9190613c42565b612bb79190613c42565b600287015560c9546040516000916001600160a01b03169086908381818185875af1925050503d8060008114612c09576040519150601f19603f3d011682016040523d82523d6000602084013e612c0e565b606091505b5050905080612c2f5760405162461bcd60e51b8152600401610c4f90613dc8565b612c3988856122f0565b612c438884612455565b3360008181526008890160205260408082205460038b0154915190939192600080516020613eff833981519152926112de9290918e9160019182918f918f918f918f918f918e918e91908190613ca3565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b600054610100900460ff16612d0d5760405162461bcd60e51b8152600401610c4f90613e28565b611539613436565b600054610100900460ff166115395760405162461bcd60e51b8152600401610c4f90613e28565b610fbc82826125da565b60006003821115612da75750806000612d60600283613d90565b612d6b906001613c2a565b90505b81811015612da157905080600281612d868186613d90565b612d909190613c2a565b612d9a9190613d90565b9050612d6e565b50919050565b8115611bf357506001919050565b600080825160411415612dec5760208301516040840151606085015160001a612de087828585613466565b94509450505050612df4565b506000905060025b9250929050565b6000816004811115612e0f57612e0f613e73565b1415612e185750565b6001816004811115612e2c57612e2c613e73565b1415612e7a5760405162461bcd60e51b815260206004820152601860248201527f45434453413a20696e76616c6964207369676e617475726500000000000000006044820152606401610c4f565b6002816004811115612e8e57612e8e613e73565b1415612edc5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e677468006044820152606401610c4f565b6003816004811115612ef057612ef0613e73565b1415610f155760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604482015261756560f01b6064820152608401610c4f565b612f53828261191a565b610fbc57612f608161352a565b612f6b83602061353c565b604051602001612f7c929190613e89565b60408051601f198184030181529082905262461bcd60e51b8252610c4f91600401613ac8565b600080600080612fb287866136df565b9150915081612ff45760405162461bcd60e51b815260206004820152600e60248201526d125b9d985b1a5908185b5bdd5b9d60921b6044820152606401610c4f565b6001600160a01b038716600090815260d0602090815260408083205460d19092529091205410156131d857604080518082018252600080825260208083018281526001600160a01b038c811680855260d18452958420805460018082018355828752948620875160029092020180546001600160a01b0319169190931617825591519083015593825292549192909161308d9190613c42565b90505b828111156131d1576001600160a01b038916600090815260d1602052604090206130bb600183613c42565b815481106130cb576130cb613db2565b600091825260208083206002909202909101546001600160a01b038c8116845260d1909252604090922080549190921691908390811061310d5761310d613db2565b6000918252602080832060029290920290910180546001600160a01b0319166001600160a01b03948516179055918b16815260d190915260409020613153600183613c42565b8154811061316357613163613db2565b90600052602060002090600202016001015460d160008b6001600160a01b03166001600160a01b0316815260200190815260200160002082815481106131ab576131ab613db2565b6000918252602090912060016002909202010155806131c981613df6565b915050613090565b505061339a565b6001600160a01b038716600090815260d160205260408120805490919061320157613201613db2565b600091825260208083206002909202909101546001600160a01b038a8116845260d1909252604083208054929091169650919061324057613240613db2565b906000526020600020906002020160010154925060005b81811015613398576001600160a01b038816600090815260d160205260409020613282826001613c2a565b8154811061329257613292613db2565b600091825260208083206002909202909101546001600160a01b038b8116845260d190925260409092208054919092169190839081106132d4576132d4613db2565b6000918252602080832060029290920290910180546001600160a01b0319166001600160a01b03948516179055918a16815260d19091526040902061331a826001613c2a565b8154811061332a5761332a613db2565b90600052602060002090600202016001015460d160008a6001600160a01b03166001600160a01b03168152602001908152602001600020828154811061337257613372613db2565b60009182526020909120600160029092020101558061339081613e0d565b915050613257565b505b6001600160a01b038716600090815260d1602052604090208054879190839081106133c7576133c7613db2565b6000918252602080832060029290920290910180546001600160a01b0319166001600160a01b03948516179055918916815260d19091526040902080548691908390811061341757613417613db2565b9060005260206000209060020201600101819055505050935093915050565b600054610100900460ff1661345d5760405162461bcd60e51b8152600401610c4f90613e28565b61153933612c94565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561349d5750600090506003613521565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa1580156134f1573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b03811661351a57600060019250925050613521565b9150600090505b94509492505050565b6060610aec6001600160a01b03831660145b6060600061354b836002613d71565b613556906002613c2a565b67ffffffffffffffff81111561356e5761356e6138ff565b6040519080825280601f01601f191660200182016040528015613598576020820181803683370190505b509050600360fc1b816000815181106135b3576135b3613db2565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106135e2576135e2613db2565b60200101906001600160f81b031916908160001a9053506000613606846002613d71565b613611906001613c2a565b90505b6001811115613689576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061364557613645613db2565b1a60f81b82828151811061365b5761365b613db2565b60200101906001600160f81b031916908160001a90535060049490941c9361368281613df6565b9050613614565b5083156136d85760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610c4f565b9392505050565b6000806136eb84611b5e565b6001600160a01b038516600090815260d16020526040902054908410159250158015906137155750815b15612df4576001600160a01b038416600090815260d0602090815260408083205460d190925282205410156137ce57506001600160a01b038416600090815260d160205260409020545b6000811180156137b257506001600160a01b038516600090815260d16020526040902061378d600183613c42565b8154811061379d5761379d613db2565b90600052602060002090600202016001015484105b156137c957806137c181613df6565b91505061375f565b613857565b6001600160a01b038516600090815260d160205260409020546137f390600190613c42565b90505b60008111801561384057506001600160a01b038516600090815260d16020526040902080548290811061382b5761382b613db2565b90600052602060002090600202016001015484105b15613857578061384f81613df6565b9150506137f6565b90509250929050565b60006020828403121561387257600080fd5b81356001600160e01b0319811681146136d857600080fd5b60006020828403121561389c57600080fd5b5035919050565b80356001600160a01b0381168114611bf357600080fd5b600080604083850312156138cd57600080fd5b6138d6836138a3565b946020939093013593505050565b6000602082840312156138f657600080fd5b6136d8826138a3565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261392657600080fd5b813567ffffffffffffffff80821115613941576139416138ff565b604051601f8301601f19908116603f01168101908282118183101715613969576139696138ff565b8160405283815286602085880101111561398257600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600080608085870312156139b857600080fd5b6139c1856138a3565b93506139cf602086016138a3565b925060408501359150606085013567ffffffffffffffff8111156139f257600080fd5b6139fe87828801613915565b91505092959194509250565b60008060408385031215613a1d57600080fd5b82359150613857602084016138a3565b600080600080600060a08688031215613a4557600080fd5b613a4e866138a3565b9450602086013593506040860135925060608601359150608086013567ffffffffffffffff811115613a7f57600080fd5b613a8b88828901613915565b9150509295509295909350565b60005b83811015613ab3578181015183820152602001613a9b565b83811115613ac2576000848401525b50505050565b6020815260008251806020840152613ae7816040850160208701613a98565b601f01601f19169190910160400192915050565b60008060408385031215613b0e57600080fd5b50508035926020909101359150565b60008060008060808587031215613b3357600080fd5b613b3c856138a3565b9350613b4a602086016138a3565b93969395505050506040820135916060013590565b600080600060608486031215613b7457600080fd5b613b7d846138a3565b95602085013595506040909401359392505050565b602080825282518282018190526000919060409081850190868401855b82811015613bdd57815180516001600160a01b03168552860151868501529284019290850190600101613baf565b5091979650505050505050565b60008060408385031215613bfd57600080fd5b613c06836138a3565b9150613857602084016138a3565b634e487b7160e01b600052601160045260246000fd5b60008219821115613c3d57613c3d613c14565b500190565b600082821015613c5457613c54613c14565b500390565b6020808252602a908201527f43616c6c657220646f65736e27742068617665207065726d697373696f6e206f604082015269331037b832b930ba37b960b11b606082015260800190565b6001600160a01b039d8e1681529b909c1660208c015298151560408b015260608a0197909752608089019590955260a088019390935260c087019190915260e086015261010085015261012084015261014083015215156101608201529015156101808201526101a00190565b60208082526017908201527f496e697469616c20736861726573206578636565646564000000000000000000604082015260600190565b60208082526010908201526f14da185c99481c1bdbdb08195e1a5cdd60821b604082015260600190565b6000816000190483118215151615613d8b57613d8b613c14565b500290565b600082613dad57634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b602080825260149082015273556e61626c6520746f2073656e642066756e647360601b604082015260600190565b600081613e0557613e05613c14565b506000190190565b6000600019821415613e2157613e21613c14565b5060010190565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b634e487b7160e01b600052602160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351613ec1816017850160208801613a98565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351613ef2816028840160208801613a98565b0160280194935050505056fe0bd0eb03ae3622020e1cc9e94570c94b9e276bc263af8ac1c42747b11074f5fc97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929a264697066735822122082a913542c7159820fddec4458562fa50101a0102d7199f40cb8883caec5928864736f6c63430008090033